コード例 #1
0
ファイル: edit.json.php プロジェクト: go38/moodle-mod_vpl
            break;
        case 'debug':
            if (!$instance->debug and !$vpl->has_capability(VPL_GRADE_CAPABILITY)) {
                throw new Exception(get_string('notavailable'));
            }
            $outcome->response = mod_vpl_edit::execute($vpl, $userid, $action);
            break;
        case 'evaluate':
            if (!$instance->evaluate and !$vpl->has_capability(VPL_GRADE_CAPABILITY)) {
                throw new Exception(get_string('notavailable'));
            }
            $outcome->response = mod_vpl_edit::execute($vpl, $userid, $action);
            break;
        case 'retrieve':
            $outcome->response = mod_vpl_edit::retrieve_result($vpl, $userid);
            break;
        case 'cancel':
            $outcome->response = mod_vpl_edit::cancel($vpl, $userid);
            break;
        case 'getjails':
            $outcome->response->servers = vpl_jailserver_manager::get_https_server_list($vpl->get_instance()->jailservers);
            break;
        default:
            throw new Exception('ajax action error');
    }
} catch (Exception $e) {
    $outcome->success = false;
    $outcome->error = $e->getMessage();
}
echo json_encode($outcome);
die;
コード例 #2
0
 function jailRequestAction($data, $maxmemory, $localservers, &$server)
 {
     $error = '';
     $server = vpl_jailserver_manager::get_server($maxmemory, $localservers, $error);
     if ($server == '') {
         $manager = $this->vpl->has_capability(VPL_MANAGE_CAPABILITY);
         $men = get_string('nojailavailable', VPL);
         if ($manager) {
             $men .= ": " . $error;
         }
         throw new Exception($men);
     }
     return $this->jailAction($server, 'request', $data);
 }
コード例 #3
0
 /**
  * Return the https URL servers list
  * @param string $localserverlisttext='' List of local server in text
  * @return array of URLs
  */
 static function get_https_server_list($localserverlisttext = '')
 {
     global $CFG;
     global $DB;
     if (!function_exists('xmlrpc_encode_request')) {
         throw new Exception('PHP XMLRPC required');
     }
     $data = new stdClass();
     $data->maxmemory = (int) 1024 * 10;
     $requestReady = xmlrpc_encode_request('available', $data, array('encoding' => 'UTF-8'));
     $serverlist = array_unique(vpl_jailserver_manager::get_server_list($localserverlisttext));
     $list = array();
     foreach ($serverlist as $server) {
         if (vpl_jailserver_manager::is_checkable($server)) {
             $response = self::get_response($server, $requestReady, $error);
             if ($response === false) {
                 vpl_jailserver_manager::server_fail($server, $error);
             } elseif (!isset($response['status'])) {
                 vpl_jailserver_manager::server_fail($server, $error);
             } else {
                 if ($response['status'] == 'ready') {
                     $parsed = parse_url($server);
                     $list[] = 'https://' . $parsed['host'] . ':' . $response['secureport'] . '/OK';
                 }
             }
         }
     }
     return $list;
 }
コード例 #4
0
require_once dirname(__FILE__) . '/../../../config.php';
require_once dirname(__FILE__) . '/../vpl.class.php';
require_once dirname(__FILE__) . '/../jail/jailserver_manager.class.php';
require_login();
$id = required_param('id', PARAM_INT);
$vpl = new mod_vpl($id);
$vpl->prepare_page('views/checkjailservers.php', array('id' => $id));
$vpl->require_capability(VPL_MANAGE_CAPABILITY);
//Display page
$PAGE->requires->css(new moodle_url('/mod/vpl/css/checkjailservers.css'));
$course = $vpl->get_course();
$vpl->print_header(get_string('check_jail_servers', VPL));
$vpl->print_heading_with_help('check_jail_servers');
$vpl->print_configure_tabs(basename(__FILE__));
\mod_vpl\event\vpl_jail_servers_tested::log($vpl);
$servers = vpl_jailserver_manager::check_servers($vpl->get_instance()->jailservers);
$table = new html_table();
$table->head = array('#', get_string('server', VPL), get_string('currentstatus', VPL), get_string('lasterror', VPL), get_string('lasterrordate', VPL), get_string('totalnumberoferrors', VPL));
$table->align = array('right', 'left', 'left', 'left', 'left', 'right');
$table->data = array();
$num = 0;
$clean_url = !$vpl->has_capability(VPL_SETJAILS_CAPABILITY) || !$vpl->has_capability(VPL_MANAGE_CAPABILITY);
foreach ($servers as $server) {
    $serverurl = $server->server;
    if ($clean_url) {
        $serverurl = parse_url($serverurl, PHP_URL_HOST);
    }
    $num++;
    if ($server->offline) {
        $status = '<div class="vpl_server_failed">' . $server->current_status . '</div>';
    } else {