/**
 * Show the module data
 *
 * @return array
 *
*/
function api_module_data()
{
    global $config, $vars;
    if ($config['api']['module']['inventory']) {
        if (api_device_permitted($vars['device'])) {
            $res = api_inventory_db($vars);
        } else {
            $res = api_errorcodes("310");
        }
    } else {
        $res = api_errorcodes("212");
    }
    return $res;
}
예제 #2
0
/**
 * Encrypt data into json format
 *
 * @return string
 * @param  data
 *
*/
function api_json_data($data)
{
    if (is_array($data)) {
        $res = json_encode($data);
    } else {
        $error = api_errorcodes("402");
        $res = json_encode($error);
    }
    api_show_debug("Returned JSON data", $data);
    api_show_debug("Returned Encrypted JSON data", $res);
    return $res;
}
예제 #3
0
if ($vars['debug']) {
    $debug = "1";
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    ini_set('log_errors', 1);
    ini_set('error_reporting', E_ALL);
    $data['debug'] = api_errorcodes("100", "info");
} else {
    $debug = FALSE;
    ini_set('display_errors', 0);
    ini_set('display_startup_errors', 0);
    ini_set('log_errors', 0);
    ini_set('error_reporting', 0);
}
if ($config['api']['enabled']) {
    $vars['user'] = api_authenticate_user($vars['username'], $vars['password']);
    if ($vars['user']['id'] != 0 || $vars['user']['id'] != "") {
        $data['login'] = api_errorcodes("101", "success");
        if (api_load_module($vars['module'])) {
            $data['data'] = api_module_data();
        } else {
            $data['data'] = api_errorcodes("201");
        }
    } else {
        $data['login'] = api_errorcodes("301");
    }
} else {
    $data['login'] = api_errorcodes("200");
}
echo api_json_data($data);
// EOF
/**
 * Encrypt data into json format
 *
 * @return string
 * @param  data
 *
*/
function api_json_data($data)
{
    if (is_array($data)) {
        $res = json_encode($data);
    } else {
        $error = api_errorcodes("402");
        $res = json_encode($error);
    }
    api_show_debug("返回JSON数据", $data);
    api_show_debug("返回加密JSON数据", $res);
    return $res;
}
예제 #5
0
/**
 * Show the module data
 *
 * @return array
 *
*/
function api_module_data()
{
    $res = api_errorcodes("102", "info");
    $res['value'] = "This is only a demo module witch doesn't return any live data.";
    return $res;
}
예제 #6
0
/**
 * Grab the mysql traffic data
 *
 * @return array
 * @param  vars
 *
*/
function api_traffic_db($vars)
{
    global $config;
    $res = array();
    if (api_bill_permitted($vars['bill'])) {
        $start = is_numeric($vars['from']) ? $vars['from'] : strtotime("-1 month");
        $end = is_numeric($vars['to']) ? $vars['to'] : strtotime("now");
        $group = isset($vars['group']) ? $vars['group'] : "day";
        //$group = (($group == "5min" or $group == "hour" or $group == "day" or $group == "week" or $group == "month") ? $group : "day");
        $sql["vars"] = array($vars['bill'], $start, $end);
        if ($vars['group'] == "hour") {
            $sql["query"] = "SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM `bill_data` WHERE `bill_id`= ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY timestamp ASC";
        } elseif ($vars['group'] == "day") {
            $sql["query"] = "SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM `bill_data` WHERE `bill_id`= ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DAY(timestamp) ORDER BY timestamp ASC";
        } elseif ($vars['group'] == "week") {
            $sql["query"] = "SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM `bill_data` WHERE `bill_id`= ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY WEEK(timestamp) ORDER BY timestamp ASC";
        } elseif ($vars['group'] == "month") {
            $sql["query"] = "SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM `bill_data` WHERE `bill_id`= ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY MONTH(timestamp) ORDER BY timestamp ASC";
        } else {
            $sql["query"] = "SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, delta as traf_total, in_delta as traf_in, out_delta as traf_out FROM `bill_data` WHERE `bill_id`= ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) ORDER BY timestamp ASC";
        }
        foreach (dbFetchRows($sql["query"], $sql["vars"]) as $traffic) {
            if ($config['api']['module']['encryption']) {
                $tmp = array();
                foreach ($traffic as $item => $value) {
                    $tmp[$item] = api_encrypt_data($value, $config['api']['encryption']['key']);
                }
                $res[] = $tmp;
                unset($tmp);
            } else {
                $res[] = $traffic;
            }
        }
    } else {
        $res = api_errorcodes("310");
    }
    return $res;
}