summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/system_firmware_settings.php
blob: 5e62809a1bbbc4fb88d09205a8b1f0a5ec874629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<?php
/*
	system_firmware_settings.php
*/
/* ====================================================================
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
 *	Copyright (c)  2005 Colin Smith
 *
 *	Redistribution and use in source and binary forms, with or without modification,
 *	are permitted provided that the following conditions are met:
 *
 *	1. Redistributions of source code must retain the above copyright notice,
 *		this list of conditions and the following disclaimer.
 *
 *	2. Redistributions in binary form must reproduce the above copyright
 *		notice, this list of conditions and the following disclaimer in
 *		the documentation and/or other materials provided with the
 *		distribution.
 *
 *	3. All advertising materials mentioning features or use of this software
 *		must display the following acknowledgment:
 *		"This product includes software developed by the pfSense Project
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
 *
 *	4. The names "pfSense" and "pfSense Project" must not be used to
 *		 endorse or promote products derived from this software without
 *		 prior written permission. For written permission, please contact
 *		 coreteam@pfsense.org.
 *
 *	5. Products derived from this software may not be called "pfSense"
 *		nor may "pfSense" appear in their names without prior written
 *		permission of the Electric Sheep Fencing, LLC.
 *
 *	6. Redistributions of any form whatsoever must retain the following
 *		acknowledgment:
 *
 *	"This product includes software developed by the pfSense Project
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
 *
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *	====================================================================
 *
 */
/*
	pfSense_BUILDER_BINARIES:	/usr/bin/fetch
	pfSense_MODULE: firmware
*/

##|+PRIV
##|*IDENT=page-system-firmware-settings
##|*NAME=System: Firmware: Settings page
##|*DESCR=Allow access to the 'System: Firmware: Settings' page.
##|*MATCH=system_firmware_settings.php*
##|-PRIV

require("guiconfig.inc");

if ($_POST) {
	unset($input_errors);

	/* input validation */
	if (($_POST['alturlenable'] == "yes") && (empty($_POST['firmwareurl']))) {
		$input_errors[] = gettext("A Firmware Auto Update Base URL must be specified when \"Use an unofficial server for firmware upgrades\" is enabled.");
	}

	if (!$input_errors) {
		if ($_POST['alturlenable'] == "yes") {
			$config['system']['firmware']['alturl']['enable'] = true;
			$config['system']['firmware']['alturl']['firmwareurl'] = $_POST['firmwareurl'];
		} else {
			unset($config['system']['firmware']['alturl']['enable']);
			unset($config['system']['firmware']['alturl']['firmwareurl']);
			unset($config['system']['firmware']['alturl']);
			unset($config['system']['firmware']);
		}
		if ($_POST['allowinvalidsig'] == "yes") {
			$config['system']['firmware']['allowinvalidsig'] = true;
		} else {
			unset($config['system']['firmware']['allowinvalidsig']);
		}

		if ($_POST['disablecheck'] == "yes") {
			$config['system']['firmware']['disablecheck'] = true;
		} else {
			unset($config['system']['firmware']['disablecheck']);
		}

		if ($_POST['synconupgrade'] == "yes") {
			$config['system']['gitsync']['synconupgrade'] = true;
		} else {
			unset($config['system']['gitsync']['synconupgrade']);
		}
		$config['system']['gitsync']['repositoryurl'] = $_POST['repositoryurl'];
		$config['system']['gitsync']['branch'] = $_POST['branch'];

		write_config();
	}
}

$curcfg = $config['system']['firmware'];
$gitcfg = $config['system']['gitsync'];

$pgtitle = array(gettext("System"), gettext("Firmware"), gettext("Settings"));
$closehead = false;

exec("/usr/bin/fetch -q -o {$g['tmp_path']}/manifest \"{$g['update_manifest']}\"");
if (file_exists("{$g['tmp_path']}/manifest")) {
	$preset_urls_split = explode("\n", file_get_contents("{$g['tmp_path']}/manifest"));
}

include("head.inc");

if ($input_errors)
	print_input_errors($input_errors);

if ($savemsg)
	print_info_box($savemsg, 'success');

$tab_array = array();
$tab_array[] = array(gettext("Updater Settings"), true, "system_firmware_settings.php");
display_top_tabs($tab_array);

require_once('classes/Form.class.php');

$form = new Form();

$section = new Form_Section('Firmware Branch');

