Changeset 852
- Timestamp:
- Oct 25, 2017, 10:55:05 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Install/deb/debian/control
r850 r852 8 8 Package: centrala 9 9 Architecture: all 10 Depends: ${shlibs:Depends}, ${misc:Depends}, apache2, php, dbconfig-mysql, fping, htmldoc 10 Depends: ${shlibs:Depends}, ${misc:Depends}, apache2, php, dbconfig-mysql, fping, htmldoc, php-mbstring 11 11 Description: User portal and network administration web system 12 12 HomePage: http://svn.zdechov.net/trac/centrala -
trunk/Modules/NetworkConfigLinux/Generators/Latency.php
r842 r852 22 22 exec('fping -e -r '.$RetryLimit.' -t '.$Timeout.' -a '.implode(' ', $Hosts).' 2>/dev/null', $Output); 23 23 24 $this->Database->query('BEGIN'); 25 foreach($Output as $Index => $Line) { 24 $Queries = array(); 25 foreach($Output as $Index => $Line) 26 { 26 27 $IP = substr($Line, 0, strPos($Line, ' ')); 27 28 $Line = substr($Line, strpos($Line, '(') + 1); 28 29 $Value = substr($Line, 0, strpos($Line, ' ')); 29 30 //echo($IP.' '.$Value."\n"); 30 $ this->Database->insert('NetworkInterfaceLatency', array('Interface' => $HostInterface[$IP],31 $Queries[] = $this->Database->GetInsert('NetworkInterfaceLatency', array('Interface' => $HostInterface[$IP], 31 32 'Value' => $Value, 'Time' => TimeToMysqlDateTime($Time))); 32 33 } 33 $this->Database-> query('COMMIT');34 $this->Database->Transaction($Queries); 34 35 } 35 36 -
trunk/Modules/NetworkConfigRouterOS/Generators/NetwatchImport.php
r841 r852 42 42 } 43 43 44 $this->Database->query('BEGIN'); 45 44 $Queries = array(); 46 45 foreach($Interfaces as $Index => $Interface) 47 46 { 48 47 // Update last online time if still online 49 48 if($Interface['NewOnline']) 50 $ DbResult = $this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',49 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = "'.$Interface['Id'].'"', 51 50 array('LastOnline' => TimeToMysqlDateTime($StartTime))); 52 51 … … 54 53 { 55 54 // Online state changed 56 $ DbResult = $this->Database->query('INSERT INTO `NetworkInterfaceUpDown` (`Interface`,55 $Queries[] = 'INSERT INTO `NetworkInterfaceUpDown` (`Interface`, 57 56 `State`, `Time`, `Duration`) VALUES ('.$Interface['Id'].', '.$Interface['NewOnline'].', "'. 58 TimeToMysqlDateTime($StartTime).'", NULL)' );57 TimeToMysqlDateTime($StartTime).'", NULL)'; 59 58 // Update previous record duration in UpDown table 60 $ this->Database->query('UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '.59 $Queries[] = 'UPDATE `NetworkInterfaceUpDown` AS `TM` SET `Duration` = TIMESTAMPDIFF(SECOND, '. 61 60 '`TM`.`Time`, (SELECT `Time` FROM (SELECT * FROM `NetworkInterfaceUpDown`) AS `TA` WHERE (`TA`.`Time` > `TM`.`Time`) '. 62 61 'AND (`TA`.`Interface`=`TM`.`Interface`) ORDER BY `TA`.`Time` ASC LIMIT 1)) '. 63 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')' );64 $ this->Database->update('NetworkInterface', '`Id` = "'.$Interface['Id'].'"',62 'WHERE (`TM`.`Duration` IS NULL) AND (`TM`.`Interface` ='.$Interface['Id'].')'; 63 $Queries[] = $this->Database->GetUpdate('NetworkInterface', '`Id` = "'.$Interface['Id'].'"', 65 64 array('Online' => $Interface['NewOnline'])); 66 65 } 67 66 } 67 $this->Database->Transaction($Queries); 68 68 69 69 // Set offline all interfaces which were not updated as online … … 81 81 } 82 82 83 $Queries = array(); 83 84 // Update device online state 84 85 $DbResult = $this->Database->select('NetworkInterface', '`Device`, SUM(`Online`) AS `SumOnline`', '`Online` = 1 GROUP BY `Device`'); … … 86 87 { 87 88 if($Device['SumOnline'] > 0) 88 $ this->Database->update('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1));89 $Queries[] = $this->Database->GetUpdate('NetworkDevice', 'Id='.$Device['Device'], array('LastOnline' => TimeToMysqlDateTime($StartTime), 'Online' => 1)); 89 90 } 90 $this->Database->update('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0)); 91 92 $this->Database->query('COMMIT'); 91 $Queries[] = $this->Database->GetUpdate('NetworkDevice', '`LastOnline` < "'.TimeToMysqlDateTime($StartTime).'"', array('Online' => 0)); 92 $this->Database->Transaction($Queries); 93 93 } 94 94 -
trunk/Packages/Common/Database.php
r851 r852 3 3 // Extended database class 4 4 // Date: 2016-01-11 5 6 function microtime_float() 7 { 8 list($usec, $sec) = explode(" ", microtime()); 9 return ((float)$usec + (float)$sec); 10 } 5 11 6 12 class DatabaseResult … … 51 57 $this->LogFile = dirname(__FILE__).'/../../Query.log'; 52 58 } 59 53 60 54 61 function Connect($Host, $User, $Password, $Database) … … 85 92 { 86 93 if(!$this->Connected()) throw new Exception(T('Not connected to database')); 87 if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime ();94 if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float(); 88 95 $this->LastQuery = $Query; 96 //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float()); 89 97 if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) 90 $Duration = ' ; '.round(microtime () - $QueryStartTime, 4). ' s';98 $Duration = ' ; '.round(microtime_float() - $QueryStartTime, 4). ' s'; 91 99 if($this->LogSQLQuery == true) 92 100 file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND); … … 123 131 function insert($Table, $Data) 124 132 { 133 $this->query($this->GetInsert($Table, $Data)); 134 $this->insert_id = $this->PDO->lastInsertId(); 135 } 136 137 function GetInsert($Table, $Data) 138 { 125 139 $Name = ''; 126 140 $Values = ''; … … 137 151 $Name = substr($Name, 1); 138 152 $Values = substr($Values, 1); 139 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 140 $this->insert_id = $this->PDO->lastInsertId(); 153 return('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 141 154 } 142 155 143 156 function update($Table, $Condition, $Data) 157 { 158 $this->query($this->GetUpdate($Table, $Condition, $Data)); 159 } 160 161 function GetUpdate($Table, $Condition, $Data) 144 162 { 145 163 $Values = ''; … … 154 172 } 155 173 $Values = substr($Values, 2); 156 //echo('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 157 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 174 return('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')'); 158 175 } 159 176
Note:
See TracChangeset
for help on using the changeset viewer.