Revision a1aa91de
Added by Steve Beaver almost 7 years ago
src/etc/inc/config.lib.inc | ||
---|---|---|
545 | 545 |
} |
546 | 546 |
|
547 | 547 |
// Try the core AutoConfigBackup system |
548 |
if (is_array($config['system']['acb']) && $config['system']['acb']['enable'] == "yes") { |
|
548 |
if (is_array($config['system']['acb']) && $config['system']['acb']['enable'] == "yes" && |
|
549 |
(!isset($config['system']['acb']['frequency']) || $config['system']['acb']['frequency'] == "every") || file_exists("/tmp/forceacb")) { |
|
549 | 550 |
require_once("acb.inc"); |
550 | 551 |
upload_config(); |
552 |
if (file_exists("/tmp/forceacb")) { |
|
553 |
unlink("/tmp/forceacb"); |
|
554 |
} |
|
551 | 555 |
} |
552 | 556 |
|
553 | 557 |
return $config; |
src/usr/local/sbin/execacb.php | ||
---|---|---|
1 |
<?php |
|
2 |
/* |
|
3 |
* execacb.php |
|
4 |
* |
|
5 |
* part of pfSense (https://www.pfsense.org) |
|
6 |
* Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate) |
|
7 |
* Copyright (c) 2009 Erik Kristensen |
|
8 |
* All rights reserved. |
|
9 |
* |
|
10 |
* originally part of m0n0wall (http://m0n0.ch/wall) |
|
11 |
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>. |
|
12 |
* All rights reserved. |
|
13 |
* |
|
14 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
15 |
* you may not use this file except in compliance with the License. |
|
16 |
* You may obtain a copy of the License at |
|
17 |
* |
|
18 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
19 |
* |
|
20 |
* Unless required by applicable law or agreed to in writing, software |
|
21 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
23 |
* See the License for the specific language governing permissions and |
|
24 |
* limitations under the License. |
|
25 |
*/ |
|
26 |
|
|
27 |
// Called from cron, this script makes a remote backup of the current configuration |
|
28 |
// via the ACB system |
|
29 |
|
|
30 |
require_once("config.inc"); |
|
31 |
require_once("acb.inc"); |
|
32 |
|
|
33 |
if ($config['system']['acb']['enable'] == "yes") { |
|
34 |
write_config("Scheduled backup"); |
|
35 |
upload_config(); |
|
36 |
} |
|
37 |
|
|
38 |
?> |
src/usr/local/www/js/pfSense.js | ||
---|---|---|
221 | 221 |
all.prop('checked', (all.length != checked.length)); |
222 | 222 |
}); |
223 | 223 |
|
224 |
a.appendTo($(this)); |
|
224 |
if ( ! $(this).parent().hasClass("notoggleall")) { |
|
225 |
a.appendTo($(this)); |
|
226 |
} |
|
225 | 227 |
}); |
226 | 228 |
|
227 | 229 |
// The need to NOT hide the advanced options if the elements therein are not set to the system |
src/usr/local/www/services_acb_backup.php | ||
---|---|---|
18 | 18 |
* See the License for the specific language governing permissions and |
19 | 19 |
* limitations under the License. |
20 | 20 |
*/ |
21 |
require("globals.inc"); |
|
22 |
require("guiconfig.inc"); |
|
23 |
require("acb.inc"); |
|
21 |
require_once("globals.inc");
|
|
22 |
require_once("guiconfig.inc");
|
|
23 |
require_once("acb.inc");
|
|
24 | 24 |
|
25 | 25 |
if ($_POST) { |
26 | 26 |
|
... | ... | |
28 | 28 |
touch("/tmp/acb_nooverwrite"); |
29 | 29 |
} |
30 | 30 |
|
31 |
touch("/tmp/forceacb"); |
|
32 |
|
|
31 | 33 |
if ($_REQUEST['reason']) { |
32 | 34 |
if (write_config($_REQUEST['reason'])) { |
33 | 35 |
$savemsg = "Backup completed successfully."; |
src/usr/local/www/services_acb_settings.php | ||
---|---|---|
32 | 32 |
|
33 | 33 |
require_once("guiconfig.inc"); |
34 | 34 |
require_once("functions.inc"); |
35 |
require_once("pfsense-utils.inc"); |
|
36 |
require_once("services.inc"); |
|
35 | 37 |
|
38 |
function index_of_command() { |
|
39 |
global $croncmd, $a_cron; |
|
40 |
|
|
41 |
$i = 0; |
|
42 |
$rv = -1; |
|
43 |
|
|
44 |
if (count($a_cron) > 0) { |
|
45 |
foreach ($a_cron as $ent) { |
|
46 |
if ($ent['command'] === $croncmd) { |
|
47 |
return $i; |
|
48 |
} |
|
49 |
|
|
50 |
$i++; |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
return $rv; |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
$croncmd = "/usr/bin/nice -n20 /usr/local/bin/php /usr/local/sbin/execacb.php"; |
|
59 |
$a_cron = &$config['cron']['item']; |
|
36 | 60 |
$pconfig = $config['system']['acb']; |
37 | 61 |
|
38 | 62 |
|
... | ... | |
63 | 87 |
} |
64 | 88 |
} |
65 | 89 |
|
90 |
if ($_POST['frequency'] === 'cron') { |
|
91 |
if(!preg_match('/^[0-9\*\/]+$/', $_POST['hours'])) { |
|
92 |
$input_errors[] = gettext("Schedule hours may only contin numbers '*' or '/'"); |
|
93 |
} |
|
94 |
|
|
95 |
if(!preg_match('/^[0-9\*\/]+$/', $_POST['day'])) { |
|
96 |
$input_errors[] = gettext("Schedule days may only contin numbers '*' or '/'"); |
|
97 |
} |
|
98 |
|
|
99 |
if(!preg_match('/^[0-9\*\/]+$/', $_POST['month'])) { |
|
100 |
$input_errors[] = gettext("Schedule month may only contin numbers '*' or '/'"); |
|
101 |
} |
|
102 |
|
|
103 |
if(!preg_match('/^[0-9\*\/]+$/', $_POST['dow'])) { |
|
104 |
$input_errors[] = gettext("Schedule day of week may only contin numbers '*' or '/'"); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
66 | 108 |
// Validate legacy settings |
67 | 109 |
// All blank is allowed, otherwise they must be valid |
68 | 110 |
if ($pconfig['legacy'] == 'yes') { |
... | ... | |
118 | 160 |
|
119 | 161 |
$config['system']['acb']['gold_username'] = $pconfig['gold_username']; |
120 | 162 |
$config['system']['acb']['hint'] = $pconfig['hint']; |
163 |
$config['system']['acb']['frequency'] = $pconfig['frequency']; |
|
164 |
$config['system']['acb']['hours'] = $pconfig['hours']; |
|
165 |
$config['system']['acb']['month'] = $pconfig['month']; |
|
166 |
$config['system']['acb']['day'] = $pconfig['day']; |
|
167 |
$config['system']['acb']['dow'] = $pconfig['dow']; |
|
168 |
|
|
169 |
// Remove any existing cron jobs |
|
170 |
$cronid = index_of_command(); |
|
171 |
|
|
172 |
if ($cronid >= 0) { |
|
173 |
unset($a_cron[$cronid]); |
|
174 |
} |
|
175 |
|
|
176 |
if ($pconfig['frequency'] === "cron") { |
|
177 |
$ent = array(); |
|
178 |
$ent['minute'] = '0'; |
|
179 |
$ent['hour'] = $pconfig['hours']; |
|
180 |
$ent['mday'] = $pconfig['day']; |
|
181 |
$ent['month'] = $pconfig['month']; |
|
182 |
$ent['wday'] = $pconfig['dow']; |
|
183 |
$ent['who'] = 'root'; |
|
184 |
$ent['command'] = $croncmd; |
|
185 |
|
|
186 |
$a_cron[] = $ent; |
|
187 |
|
|
188 |
} |
|
121 | 189 |
|
122 | 190 |
write_config("AutoConfigBackup settings updated"); |
191 |
configure_cron(); |
|
123 | 192 |
} |
124 | 193 |
} |
125 | 194 |
|
... | ... | |
153 | 222 |
($pconfig['enable'] == "yes") |
154 | 223 |
)); |
155 | 224 |
|
225 |
$group = new Form_MultiCheckboxGroup('Backup Frequency'); |
|
226 |
|
|
227 |
$group->add(new Form_MultiCheckbox( |
|
228 |
'frequency', |
|
229 |
'', |
|
230 |
'Automatically backup on every configuration change', |
|
231 |
(!isset($pconfig['frequency']) || $pconfig['frequency'] === 'every'), |
|
232 |
'every' |
|
233 |
))->displayasRadio(); |
|
234 |
/* |
|
235 |
$group->add(new Form_MultiCheckbox( |
|
236 |
'frequency', |
|
237 |
'', |
|
238 |
'Backup manually only', |
|
239 |
($pconfig['frequency'] === 'manual'), |
|
240 |
'manual' |
|
241 |
))->displayasRadio(); |
|
242 |
*/ |
|
243 |
$group->add(new Form_MultiCheckbox( |
|
244 |
'frequency', |
|
245 |
'', |
|
246 |
'Automatically backup on a regular schedule', |
|
247 |
($pconfig['frequency'] === 'cron'), |
|
248 |
'cron' |
|
249 |
))->displayasRadio(); |
|
250 |
|
|
251 |
$group->addClass("notoggleall"); |
|
252 |
$section->add($group); |
|
253 |
|
|
254 |
|
|
255 |
$group = new Form_Group("Schedule"); |
|
256 |
|
|
257 |
$group->add(new Form_Input( |
|
258 |
'hours', |
|
259 |
'Hour', |
|
260 |
'text', |
|
261 |
(isset($pconfig['hours']) ? $pconfig['hours']:'*') |
|
262 |
))->setHelp("Hours (0-23)"); |
|
263 |
|
|
264 |
$group->add(new Form_Input( |
|
265 |
'day', |
|
266 |
'Day of month', |
|
267 |
'text', |
|
268 |
(isset($pconfig['day']) ? $pconfig['day']:'*') |
|
269 |
))->setHelp("Day (1-31)"); |
|
270 |
|
|
271 |
$group->add(new Form_Input( |
|
272 |
'month', |
|
273 |
'Month', |
|
274 |
'text', |
|
275 |
(isset($pconfig['month']) ? $pconfig['month']:'*') |
|
276 |
))->setHelp("Month (1-12)"); |
|
277 |
|
|
278 |
$group->add(new Form_Input( |
|
279 |
'dow', |
|
280 |
'Day of week', |
|
281 |
'text', |
|
282 |
(isset($pconfig['dow']) ? $pconfig['dow']:'*') |
|
283 |
))->setHelp("Day of week (0-6)"); |
|
284 |
|
|
285 |
$group->addClass("cronsched"); |
|
286 |
$group->setHelp(sprintf('Use * ("every"), divisor or exact value. Minutes are fixed at 0. See %s for more information.', |
|
287 |
'<a href="https://www.freebsd.org/cgi/man.cgi?crontab(5)" target="_blank">Cron format</a>')); |
|
288 |
$section->add($group); |
|
289 |
|
|
156 | 290 |
$section->addPassword(new Form_Input( |
157 | 291 |
'encryption_password', |
158 | 292 |
'*Encryption Password', |
... | ... | |
227 | 361 |
$('#legacy').val('no'); |
228 | 362 |
} |
229 | 363 |
}); |
364 |
|
|
365 |
$('input:radio[name=frequency]').click(function() { |
|
366 |
hideClass("cronsched", ($(this).val() != 'cron')); |
|
367 |
}); |
|
368 |
|
|
369 |
hideClass("cronsched", ("<?=$pconfig['frequency']?>" != 'cron')); |
|
230 | 370 |
}); |
231 | 371 |
//]]> |
232 | 372 |
</script> |
Also available in: Unified diff
Added scheduled config backup
Fixed: #8947