Revision f21d4f79
Added by Viktor Gurov almost 5 years ago
src/usr/local/www/diag_backup.php | ||
---|---|---|
121 | 121 |
} |
122 | 122 |
} |
123 | 123 |
|
124 |
function voucher_data_xml($tab=false) { |
|
125 |
global $g; |
|
126 |
|
|
127 |
$voucher_files = glob("{$g['vardb_path']}/voucher_*.db"); |
|
128 |
if (empty($voucher_files)) { |
|
129 |
return; |
|
130 |
} |
|
131 |
$t = ($tab) ? "\t" : ""; |
|
132 |
$result = "\t<voucherdata>\n"; |
|
133 |
foreach ($voucher_files as $voucher_file) { |
|
134 |
$basename = basename($voucher_file); |
|
135 |
$db_data = file_get_contents($voucher_file); |
|
136 |
if ($db_data !== false) { |
|
137 |
$result .= "{$t}\t\t<voucherdbfile>\n"; |
|
138 |
$result .= "{$t}\t\t\t<filename>{$basename}</filename>\n"; |
|
139 |
$result .= "{$t}\t\t\t<dbdata>" . base64_encode(gzdeflate($db_data)) . "</dbdata>\n"; |
|
140 |
$result .= "{$t}\t\t</voucherdbfile>\n"; |
|
141 |
} |
|
142 |
} |
|
143 |
$result .= "{$t}\t</voucherdata>\n"; |
|
144 |
|
|
145 |
return $result; |
|
146 |
} |
|
147 |
|
|
148 |
function restore_voucher_data() { |
|
149 |
global $config, $g; |
|
150 |
foreach ($config['voucher']['voucherdata']['voucherdbfile'] as $db) { |
|
151 |
$voucherdb_file = "{$g['vardb_path']}/{$db['filename']}"; |
|
152 |
if (file_put_contents($voucherdb_file, gzinflate(base64_decode($db['dbdata']))) === false) { |
|
153 |
log_error(sprintf(gettext("Cannot write %s"), $voucherdb_file)); |
|
154 |
continue; |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
124 | 159 |
function remove_bad_chars($string) { |
125 | 160 |
return preg_replace('/[^a-z_0-9]/i', '', $string); |
126 | 161 |
} |
... | ... | |
187 | 222 |
} else if ($_POST['backuparea'] === "rrddata") { |
188 | 223 |
$data = rrd_data_xml(); |
189 | 224 |
$name = "{$_POST['backuparea']}-{$name}"; |
225 |
} else if ($_POST['backuparea'] === "voucher") { |
|
226 |
$data = backup_config_section($_POST['backuparea']); |
|
227 |
$voucher_data_xml = voucher_data_xml(); |
|
228 |
$closing_tag = "</voucher>"; |
|
229 |
$data = str_replace($closing_tag, $voucher_data_xml . $closing_tag, $data); |
|
230 |
$name = "{$_POST['backuparea']}-{$name}"; |
|
190 | 231 |
} else { |
191 | 232 |
/* backup specific area of configuration */ |
192 | 233 |
$data = backup_config_section($_POST['backuparea']); |
... | ... | |
206 | 247 |
$data = preg_replace("/[[:blank:]]*<rrddata>.*<\\/rrddata>[[:blank:]]*\n*/s", "", $data); |
207 | 248 |
$data = preg_replace("/[[:blank:]]*<rrddata\\/>[[:blank:]]*\n*/", "", $data); |
208 | 249 |
|
250 |
if (!$_POST['backuparea'] && !empty($config['voucher'])) { |
|
251 |
$voucher_data_xml = voucher_data_xml(true); |
|
252 |
$closing_tag = "</voucher>"; |
|
253 |
$data = str_replace($closing_tag, $voucher_data_xml . $closing_tag, $data); |
|
254 |
} |
|
255 |
|
|
209 | 256 |
if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) { |
210 | 257 |
$rrd_data_xml = rrd_data_xml(); |
211 | 258 |
$closing_tag = "</" . $g['xml_rootobj'] . ">"; |
... | ... | |
266 | 313 |
if (!restore_config_section($_POST['restorearea'], $data)) { |
267 | 314 |
$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located."); |
268 | 315 |
} else { |
269 |
if ($config['rrddata']) { |
|
270 |
restore_rrddata(); |
|
271 |
unset($config['rrddata']); |
|
316 |
if ($config['rrddata'] || $config['voucher']['voucherdata']) { |
|
317 |
if ($config['rrddata']) { |
|
318 |
restore_rrddata(); |
|
319 |
unset($config['rrddata']); |
|
320 |
write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea'])); |
|
321 |
} |
|
322 |
if (($_POST['restorearea'] == 'voucher') && $config['voucher']['voucherdata']) { |
|
323 |
restore_voucher_data(); |
|
324 |
unset($config['voucher']['voucherdata']); |
|
325 |
write_config(sprintf(gettext("Unset Voucher data from configuration after restoring %s configuration area"), $_POST['restorearea'])); |
|
326 |
} |
|
272 | 327 |
unlink_if_exists("{$g['tmp_path']}/config.cache"); |
273 |
write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea'])); |
|
274 | 328 |
convert_config(); |
275 | 329 |
} |
276 | 330 |
filter_configure(); |
... | ... | |
334 | 388 |
unset($loaderconf); |
335 | 389 |
} |
336 | 390 |
/* extract out rrd items, unset from $config when done */ |
337 |
if ($config['rrddata']) { |
|
338 |
restore_rrddata(); |
|
339 |
unset($config['rrddata']); |
|
391 |
if ($config['rrddata'] || $config['voucher']['voucherdata']) { |
|
392 |
if ($config['rrddata']) { |
|
393 |
restore_rrddata(); |
|
394 |
unset($config['rrddata']); |
|
395 |
} |
|
396 |
if ($config['voucher']['voucherdata']) { |
|
397 |
restore_voucher_data(); |
|
398 |
unset($config['voucher']['voucherdata']); |
|
399 |
} |
|
400 |
write_config(gettext("Unset RRD and Voucher data from configuration after full restore.")); |
|
340 | 401 |
unlink_if_exists("{$g['tmp_path']}/config.cache"); |
341 |
write_config(gettext("Unset RRD data from configuration after restoring full configuration")); |
|
342 | 402 |
convert_config(); |
343 | 403 |
} |
344 | 404 |
if ($m0n0wall_upgrade == true) { |
Also available in: Unified diff
Active voucher restore from backup. Implements #3128