Browse Source

Addidng some stuff for Server Package Creation Script

pull/7/head
Evgeny Gagua 9 months ago
parent
commit
b8875faf61
  1. 119
      Distro/tmp_serv/MySQL_class.php
  2. 150
      Distro/tmp_serv/MySQLi_class.php
  3. 139
      Distro/tmp_serv/SQLite_Class.php
  4. 48
      Distro/tmp_serv/after.php
  5. 70
      Distro/tmp_serv/before.php
  6. 341
      Distro/tmp_serv/inst_lib.php

119
Distro/tmp_serv/MySQL_class.php

@ -0,0 +1,119 @@
<?php
class MySQL_DB{
var $DBHost;
var $DBName;
var $DBUser;
var $DBPassword;
var $DBLink;
var $CachePath;
var $isConnected=false;
var $isCached=false;
function MySQL_DB( $Host,$Name,$User,$Password){
$this->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!!<br>";
}
}
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<br>";
}
}
function getLastInsertID(){
if($this->isConnected){
return mysql_insert_id( $this->DBLink );
};
return -1;
}
function __destruct(){
mysql_close($this->DBLink);
}
}
?>

150
Distro/tmp_serv/MySQLi_class.php

@ -0,0 +1,150 @@
<?php
class MySQLi_DB{
var $DBHost;
var $DBName;
var $DBUser;
var $DBPassword;
var $DBLink;
var $CachePath;
var $isConnected=false;
var $isCached=false;
function MySQLi_DB( $Host, $Name, $User, $Password, $DBCREATE = false ){
$this->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<br>";
};
}
function getLastInsertID(){
if($this->isConnected){
return $this->DBLink->insert_id;
};
return -1;
}
function __destruct(){
if( $this->isConnected ){
$this->DBLink->close();
};
}
}
?>

139
Distro/tmp_serv/SQLite_Class.php

@ -0,0 +1,139 @@
<?php
class SQLite_DB{
var $DBFILE;
var $DBFLAGS;
var $DBENCRYPT;
var $DBLink;
var $CachePath;
var $isConnected=false;
var $isCached=false;
var $DebugLog = '';
function __construct( $DBFILE, $flags = SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $encryptionKey = "" ){
$this->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<br>";
};
}
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 );
};
}
}
?>

48
Distro/tmp_serv/after.php

@ -0,0 +1,48 @@
<?php
// require_once( $WDIR . '/inst_lib.php');
echo "\n\n\nAFTER!!\n\n\n";
$DBHost="localhost";
$DBName="argus";
$DBUser="argus";
$DBPassword="Jc8zYWEhqGAGGYJRum92tm";
run_command( 'cp -f /srv/etc/ag_nginx/argus_nginx.service /etc/systemd/system/argus_nginx.service');
run_command( 'cp -f /srv/etc/argus_shutdown.service /etc/systemd/system/argus_shutdown.service');
run_command( 'systemctl enable argus_nginx');
run_command( 'systemctl enable argus_shutdown');
run_command( 'systemctl daemon-reload');
run_command( 'cp -f /srv/etc/nginx/default /etc/nginx/sites-available/default');
run_command( 'cp -f /srv/etc/rc.local /etc/rc.local');
run_command( 'chown -R www-data:www-data /srv/data');
run_command( 'chmod -R 0775 /srv/data');
run_command( 'ln -s /srv/data /srv/serva/data');
run_command( 'ln -s /srv/data /srv/www/web/lib/controller/data');
//Restore Settings
function restore_whole_line( $A, $B , $C ){
$POPIN = array();
foreach( $C as $Key=>$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');
?>

70
Distro/tmp_serv/before.php

@ -0,0 +1,70 @@
<?php
echo "\n\n\nBEFORE\n\n\n";
$DBHost="localhost";
$DBName="argus";
$DBUser="argus";
$DBPassword="Jc8zYWEhqGAGGYJRum92tm";
run_command( 'systemctl stop argus_nginx');
run_command( 'systemctl stop nginx');
run_command( 'killall -s 9 starProcDaemon -q');
run_command( 'killall -s 9 serva -q');
run_command( 'killall -s 9 serva_d -q' );
sleep( 3 );
//Try Save Settings
$USERS_SETTINGS=array();
$SYSTEM_SETTINGS=array();
$TOPOLOGY_SETTINGS=array();
$INS_TIME_DB = false;
$TT_123 = explode( '.', PHP_VERSION );
if( $TT_123[0] == '4' ){
require_once( $WDIR . '/MySQL_class.php' );
$INS_TIME_DB = new MySQL_DB($DBHost, $DBName, $DBUser, $DBPassword);
} elseif( $TT_123[0] > '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 );
?>

341
Distro/tmp_serv/inst_lib.php

@ -0,0 +1,341 @@
<?php
function ps_current_application_config(){
$DATA = array(
'server'=>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 );
};
?>
Loading…
Cancel
Save