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.

128 lines
4.4 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. //Setup MediaMTX
  14. $CMD = `systemctl stop mediamtx.service`; // just to be sure
  15. $CMD = `rm -f -R /opt/mediamtx`;
  16. $CMD = `mv -f /srv/mediamtx /opt`;
  17. $CMD = `mv -f /opt/mediamtx/mediamtx.service /etc/systemd/system/mediamtx.service`;
  18. $CMD = `systemctl daemon-reload`;
  19. $CMD = `systemctl enable mediamtx.service`;
  20. $CMD = `systemctl enable argus_nginx`;
  21. //Restore Settings
  22. function restore_whole_line( $A, $B , $C ){
  23. $POPIN = array();
  24. foreach( $C as $Key=>$Value ){
  25. if( $Key != 'id' ){
  26. switch( $B ){
  27. case 'target_filter_train':{
  28. switch( $Key ){
  29. //Update DB to 08.01.2026
  30. case 'MINIMAL_RANGE':{
  31. $POPIN[]="`MINIMAL_RIGHT_RANGE`='".$Value."'";
  32. $POPIN[]="`MINIMAL_LEFT_RANGE`='".$Value."'";
  33. break;
  34. };
  35. default:
  36. $POPIN[]="`".$Key."`='".$Value."'";
  37. };
  38. break;
  39. };
  40. default:
  41. $POPIN[]="`".$Key."`='".$Value."'";
  42. };
  43. };
  44. };
  45. $QS = "UPDATE `{$B}` SET ". implode(",",$POPIN)." WHERE `id`=" . $C['id'];
  46. out_log( $QS );
  47. $A->Query( $QS );
  48. };
  49. function restore_line( $A, $B , $C ){
  50. foreach( $C as $Key=>$Value ){
  51. if( $Key != 'id' ){
  52. switch( $B ){
  53. case 'target_filter_train':{
  54. switch( $Key ){
  55. //Ignore that field
  56. case 'OLD_MINIMAL_RANGE':{
  57. break;
  58. };
  59. //Update DB to 08.01.2026
  60. case 'MINIMAL_RANGE':{
  61. $P="`MINIMAL_RIGHT_RANGE`='".$Value."'";
  62. $QS = "UPDATE `{$B}` SET ".$P." WHERE `id`=" . $C['id'];
  63. out_log( $QS );
  64. $A->Query( $QS );
  65. $P="`MINIMAL_LEFT_RANGE`='".$Value."'";
  66. break;
  67. };
  68. default:
  69. $P="`".$Key."`='".$Value."'";
  70. };
  71. break;
  72. };
  73. default:
  74. $P="`".$Key."`='".$Value."'";
  75. };
  76. //If Not Ignored Then issue Query
  77. if( $P!='' ){
  78. $QS = "UPDATE `{$B}` SET ".$P." WHERE `id`=" . $C['id'];
  79. out_log( $QS );
  80. @$A->Query( $QS );
  81. };
  82. };
  83. };
  84. };
  85. function add_whole_line( $A, $B , $C ){
  86. $POPIN = array();
  87. foreach( $C as $Key=>$Value ){
  88. if( $Key != 'id' ){
  89. $POPIN[]=$Value;
  90. $POLE[]=$Key;
  91. };
  92. };
  93. $QS = "INSERT INTO `{$B}`(`".implode("`,`",$POLE )."`) VALUES('". implode("','",$POPIN )."')";
  94. out_log( $QS );
  95. @$A->Query( $QS );
  96. };
  97. if( file_exists('/srv/www/module/lib/controller/data/mysqlitedb.db') ){
  98. //Run Database Upgrade
  99. $CMD = `cd /srv/www/module/lib; php ./upgrade_database.php`;
  100. if( !class_exists( 'SQLite_DB' ) ){
  101. require_once( $WDIR . '/SQLite_Class.php');
  102. };
  103. out_log("New Database Exists!");
  104. $INS_TIME_DB = new SQLite_DB('/srv/www/module/lib/controller/data/mysqlitedb.db');
  105. foreach( $CAMERA_SETTINGS as $CS ){
  106. restore_line( $INS_TIME_DB, 'cameras', $CS );
  107. $QS = "UPDATE `nodes` SET `name`='{$CS['name']}' WHERE `type`={$CS['type']} AND `aux_id`={$CS['id']}";
  108. out_log( $QS );
  109. $INS_TIME_DB->Query( $QS );
  110. };
  111. if( isset( $SENSOR_SETTINGS ) ) foreach( $SENSOR_SETTINGS as $SS ) restore_line( $INS_TIME_DB, 'lrf_sensors', $SS );
  112. if( isset( $TRAIN_FILTER_SETTINGS ) ) foreach( $TRAIN_FILTER_SETTINGS as $FS ) restore_line( $INS_TIME_DB, 'target_filter_train', $FS );
  113. if( isset( $BUBBLE_FILTER_SETTINGS ) ) foreach( $BUBBLE_FILTER_SETTINGS as $FS ) restore_line( $INS_TIME_DB, 'target_filter_bubble', $FS );
  114. if( isset( $FROZEN_BUBBLES ) ) foreach( $FROZEN_BUBBLES as $FS ) add_whole_line( $INS_TIME_DB, 'target_bubbles', $FS );
  115. if( isset( $DRAW_SETTINGS ) ) foreach( $DRAW_SETTINGS as $DS ) add_whole_line( $INS_TIME_DB, 'lrf_draw', $DS );
  116. unset( $INS_TIME_DB );
  117. copy( '/srv/www/module/lib/controller/data/mysqlitedb.db', '/srv/www/distro/lib/data/mysqlitedb.db' );
  118. } else out_log("New Database Not exists!");
  119. //Services are managed before
  120. $CMD = `systemctl start argus_nginx`;
  121. $CMD = `systemctl enable argus_nginx`;
  122. $CMD = `systemctl start nginx`;
  123. $CMD = `reboot`;
  124. ?>