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.

131 lines
4.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. // require_once( $WDIR . '/inst_lib.php');
  3. echo "\n\n\nAFTER!!\n\n\n";
  4. $CMD = `cp -f /srv/etc/ag_nginx/argus_nginx.service /etc/systemd/system/argus_nginx.service`;
  5. //$CMD = `systemctl daemon-reload`;
  6. $CMD = `cp -f /srv/etc/nginx/default /etc/nginx/sites-available/default`;
  7. $CMD = `cp -f /srv/etc/rc.local /etc/rc.local`;
  8. mkdir( '/srv/www/module/lib/controller/data/uploads' );
  9. $CMD = `chown -R www-data:www-data /srv/www/module/lib/controller/data/uploads`;
  10. $CMD = `chmod -R 0775 /srv/www/module/lib/controller/data/reports`;
  11. $CMD = `chown -R www-data:www-data /srv/www/module/lib/controller/data/uploads`;
  12. $CMD = `chmod -R 0775 /srv/www/module/lib/controller/data/reports`;
  13. //MediaMTX is not installed any more: la_mojo serves the live view (WebRTC) and the recording itself.
  14. //A mediamtx service left by an older package would hold the WebRTC port: stop and disable it.
  15. $OUT = array();
  16. $RC = 1;
  17. exec( 'systemctl list-unit-files --no-legend mediamtx.service 2>/dev/null', $OUT, $RC );
  18. if( ( $RC == 0 && count( $OUT ) > 0 ) || file_exists( '/etc/systemd/system/mediamtx.service' ) ){
  19. echo "MediaMTX service found: stopping and disabling it\n";
  20. $CMD = `systemctl stop mediamtx.service 2>&1`;
  21. $CMD = `systemctl disable mediamtx.service 2>&1`;
  22. };
  23. $CMD = `systemctl daemon-reload`;
  24. $CMD = `systemctl enable argus_nginx`;
  25. //Restore Settings
  26. function restore_whole_line( $A, $B , $C ){
  27. $POPIN = array();
  28. foreach( $C as $Key=>$Value ){
  29. if( $Key != 'id' ){
  30. switch( $B ){
  31. case 'target_filter_train':{
  32. switch( $Key ){
  33. //Update DB to 08.01.2026
  34. case 'MINIMAL_RANGE':{
  35. $POPIN[]="`MINIMAL_RIGHT_RANGE`='".$Value."'";
  36. $POPIN[]="`MINIMAL_LEFT_RANGE`='".$Value."'";
  37. break;
  38. };
  39. default:
  40. $POPIN[]="`".$Key."`='".$Value."'";
  41. };
  42. break;
  43. };
  44. default:
  45. $POPIN[]="`".$Key."`='".$Value."'";
  46. };
  47. };
  48. };
  49. $QS = "UPDATE `{$B}` SET ". implode(",",$POPIN)." WHERE `id`=" . $C['id'];
  50. out_log( $QS );
  51. $A->Query( $QS );
  52. };
  53. function restore_line( $A, $B , $C ){
  54. foreach( $C as $Key=>$Value ){
  55. if( $Key != 'id' ){
  56. switch( $B ){
  57. case 'target_filter_train':{
  58. switch( $Key ){
  59. //Ignore that field
  60. case 'OLD_MINIMAL_RANGE':{
  61. break;
  62. };
  63. //Update DB to 08.01.2026
  64. case 'MINIMAL_RANGE':{
  65. $P="`MINIMAL_RIGHT_RANGE`='".$Value."'";
  66. $QS = "UPDATE `{$B}` SET ".$P." WHERE `id`=" . $C['id'];
  67. out_log( $QS );
  68. $A->Query( $QS );
  69. $P="`MINIMAL_LEFT_RANGE`='".$Value."'";
  70. break;
  71. };
  72. default:
  73. $P="`".$Key."`='".$Value."'";
  74. };
  75. break;
  76. };
  77. default:
  78. $P="`".$Key."`='".$Value."'";
  79. };
  80. //If Not Ignored Then issue Query
  81. if( $P!='' ){
  82. $QS = "UPDATE `{$B}` SET ".$P." WHERE `id`=" . $C['id'];
  83. out_log( $QS );
  84. @$A->Query( $QS );
  85. };
  86. };
  87. };
  88. };
  89. function add_whole_line( $A, $B , $C ){
  90. $POPIN = array();
  91. foreach( $C as $Key=>$Value ){
  92. if( $Key != 'id' ){
  93. $POPIN[]=$Value;
  94. $POLE[]=$Key;
  95. };
  96. };
  97. $QS = "INSERT INTO `{$B}`(`".implode("`,`",$POLE )."`) VALUES('". implode("','",$POPIN )."')";
  98. out_log( $QS );
  99. @$A->Query( $QS );
  100. };
  101. if( file_exists('/srv/www/module/lib/controller/data/mysqlitedb.db') ){
  102. //Run Database Upgrade
  103. $CMD = `cd /srv/www/module/lib; php ./upgrade_database.php`;
  104. if( !class_exists( 'SQLite_DB' ) ){
  105. require_once( $WDIR . '/SQLite_Class.php');
  106. };
  107. out_log("New Database Exists!");
  108. $INS_TIME_DB = new SQLite_DB('/srv/www/module/lib/controller/data/mysqlitedb.db');
  109. foreach( $CAMERA_SETTINGS as $CS ){
  110. restore_line( $INS_TIME_DB, 'cameras', $CS );
  111. $QS = "UPDATE `nodes` SET `name`='{$CS['name']}' WHERE `type`={$CS['type']} AND `aux_id`={$CS['id']}";
  112. out_log( $QS );
  113. $INS_TIME_DB->Query( $QS );
  114. };
  115. if( isset( $SENSOR_SETTINGS ) ) foreach( $SENSOR_SETTINGS as $SS ) restore_line( $INS_TIME_DB, 'lrf_sensors', $SS );
  116. if( isset( $TRAIN_FILTER_SETTINGS ) ) foreach( $TRAIN_FILTER_SETTINGS as $FS ) restore_line( $INS_TIME_DB, 'target_filter_train', $FS );
  117. if( isset( $BUBBLE_FILTER_SETTINGS ) ) foreach( $BUBBLE_FILTER_SETTINGS as $FS ) restore_line( $INS_TIME_DB, 'target_filter_bubble', $FS );
  118. if( isset( $FROZEN_BUBBLES ) ) foreach( $FROZEN_BUBBLES as $FS ) add_whole_line( $INS_TIME_DB, 'target_bubbles', $FS );
  119. if( isset( $DRAW_SETTINGS ) ) foreach( $DRAW_SETTINGS as $DS ) add_whole_line( $INS_TIME_DB, 'lrf_draw', $DS );
  120. unset( $INS_TIME_DB );
  121. copy( '/srv/www/module/lib/controller/data/mysqlitedb.db', '/srv/www/distro/lib/data/mysqlitedb.db' );
  122. } else out_log("New Database Not exists!");
  123. //Services are managed before
  124. $CMD = `systemctl start argus_nginx`;
  125. $CMD = `systemctl enable argus_nginx`;
  126. $CMD = `systemctl start nginx`;
  127. $CMD = `reboot`;
  128. ?>