mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-17 10:04:41 +00:00
inc: remove more config bootstrapping cruft
This commit is contained in:
parent
82c15d9f3c
commit
24b0307cdb
@ -49,98 +49,12 @@ require_once("xmlparse.inc");
|
||||
require_once("crypt.inc");
|
||||
require_once("globals.inc");
|
||||
|
||||
|
||||
/* if /debugging exists, lets set $debugging
|
||||
so we can output more information */
|
||||
if(file_exists("/debugging")) {
|
||||
$debugging = true;
|
||||
$g['debug'] = true;
|
||||
}
|
||||
|
||||
/* if our config file exists bail out, we're already set. */
|
||||
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 (is_install_media()) {
|
||||
/* config is on install media CD-ROM/Flash 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* write device name to a file for rc.firmware */
|
||||
$fd = fopen("{$g['varetc_path']}/cfdevice", "w");
|
||||
fwrite($fd, $cfgdevice . "\n");
|
||||
fclose($fd);
|
||||
|
||||
/* 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) {
|
||||
$timezone = "Etc/UTC";
|
||||
$timezone = 'Etc/UTC';
|
||||
}
|
||||
|
||||
date_default_timezone_set("$timezone");
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
@ -1,8 +1,4 @@
|
||||
<?php
|
||||
require_once("xmlparse.inc");
|
||||
require_once("crypt.inc");
|
||||
require_once("globals.inc");
|
||||
require_once("script/load_phalcon.php");
|
||||
|
||||
/*
|
||||
Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
|
||||
@ -33,6 +29,10 @@ require_once("script/load_phalcon.php");
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
require_once("globals.inc");
|
||||
require_once("xmlparse.inc");
|
||||
require_once("crypt.inc");
|
||||
require_once("script/load_phalcon.php");
|
||||
|
||||
/****f* config/parse_config
|
||||
* NAME
|
||||
@ -58,80 +58,13 @@ function parse_config()
|
||||
}
|
||||
}
|
||||
|
||||
/* make alias table (for faster lookups) */
|
||||
alias_make_table($config);
|
||||
|
||||
// return config data as array, use old "listags" construction to mark certain elements as array (even if they're not recurring)
|
||||
return $cnf->toArray(listtags());
|
||||
}
|
||||
|
||||
|
||||
/****f* config/parse_config_bootup
|
||||
* NAME
|
||||
* parse_config_bootup - Bootup-specific configuration checks.
|
||||
* RESULT
|
||||
* null
|
||||
******/
|
||||
function parse_config_bootup()
|
||||
{
|
||||
global $config, $g;
|
||||
|
||||
$config_xml = '/conf/config.xml';
|
||||
|
||||
if (!file_exists($config_xml)) {
|
||||
if (file_exists("/var/run/booting")) {
|
||||
if (is_install_media()) {
|
||||
/* 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 {
|
||||
$cnf = OPNsense\Core\Config::getInstance();
|
||||
$backups = $cnf->getBackups();
|
||||
if (count($backups) > 0) {
|
||||
log_error("No config.xml found, attempting last known config restore.");
|
||||
file_notice("config.xml", gettext("No config.xml found, attempting last known config restore."), "pfSenseConfigurator", "");
|
||||
$cnf->restoreBackup($backups[0]);
|
||||
} else {
|
||||
echo sprintf(gettext("XML configuration file not found. %s cannot continue booting."), $g['product_name']) . "\n";
|
||||
mwexec("/sbin/halt");
|
||||
exit;
|
||||
}
|
||||
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 {
|
||||
log_error(gettext("Could not find a usable configuration file! Exiting...."));
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$config = parse_config();
|
||||
|
||||
if ((float)$config['version'] > (float)$g['latest_config']) {
|
||||
echo <<<EOD
|
||||
|
||||
|
||||
*******************************************************************************
|
||||
* WARNING! *
|
||||
* The current configuration has been created with a newer version of {$g['product_name']} *
|
||||
* than this one! This can lead to serious misbehavior and even security *
|
||||
* holes! You are urged to either upgrade to a newer version of {$g['product_name']} or *
|
||||
* revert to the default configuration immediately! *
|
||||
*******************************************************************************
|
||||
|
||||
|
||||
EOD;
|
||||
}
|
||||
|
||||
/* make alias table (for faster lookups) */
|
||||
alias_make_table($config);
|
||||
}
|
||||
|
||||
|
||||
/****f* config/convert_config
|
||||
* NAME
|
||||
* convert_config - Attempt to update config.xml.
|
||||
@ -503,5 +436,3 @@ function backup_to_google_drive() {
|
||||
}
|
||||
|
||||
register_shutdown_function('pfSense_clear_globals');
|
||||
|
||||
?>
|
||||
|
||||
@ -123,10 +123,6 @@ echo " done.\n";
|
||||
/* save dmesg output to file */
|
||||
system_dmesg_save();
|
||||
|
||||
/* remove previous firmware upgrade if present */
|
||||
if (file_exists("/root/firmware.tgz"))
|
||||
unlink("/root/firmware.tgz");
|
||||
|
||||
/* start devd (dhclient now uses it) */
|
||||
echo "Starting device manager (devd)...";
|
||||
mute_kernel_msgs();
|
||||
@ -144,7 +140,8 @@ if (is_install_media()) {
|
||||
}
|
||||
|
||||
echo "Loading configuration...";
|
||||
parse_config_bootup();
|
||||
global $config;
|
||||
$config = parse_config();
|
||||
echo "done.\n";
|
||||
|
||||
/*
|
||||
|
||||
@ -1099,9 +1099,8 @@ function rule_popup($src,$srcport,$dst,$dstport){
|
||||
}
|
||||
|
||||
$timezone = $config['system']['timezone'];
|
||||
if (!$timezone)
|
||||
$timezone = "Etc/UTC";
|
||||
if (!$timezone) {
|
||||
$timezone = 'Etc/UTC';
|
||||
}
|
||||
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user