Ejemplo n.º 1
0
 function __construct()
 {
     global $amp_conf, $db;
     $this->amp_conf =& $amp_conf;
     $this->auth = new RestAuth($this);
     $this->db =& $db;
     //import our db object
     $this->hash_algo = 'sha256';
     $this->opts = restapi_opts_get();
     if ($this->opts['logging'] == 'enabled') {
         $this->log = new RestLogger($this);
     } else {
         $this->log = NULL;
     }
     $this->mods = modulelist::create($this->db);
     //matched routes, if any
     $this->_register_routes();
     $this->res = new stdClass();
     $this->res->nonce = restapi_tokens_generate();
     //setup $this->req
     $this->_get_req();
     if ($this->log) {
         $this->log->init();
     }
 }
Ejemplo n.º 2
0
function restapi_opts_put($vars)
{
    global $db;
    //never accept a new token or key
    $orig = restapi_opts_get();
    if ($orig['token'] && $orig['tokenkey']) {
        $vars['token'] = $orig['token'];
        $vars['tokenkey'] = $orig['tokenkey'];
    }
    foreach ($vars as $k => $v) {
        switch ($k) {
            case 'status':
            case 'token':
            case 'tokenkey':
            case 'logging':
                $data[] = array($k, $v);
                break;
        }
    }
    $sql = $db->prepare('REPLACE INTO restapi_general (keyword, value) VALUES (?, ?)');
    $ret = $db->executeMultiple($sql, $data);
    db_e($ret);
    return true;
}
Ejemplo n.º 3
0
<?php

$vars = array('status' => '', 'logging' => '', 'action' => '');
foreach ($vars as $k => $v) {
    $vars[$k] = isset($_REQUEST[$k]) ? $_REQUEST[$k] : $v;
}
if (isset($vars['action'])) {
    switch ($vars['action']) {
        case 'save_general':
            restapi_opts_put($vars);
            break;
        default:
            break;
    }
}
$vars = array_merge($vars, restapi_opts_get());
//if we dont have tokens, create new ones
if (!$vars['token'] && !$vars['tokenkey']) {
    $vars['token'] = restapi_tokens_generate();
    $vars['tokenkey'] = restapi_tokens_generate();
}
?>
<div class="container-fluid">
	<div class="row">
		<div class="col-sm-12">
			<h1><?php 
echo _('Rest API');
?>
</h1>
			<div class="panel panel-info">
				<div class="panel-heading">