Changeset 873 for trunk/Modules/NetworkConfigRouterOS/Routerboard.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/Routerboard.php
r860 r873 22 22 { 23 23 $Output = array(); 24 if (is_array($Commands))24 if (is_array($Commands)) 25 25 { 26 26 $I = 0; 27 27 $Batch = array(); 28 while ($I < count($Commands))29 { 30 if (($I % $this->MaxBurstLineCount) == 0)31 { 32 if (count($Batch) > 0)28 while ($I < count($Commands)) 29 { 30 if (($I % $this->MaxBurstLineCount) == 0) 31 { 32 if (count($Batch) > 0) 33 33 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 34 34 $Batch = array(); … … 37 37 $I++; 38 38 } 39 if (count($Batch) > 0)39 if (count($Batch) > 0) 40 40 $Output = array_merge($Output, $this->ExecuteBatch(implode(';', $Batch))); 41 41 } else 42 42 $Output = array_merge($Output, $this->ExecuteBatch($Commands)); 43 return ($Output);43 return ($Output); 44 44 } 45 45 … … 47 47 { 48 48 $Commands = trim($Commands); 49 if ($Commands != '')49 if ($Commands != '') 50 50 { 51 51 $Commands = addslashes($Commands); … … 57 57 $Command = $this->SSHPath.' -oBatchMode=no -o ConnectTimeout='.$this->Timeout.' -l '.$this->UserName. 58 58 $PrivKey.' '.$this->HostName.' "'.$Commands.'"'; 59 if ($this->Debug) echo($Command);59 if ($this->Debug) echo($Command); 60 60 $Output = array(); 61 61 exec($Command, $Output); 62 62 } else $Output = ''; 63 if ($this->Debug) print_r($Output);64 return ($Output);63 if ($this->Debug) print_r($Output); 64 return ($Output); 65 65 } 66 66 … … 70 70 array_pop($Result); 71 71 $List = array(); 72 foreach ($Result as $ResultLine)72 foreach ($Result as $ResultLine) 73 73 { 74 74 $ResultLineParts = explode(' ', trim($ResultLine)); 75 if (count($ResultLineParts) > 1)76 { 77 if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes75 if (count($ResultLineParts) > 1) 76 { 77 if ($ResultLineParts[1]{0} == '"') $ResultLineParts[1] = substr($ResultLineParts[1], 1, -1); // Remove quotes 78 78 $List[substr($ResultLineParts[0], 0, -1)] = $ResultLineParts[1]; 79 79 } else $List[substr($ResultLineParts[0], 0, -1)] = ''; 80 80 } 81 return ($List);81 return ($List); 82 82 } 83 83 … … 85 85 { 86 86 $PropertyList = '"'; 87 foreach ($Properties as $Index => $Property)87 foreach ($Properties as $Index => $Property) 88 88 { 89 89 $PropertyList .= $Index.'=".[get $i '.$Property.']." '; … … 92 92 93 93 $ConditionList = ''; 94 foreach ($Conditions as $Index => $Item)95 { 96 if ($Item == 'no') $ConditionList .= $Index.'='.$Item.' ';94 foreach ($Conditions as $Index => $Item) 95 { 96 if ($Item == 'no') $ConditionList .= $Index.'='.$Item.' '; 97 97 else $ConditionList .= $Index.'="'.$Item.'" '; 98 98 } … … 101 101 $Result = $this->Execute(implode(' ', $Path).' {:foreach i in=[find '.$ConditionList.'] do={:put ('.$PropertyList.')}}'); 102 102 $List = array(); 103 foreach ($Result as $ResultLine)103 foreach ($Result as $ResultLine) 104 104 { 105 105 $ResultLineParts = explode(' ', $ResultLine); 106 106 $ListItem = array(); 107 foreach ($ResultLineParts as $ResultLinePart)107 foreach ($ResultLineParts as $ResultLinePart) 108 108 { 109 109 $Value = explode('=', $ResultLinePart); 110 if (count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1];110 if (count($Value) > 1) $ListItem[$Properties[$Value[0]]] = $Value[1]; 111 111 else $ListItem[$Properties[$Value[0]]] = ''; 112 112 } 113 113 $List[] = $ListItem; 114 114 } 115 return ($List);115 return ($List); 116 116 } 117 117 … … 119 119 { 120 120 $ConditionList = ''; 121 foreach ($Conditions as $Index => $Item)121 foreach ($Conditions as $Index => $Item) 122 122 { 123 123 $ConditionList .= $Index.'="'.$Item.'" '; 124 124 } 125 125 $ConditionList = substr($ConditionList, 0, -1); 126 if (trim($ConditionList) != '')126 if (trim($ConditionList) != '') 127 127 $ConditionList = ' where '.$ConditionList; 128 128 129 129 $Result = $this->Execute(implode(' ', $Path).' print terse'.$ConditionList); 130 130 $List = array(); 131 foreach ($Result as $ResultLine)131 foreach ($Result as $ResultLine) 132 132 { 133 133 $ResultLineParts = explode(' ', $ResultLine); 134 134 $ListItem = array(); 135 foreach ($ResultLineParts as $ResultLinePart)135 foreach ($ResultLineParts as $ResultLinePart) 136 136 { 137 137 $Value = explode('=', $ResultLinePart); 138 if (in_array($Value[0], $Properties))139 { 140 if (count($Value) > 1)138 if (in_array($Value[0], $Properties)) 139 { 140 if (count($Value) > 1) 141 141 { 142 if ($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1);143 //if (strlen($Value[1]) > 0)142 if ($Value[1]{0} == '"') $Value[1] = substr($Value[1], 1, -1); 143 //if (strlen($Value[1]) > 0) 144 144 $ListItem[$Value[0]] = $Value[1]; 145 145 } else $ListItem[$Value[0]] = ''; 146 146 } 147 147 } 148 if (count($ListItem) > 0) $List[] = $ListItem;149 } 150 return ($List);148 if (count($ListItem) > 0) $List[] = $ListItem; 149 } 150 return ($List); 151 151 } 152 152 … … 159 159 { 160 160 // Get current list from routerboard 161 if ($UsePrint == 0)161 if ($UsePrint == 0) 162 162 { 163 163 $List = $this->ListGet($Path, $Properties, $Condition); 164 164 // Change boolean values yes/no to true/false 165 foreach ($List as $Index => $ListItem)166 { 167 foreach ($ListItem as $Index2 => $Item2)168 { 169 if ($Item2 == 'true') $List[$Index][$Index2] = 'yes';170 if ($Item2 == 'false') $List[$Index][$Index2] = 'no';165 foreach ($List as $Index => $ListItem) 166 { 167 foreach ($ListItem as $Index2 => $Item2) 168 { 169 if ($Item2 == 'true') $List[$Index][$Index2] = 'yes'; 170 if ($Item2 == 'false') $List[$Index][$Index2] = 'no'; 171 171 } 172 172 } … … 178 178 179 179 // Add empty properties to values 180 foreach ($Values as $Index => $Item)181 { 182 foreach ($Properties as $Property)183 { 184 if (!array_key_exists($Property, $Item))180 foreach ($Values as $Index => $Item) 181 { 182 foreach ($Properties as $Property) 183 { 184 if (!array_key_exists($Property, $Item)) 185 185 $Item[$Property] = ''; 186 186 } 187 187 $Values[$Index] = $Item; 188 188 } 189 foreach ($List as $Index => $Item)190 { 191 foreach ($Properties as $Property)192 { 193 if (!array_key_exists($Property, $Item))189 foreach ($List as $Index => $Item) 190 { 191 foreach ($Properties as $Property) 192 { 193 if (!array_key_exists($Property, $Item)) 194 194 $Item[$Property] = ''; 195 195 } … … 198 198 199 199 // Sort properties 200 foreach ($Values as $Index => $Item)200 foreach ($Values as $Index => $Item) 201 201 { 202 202 ksort($Values[$Index]); 203 203 } 204 foreach ($List as $Index => $Item)204 foreach ($List as $Index => $Item) 205 205 { 206 206 ksort($List[$Index]); 207 207 } 208 if ($this->Debug) print_r($List);209 if ($this->Debug) print_r($Values);208 if ($this->Debug) print_r($List); 209 if ($this->Debug) print_r($Values); 210 210 211 211 // Erase all items not existed in $Values 212 foreach ($List as $Index => $ListItem)213 { 214 if (!in_array($ListItem, $Values))212 foreach ($List as $Index => $ListItem) 213 { 214 if (!in_array($ListItem, $Values)) 215 215 { 216 216 $Prop = ''; 217 foreach ($ListItem as $Index => $Property)218 { 219 if ($Property != '')217 foreach ($ListItem as $Index => $Property) 218 { 219 if ($Property != '') 220 220 { 221 if (($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' ';221 if (($Property == 'yes') or ($Property == 'no')) $Prop .= $Index.'='.$Property.' '; 222 222 else $Prop .= $Index.'="'.$Property.'" '; 223 223 } 224 224 } 225 225 $Prop = substr($Prop, 0, -1); 226 if (trim($Prop) != '')226 if (trim($Prop) != '') 227 227 $Commands[] = implode(' ', $Path).' remove [find '.$Prop.']'; 228 228 } … … 230 230 231 231 // Add new items 232 foreach ($Values as $ListItem)233 { 234 if (!in_array($ListItem, $List))232 foreach ($Values as $ListItem) 233 { 234 if (!in_array($ListItem, $List)) 235 235 { 236 236 $Prop = ''; 237 foreach ($ListItem as $Index => $Property)238 { 239 if ($Property != '') $Prop .= $Index.'="'.$Property.'" ';237 foreach ($ListItem as $Index => $Property) 238 { 239 if ($Property != '') $Prop .= $Index.'="'.$Property.'" '; 240 240 } 241 241 $Prop = substr($Prop, 0, -1); … … 243 243 } 244 244 } 245 if ($this->Debug) print_r($Commands);246 return ($this->Execute($Commands));245 if ($this->Debug) print_r($Commands); 246 return ($this->Execute($Commands)); 247 247 } 248 248 }
Note:
See TracChangeset
for help on using the changeset viewer.