Changeset 240 for trunk/system/routerboard.php
- Timestamp:
- Aug 2, 2009, 12:19:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/routerboard.php
r239 r240 9 9 var $Password; 10 10 var $PrivateKey = 'id_dsa'; 11 var $MaxBurstLineCount = 100; 11 12 12 13 function __construct($HostName = 'localhost', $UserName = 'admin', $Password = '') … … 18 19 19 20 function Execute($Commands) 21 { 22 $Output = array(); 23 if(is_array($Commands)) 24 { 25 $I = 0; 26 $Batch = array(); 27 while($I < count($Commands)) 28 { 29 if(($I % $this->MaxBurstLineCount) == 0) 30 { 31 if(count($Batch) > 0) 32 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 33 $Batch = array(); 34 } 35 $Batch[] = $Commands[$I]; 36 $I++; 37 } 38 if(count($Batch) > 0) 39 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 40 } else 41 $Output = array_merge($Output, $this->ExecuteBatch($Commands)); 42 return($Output); 43 } 44 45 function ExecuteBatch($Commands) 20 46 { 21 if(is_array($Commands)) $Commands = implode(';', $Commands);22 47 $Commands = trim($Commands); 23 48 if($Commands != '') … … 27 52 $Commands = str_replace('$', '\$', $Commands); 28 53 $Command = $this->SSHPath.' -o ConnectTimeout='.$this->Timeout.' -l '.$this->UserName.' -i '.$this->PrivateKey.' '.$this->HostName.' "'.$Commands.'"'; 29 //echo($Command);54 echo($Command); 30 55 exec($Command, $Output); 31 56 } else $Output = ''; 32 //print_r($Output);57 print_r($Output); 33 58 return($Output); 34 59 } … … 76 101 { 77 102 $Value = explode('=', $ResultLinePart); 78 $ListItem[$Properties[$Value[0]]] = $Value[1]; 103 if(count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1]; 104 else $ListItem[$Properties[$Value[0]]] = ''; 79 105 } 80 106 $List[] = $ListItem; … … 91 117 { 92 118 $List = $this->ListGet($Path, $Properties, $Condition); 93 //print_r($List);94 //print_r($Values);95 119 $Commands = array(); 120 121 // Add empty properties to values 122 foreach($Values as $Index => $Item) 123 { 124 foreach($Properties as $Property) 125 { 126 if(!array_key_exists($Property, $Item)) 127 $Item[$Property] = ''; 128 } 129 $Values[$Index] = $Item; 130 } 131 132 print_r($List); 133 print_r($Values); 96 134 97 135 // Erase all items not existed in $Values … … 103 141 foreach($ListItem as $Index => $Property) 104 142 { 105 $Prop .= $Index.'="'.$Property.'" ';143 if($Property != '') $Prop .= $Index.'="'.$Property.'" '; 106 144 } 107 145 $Prop = substr($Prop, 0, -1); … … 118 156 foreach($ListItem as $Index => $Property) 119 157 { 120 $Prop .= $Index.'='.$Property.'';158 if($Property != '') $Prop .= $Index.'="'.$Property.'" '; 121 159 } 122 160 $Prop = substr($Prop, 0, -1); … … 124 162 } 125 163 } 126 //print_r($Commands);164 print_r($Commands); 127 165 return($this->Execute($Commands)); 128 166 }
Note:
See TracChangeset
for help on using the changeset viewer.