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.

279 lines
11 KiB

​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
3 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
​
4 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( "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. }
  52. //$QS = "SELECT * FROM nodes ORDER BY `type`";
  53. $QS = "SELECT * FROM nodes WHERE `type` > 0 AND `type` < 14";
  54. $result = $DATABASE->Query( $QS, false );
  55. if( count( $result ) > 0 ){
  56. foreach( $result as $R ){
  57. $CN = array();
  58. $CN['id'] = $R['id'];
  59. $CN['type'] = intval($R['type']);
  60. $CN['status'] = intval($R['online']);
  61. if( $CN['status'] ){
  62. switch( $R['type'] ){
  63. case ARGUS_SERVER:{
  64. /*
  65. $QS="SELECT * FROM `servers` WHERE `id`={$R['aux_id']}";
  66. $zult = $DATABASE->Query( $QS );
  67. if( $zult[0]['online'] == 1 ){
  68. $STS = intval( $zult[0]['ts'] );
  69. $CN['CTS'] = $Data['CTS'];
  70. $CN['STS'] = $STS;
  71. if( ( $CN['CTS'] - $STS ) > 1 ){ //3 seconds offline
  72. $ServerIsOnLine = false;
  73. $CN['status'] = 0;
  74. } else {
  75. $CN['status'] = 1;
  76. };
  77. } else {
  78. $ServerIsOnLine = false;
  79. $CN['status'] = 0;
  80. };
  81. $CN['cpu1'] = intval( $zult[0]['stat_cpu1'] * 2.5 );
  82. $CN['cpu5'] = intval( $zult[0]['stat_cpu5'] );
  83. $CN['cpu15'] = intval( $zult[0]['stat_cpu15'] * 2.5 );
  84. $CN['mem'] = intval( $zult[0]['stat_mem']*100 );
  85. $CN['disk']= intval( $zult[0]['stat_disk']*100 );
  86. */
  87. break;
  88. };
  89. case ARGUS_ALS_SENSOR:
  90. case ARGUS_LFS_SENSOR:
  91. case ARGUS_PLS_200_SENSOR:
  92. case ARGUS_PLS_360_SENSOR:
  93. case ARGUS_NET_PLS_200:{
  94. $QS = "SELECT `data_status` FROM `lrf_sensors` WHERE `id`={$R['aux_id']}";
  95. $JJ = $DATABASE->Query( $QS );
  96. $CS = $JJ[0];
  97. $CN['status'] = $CS['data_status'];
  98. $CN['masks_status'] = 0;
  99. $CN['masks_exist'] = 0;
  100. $QS = "SELECT * FROM `lrf_masks` WHERE `sensor_id`={$R['aux_id']}";
  101. $JJ = $DATABASE->Query( $QS );
  102. if( count( $JJ ) ) foreach( $JJ as $J ) {
  103. $CN['masks_exist'] |= (1<<intval($J['layer']));
  104. if( $J['status'] == 'E' ) $CN['masks_status'] |= (1<<intval($J['layer']));
  105. };
  106. // check draw
  107. if( $LastTS > 0 ){
  108. $QS = "SELECT `id` FROM `lrf_draw` WHERE `node_id`={$R['id']} AND `ts` > {$LastTS}";
  109. $R = $DATABASE->Query( $QS );
  110. if( count( $R ) ){
  111. $CN['reload_draw'] = true;
  112. } else {
  113. $CN['reload_draw'] = false;
  114. };
  115. } else {
  116. $CN['reload_draw'] = true;
  117. };
  118. if( ( $CN['status'] == 5 ) || 1 ){
  119. // check Targets
  120. $CN['targets'] = array();
  121. $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 ) ORDER BY ts DESC, ts_ms DESC LIMIT 32";
  122. //$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";
  123. //$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";
  124. //echo $QS . "\n\n";
  125. $zult = $ZIZI->Query( $QS );
  126. if( count( $zult ) ){
  127. $CT = array();
  128. foreach( $zult as $Z ){
  129. $TT = intval( $Z['evt_type'] );
  130. if( ( $TT == 52 ) || ( $TT == 53 ) || ( $TT == 54 ) ) break;
  131. //if( !( $TT == 10 || $TT == 11 ||$TT == 12 ||$TT == 13 || $TT == 14 || $TT == 36 ) ) continue;
  132. //$CT['type'] = $TT;
  133. $CT['digital'] = intval( $Z['range_digital']);
  134. if( $SYS['local_binding'] == 0 ){
  135. $CT['lat'] = floatval( $Z['lat'] );
  136. $CT['lon'] = floatval( $Z['lon'] );
  137. } else {
  138. $CT['lat'] = floatval( $SYS['anchor_lat'] ) + floatval( $Z['lat'] );
  139. $CT['lon'] = floatval( $SYS['anchor_lon'] ) + floatval( $Z['lon'] );
  140. };
  141. $CT['az'] = floatval( $Z['azimuth'] );
  142. $CN['targets'][] = $CT;
  143. };
  144. //if( count( $CN['targets'] ) ) $CN['status'] = 5;
  145. };
  146. };
  147. break;
  148. };
  149. case ARGUS_3D_SENSOR:{
  150. // check draw
  151. if( $LastTS > 0 ){
  152. $QS = "SELECT `id` FROM `lrf_draw` WHERE `node_id`={$R['id']} AND UNIX_TIMESTAMP(`ts`) > {$FirstTS}";
  153. $BB = $DATABASE->Query( $QS );
  154. if( count( $BB ) ){
  155. $CN['reload_draw'] = true;
  156. } else {
  157. $CN['reload_draw'] = false;
  158. };
  159. } else {
  160. $CN['reload_draw'] = false;
  161. }; //663552
  162. $CN['master_present'] = false;
  163. $CN['slave_present'] = false;
  164. $CN['stat_present'] = false;
  165. if( $CN['status'] == 1 ){
  166. $CN['master_present'] = true;
  167. $QS = "SELECT * FROM `lrf_runtime_status` WHERE `lrf_id`={$R['aux_id']}";
  168. $Stat = $DATABASE->Query( $QS );
  169. if( count( $Stat ) ){
  170. $CS = $Stat[0];
  171. $MP = array();
  172. $GP = array();
  173. $WP = array();
  174. for( $idx = 0; $idx < 8; $idx++ ){
  175. $MP[] = round( floatval( $CS['master_mp_' . $idx ] ) / 663552.0, 2 );
  176. $GP[] = round( floatval( $CS['master_gp_' . $idx ] ) / 663552.0, 2 );
  177. $WP[] = round( floatval( $CS['master_wp_' . $idx ] ) / 663552.0, 2 );
  178. };
  179. for( $idx = 0; $idx < 8; $idx++ ){
  180. $MP[] = round( floatval( $CS['slave_mp_' . $idx ] ) / 663552.0, 2 );
  181. $GP[] = round( floatval( $CS['slave_gp_' . $idx ] ) / 663552.0, 2 );
  182. $WP[] = round( floatval( $CS['slave_wp_' . $idx ] ) / 663552.0, 2 );
  183. };
  184. $CN['runtime']['gp'] = $GP;
  185. $CN['runtime']['mp'] = $MP;
  186. $CN['runtime']['wp'] = $WP;
  187. $CN['stat_present'] = true;
  188. if( $CS['twinc']!= 0 ) $CN['slave_present'] = true;
  189. };
  190. // check Targets
  191. $CN['targets'] = array();
  192. $QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=11 OR evt_type=14) ORDER BY id DESC LIMIT 32";
  193. //$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";
  194. //$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";
  195. //echo $QS . "\n\n";
  196. $zult = $DATABASE->Query( $QS );
  197. $colors = array( 0x00f6ff, 0x6c00ff, 0xff5400, 0x00ff24, 0x00aeff, 0xbaff00, 0xff0000, 0x0024ff );
  198. if( count( $zult ) ){
  199. $CN['status'] = 4; // Alarmed
  200. $CT = array();
  201. foreach( $zult as $Z ){
  202. $CT['range'] = floatval($Z['range']);
  203. $CT['az'] = floatval($Z['azimuth']);
  204. $CT['el'] = floatval($Z['elevation']);
  205. $CT['color'] = $colors[intval($Z['lrf_id'])];
  206. $CN['targets'][] = $CT;
  207. };
  208. };
  209. };
  210. break;
  211. };
  212. case ARGUS_ANALOG_STATIC_CAMERA:
  213. case ARGUS_ANALOG_PTZ_CAMERA:
  214. case ARGUS_IP_STATIC_CAMERA:
  215. case ARGUS_IP_PTZ_CAMERA:{
  216. if( $ServerIsOnLine ){
  217. $QS="SELECT * FROM `media_streams` WHERE `id`={$R['aux_parameter']}";
  218. $SR=$DATABASE->Query( $QS );
  219. if( count( $SR ) ) {
  220. $ST = $SR[0];
  221. if( $ST['valid'] == 1 ){
  222. $CN['valid'] = true;
  223. $QS="SELECT * FROM `module_eve` WHERE `id`=1";
  224. $S=$DATABASE->Query( $QS );
  225. //$CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].':' . $S[0]['web_port'] .'/stream?id='. $R['aux_parameter'];
  226. if( $SSL_INSTALLLED ){
  227. $CN['src'] = 'https://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  228. } else {
  229. $CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  230. };
  231. break;
  232. };
  233. };
  234. };
  235. $CN['valid'] = false;
  236. $CN['src'] = "/style/assets/no-signal.png";
  237. break;
  238. };
  239. };
  240. };
  241. $Data['nodes'][] = $CN;
  242. };
  243. };
  244. // Notifications
  245. $Data['notifications'] = array();
  246. /*
  247. $QS = "SELECT * FROM `notifications` WHERE `status`='A' AND `site_id`={$SiteID} AND `id` > {$LastNID}";
  248. $result = $DATABASE->Query( $QS );
  249. if( count( $result ) ){
  250. foreach( $result as $R ){
  251. $cn['id'] = intval( $R['id'] );
  252. $cn['react'] = false;
  253. $cn['hide'] = true;
  254. $cn['action']= '';
  255. switch( intval( $R['type'] ) ){
  256. case 0:{
  257. $cn['type']= 'info';
  258. $cn['msg'] = $Labels->GetLabel('SYS_WELCOME_MSG');
  259. break;
  260. };
  261. case 1:{
  262. $cn['type']= 'error';
  263. $QS="SELECT `name` FROM `nodes` WHERE `id`={$R['obj_id']}";
  264. $RR = $DATABASE->Query( $QS );
  265. $cn['msg'] = $Labels->GetLabel('SYS_MSG_DEVINV') . ' <b>' . $RR[0]['name'] .'</b>';
  266. $cn['hide'] = false;
  267. $cn['react'] = true;
  268. $cn['action'] = $R['obj_id'].':'.$cn['id'];
  269. };
  270. };
  271. $Data['notifications'][] = $cn;
  272. };
  273. };*/
  274. } else {
  275. $Data['notifications'] = array();
  276. $Data['status']='LOGOUT';
  277. };
  278. echo json_encode( $Data );
  279. ?>