Project

General

Profile

Download (7.94 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_settings.php
5
	part of pfSense
6
	Copyright (C) 2005 Colin Smith
7
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
8
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_BUILDER_BINARIES:	/usr/bin/fetch
33
	pfSense_MODULE: firmware
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-system-firmware-settings
38
##|*NAME=System: Firmware: Settings page
39
##|*DESCR=Allow access to the 'System: Firmware: Settings' page.
40
##|*MATCH=system_firmware_settings.php*
41
##|-PRIV
42

    
43
require("guiconfig.inc");
44

    
45
if ($_POST) {
46
	unset($input_errors);
47

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

    
53
	if (!$input_errors) {
54
		if($_POST['alturlenable'] == "yes") {
55
			$config['system']['firmware']['alturl']['enable'] = true;
56
			$config['system']['firmware']['alturl']['firmwareurl'] = $_POST['firmwareurl'];
57
		} else {
58
			unset($config['system']['firmware']['alturl']['enable']);
59
			unset($config['system']['firmware']['alturl']['firmwareurl']);
60
			unset($config['system']['firmware']['alturl']);
61
			unset($config['system']['firmware']);
62
		}
63

    
64
		if($_POST['allowinvalidsig'] == "yes")
65
			$config['system']['firmware']['allowinvalidsig'] = true;
66
		else
67
			unset($config['system']['firmware']['allowinvalidsig']);
68

    
69
		if($_POST['disablecheck'] == "yes")
70
			$config['system']['firmware']['disablecheck'] = true;
71
		else
72
			unset($config['system']['firmware']['disablecheck']);
73

    
74
		if($_POST['synconupgrade'] == "yes")
75
			$config['system']['gitsync']['synconupgrade'] = true;
76
		else
77
			unset($config['system']['gitsync']['synconupgrade']);
78

    
79
		$config['system']['gitsync']['repositoryurl'] = $_POST['repositoryurl'];
80
		$config['system']['gitsync']['branch'] = $_POST['branch'];
81

    
82
		write_config();
83
	}
84
}
85

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

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

    
92
exec("/usr/bin/fetch -q -o {$g['tmp_path']}/manifest \"{$g['update_manifest']}\"");
93

    
94
if(file_exists("{$g['tmp_path']}/manifest")) {
95
	$preset_urls_split = explode("\n", file_get_contents("{$g['tmp_path']}/manifest"));
96
}
97

    
98
include("head.inc");
99

    
100
if ($input_errors)
101
	print_input_errors($input_errors);
102

    
103
if ($savemsg)
104
	print_info_box($savemsg, 'success');
105

    
106
$tab_array = array();
107
$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
108
$tab_array[] = array(gettext("Auto Update"), false, "system_firmware_check.php");
109
$tab_array[] = array(gettext("Updater Settings"), true, "system_firmware_settings.php");
110

    
111
if($g['hidedownloadbackup'] == false)
112
	$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
113

    
114
display_top_tabs($tab_array);
115

    
116
require('classes/Form.class.php');
117

    
118
$form = new Form();
119

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

    
122
if(is_array($preset_urls_split)) {
123
	$urllist = array();
124

    
125
	foreach($preset_urls_split as $pus) {
126
		$pus_text = explode("\t", $pus);
127
		if (empty($pus_text[0]))
128
			continue;
129
		if (stristr($pus_text[0], php_uname("m")) !== false) {
130
			$yourarch = " (Current architecture)";
131
			$choice = $pus_text[1];
132
		} else {
133
			$yourarch = "";
134
		}
135

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

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

    
147
	$form->add($section);
148
}
149

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

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

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

    
166
$form->add($section);
167

    
168
$section = new Form_Section('Updates');
169

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

    
177
$section->addInput(new Form_Checkbox(
178
	'disablecheck',
179
	'Dashboard check',
180
	'Disable the automatic dashboard auto-update check',
181
	isset($curcfg['disablecheck'])
182
	));
183

    
184
$form->add($section);
185

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

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

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

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

    
210
	if(is_dir("/root/pfsense/pfSenseGITREPO/pfSenseGITREPO")) {
211
		exec("cd /root/pfsense/pfSenseGITREPO/pfSenseGITREPO && git branch", $output_str);
212
		if(is_array($output_str)) {
213
			foreach($output_str as $output_line) {
214
				if(strstr($output_line, '* ')) {
215
					$lastbranch = substr($output_line, 2);
216
					break;
217
				}
218
			}
219
		}
220
		unset($output_str);
221
	}
222

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

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

    
234
print($form);
235
?>
236

    
237
<script>
238
// Update firmwareurl from preseturls
239
function update_firmwareurl() {
240
	var pre = document.getElementById("preseturls");
241
	var preVal = pre.options[pre.selectedIndex].value;
242
	var firm = document.getElementById("firmwareurl");
243
	firm.value = preVal;
244
}
245

    
246
// Call it when preseturls changes
247
events.push(function(){
248
	$('#preseturls').on('change', function(){
249
	update_firmwareurl();
250
	})
251
});
252

    
253
// And call it on page load
254
update_firmwareurl();
255

    
256
</script>
257
<?php
258

    
259
include("foot.inc");
(205-205/241)