From b8875faf610c3034033806c964f632048a50878d Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Tue, 24 Feb 2026 01:09:55 +0200 Subject: [PATCH] Addidng some stuff for Server Package Creation Script --- Distro/tmp_serv/MySQL_class.php | 119 +++++++++++ Distro/tmp_serv/MySQLi_class.php | 150 ++++++++++++++ Distro/tmp_serv/SQLite_Class.php | 139 +++++++++++++ Distro/tmp_serv/after.php | 48 +++++ Distro/tmp_serv/before.php | 70 +++++++ Distro/tmp_serv/inst_lib.php | 341 +++++++++++++++++++++++++++++++ 6 files changed, 867 insertions(+) create mode 100644 Distro/tmp_serv/MySQL_class.php create mode 100644 Distro/tmp_serv/MySQLi_class.php create mode 100644 Distro/tmp_serv/SQLite_Class.php create mode 100644 Distro/tmp_serv/after.php create mode 100644 Distro/tmp_serv/before.php create mode 100644 Distro/tmp_serv/inst_lib.php diff --git a/Distro/tmp_serv/MySQL_class.php b/Distro/tmp_serv/MySQL_class.php new file mode 100644 index 00000000..55c5a70e --- /dev/null +++ b/Distro/tmp_serv/MySQL_class.php @@ -0,0 +1,119 @@ +DBHost=$Host; + $this->DBName=$Name; + $this->DBUser=$User; + $this->DBPassword=$Password; + if ($this->DBLink = mysql_connect($this->DBHost, $this->DBUser, $this->DBPassword)) { + //mysql_query("SET NAMES 'UTF8'",$this->DBLink); + mysql_set_charset('utf8', $this->DBLink ); + $this->isConnected=true; + } else { + $this->isConnected=false; + //echo "Error During Connection to Database!!
"; + } + } + function CleanUpCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_') && (time()-filemtime($CF))>360){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function ResetCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_')){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function SetCacheDir($Path){ + $this->CachePath = $Path; + $this->isCached = is_dir($this->CachePath) && is_writable($this->CachePath); + if ($this->isCached) $this->CleanUpCache(); + } + function escape( $Str ){ + if($this->isConnected){ + return $this->DBLink->real_escape_string( $Str ); + }; + return ''; + } + function Query($QS,$ChacheIfAveable=true){ + if($this->isConnected){ + if ($this->isCached && $ChacheIfAveable){ + $QMD5=md5($QS); + $Prefetch=$this->CachePath.'/dbchache_'.$QMD5; + + if ( is_file($Prefetch)){ + + if ( (time()- filemtime($Prefetch))<360){ + $FData=file_get_contents($Prefetch); + return unserialize($FData); + } else { + + $result = mysql_db_query($this->DBName,$QS,$this->DBLink) or die (" Error during query [$QS]:".mysql_error($this->DBLink)); + $RetVal=array(); + while($array=mysql_fetch_assoc($result)) $RetVal[]=$array; + $FData=serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + + return $RetVal; + } + } else { + $result = mysql_db_query($this->DBName,$QS,$this->DBLink) or die (" Error during query [$QS]:".mysql_error($this->DBLink)); + $RetVal=array(); + while($array=mysql_fetch_assoc($result)) $RetVal[]=$array; + $FData = serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + + return $RetVal; + } + } else { + $result = mysql_db_query($this->DBName,$QS,$this->DBLink) or die (" Error during query [$QS]:".mysql_error($this->DBLink)); + $RetVal=array(); + if (is_resource($result)){ + while($array=mysql_fetch_assoc($result)) $RetVal[]=$array; + }; + return $RetVal; + }; + } else { + echo "No Connection to DB
"; + } + } + function getLastInsertID(){ + if($this->isConnected){ + return mysql_insert_id( $this->DBLink ); + }; + return -1; + } + function __destruct(){ + mysql_close($this->DBLink); + } +} + +?> \ No newline at end of file diff --git a/Distro/tmp_serv/MySQLi_class.php b/Distro/tmp_serv/MySQLi_class.php new file mode 100644 index 00000000..ad4eee10 --- /dev/null +++ b/Distro/tmp_serv/MySQLi_class.php @@ -0,0 +1,150 @@ +DBHost=$Host; + $this->DBName=$Name; + $this->DBUser=$User; + $this->DBPassword=$Password; + $this->DBLink = new mysqli( $this->DBHost, $this->DBUser, $this->DBPassword, $this->DBName ); + if( $this->DBLink->connect_error ){ + if( $DBCREATE ){ + $this->DBLink = new mysqli( $this->DBHost, $this->DBUser, $this->DBPassword ); + if( $this->DBLink->connect_error ){ + $this->isConnected=false; + //echo 'Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; + } else { + if (!$this->DBLink->set_charset("utf8")) { + printf("Error loading character set utf8: %s\n", $mysqli->error); + } else { + //printf("Current character set: %s\n", $mysqli->character_set_name()); + }; + $QS = "CREATE DATABASE {$Name}"; + if( mysqli_query( $this->DBLink, $QS ) === false ) { + echo " Error during query [$QS]:".mysqli_error($this->DBLink); + $this->isConnected=false; + } else { + $this->isConnected=true; + }; + }; + } else { + $this->isConnected=false; + //echo 'Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error; + }; + } else { + //mysql_query("SET NAMES 'UTF8'",$this->DBLink); + if (!$this->DBLink->set_charset("utf8")) { + printf("Error loading character set utf8: %s\n", $mysqli->error); + } else { + //printf("Current character set: %s\n", $mysqli->character_set_name()); + }; + $this->isConnected=true; + }; + } + function CleanUpCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_') && (time()-filemtime($CF))>360){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function ResetCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_')){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function SetCacheDir($Path){ + $this->CachePath = $Path; + $this->isCached = is_dir($this->CachePath) && is_writable($this->CachePath); + if ($this->isCached) $this->CleanUpCache(); + } + function escape( $Str ){ + if($this->isConnected){ + return $this->DBLink->real_escape_string( $Str ); + }; + return ''; + } + function Query($QS,$ChacheIfAveable=true){ + if($this->isConnected){ + if ($this->isCached && $ChacheIfAveable){ + $QMD5=md5($QS); + $Prefetch=$this->CachePath.'/dbchache_'.$QMD5; + + if ( is_file($Prefetch)){ + + if ( (time()- filemtime($Prefetch))<360){ + $FData=file_get_contents($Prefetch); + return unserialize($FData); + } else { + + $result = mysqli_query( $this->DBLink, $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + while($array=mysqli_fetch_assoc($result)) $RetVal[]=$array; + $FData=serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + + return $RetVal; + } + } else { + $result = mysqli_query( $this->DBLink, $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + while($array=mysqli_fetch_assoc($result)) $RetVal[]=$array; + $FData = serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + + return $RetVal; + } + } else { + $result = mysqli_query( $this->DBLink, $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + if ($result !== false && is_a( $result, 'mysqli_result' ) ){ + while($array=mysqli_fetch_assoc($result)) $RetVal[]=$array; + }; + return $RetVal; + }; + } else { + echo "No Connection to DB
"; + }; + } + function getLastInsertID(){ + if($this->isConnected){ + return $this->DBLink->insert_id; + }; + return -1; + } + function __destruct(){ + if( $this->isConnected ){ + $this->DBLink->close(); + }; + } +} + + + + +?> \ No newline at end of file diff --git a/Distro/tmp_serv/SQLite_Class.php b/Distro/tmp_serv/SQLite_Class.php new file mode 100644 index 00000000..06d9f54c --- /dev/null +++ b/Distro/tmp_serv/SQLite_Class.php @@ -0,0 +1,139 @@ +DBFILE=$DBFILE; + $this->DBFLAGS=$flags; + $this->DBENCRYPT=$encryptionKey; + try{ + $this->DBLink = new SQLite3( $this->DBFILE, $this->DBFLAGS, $this->DBENCRYPT ); + $this->DBLink->busyTimeout(5000); + // WAL mode has better control over concurrency. + // Source: https://www.sqlite.org/wal.html + $this->DBLink->exec('PRAGMA journal_mode = wal;'); + $this->isConnected = true; + }catch( Exception $e ){ + echo $e->getMessage(); + }; + } + function CleanUpCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_') && (time()-filemtime($CF))>360){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function ResetCache(){ + if ($DD=@opendir($this->CachePath)){ + while($FN=readdir($DD)){ + $CF=$this->CachePath.'/'.$FN; + if (is_file($CF)){ + if ( strstr($FN,'dbchache_')){ + @unlink($CF); + }; + }; + }; + closedir($DD); + } else $this->isCached=false; + } + function SetCacheDir($Path){ + $this->CachePath = $Path; + $this->isCached = is_dir($this->CachePath) && is_writable($this->CachePath); + if ($this->isCached) $this->CleanUpCache(); + } + function escape( $Str ){ + if( $this->isConnected ){ + return $this->DBLink->escapeString( $Str ); + }; + return ''; + } + function Query($QS,$ChacheIfAveable=true){ + if($this->isConnected){ + $QS = trim( $QS ); + if( $this->isCached && $ChacheIfAveable ){ + $QMD5=md5($QS); + $Prefetch=$this->CachePath.'/dbchache_'.$QMD5; + + if ( is_file($Prefetch)){ + + if ( (time()- filemtime($Prefetch))<360){ + $FData=file_get_contents($Prefetch); + $this->DebugLog .="[{$QS}] as (Cahed Data),\n"; + return unserialize($FData); + } else { + + $result = $this->DBLink->query( $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + if( ( stripos( $QS, 'insert' ) === false ) && ( stripos( $QS, 'update' ) === false ) && $result !== false && is_a( $result, 'SQLite3Result' ) ){ + while( $array = $result->fetchArray( SQLITE3_ASSOC )) $RetVal[]=$array; + $result->finalize(); + }; + $FData=serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + $this->DebugLog .="[{$QS}] as (".$this->DBLink->lastInsertRowID()."),\n"; + return $RetVal; + } + } else { + $result = $this->DBLink->query( $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + if( ( stripos( $QS, 'insert' ) === false ) && ( stripos( $QS, 'update' ) === false ) && $result !== false && is_a( $result, 'SQLite3Result' ) ){ + while( $array = $result->fetchArray( SQLITE3_ASSOC )) $RetVal[]=$array; + $result->finalize(); + }; + $FData = serialize($RetVal); + $FD=fopen($Prefetch,'w'); + fwrite($FD,$FData); + fclose($FD); + $this->DebugLog .="[{$QS}] as (".$this->DBLink->lastInsertRowID()."),\n"; + return $RetVal; + } + } else { + $result = $this->DBLink->query( $QS ) or die (" Error during query [$QS]:".mysqli_error($this->DBLink)); + $RetVal=array(); + if( ( stripos( $QS, 'insert' ) === false ) && ( stripos( $QS, 'update' ) === false ) && $result !== false && is_a( $result, 'SQLite3Result' ) ){ + while( $array = $result->fetchArray( SQLITE3_ASSOC )) $RetVal[]=$array; + $result->finalize(); + }; + $this->DebugLog .="[{$QS}] as (".$this->DBLink->lastInsertRowID()."),\n"; + return $RetVal; + }; + } else { + echo "No Connection to DB
"; + }; + } + function getLastInsertID(){ + if($this->isConnected){ + return $this->DBLink->lastInsertRowID(); + }; + return -1; + } + function getDebugLog(){ + return $this->DebugLog; + } + function __destruct(){ + if( $this->isConnected ){ + $this->DBLink->close(); + unset( $this->DBLink ); + }; + } +} + + + + +?> \ No newline at end of file diff --git a/Distro/tmp_serv/after.php b/Distro/tmp_serv/after.php new file mode 100644 index 00000000..d57e0a39 --- /dev/null +++ b/Distro/tmp_serv/after.php @@ -0,0 +1,48 @@ +$Value ){ + if( $Key != 'id' ){ + $POPIN[]="`".$Key."`='".$Value."'"; + }; + }; + $QS = "UPDATE `{$B}` SET ". implode(",",$POPIN)." WHERE `id`=" . $C['id']; + out_log( $QS ); + $A->Query( $QS ); + }; + function restore_line( $A, $B , $C ){ + foreach( $C as $Key=>$Value ){ + if( $Key != 'id' ){ + $P="`".$Key."`='".$Value."'"; + $QS = "UPDATE `{$B}` SET ".$P." WHERE `id`=" . $C['id']; + out_log( $QS ); + $A->Query( $QS ); + }; + }; + }; + run_command( 'systemctl start argus_nginx'); + //run_command( 'systemctl enable argus_nginx'); + //run_command( 'systemctl enable argus_shutdown'); + run_command( 'systemctl start nginx'); +?> diff --git a/Distro/tmp_serv/before.php b/Distro/tmp_serv/before.php new file mode 100644 index 00000000..c3ce5968 --- /dev/null +++ b/Distro/tmp_serv/before.php @@ -0,0 +1,70 @@ + '4' ){ + require_once( $WDIR . '/MySQLi_class.php' ); + $INS_TIME_DB = new MySQLi_DB($DBHost, $DBName, $DBUser, $DBPassword); + }; + if( $INS_TIME_DB !== false ){ + out_log("Old Database Exists!"); + $QS="SELECT * FROM `users`"; + $USERS_SETTINGS = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `system_props`"; + $SYSTEM_SETTINGS = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_lines`"; + $TOPOLOGY_SETTINGS['metro_lines'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_stations`"; + $TOPOLOGY_SETTINGS['metro_stations'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_platforms`"; + $TOPOLOGY_SETTINGS['metro_platforms'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_tracks`"; + $TOPOLOGY_SETTINGS['metro_tracks'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_modules`"; + $TOPOLOGY_SETTINGS['metro_modules'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_platforms_2_lines`"; + $TOPOLOGY_SETTINGS['metro_platforms_2_lines'] = $INS_TIME_DB->Query( $QS ); + $QS="SELECT * FROM `metro_stations_2_lines`"; + $TOPOLOGY_SETTINGS['metro_stations_2_lines'] = $INS_TIME_DB->Query( $QS ); + unset( $INS_TIME_DB ); + out_log("Old Settings Read!"); + }; + //Web Interface + run_command( 'rm -R -f /srv/www' ); + //$CC = `rm -R -f /srv/www/web/style`; + //$CC = `rm -R -f /srv/www/web/lib/controller/data/uploads`; + //$CC = `rm -R -f /srv/www/web/lib/controller/dash`; + //$CC = `rm -R -f /srv/www/web/lib/controller/props`; + //$CC = `rm -R -f /srv/www/web/lib/controller/report`; + //$CC = `rm -f /srv/www/web/lib/controller/*.php`;//*/ + //$CC = `rm -R -f /srv/www/web/lib/javascript`; + //$CC = `rm -R -f /srv/www/web/lib/php`; + //Control Panel + //$CC = `rm -R -f /srv/www/distro`; + + //Application + run_command( 'rm -R -f /srv/serva' ); + run_command( 'rm -R -f /srv/start' ); + //Settings + run_command( 'rm -R -f /srv/etc' ); + run_command( 'rm -R -f /srv/scripts' ); + sleep( 5 ); +?> diff --git a/Distro/tmp_serv/inst_lib.php b/Distro/tmp_serv/inst_lib.php new file mode 100644 index 00000000..0371fcf1 --- /dev/null +++ b/Distro/tmp_serv/inst_lib.php @@ -0,0 +1,341 @@ +array( 'id'=>1, 'identity'=>'3638eedfe4370b4b53285ae524b88343', 'site_id'=>1 ), + 'nodes'=>array(), + 'resources'=>array(), + 'sensors'=>array(), + 'cameras'=>array(), + 'modules'=>array(), + 'filters'=>array(), + 'system_props'=>array(), + 'users'=>array() + ); + $fid = fopen( '/srv/mojo/server.conf', "r" ); + if( $fid !== false ){ + while( !feof( $fid ) ){ + $CL = trim( fgets( $fid ) ); + $CL = str_replace( ' ', '', $CL ); + $CL = str_replace( '"', '', $CL ); + $CL = str_replace( ';', '', $CL ); + $TArr = explode('=', $CL ); + if( stripos( $CL, 'IDENTITY' ) !== false ){ + $DATA['server']['identity'] = $TArr[1]; + }; + if( stripos( $CL, 'SITE_ID' ) !== false ){ + $DATA['server']['site_id'] = $TArr[1]; + }; + }; + fclose( $fid ); + }; + $DB = new SQLite_DB('/srv/www/web/lib/controller/data/mysqlitedb.db'); + $QS = "SELECT * FROM `nodes`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + $DATA['nodes'][] = $CN; + }; + $QS = "SELECT * FROM `resources`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + switch( $CN['type'] ){ + case 1:{ + $QS = "SELECT * FROM `uart_settings` WHERE `id`={$CN['aux_id']}"; + $J = $DB->Query( $QS ); + $PP = array(); + foreach( $J[0] as $l=>$v ) $PP[$l]=$v; + $CN['private'] = $PP; + }; + }; + $DATA['resources'][] = $CN; + }; + $QS = "SELECT * FROM `cameras`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + $QS = "SELECT * FROM `media_streams` WHERE `source_id`={$CN['id']}"; + $CN['streams'] = $DB->Query( $QS ); + $DATA['cameras'][] = $CN; + }; + $QS = "SELECT * FROM `lrf_sensors`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + $QS = "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`={$CN['id']}"; + $CN['private'] = $DB->Query( $QS ); + $DATA['sensors'][] = $CN; + }; + $QS = "SELECT * FROM `modules`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + switch( $CN['type'] ){ + case 8:{ + $PP = array(); + $QS = "SELECT * FROM `module_eve` WHERE `id`={$CN['aux_id']}"; + $K = $DB->Query( $QS ); + $PP = $K[0]; + $CN['private'] = $PP; + break; + }; + }; + $DATA['modules'][] = $CN; + }; + $QS = "SELECT * FROM `target_filters`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + switch( $CN['type'] ){ + case 1:{ + $PP = array(); + $QS = "SELECT * FROM `target_filter_train` WHERE `id`={$CN['aux_id']}"; + $K = $DB->Query( $QS ); + $PP = $K[0]; + $CN['private'] = $PP; + break; + }; + }; + $DATA['filters'][] = $CN; + }; + $QS = "SELECT * FROM `system_props`"; + $R = $DB->Query( $QS ); + $DATA['system_props'] = $R[0]; + $QS = "SELECT * FROM `users`"; + $R = $DB->Query( $QS ); + foreach( $R as $T ){ + if( $T['id'] > 1 ){ + $CN = array(); + foreach( $T as $key=>$val ) $CN[$key] = $val; + $DATA['users'][] = $CN; + }; + }; + unset( $DB ); + return json_encode( $DATA ); +}; + +function ap_application_config( $A, $DBF ){ + $DB = new SQLite_DB( $DBF ); + $DATA = json_decode( $A, true ); + foreach( $DATA as $Key=>$Val ){ + switch( $Key ){ + case 'users':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `users`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + }; + break; + }; + case 'server':{ + foreach( $Val as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `servers`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + break; + }; + case 'nodes':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `nodes`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + }; + break; + }; + case 'resources':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + if( $A!='private' ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + }; + $QS = "INSERT INTO `resources`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + switch( $T['type'] ){ + case 1:{ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T['private'] as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `uart_settings`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + break; + }; + }; + }; + break; + }; + case 'sensors':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + if( $A!='private' ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + }; + $QS = "INSERT INTO `lrf_sensors`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + if( count( $T['private'] ){ + foreach( $T['private'] as $P ){ + foreach( $P as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `lrf_detection_profiles`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + }; + }; + }; + break; + }; + case 'cameras':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + if( $A!='streams' ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + }; + $QS = "INSERT INTO `cameras`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + foreach( $T['streams'] as $S ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $S as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `media_streams`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + }; + }; + break; + }; + case 'modules':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + if( $A!='private' ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + }; + $QS = "INSERT INTO `modules`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + switch( $T['type'] ){ + case 8:{ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T['private'] as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `module_eve`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + break; + }; + }; + }; + break; + }; + case 'filters':{ + foreach( $Val as $T ){ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T as $A=>$B ){ + if( $A!='private' ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + }; + $QS = "INSERT INTO `target_filters`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + switch( $T['type'] ){ + case 1:{ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $T['private'] as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `target_filter_train`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + break; + }; + }; + }; + break; + }; + case 'system_props':{ + $flds = array(); + $values = array(); + $updates = array(); + foreach( $Val as $A=>$B ){ + $flds[] = "`{$A}`"; + $values[]="'{$B}'"; + if( $A!='id' ) $updates[] = "`{$A}`='{$B}'"; + }; + $QS = "INSERT INTO `system_props`(" . implode( ',', $flds ).") VALUES (".implode( ',', $values ).") ON CONFLICT(`id`) DO UPDATE SET ".implode( ',', $updates ); + $DB->Query( $QS ); + break; + }; + }; + }; + unset( $DB ); +}; + + +?> \ No newline at end of file