示例#1
0
<?php

include '../libs/helper.php';
include '../libs/accesscontrol.php';
include '../libs/configer.php';
include '../libs/sql.php';
$headers = apache_request_headers();
$json = file_get_contents('php://input');
if (!isset($headers['X-Console-Key']) && isset($headers['Authorization'])) {
    //    $secret = $headers['X-Console-Key'];
    $oauth = $headers['Authorization'];
    ///    $profile_id = get_profile_id_from_secret($secret, $oauth);
    $profile_id = get_profile_id_from_oauth($oauth);
    if ($profile_id) {
        $sql = "SELECT * FROM " . $dbname . ".course";
        $result = $conn->query($sql);
        $all_courses = array();
        while ($row = $result->fetch_assoc()) {
            $myarray = array();
            $myarray['course_id'] = $row['course_id'];
            $decoded_json = json_decode($row['json_dump']);
            $myarray['details'] = $decoded_json->{'description'};
            $myarray['is_admin'] = false;
            if (check_enroll($row['course_id'], $profile_id)) {
                $myarray['is_enroll'] = true;
            } else {
                $myarray['is_enroll'] = false;
            }
            $all_courses[] = $myarray;
        }
        $result_array = array('status' => 'Success', 'message' => 'Courses found', 'all_courses' => $all_courses);
示例#2
0
<?php

include '../libs/helper.php';
include '../libs/accesscontrol.php';
include '../libs/configer.php';
include '../libs/sql.php';
$headers = apache_request_headers();
$json = file_get_contents('php://input');
$obj = json_decode($json);
if (isset($_GET['course_id']) && isset($headers['Authorization']) && !empty($headers['Authorization'])) {
    $oauth_key = $headers['Authorization'];
    $profile_id = get_profile_id_from_oauth($oauth_key);
    if ($profile_id) {
        $id = $_GET['course_id'];
        $sql = "SELECT json_dump FROM " . $dbname . ".course where course_id={$id}";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
            $row = $result->fetch_assoc();
            $json = $row['json_dump'];
            print_r($json);
        }
    } else {
        header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['status_notfound']);
        $result_array = array('status' => 'Error', 'message' => 'Course details not found');
        print_r(json_encode($result_array));
    }
} else {
    header($_SERVER["SERVER_PROTOCOL"] . " " . $GLOBALS['bad_request']);
    $result_array = array('status' => 'Error', 'message' => 'Method not allowed');
    print_r(json_encode($result_array));
}
示例#3
0
function wsOnMessage($clientID, $message, $messageLength, $binary)
{
    global $Server;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    if ($message == "quit") {
        //Send the message to everyone but the person who said it
        foreach ($Server->wsClients as $id => $client) {
            if ($id != $clientID) {
                if ($Server->{"userData"}["{$id}"] == $Server->{"userData"}["{$clientID}"]) {
                    $Server->wsSend($id, json_decode($Server->{"deviceData"}["{$clientID}"])->{"device-details"});
                }
            }
        }
        $Server->wsRemoveClient($clientID);
    } else {
        if ($message == "show") {
            //        $Server->wsSend($clientID, ">oauth::" . $Server->{"data"}["$clientID"]." profile id::".$Server->{"userData"}["$clientID"]).
            //            " device::".$Server->{"deviceData"}["$clientID"];
            $logout = array("oauth" => json_decode($Server->{"deviceData"}["{$clientID}"])->{"device-details"});
            $Server->wsSend($clientID, json_encode($logout));
        } else {
            if ($message == "test") {
                $Server->log("message froma  server");
            } else {
                if ($message == "BROADCAST_LOGIN") {
                    $Server->log($message);
                    foreach ($Server->wsClients as $id => $client) {
                        if ($id != $clientID) {
                            if ($Server->{"userData"}["{$id}"] == $Server->{"userData"}["{$clientID}"]) {
                                $myres = array("LOGIN" => json_decode($Server->{"deviceData"}["{$clientID}"])->{"device-details"});
                                $Server->wsSend($id, json_encode($myres));
                            }
                        }
                    }
                } else {
                    if ($message == "BROADCAST_LOGOUT") {
                        $Server->log($message);
                        foreach ($Server->wsClients as $id => $client) {
                            if ($id != $clientID) {
                                if ($Server->{"userData"}["{$id}"] == $Server->{"userData"}["{$clientID}"]) {
                                    $myres = array("LOGOUT" => json_decode($Server->{"deviceData"}["{$clientID}"])->{"device-details"});
                                    $Server->wsSend($id, json_encode($myres));
                                }
                            }
                        }
                    } else {
                        if ($message == "BROADCAST_LOGOUT_ALL") {
                            $Server->log($message);
                            foreach ($Server->wsClients as $id => $client) {
                                if ($Server->{"userData"}["{$id}"] == $Server->{"userData"}["{$clientID}"]) {
                                    $myres = array("LOGOUT_ALL" => "logout from your device please!");
                                    $Server->wsSend($id, json_encode($myres));
                                }
                            }
                        } else {
                            $Server->{"data"}["{$clientID}"] = $message;
                            $myres = array("oauth" => $Server->{"data"}["{$clientID}"]);
                            $Server->wsSend($clientID, json_encode($myres));
                            $Server->{"flags"}["{$clientID}"] = "false";
                            /*
                             * fetch the user data and store
                             */
                            $Server->{"userData"}["{$clientID}"] = get_profile_id_from_oauth($Server->{"data"}["{$clientID}"]);
                            $Server->{"deviceData"}["{$clientID}"] = get_device_data($Server->{"userData"}["{$clientID}"], $Server->{"data"}["{$clientID}"]);
                        }
                    }
                }
            }
        }
    }
    //    else
    //    {
    //        $Server->log("some ass sent this".$message);
    //      $Server->wsSend($clientID, "get lost:");
    //    }
}
示例#4
0
function my_file_upload($oauth_key, $course_id, $type)
{
    if ($_FILES['file']['name'] != "" && isset($oauth_key)) {
        $profile_id = get_profile_id_from_oauth($oauth_key);
        $filename = $_FILES['file']['tmp_name'];
        //        echo $filename;exit;
        if ($type == "video") {
            $destination = "C:/xampp/htdocs/vsm/files/cloud/video/" . $_FILES['file']['name'];
        }
        if ($type == "image") {
            $destination = "C:/xampp/htdocs/vsm/files/cloud/image/" . $_FILES['file']['name'];
        }
        if (move_uploaded_file($filename, $destination) or print_r("Could not copy file!")) {
            /*
             * entry into database
             * 
             */
            my_file_meta($course_id, $destination, $type);
            $result_array = array('status' => 'sucess', 'file_path' => $destination);
            print_r(json_encode($result_array));
        } else {
            $result_array = array('status' => 'failure', 'file_path' => "failed to upload");
            print_r(json_encode($result_array));
        }
    } else {
        print_r("No file specified!");
    }
}
示例#5
0
<?php

include '../libs/configer.php';
include '../libs/helper.php';
include '../libs/accesscontrol.php';
include '../sockets/socketConnector.php';
require '../sockets/class.PHPWebSocket.php';
$headers = apache_request_headers();
//print_r($headers);
$json = file_get_contents('php://input');
$obj = json_decode($json);
if (isset($headers['Authorization']) && isset($obj->{'logout_all_devices'})) {
    logout_from_all_devices(get_profile_id_from_oauth($headers['Authorization']), $headers['Authorization']);
} else {
    if (isset($headers['Authorization']) && isset($obj->{'fingerprint'})) {
        $profile_id = get_profile_id_from_oauth($headers['Authorization']);
        // print_r($obj->{'fingerprint'});
        logout_specific_device($profile_id, $obj->{'fingerprint'});
    } else {
        if (isset($headers['Authorization'])) {
            logout($headers['Authorization']);
        }
    }
}