2017-01-27 20:00:06 +00:00
|
|
|
<?php
|
|
|
|
|
2017-01-30 09:39:45 +00:00
|
|
|
require_once __DIR__.'/../../include/php/const';
|
2017-01-27 20:00:06 +00:00
|
|
|
|
|
|
|
function api_fetch(){
|
|
|
|
|
2017-09-26 08:26:02 +00:00
|
|
|
$data = [];
|
2017-02-21 09:23:34 +00:00
|
|
|
|
2017-09-26 08:26:02 +00:00
|
|
|
/* [1] Get the list of daemons (features)
|
|
|
|
=========================================================*/
|
|
|
|
$f = new SplFileObject(ETREE_CONF, 'r');
|
2017-02-21 09:23:34 +00:00
|
|
|
|
|
|
|
while( !$f->eof() ){
|
|
|
|
|
|
|
|
/* (1) Try to parse each line */
|
2017-09-27 16:29:18 +00:00
|
|
|
$etree = trim($f->fgets(), "\n");
|
2017-02-21 09:23:34 +00:00
|
|
|
|
|
|
|
/* (2) Manage error */
|
2017-09-27 16:29:18 +00:00
|
|
|
if( is_null($etree) || strlen($etree) == 0 )
|
2017-02-21 09:23:34 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* (3) Add entry to log */
|
2017-09-26 08:26:02 +00:00
|
|
|
$data['feature'][$etree] = [];
|
2017-02-21 09:23:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-26 08:26:02 +00:00
|
|
|
/* [2] Fetch & generate useful data from features
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Get identity
|
2017-02-21 09:23:34 +00:00
|
|
|
---------------------------------------------------------*/
|
2017-09-26 08:26:02 +00:00
|
|
|
$data['identity'] = [
|
|
|
|
'ap' => syscall(SOURCE_DIR.'/lib/netid/ap'),
|
|
|
|
'ip' => syscall(SOURCE_DIR.'/lib/netid/ip')
|
|
|
|
];
|
2017-02-21 09:23:34 +00:00
|
|
|
|
|
|
|
|
2017-09-26 08:26:02 +00:00
|
|
|
/* (2) Fetch for each feature which generates data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
foreach($data['feature'] as $feat_name=>$feat_data){
|
2017-02-21 09:23:34 +00:00
|
|
|
|
|
|
|
/* (5) Check for feature access log */
|
|
|
|
if( !file_exists(DATA_DIR."/$feat_name") )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* (6) Try to read log file */
|
|
|
|
$f = new SplFileObject(DATA_DIR."/$feat_name", "r");
|
|
|
|
|
|
|
|
while( !$f->eof() ){
|
|
|
|
|
|
|
|
// {1} Try to parse JSON //
|
|
|
|
$parsed = json_decode($f->fgets(), true);
|
|
|
|
|
|
|
|
// {2} Manage error //
|
|
|
|
if( is_null($parsed) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// {3} If correct -> add entry to feature //
|
|
|
|
$data['feature'][$feat_name][] = $parsed;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (7) Free file handler */
|
|
|
|
$f = null;
|
|
|
|
|
|
|
|
}
|
2017-01-28 10:45:09 +00:00
|
|
|
|
2017-07-21 14:06:49 +00:00
|
|
|
|
|
|
|
|
2017-02-21 09:23:34 +00:00
|
|
|
return json_encode($data);
|
2017-01-27 20:00:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo api_fetch();
|
2017-07-21 14:06:49 +00:00
|
|
|
|
|
|
|
|
2017-01-27 20:00:06 +00:00
|
|
|
|
|
|
|
?>
|