Example #1
0
 public function lsow_admin_ajax()
 {
     // check the nonce
     $this->lsow_check_nonce();
     // retrieve data
     $this->ajax_data = isset($_POST) ? $_POST : $_GET;
     // retrieve function
     $func = $this->ajax_data['func'];
     switch ($func) {
         case 'lsow_save_settings':
             $response = $this->save_settings_callback();
             break;
         case 'lsow_reset_settings':
             $response = $this->save_settings_callback();
             break;
         default:
             $response = ajax_response(false, __('Sorry, an unknown error occurred...', 'livemesh-so-widgets'), null);
             break;
     }
     // send json response and die
     wp_send_json($response);
 }
Example #2
0
 function invalidate_sessions($params)
 {
     global $dbc;
     // Force any sessions off that have been around for 2 hours
     // or haven't pinged for 4 mins (gives them a couple chances to
     // ping late)
     $q = 'SELECT id, url, port FROM servers WHERE occupied=1 AND ' . '(DATE_ADD(acquire_time, INTERVAL 2 HOUR) < NOW() OR ' . 'DATE_ADD(last_used, INTERVAL 4 MINUTE) < NOW())';
     $r = mysqli_query($dbc, $q);
     $rows = array();
     $ids = array();
     while ($row = mysqli_fetch_assoc($r)) {
         $rows[] = $row;
         $ids[] = (int) $row['id'];
     }
     $q = 'UPDATE servers SET occupied=0 WHERE id IN (' . implode(',', $ids) . ')';
     $r = mysqli_query($dbc, $q);
     // TODO: tell server to reset its data for users.
     // TODO:
     // Shut down the instance if no servers have been accessed in 4 hours.
     $q = 'SELECT id FROM servers WHERE DATE_ADD(last_used, INTERVAL 4 HOUR) < NOW()';
     // Ping servers and remove from the list if they're not up.
     $servers = $this->get_servers_list();
     $ids = array();
     foreach ($servers as $server) {
         $ch = curl_init($server['url'] . ':' . $server['port'] . '/crossdomain.xml');
         curl_setopt($ch, CURLOPT_NOBODY, true);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         curl_exec($ch);
         $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         curl_close($ch);
         if ($code != 200) {
             $ids[] = $server['id'];
         }
     }
     if (count($ids) > 0) {
         $q = '';
         if (count($ids) == count($servers)) {
             $q = 'TRUNCATE servers';
         } else {
             $q = 'DELETE FROM servers WHERE id IN (' . implode(',', $ids) . ')';
         }
         $r = mysqli_query($dbc, $q);
     }
     // clean up old sessions
     clean_session(60 * 60 * 3);
     return ajax_response('Okay');
 }
Example #3
0
$a = $_GET['a'];
switch ($a) {
    case 1:
        uploadDir($oss, $bucket);
        break;
    case 2:
        fenduan($oss, $object, $bucket, $upload_file);
        break;
    case 3:
        get_obj_list($oss, $bucket, $options);
        break;
    case 4:
        create_obj($oss, $bucket);
        break;
    case 5:
        ajax_upload($oss, $bucket);
        break;
    case 6:
        ajax_response();
        break;
}
function ajax_upload($oss, $bucket)
{
    $object = $_FILES['file']['name'];
    $upload_file = $_FILES['file']['tmp_name'];
    echo fenduan($oss, $object, $bucket, $upload_file);
}
function ajax_response()
{
    print_r($_SESSION);
}
Example #4
0
/**
 * Called via ajax. Handler for the submit in the session settings form
 */
function action_save_module_settings()
{
    if (isset($_POST['user_standard_module_hours'])) {
        // Set or reset standard module hours for the user?
        if (!ctype_digit($_POST['user_standard_module_hours']) || $_POST['user_standard_module_hours'] == 0) {
            save_standard_module_hours(LOADED_COURSE_ID, null);
        } else {
            save_standard_module_hours(LOADED_COURSE_ID, $_POST['user_standard_module_hours']);
        }
    }
    // Iterate supplied modules. Only those changed client side is submitted
    foreach ($_POST as $key => $value) {
        if (preg_match('/^module-(\\d+)$/', $key, $m)) {
            $module_id = $m[1];
            // Check that we got a valid module id
            if (!get_module_by_id($module_id)) {
                ajax_response(true, 'Invalid module id');
            }
            // Reset to standard
            if (!ctype_digit($value) || $value == null) {
                save_module_hours($module_id, null);
            } else {
                save_module_hours($module_id, $value);
            }
        }
    }
    ajax_response();
}