Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
13 KiB

​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
3 years ago
​
​
​
​
​
​
​
4 years ago
2 years ago
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
4 years ago
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
3 years ago
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
3 years ago
​
​
​
3 years ago
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
3 years ago
3 years ago
​
​
3 years ago
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
3 years ago
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. $UID = intval( $CUser->Data['id'] );
  4. $ACCESS = intval( $CUser->Data['access'] );
  5. if( $UID > 1 ){
  6. $SiteID = intval( $_POST['SITE'] );
  7. $LastNID = intval( $_POST['LNID'] );
  8. $LastTS = intval( $_POST['SPID'] );
  9. $LLID = intval( $_POST['LSID'] );
  10. $Data = array();
  11. $ServerWasHuped = false;
  12. $ServerIsOnLine = true;
  13. $Data['status'] = 'OK';
  14. $Data['CTS'] = time();
  15. $Data['nodes'] = array();
  16. $Data['log'] = array();
  17. $QS = "SELECT * FROM `system_props` LIMIT 1";
  18. $SD = $DATABASE->Query( $QS );
  19. $SYS = $SD[0];
  20. $STATS = new SQLite_DB( '/srv/www/web/lib/controller/data/reports/stat.db');
  21. $QS = "SELECT `year`, `month`, `day` FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1";
  22. $STR = $STATS->Query( $QS );
  23. if( count( $STR ) ){
  24. $DTS = sprintf("%04d/%02d/%02d", intval($STR[0]['year']), intval($STR[0]['month']), intval($STR[0]['day']));
  25. $ZIZI = new SQLite_DB( '/srv/www/web/lib/controller/data/reports/'.$DTS.'/report.db');
  26. $QS = "SELECT `id` FROM `events` WHERE `id` > {$LLID} LIMIT 1";
  27. $CH = $ZIZI->Query( $QS );
  28. if( count( $CH ) ){
  29. $QS = "SELECT * FROM nodes";
  30. $result = $DATABASE->Query( $QS, false );
  31. $NodeNames = array();
  32. foreach( $result as $R ) $NodeNames[$R['id']] = $R['name'];
  33. $QS = "SELECT `id`,`node_id`, `evt_type`, `ts`, `ts_ms`, `range_digital`, `azimuth`, `elevation`, `range`, `area` FROM `events` WHERE `id` > {$LLID} ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 32";
  34. $LREC = $ZIZI->Query( $QS );
  35. foreach( $LREC as $REC ){
  36. $CR['id'] = intval( $REC['id'] );
  37. $CR['node_id'] = intval( $REC['node_id'] );
  38. $CR['node_name'] = $NodeNames[$CR['node_id']];
  39. $CR['ts'] = intval( $REC['ts'] );
  40. $CR['ms'] = sprintf( "%03d", intval( $REC['ts_ms'] ));
  41. $CR['dts'] = date( "Y-m-d H:i:s.{$CR['ms']}", $CR['ts'] );
  42. $CR['type'] = intval( $REC['evt_type'] );
  43. $CR['range'] = sprintf( "%0.2f", floatval( $REC['range'] ));
  44. $CR['az'] = sprintf( "%0.2f", floatval( $REC['azimuth'] ));
  45. $CR['el'] = sprintf( "%0.2f", floatval( $REC['elevation'] ));
  46. $CR['r'] = intval( $REC['range_digital'] );
  47. $CR['width'] = intval( $REC['area'] );
  48. $Data['log'][] = $CR;
  49. };
  50. };
  51. } else {
  52. echo json_encode( $Data );
  53. exit();
  54. };
  55. //$QS = "SELECT * FROM nodes ORDER BY `type`";
  56. $QS = "SELECT * FROM nodes WHERE `type` > 0 AND `type` < 16";
  57. $result = $DATABASE->Query( $QS, false );
  58. if( count( $result ) > 0 ){
  59. foreach( $result as $R ){
  60. $CN = array();
  61. $CN['id'] = $R['id'];
  62. $CN['type'] = intval($R['type']);
  63. $CN['status'] = intval($R['online']);
  64. if( $CN['status'] ){
  65. switch( $R['type'] ){
  66. case ARGUS_SERVER:{
  67. /*
  68. $QS="SELECT * FROM `servers` WHERE `id`={$R['aux_id']}";
  69. $zult = $DATABASE->Query( $QS );
  70. if( $zult[0]['online'] == 1 ){
  71. $STS = intval( $zult[0]['ts'] );
  72. $CN['CTS'] = $Data['CTS'];
  73. $CN['STS'] = $STS;
  74. if( ( $CN['CTS'] - $STS ) > 1 ){ //3 seconds offline
  75. $ServerIsOnLine = false;
  76. $CN['status'] = 0;
  77. } else {
  78. $CN['status'] = 1;
  79. };
  80. } else {
  81. $ServerIsOnLine = false;
  82. $CN['status'] = 0;
  83. };
  84. $CN['cpu1'] = intval( $zult[0]['stat_cpu1'] * 2.5 );
  85. $CN['cpu5'] = intval( $zult[0]['stat_cpu5'] );
  86. $CN['cpu15'] = intval( $zult[0]['stat_cpu15'] * 2.5 );
  87. $CN['mem'] = intval( $zult[0]['stat_mem']*100 );
  88. $CN['disk']= intval( $zult[0]['stat_disk']*100 );
  89. */
  90. break;
  91. };
  92. case ARGUS_ALS_SENSOR:
  93. case ARGUS_LFS_SENSOR:
  94. case ARGUS_PLS_200_SENSOR:
  95. case ARGUS_PLS_360_SENSOR:
  96. case ARGUS_NET_PLS_200:{
  97. $QS = "SELECT `data_status` FROM `lrf_sensors` WHERE `id`={$R['aux_id']}";
  98. $JJ = $DATABASE->Query( $QS );
  99. $CS = $JJ[0];
  100. $CN['status'] = $CS['data_status'];
  101. $CN['masks_status'] = 0;
  102. $CN['masks_exist'] = 0;
  103. $QS = "SELECT * FROM `lrf_masks` WHERE `sensor_id`={$R['aux_id']}";
  104. $JJ = $DATABASE->Query( $QS );
  105. if( count( $JJ ) ) foreach( $JJ as $J ) {
  106. $CN['masks_exist'] |= (1<<intval($J['layer']));
  107. if( $J['status'] == 'E' ) $CN['masks_status'] |= (1<<intval($J['layer']));
  108. };
  109. // check draw
  110. if( $LastTS > 0 ){
  111. $QS = "SELECT `id` FROM `lrf_draw` WHERE `node_id`={$R['id']} AND `ts` > {$LastTS}";
  112. $R = $DATABASE->Query( $QS );
  113. if( count( $R ) ){
  114. $CN['reload_draw'] = true;
  115. } else {
  116. $CN['reload_draw'] = false;
  117. };
  118. } else {
  119. $CN['reload_draw'] = true;
  120. };
  121. if( ( $CN['status'] == 5 ) || 1 ){
  122. // check Targets
  123. $CN['targets'] = array();
  124. $QS="SELECT * FROM events WHERE ( node_id={$CN['id']} OR node_id=1 ) AND ( evt_type=10 OR evt_type=11 OR evt_type=12 OR evt_type=13 OR evt_type=14 OR evt_type=52 OR evt_type=53 OR evt_type=54 OR evt_type=39 OR evt_type=40 OR evt_type=41 OR evt_type=42 OR evt_type=43 OR evt_type=44 OR evt_type=45 OR evt_type=46 OR evt_type=47 OR evt_type=48 OR evt_type=49 ) ORDER BY ts DESC, ts_ms DESC LIMIT 32";
  125. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=13 OR evt_type=14) AND (UNIX_TIMESTAMP(NOW())-ts)<60 ORDER BY id DESC LIMIT 32";
  126. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=13 OR evt_type=14) ORDER BY ts, ts_ms DESC LIMIT 32";
  127. //echo $QS . "\n\n";
  128. $zult = $ZIZI->Query( $QS );
  129. if( count( $zult ) ){
  130. $CT = array();
  131. foreach( $zult as $Z ){
  132. $TT = intval( $Z['evt_type'] );
  133. if( ( $TT == 52 ) || ( $TT == 53 ) || ( $TT == 54 ) ) break;
  134. //if( !( $TT == 10 || $TT == 11 ||$TT == 12 ||$TT == 13 || $TT == 14 || $TT == 36 ) ) continue;
  135. //$CT['type'] = $TT;
  136. $CT['digital'] = intval( $Z['range_digital']);
  137. if( $SYS['local_binding'] == 0 ){
  138. $CT['lat'] = floatval( $Z['lat'] );
  139. $CT['lon'] = floatval( $Z['lon'] );
  140. } else {
  141. $CT['lat'] = floatval( $SYS['anchor_lat'] ) + floatval( $Z['lat'] );
  142. $CT['lon'] = floatval( $SYS['anchor_lon'] ) + floatval( $Z['lon'] );
  143. };
  144. $CT['az'] = floatval( $Z['azimuth'] );
  145. if( $TT > 38 ){
  146. $CT['color'] = 'ff00ff';
  147. $CT['stroke'] = '800080';
  148. } else {
  149. $CT['color'] = 'ff0000';
  150. $CT['stroke'] = '800000';
  151. };
  152. $CN['targets'][] = $CT;
  153. };
  154. //if( count( $CN['targets'] ) ) $CN['status'] = 5;
  155. };
  156. };
  157. break;
  158. };
  159. case ARGUS_3D_SENSOR:{
  160. $QS = "SELECT `data_status` FROM `lrf_sensors` WHERE `id`={$R['aux_id']}";
  161. $JJ = $DATABASE->Query( $QS );
  162. $CS = $JJ[0];
  163. $CN['status'] = intval($CS['data_status']);
  164. $CN['masks_status'] = 0;
  165. $CN['masks_exist'] = 0;
  166. // check draw
  167. if( $LastTS > 0 ){
  168. $QS = "SELECT `id` FROM `lrf_draw` WHERE `node_id`={$R['id']} AND `ts` > {$LastTS}";
  169. $R = $DATABASE->Query( $QS );
  170. if( count( $R ) ){
  171. $CN['reload_draw'] = true;
  172. } else {
  173. $CN['reload_draw'] = false;
  174. };
  175. } else {
  176. $CN['reload_draw'] = true;
  177. }; //663552
  178. $CN['master_present'] = false;
  179. $CN['slave_present'] = false;
  180. $CN['stat_present'] = false;
  181. if( $CN['status'] ){
  182. $CN['master_present'] = true;
  183. //$QS = "SELECT * FROM `lrf_runtime_status` WHERE `lrf_id`={$R['aux_id']}";
  184. //$Stat = $DATABASE->Query( $QS );
  185. //if( count( $Stat ) ){
  186. // $CS = $Stat[0];
  187. // $MP = array();
  188. // $GP = array();
  189. // $WP = array();
  190. // for( $idx = 0; $idx < 8; $idx++ ){
  191. // $MP[] = round( floatval( $CS['master_mp_' . $idx ] ) / 663552.0, 2 );
  192. // $GP[] = round( floatval( $CS['master_gp_' . $idx ] ) / 663552.0, 2 );
  193. // $WP[] = round( floatval( $CS['master_wp_' . $idx ] ) / 663552.0, 2 );
  194. // };
  195. // for( $idx = 0; $idx < 8; $idx++ ){
  196. // $MP[] = round( floatval( $CS['slave_mp_' . $idx ] ) / 663552.0, 2 );
  197. // $GP[] = round( floatval( $CS['slave_gp_' . $idx ] ) / 663552.0, 2 );
  198. // $WP[] = round( floatval( $CS['slave_wp_' . $idx ] ) / 663552.0, 2 );
  199. // };
  200. // $CN['runtime']['gp'] = $GP;
  201. // $CN['runtime']['mp'] = $MP;
  202. // $CN['runtime']['wp'] = $WP;
  203. // $CN['stat_present'] = true;
  204. // if( $CS['twinc']!= 0 ) $CN['slave_present'] = true;
  205. //};
  206. // check Targets
  207. $CN['targets'] = array();
  208. $QS="SELECT * FROM events WHERE ( node_id={$CN['id']} OR node_id=1 ) AND ( evt_type=11 OR evt_type=12 OR evt_type=8 OR evt_type=52 OR evt_type=53 OR evt_type=54 ) ORDER BY ts DESC, ts_ms DESC LIMIT 32";
  209. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=11 OR evt_type=14) ORDER BY id DESC LIMIT 32";
  210. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=13 OR evt_type=14) AND (UNIX_TIMESTAMP(NOW())-ts)<60 ORDER BY id DESC LIMIT 32";
  211. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=13 OR evt_type=14) ORDER BY ts, ts_ms DESC LIMIT 32";
  212. //echo $QS . "\n\n";
  213. $zult = $ZIZI->Query( $QS );
  214. $colors = array( 0x00f6ff, 0x6c00ff, 0xff5400, 0x00ff24, 0x00aeff, 0xbaff00, 0xff0000, 0x0024ff );
  215. $CN['debug']=count( $zult );
  216. if( count( $zult ) ){
  217. $CT = array();
  218. foreach( $zult as $Z ){
  219. $TT = intval( $Z['evt_type'] );
  220. if( ( $TT == 8 ) || ( $TT == 52 ) || ( $TT == 53 ) || ( $TT == 54 ) ){
  221. //$CN['debug2']='break by evt!';
  222. break;
  223. }
  224. $CN['status'] = 5; // Alarmed
  225. $CT['range'] = floatval($Z['range']);
  226. $CT['digital'] = intval( $Z['range_digital']);
  227. if( $SYS['local_binding'] == 0 ){
  228. $CT['lat'] = floatval( $Z['lat'] );
  229. $CT['lon'] = floatval( $Z['lon'] );
  230. } else {
  231. $CT['lat'] = floatval( $SYS['anchor_lat'] ) + floatval( $Z['lat'] );
  232. $CT['lon'] = floatval( $SYS['anchor_lon'] ) + floatval( $Z['lon'] );
  233. };
  234. $CT['az'] = floatval($Z['azimuth']);
  235. $CT['el'] = floatval($Z['elevation']);
  236. if( isset( $Z['lrf_id'] ) ){
  237. $CT['color'] = $colors[intval($Z['lrf_id'])];
  238. } else {
  239. $CT['color'] = 0xff0000;
  240. };
  241. $CN['targets'][] = $CT;
  242. };
  243. };
  244. };
  245. break;
  246. };
  247. case ARGUS_ANALOG_STATIC_CAMERA:
  248. case ARGUS_ANALOG_PTZ_CAMERA:
  249. case ARGUS_IP_STATIC_CAMERA:
  250. case ARGUS_IP_PTZ_CAMERA:
  251. case 14:
  252. case 15:{
  253. if( $ServerIsOnLine ){
  254. $QS="SELECT * FROM `media_streams` WHERE `id`={$R['aux_parameter']}";
  255. $SR=$DATABASE->Query( $QS );
  256. if( count( $SR ) ) {
  257. $ST = $SR[0];
  258. if( $ST['valid'] == 1 ){
  259. $CN['valid'] = true;
  260. $QS="SELECT * FROM `module_eve` WHERE `id`=1";
  261. $S=$DATABASE->Query( $QS );
  262. //$CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].':' . $S[0]['web_port'] .'/stream?id='. $R['aux_parameter'];
  263. if( $SSL_INSTALLLED ){
  264. $CN['src'] = 'https://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  265. } else {
  266. $CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  267. //$CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].'/video_feed/preview?id='. $R['aux_parameter'];
  268. };
  269. break;
  270. };
  271. };
  272. };
  273. $CN['valid'] = false;
  274. $CN['src'] = "/style/assets/no-signal.png";
  275. break;
  276. };
  277. };
  278. };
  279. $Data['nodes'][] = $CN;
  280. };
  281. };
  282. // Notifications
  283. $Data['notifications'] = array();
  284. /*
  285. $QS = "SELECT * FROM `notifications` WHERE `status`='A' AND `site_id`={$SiteID} AND `id` > {$LastNID}";
  286. $result = $DATABASE->Query( $QS );
  287. if( count( $result ) ){
  288. foreach( $result as $R ){
  289. $cn['id'] = intval( $R['id'] );
  290. $cn['react'] = false;
  291. $cn['hide'] = true;
  292. $cn['action']= '';
  293. switch( intval( $R['type'] ) ){
  294. case 0:{
  295. $cn['type']= 'info';
  296. $cn['msg'] = $Labels->GetLabel('SYS_WELCOME_MSG');
  297. break;
  298. };
  299. case 1:{
  300. $cn['type']= 'error';
  301. $QS="SELECT `name` FROM `nodes` WHERE `id`={$R['obj_id']}";
  302. $RR = $DATABASE->Query( $QS );
  303. $cn['msg'] = $Labels->GetLabel('SYS_MSG_DEVINV') . ' <b>' . $RR[0]['name'] .'</b>';
  304. $cn['hide'] = false;
  305. $cn['react'] = true;
  306. $cn['action'] = $R['obj_id'].':'.$cn['id'];
  307. };
  308. };
  309. $Data['notifications'][] = $cn;
  310. };
  311. };*/
  312. } else {
  313. $Data['notifications'] = array();
  314. $Data['status']='LOGOUT';
  315. };
  316. echo json_encode( $Data );
  317. ?>