コード例 #1
0
/**
 * Grab the mysql data
 *
 * @return array
 * @param  vars
 *
*/
function api_inventory_db($vars)
{
    global $config;
    $res = array();
    foreach (dbFetchRows("SELECT * FROM `hrDevice` WHERE `device_id` = ? ORDER BY `hrDeviceIndex`", array($vars['device'])) as $hrdevice) {
        if ($config['api']['module']['encryption']) {
            $tmp = array();
            foreach ($hrdevice as $item => $value) {
                $tmp[$item] = api_encrypt_data($value, $config['api']['encryption']['key']);
            }
            $res[] = $tmp;
            unset($tmp);
        } else {
            $res[] = $hrdevice;
        }
    }
    return $res;
}
コード例 #2
0
/**
 * Grab the mysql data
 *
 * @return array
 * @param  vars
 *
*/
function api_packages_db($vars)
{
    global $config;
    $res = array();
    foreach (dbFetchRows("SELECT * FROM `packages` WHERE `device_id` = ? GROUP BY `name`", array($vars['device'])) as $packages) {
        if ($config['api']['module']['encryption']) {
            $tmp = array();
            foreach ($packages as $item => $value) {
                $tmp[$item] = api_encrypt_data($value, $config['api']['encryption']['key']);
            }
            $res[] = $tmp;
            unset($tmp);
        } else {
            $res[] = $packages;
        }
    }
    return $res;
}
コード例 #3
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;
}