Commit 511eb60e authored by Franco Fichtner's avatar Franco Fichtner

src: zap code that handled "cdrom" idiosyncrasies

We can do without those on the install media.  Instead, route
necessary code parts through is_install_media().  A lot of
stale and forgotten code got ditched in the process--e.g. when
did we ever run without an /etc/fstab?
parent c93d5dcb
......@@ -54,12 +54,13 @@ function set_networking_interfaces_ports()
$iflist = get_interface_list();
/* Function flow is based on $key and $auto_assign or the lack thereof */
/* Function flow is based on $key and $auto_assign or the lack thereof */
$key = null;
/* Only present auto interface option if running from LiveCD and interface mismatch*/
if ((preg_match("/cdrom/", $g['platform'])) && is_interface_mismatch())
/* Only present auto interface option if running from LiveCD and interface mismatch*/
if (is_install_media() && is_interface_mismatch()) {
$auto_assign = false;
}
echo <<<EOD
......
......@@ -71,103 +71,19 @@ if(file_exists("/var/run/booting") && file_exists("/conf/config.xml")) {
}
}
/* if our config file exists bail out, we're already set. */
else if (file_exists("/var/run/booting") && !file_exists('/conf/config.xml')) {
/* find the device where config.xml resides and write out an fstab */
unset($cfgdevice);
/* check if there's already an fstab (NFS booting?) */
if (!file_exists('/etc/fstab')) {
if (strstr($g['platform'], "cdrom")) {
/* config is on floppy disk for CD-ROM version */
$cfgdevice = $cfgpartition = "fd0";
$_gb = exec('/sbin/dmesg -a', $dmesg);
if(preg_match("/da0/", $dmesg) == true) {
$cfgdevice = $cfgpartition = "da0" ;
if (mwexec("/sbin/mount -r /dev/{$cfgdevice} /cf")) {
/* could not mount, fallback to floppy */
$cfgdevice = $cfgpartition = "fd0";
}
}
$cfgfstype = "msdosfs";
echo gettext("CDROM build") . "\n";
echo " " . gettext("CFG:") . " {$cfgpartition}\n";
echo " " . gettext("CFG:") . " {$cfgpartition}\n";
echo " " . gettext("TYPE:") . " {$cfgfstype}\n";
} else {
/* probe kernel known disks until we find one with config.xml */
$disks = explode(" ", get_single_sysctl("kern.disks"));
foreach ($disks as $mountdisk) {
/* skip mfs mounted filesystems */
if (strstr($mountdisk, "md"))
continue;
if (mwexec("/sbin/mount -r /dev/{$mountdisk}a /cf") == 0) {
if (file_exists('/conf/config.xml')) {
/* found it */
$cfgdevice = $mountdisk;
$cfgpartition = $cfgdevice . "a";
$cfgfstype = "ufs";
printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
}
mwexec("/sbin/umount -f /cf");
if ($cfgdevice)
break;
}
if (mwexec("/sbin/mount -r /dev/{$mountdisk}d /cf") == 0) {
if (file_exists('/conf/config.xml')) {
/* found it */
$cfgdevice = $mountdisk;
$cfgpartition = $cfgdevice . "d";
$cfgfstype = "ufs";
printf(gettext("Found configuration on %s.%s"), $cfgdevice, "\n");
}
mwexec("/sbin/umount -f /cf");
if ($cfgdevice)
break;
}
}
}
if (!$cfgdevice) {
$last_backup = discover_last_backup();
if($last_backup) {
log_error(gettext("No config.xml found, attempting last known config restore."));
file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
restore_backup("/conf/backup/{$last_backup}");
} else {
log_error(gettext("No config.xml or config backups found, resetting to factory defaults."));
restore_backup('/usr/local/etc/config.xml');
}
}
/* write out an fstab */
$fd = fopen('/etc/fstab', 'w');
$fstab = "/dev/{$cfgpartition} /cf {$cfgfstype} ro,noatime 1 1\n";
$fstab .= "proc /proc procfs rw 0 0\n";
fwrite($fd, $fstab);
fclose($fd);
}
/* mount all filesystems */
mwexec("/sbin/mount -a");
}
$config = parse_config();
/* set timezone */
$timezone = $config['system']['timezone'];
if (!$timezone)
if (!$timezone) {
$timezone = "Etc/UTC";
}
date_default_timezone_set("$timezone");
if($config_parsed == true) {
if ($config_parsed == true) {
/* process packager manager custom rules */
if(is_dir("/usr/local/pkg/parse_config")) {
run_plugins("/usr/local/pkg/parse_config/");
}
}
?>
......@@ -205,17 +205,6 @@ function parse_config_bootup()
$lockkey = lock('config');
if (!file_exists($config_xml)) {
if (file_exists("/var/run/booting")) {
if (strstr($g['platform'], "cdrom")) {
/* try copying the default config. to the floppy */
echo gettext("Resetting factory defaults...") . "\n";
reset_factory_defaults(true);
if (!file_exists($config_xml)) {
echo gettext("No XML configuration file found - using factory defaults.\n" .
"Make sure that the configuration floppy disk with the conf/config.xml\n" .
"file is inserted. If it isn't, your configuration changes will be lost\n" .
"on reboot.\n");
}
} else {
$last_backup = discover_last_backup();
if($last_backup) {
log_error("No config.xml found, attempting last known config restore.");
......@@ -230,7 +219,6 @@ function parse_config_bootup()
}
log_error("Last known config found and restored. Please double check your configuration file for accuracy.");
file_notice("config.xml", gettext("Last known config found and restored. Please double check your configuration file for accuracy."), "pfSenseConfigurator", "");
}
} else {
unlock($lockkey);
log_error(gettext("Could not find a usable configuration file! Exiting...."));
......@@ -280,11 +268,11 @@ EOD;
* null
******/
/* mount flash card read/write */
function conf_mount_rw() {
function conf_mount_rw()
{
global $g, $config;
/* do not mount on cdrom platform */
if($g['platform'] == "cdrom" or $g['platform'] == "pfSense")
/* XXX do not mount (we're already set up) */
return;
if ((refcount_reference(1000) > 1) && is_writable("/"))
......@@ -318,13 +306,11 @@ function conf_mount_rw() {
* RESULT
* null
******/
function conf_mount_ro() {
function conf_mount_ro()
{
global $g, $config;
/* Do not trust $g['platform'] since this can be clobbered during factory reset. */
$platform = trim(file_get_contents("/usr/local/etc/platform"));
/* do not umount on cdrom or pfSense platforms */
if($platform == "cdrom" or $platform == "pfSense")
/* XXX do not mount (we're already set up) */
return;
if (refcount_unreference(1000) > 0)
......
......@@ -53,7 +53,6 @@ $g = array(
"product_copyright_url" => "https://www.deciso.com/",
"crashreporterurl" => "https://crash.opnsense.org/",
"latest_config" => "11.1",
"nopkg_platforms" => array("cdrom"),
"minimum_ram_warning" => "101",
"minimum_ram_warning_text" => "128 MB",
"wan_interface_name" => "wan",
......@@ -133,4 +132,22 @@ $sysctls = array(
"net.inet6.ip6.rfc6204w3" => 1,
);
function is_install_media()
{
/*
* Despite unionfs underneath, / is still not writeable,
* making the following the perfect test for install media.
*/
$file = '/.probe.for.install.media';
$fd = @fopen($file, 'w');
if ($fd) {
fclose($fd);
unlink($file);
return false;
}
return true;
}
$config_parsed = false;
......@@ -843,7 +843,7 @@ function setup_serial_port($when = 'save', $path = '')
$boot_config = "";
$serialspeed = (is_numeric($config['system']['serialspeed'])) ? $config['system']['serialspeed'] : '115200';
if ($g['platform'] != "cdrom") {
if (!is_install_media()) {
$boot_config_split = explode("\n", $boot_config);
$fd = fopen($boot_config_file,"w");
if($fd) {
......@@ -886,7 +886,7 @@ function setup_serial_port($when = 'save', $path = '')
} else if (is_serial_enabled()) {
$new_boot_config[] = 'boot_multicons="YES"';
$new_boot_config[] = 'boot_serial="YES"';
$primaryconsole = isset($g['primaryconsole_force']) ? $g['primaryconsole_force'] : $config['system']['primaryconsole'];
$primaryconsole = $config['system']['primaryconsole'];
switch ($primaryconsole) {
case "video":
$new_boot_config[] = 'console="vidconsole,comconsole"';
......@@ -932,14 +932,9 @@ function setup_serial_port($when = 'save', $path = '')
function is_serial_enabled()
{
global $g, $config;
if (!isset($g['enableserial_force']) &&
!isset($config['system']['enableserial']) &&
($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt")))
return false;
global $config;
return true;
return isset($config['system']['enableserial']);
}
function reload_ttys()
......
......@@ -1856,15 +1856,10 @@ EOD;
name => platform string (e.g. 'wrap', 'alix' etc.)
descr => human-readable description (e.g. "PC Engines WRAP")
*/
function system_identify_specific_platform() {
function system_identify_specific_platform()
{
global $g;
if ($g['platform'] == 'generic-pc')
return array('name' => 'generic-pc', 'descr' => gettext("Generic PC"));
if ($g['platform'] == 'generic-pc-cdrom')
return array('name' => 'generic-pc-cdrom', 'descr' => gettext("Generic PC (CD-ROM)"));
/* the rest of the code only deals with 'embedded' platforms */
if ($g['platform'] != 'nanobsd')
return array('name' => $g['platform'], 'descr' => $g['platform']);
......
......@@ -39,8 +39,8 @@ else
# fake a writeable environment in some subdirs
for i in conf etc home root usr var; do
/bin/mkdir -p /tmp/.cdrom/${i}
/sbin/mount_unionfs /tmp/.cdrom/${i} /${i}
/bin/mkdir -p /tmp/.install.media/${i}
/sbin/mount_unionfs /tmp/.install.media/${i} /${i}
done
fi
......
......@@ -29,24 +29,6 @@
POSSIBILITY OF SUCH DAMAGE.
*/
function is_install_media()
{
/*
* Despite unionfs underneath, / is still not writeable,
* making the following the perfect test for install media.
*/
$file = '/.probe.for.install.media';
$fd = @fopen($file, 'w');
if ($fd) {
fclose($fd);
unlink($file);
return false;
}
return true;
}
function rescue_detect_keypress()
{
$timeout = 9;
......
......@@ -29,7 +29,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/
require("guiconfig.inc");
require_once("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
......@@ -136,7 +136,7 @@ if ($_POST) {
else
unset($config['system']['webgui']['noantilockout']);
if ($_POST['enableserial'] == "yes" || $g['enableserial_force'])
if ($_POST['enableserial'] == "yes")
$config['system']['enableserial'] = true;
else
unset($config['system']['enableserial']);
......@@ -528,8 +528,6 @@ include("head.inc");
<tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Serial Communications"); ?></th>
</tr>
<?php if (!$g['enableserial_force'] && ($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt"))): ?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Serial Terminal"); ?></td>
<td width="78%" class="vtable">
......@@ -538,7 +536,6 @@ include("head.inc");
<span class="vexpl"><?=gettext("Note: This will redirect the console output and messages to the serial port. You can still access the console menu from the internal video card/keyboard. A <b>null modem</b> serial cable or adapter is required to use the serial console."); ?></span>
</td>
</tr>
<?php endif; ?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Serial Speed")?></td>
<td width="78%" class="vtable">
......@@ -553,7 +550,6 @@ include("head.inc");
<br /><?=gettext("Allows selection of different speeds for the serial console port."); ?>
</td>
</tr>
<?php if (!$g['primaryconsole_force'] && ($g['platform'] == "pfSense" || $g['platform'] == "cdrom" || file_exists("/etc/nano_use_vga.txt"))): ?>
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Primary Console")?></td>
<td width="78%" class="vtable">
......@@ -564,7 +560,6 @@ include("head.inc");
<br /><?=gettext("Select the preferred console if multiple consoles are present. The preferred console will show OPNsense boot script output. All consoles display OS boot messages, console messages, and the console menu."); ?>
</td>
</tr>
<?php endif; ?>
<tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Console Options"); ?></th>
</tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment