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.

309 lines
12 KiB

​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
4 years ago
​
​
3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 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
3 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. }
  52. //$QS = "SELECT * FROM nodes ORDER BY `type`";
  53. $QS = "SELECT * FROM nodes WHERE `type` > 0 AND `type` < 16";
  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. $CT['color'] = 0xff0000;
  143. $CN['targets'][] = $CT;
  144. };
  145. //if( count( $CN['targets'] ) ) $CN['status'] = 5;
  146. };
  147. };
  148. break;
  149. };
  150. case ARGUS_3D_SENSOR:{
  151. $QS = "SELECT `data_status` FROM `lrf_sensors` WHERE `id`={$R['aux_id']}";
  152. $JJ = $DATABASE->Query( $QS );
  153. $CS = $JJ[0];
  154. $CN['status'] = intval($CS['data_status']);
  155. $CN['masks_status'] = 0;
  156. $CN['masks_exist'] = 0;
  157. // check draw
  158. if( $LastTS > 0 ){
  159. $QS = "SELECT `id` FROM `lrf_draw` WHERE `node_id`={$R['id']} AND `ts` > {$LastTS}";
  160. $R = $DATABASE->Query( $QS );
  161. if( count( $R ) ){
  162. $CN['reload_draw'] = true;
  163. } else {
  164. $CN['reload_draw'] = false;
  165. };
  166. } else {
  167. $CN['reload_draw'] = true;
  168. }; //663552
  169. $CN['master_present'] = false;
  170. $CN['slave_present'] = false;
  171. $CN['stat_present'] = false;
  172. if( $CN['status'] ){
  173. $CN['master_present'] = true;
  174. //$QS = "SELECT * FROM `lrf_runtime_status` WHERE `lrf_id`={$R['aux_id']}";
  175. //$Stat = $DATABASE->Query( $QS );
  176. //if( count( $Stat ) ){
  177. // $CS = $Stat[0];
  178. // $MP = array();
  179. // $GP = array();
  180. // $WP = array();
  181. // for( $idx = 0; $idx < 8; $idx++ ){
  182. // $MP[] = round( floatval( $CS['master_mp_' . $idx ] ) / 663552.0, 2 );
  183. // $GP[] = round( floatval( $CS['master_gp_' . $idx ] ) / 663552.0, 2 );
  184. // $WP[] = round( floatval( $CS['master_wp_' . $idx ] ) / 663552.0, 2 );
  185. // };
  186. // for( $idx = 0; $idx < 8; $idx++ ){
  187. // $MP[] = round( floatval( $CS['slave_mp_' . $idx ] ) / 663552.0, 2 );
  188. // $GP[] = round( floatval( $CS['slave_gp_' . $idx ] ) / 663552.0, 2 );
  189. // $WP[] = round( floatval( $CS['slave_wp_' . $idx ] ) / 663552.0, 2 );
  190. // };
  191. // $CN['runtime']['gp'] = $GP;
  192. // $CN['runtime']['mp'] = $MP;
  193. // $CN['runtime']['wp'] = $WP;
  194. // $CN['stat_present'] = true;
  195. // if( $CS['twinc']!= 0 ) $CN['slave_present'] = true;
  196. //};
  197. // check Targets
  198. $CN['targets'] = array();
  199. $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";
  200. //$QS="SELECT * FROM events_cloud WHERE node_id={$CN['id']} AND ( evt_type=11 OR evt_type=14) ORDER BY id DESC LIMIT 32";
  201. //$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";
  202. //$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";
  203. //echo $QS . "\n\n";
  204. $zult = $ZIZI->Query( $QS );
  205. $colors = array( 0x00f6ff, 0x6c00ff, 0xff5400, 0x00ff24, 0x00aeff, 0xbaff00, 0xff0000, 0x0024ff );
  206. $CN['debug']=count( $zult );
  207. if( count( $zult ) ){
  208. $CT = array();
  209. foreach( $zult as $Z ){
  210. $TT = intval( $Z['evt_type'] );
  211. if( ( $TT == 8 ) || ( $TT == 52 ) || ( $TT == 53 ) || ( $TT == 54 ) ){
  212. //$CN['debug2']='break by evt!';
  213. break;
  214. }
  215. $CN['status'] = 5; // Alarmed
  216. $CT['range'] = floatval($Z['range']);
  217. $CT['digital'] = intval( $Z['range_digital']);
  218. if( $SYS['local_binding'] == 0 ){
  219. $CT['lat'] = floatval( $Z['lat'] );
  220. $CT['lon'] = floatval( $Z['lon'] );
  221. } else {
  222. $CT['lat'] = floatval( $SYS['anchor_lat'] ) + floatval( $Z['lat'] );
  223. $CT['lon'] = floatval( $SYS['anchor_lon'] ) + floatval( $Z['lon'] );
  224. };
  225. $CT['az'] = floatval($Z['azimuth']);
  226. $CT['el'] = floatval($Z['elevation']);
  227. if( isset( $Z['lrf_id'] ) ){
  228. $CT['color'] = $colors[intval($Z['lrf_id'])];
  229. } else {
  230. $CT['color'] = 0xff0000;
  231. };
  232. $CN['targets'][] = $CT;
  233. };
  234. };
  235. };
  236. break;
  237. };
  238. case ARGUS_ANALOG_STATIC_CAMERA:
  239. case ARGUS_ANALOG_PTZ_CAMERA:
  240. case ARGUS_IP_STATIC_CAMERA:
  241. case ARGUS_IP_PTZ_CAMERA:
  242. case 14:
  243. case 15:{
  244. if( $ServerIsOnLine ){
  245. $QS="SELECT * FROM `media_streams` WHERE `id`={$R['aux_parameter']}";
  246. $SR=$DATABASE->Query( $QS );
  247. if( count( $SR ) ) {
  248. $ST = $SR[0];
  249. if( $ST['valid'] == 1 ){
  250. $CN['valid'] = true;
  251. $QS="SELECT * FROM `module_eve` WHERE `id`=1";
  252. $S=$DATABASE->Query( $QS );
  253. //$CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].':' . $S[0]['web_port'] .'/stream?id='. $R['aux_parameter'];
  254. if( $SSL_INSTALLLED ){
  255. $CN['src'] = 'https://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  256. } else {
  257. $CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].'/video_feed/stream?id='. $R['aux_parameter'];
  258. //$CN['src'] = 'http://' . $_SERVER['SERVER_ADDR'].'/video_feed/preview?id='. $R['aux_parameter'];
  259. };
  260. break;
  261. };
  262. };
  263. };
  264. $CN['valid'] = false;
  265. $CN['src'] = "/style/assets/no-signal.png";
  266. break;
  267. };
  268. };
  269. };
  270. $Data['nodes'][] = $CN;
  271. };
  272. };
  273. // Notifications
  274. $Data['notifications'] = array();
  275. /*
  276. $QS = "SELECT * FROM `notifications` WHERE `status`='A' AND `site_id`={$SiteID} AND `id` > {$LastNID}";
  277. $result = $DATABASE->Query( $QS );
  278. if( count( $result ) ){
  279. foreach( $result as $R ){
  280. $cn['id'] = intval( $R['id'] );
  281. $cn['react'] = false;
  282. $cn['hide'] = true;
  283. $cn['action']= '';
  284. switch( intval( $R['type'] ) ){
  285. case 0:{
  286. $cn['type']= 'info';
  287. $cn['msg'] = $Labels->GetLabel('SYS_WELCOME_MSG');
  288. break;
  289. };
  290. case 1:{
  291. $cn['type']= 'error';
  292. $QS="SELECT `name` FROM `nodes` WHERE `id`={$R['obj_id']}";
  293. $RR = $DATABASE->Query( $QS );
  294. $cn['msg'] = $Labels->GetLabel('SYS_MSG_DEVINV') . ' <b>' . $RR[0]['name'] .'</b>';
  295. $cn['hide'] = false;
  296. $cn['react'] = true;
  297. $cn['action'] = $R['obj_id'].':'.$cn['id'];
  298. };
  299. };
  300. $Data['notifications'][] = $cn;
  301. };
  302. };*/
  303. } else {
  304. $Data['notifications'] = array();
  305. $Data['status']='LOGOUT';
  306. };
  307. echo json_encode( $Data );
  308. ?>