if(is_array($preset_urls_split)) {
	$urllist = array();

	foreach($preset_urls_split as $pus) {
		$pus_text = explode("\t", $pus);
		if (empty($pus_text[0]))
			continue;
		if (stristr($pus_text[0], php_uname("m")) !== false) {
			$yourarch = " (Current architecture)";
			$choice = $pus_text[1];
		} else {
			$yourarch = "";
		}

		$urllist[$pus_text[1]] = $pus_text[0] . $yourarch;
	}

	$section->addInput(new Form_Select(
	   'preseturls',
	   'Default Auto Update URLs',
	   $choice,
	   $urllist
	   ))->setHelp('Entries denoted by "Current architecture" match the architecture of your current installation, ' .
	   'such as %s. Changing architectures during an upgrade is not recommended, and may require a manual reboot after the update completes.', [php_uname("m")]);

	$form->add($section);
}

$section = new Form_Section('Firmware Auto Update URL');

$section->addInput(new Form_Checkbox(
	'alturlenable',
	'Unofficial',
	'Allow the use of an "unofficial" server for firmware upgrades',
	isset($curcfg['alturl']['enable'])
	));

$section->addInput(new Form_Input(
	'firmwareurl',
	'Base URL',
	'text'
	))->setHelp('This is where %s will check for newer firmware versions when the <a href="system_firmware_check.php">' .
				'System: Firmware: Auto Update</a> page is viewed', [$g['product_name']]);

$form->add($section);

$section = new Form_Section('Updates');

$section->addInput(new Form_Checkbox(
	'allowinvalidsig',
	'Unsigned images',
	'Allow auto-update firmware images with a missing or invalid digital signature to be used',
	isset($curcfg['allowinvalidsig'])
	));

$section->addInput(new Form_Checkbox(
	'disablecheck',
	'Dashboard check',
	'Disable the automatic dashboard auto-update check',
	isset($curcfg['disablecheck'])
	));

$form->add($section);

if(file_exists("/usr/local/bin/git") && $g['platform'] == $g['product_name']) {
	$section = new Form_Section('GitSync');

	$section->addInput(new Form_Checkbox(
		'synconupgrade',
		'Auto sync on update',
		'After updating, sync with the following repository/branch before reboot',
		isset($gitcfg['synconupgrade'])
		))->setHelp('After updating, sync with the following repository/branch before reboot');

	if(is_dir("/root/pfsense/pfSenseGITREPO/pfSenseGITREPO")) {
		exec("cd /root/pfsense/pfSenseGITREPO/pfSenseGITREPO && git config remote.origin.url", $output_str);
		if(is_array($output_str) && !empty($output_str[0]))
			$lastrepositoryurl = $output_str[0];
		unset($output_str);
	}

	$section->addInput(new Form_Input(
		'repositoryurl',
		'Repository URL',
		'text',
		($gitcfg['repositoryurl'] ? $gitcfg['repositoryurl'] : '')
		))->setHelp('The most recently used repository was %s. This repository will be used if the field is left blank.', [$lastrepositoryurl]);

	if(is_dir("/root/pfsense/pfSenseGITREPO/pfSenseGITREPO")) {
		exec("cd /root/pfsense/pfSenseGITREPO/pfSenseGITREPO && git branch", $output_str);
		if(is_array($output_str)) {
			foreach($output_str as $output_line) {
				if(strstr($output_line, '* ')) {
					$lastbranch = substr($output_line, 2);
					break;
				}
			}
			unset($output_str);
		}
		unset($output_str);
	}

	$section->addInput(new Form_Input(
		'branch',
		'Branch name',
		'text',
		($gitcfg['branch'] ? $gitcfg['branch'] : '')
		))->setHelp('The most recently used branch was "%s". (Usually the branch name is master)' .
					'<br />Note: Sync will not be performed if a branch is not specified', [$lastbranch]);

	$form->add($section);
} // e-o-if(file_exista()

print($form);
?>

<script>
//<![CDATA[
events.push(function(){
	// Update firmwareurl from preseturls or from the saved alternate if "Unofficial" is checked
	function update_firmwareurl() {
		if (!$('#alturlenable').prop('checked')) {
			$('#firmwareurl').prop('readonly', true)
			$('#firmwareurl').val($('#preseturls').val());
		} else {
			$('#firmwareurl').prop('readonly', false)
			$('#firmwareurl').val("<?=$config['system']['firmware']['alturl']['firmwareurl']?>");
		}
	}

	// Call it when preseturls changes

	$('#preseturls, #alturlenable').on('change', function(){
	update_firmwareurl();
	})

	// And call it on page load
	update_firmwareurl();
});

//]]>
</script>
<?php

include("foot.inc");
OpenPOWER on IntegriCloud