Пример #1
0
function checkFileExtension($inFile)
{
    // check for upload
    $allowedExtensions = array("txt", "csv", "htm", "html", "xml", "css", "doc", "xls", "rtf", "ppt", "pdf", "swf", "flv", "avi", "wmv", "mov", "jpg", "jpeg", "gif", "png");
    if (!in_array(end(explode(".", strtolower($inFile))), $allowedExtensions)) {
        die(jsonResponse(false));
    }
}
Пример #2
0
function getLastChat()
{
    global $database_b3connect, $b3connect;
    $lastPostId = getPostOrGet('lastId');
    if (is_null($lastPostId)) {
        exit;
    }
    mysql_select_db($database_b3connect, $b3connect);
    $query = sprintf("SELECT * FROM chatlog WHERE id > %s ORDER BY id DESC LIMIT 10", $lastPostId);
    $rs = mysql_query($query, $b3connect) or die(mysql_error());
    $totalRows = mysql_num_rows($rs);
    header('Content-type: text/json');
    $Amsg = array();
    while ($row = mysql_fetch_assoc($rs)) {
        array_push($Amsg, $row);
    }
    jsonResponse($Amsg);
}
Пример #3
0
$app->delete('/deleteSomething', function () use($app) {
    $response = array();
    $input = $app->request->put('input');
    // reading post params
    // add your business logic here
    $result = true;
    if ($result) {
        //deleted successfully
        $response["error"] = false;
        $response["message"] = "Deleted succesfully";
    } else {
        //failed to delete
        $response["error"] = true;
        $response["message"] = "Failed to delete. Please try again!";
    }
    jsonResponse(200, $response);
});
function jsonResponse($status_code, $response)
{
    $app = \Slim\Slim::getInstance();
    $app->status($status_code);
    $app->contentType('application/json');
    echo json_encode($response);
}
function getConnection()
{
    $db_username = "******";
    $db_password = "";
    $conn = new PDO('mysql:host=localhost;dbname=test', $db_username, $db_password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $conn;
Пример #4
0
            $log = getRoot() . "/web/api/monitor.log";
            $command = getRoot() . "/script/monitor.sh > " . $log;
            //print($command);
            system("echo '' > " . $log);
            system($command . " &");
        }
        exit(0);
    }
    if ($_GET["action"] == "stop") {
        monitor_stop();
        exit(0);
    }
}
if ($_GET["operation"] == "status") {
    if ($_GET["action"] == "all") {
        $motionConfig = json_decode(getMotionConfig(), true);
        $targetFree = round(disk_free_space($motionConfig["target_dir"]) / 1024 / 1024 / 1024, 2) . "gb";
        ob_start();
        system('/opt/vc/bin/vcgencmd measure_temp');
        $temp = split("=", ob_get_clean())[1];
        $motionRunning = isMonitorRunning();
        ob_start();
        system("tail -n 10 monitor.log");
        $log = nl2br(ob_get_clean());
        $data = ["targetFree" => $targetFree, "motionRunning" => $motionRunning, "log" => $log, "temp" => $temp];
        jsonResponse($data);
    }
}
header('HTTP/1.1 500 Internal Server Error');
print "Did not understand input parameters.<br/>";
print $_SERVER['QUERY_STRING'];
Пример #5
0
function gateway()
{
    $task = isset($_POST['task']) ? $_POST['task'] : '';
    switch ($_POST['task']) {
        case 'updateUser':
            $cph = new CPH5starHost();
            if (!isset($_POST['picture_base64'])) {
                $_POST['picture_base64'] = "";
            }
            if (!isset($_POST['picture_orientation'])) {
                $_POST['picture_orientation'] = "";
            }
            $objective = $cph->updateUser($_POST);
            if ($objective !== false) {
                jsonResponse(1, 'updated', $objective);
            } else {
                jsonResponse(0, 'user could not be updated');
            }
            break;
        default:
            $status = 0;
            $message = "missing task";
            break;
    }
}
// Read parameters
$xparam = explode(',', urldecode($_GET['x']));
$yparam = explode(',', urldecode($_GET['y']));
// Parse parameters to floats (very basic input cleansing)
foreach ($xparam as $x) {
    $xs[] = floatval($x);
}
foreach ($yparam as $y) {
    $ys[] = floatval($y);
}
// Basic input validation
if (sizeof($xs) != sizeof($ys)) {
    jsonResponse(array('error' => 'Spectral Acceleration and Annual Frequency of Exceedance ' + 'values must be the same size.', 'status' => 400), $callback);
    exit;
}
// TODO :: (Future) Add Period or Beta values to this? For now we assume
//         input data is already max-direction and use default 0.6 beta value.
$rtgm = new RTGM($xs, $ys);
$rtgm->calculate();
// JSON output
jsonResponse(array('status' => 200, 'rtgm' => $rtgm->getStructure()), $callback);
// CSV-style output better for pasting into spreadsheets
// $s = $rtgm->getStructure();
// print 'sa,' . implode(',', $s['upsampledHazardCurve']->xs) . "\n";
// print 'afe,' . implode(',', $s['upsampledHazardCurve']->ys) . "\n";
// foreach ($s['iterations'] as $i) {
// 	print 'pdf,' . implode(',', $i['pdf']) . "\n";
// 	print 'cdf,' . implode(',', $i['cdf']) . "\n";
// 	print 'integrand,' . implode(',', $i['integrand']) . "\n";
// 	print 'integral,' . implode(',', $i['integral']) . "\n";
// }
Пример #7
0
            flush();
        }
        fclose($hd);
        break;
    case 'upload':
        if (!strlen($_SERVER['HTTP_X_FILE_NAME'])) {
            // classic upload
            foreach ($_FILES as $file) {
                $destfile = $file['name'];
                checkVar($destfile);
                $target = buildPath($BASE_PATH, $destfile);
                checkFileExtension($target);
                if (move_uploaded_file($file['tmp_name'], $target)) {
                    $success = true;
                }
            }
        } else {
            // HTML5 single file upload
            $destfile = $_SERVER['HTTP_X_FILE_NAME'];
            checkVar($destfile);
            $target = buildPath($BASE_PATH, $destfile);
            checkFileExtension($target);
            if (!@file_put_contents($target, file_get_contents("php://input"))) {
                print jsonResponse(false, 'cannot create file');
                break;
            }
            $success = true;
        }
        print jsonResponse($success);
        break;
}
Пример #8
0
            if (!isset($_GET['otherid']) || !is_numeric($_GET['otherid'])) {
                throw new FFException(FFErrCode::NO_OTHER_ID);
            }
            $start = 0;
            $limit = 10;
            if (isset($_GET['start']) ^ isset($_GET['limit'])) {
                throw new FFException(FFErrCode::WRONG_REQUEST);
            }
            if (isset($_GET['start']) && isset($_GET['limit'])) {
                $start = $_GET['start'];
                $limit = $_GET['limit'];
                if (!is_numeric($start) || !is_numeric($limit)) {
                    throw new FFException(FFErrCode::WRONG_REQUEST);
                }
            }
            $response = $ff->fetchMessages($_GET['otherid'], $start, $limit);
            break;
        case 'getid':
            if (!isset($_GET['username'])) {
                throw new FFException(FFErrCode::WRONG_REQUEST);
            }
            $response = $ff->getIdFromUsername($_GET['username']);
            break;
        default:
            throw new FFException(FFErrCode::INVALID_ACTION);
    }
} catch (FFException $e) {
    $response = bakeError($e);
}
jsonResponse($response);
Пример #9
0
    $job = new Job($jobid);
    if ($job === false) {
        textResponse(204);
    }
    $machine = new Machine(Session::getMachineId());
    if (!$machine->hasJob($job->getJobId())) {
        textResponse(403, 'Job not assigned to you');
    }
    $job->unset('machine');
    $job->set('buildstatus', $_POST['buildstatus']);
    $job->set('buildreason', $_POST['buildreason']);
    $job->moveToQueue('archivequeue');
    jsonResponse(200, $job->getJobData());
})->conditions(array('jobid' => '[0-9]'));
/* Jobgroup - List details of jobgroup */
$app->get('/group/:groupid/', 'isAllowed', function ($groupid) use($app) {
    $jobgroup = new Jobgroup($groupid);
    if (!$jobgroup->exists()) {
        textResponse(404, 'Jobgroup not found');
    }
    jsonResponse(200, $jobgroup->getGroupInfo());
});
/* 404 - not found */
$app->notFound(function () use($app) {
    textResponse(404, 'Not found');
});
/* 500 - internal server error */
$app->error(function (\Exception $e) use($app) {
    textResponse(500, 'Internal Server Error');
});
$app->run();