Commit 8121fffd authored by Franco Fichtner's avatar Franco Fichtner

rc: improve the user experience on boot

First impressions are the most important ones...
parent 3606a039
......@@ -152,7 +152,7 @@
</sysctl>
<system>
<optimization>normal</optimization>
<hostname>pfSense</hostname>
<hostname>OPNsense</hostname>
<domain>localdomain</domain>
<dnsserver/>
<dnsallowoverride/>
......
<?php
/*
external config loader
Copyright (C) 2010 Scott Ullrich
All rights reserved.
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.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS 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
AUTHOR 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.
Currently supported file system types: MS-Dos, FreeBSD UFS
*/
require_once("globals.inc");
require_once("functions.inc");
require_once("config.lib.inc");
require_once("config.inc");
$debug = false;
function get_boot_disk() {
global $g, $debug;
$disk = exec("/sbin/mount | /usr/bin/grep \"on / \" | /usr/bin/cut -d'/' -f3 | /usr/bin/cut -d' ' -f1");
return $disk;
}
function get_swap_disks() {
exec("/usr/sbin/swapinfo | /usr/bin/sed '/^\/dev/!d; s,^/dev/,,; s, .*\$,,'", $disks);
return $disks;
}
function get_disk_slices($disk) {
global $g, $debug;
$slices_array = array();
$slices = trim(exec("/bin/ls " . escapeshellarg("/dev/" . $disk . "s*") . " 2>/dev/null"));
$slices = str_replace("/dev/", "", $slices);
if($slices == "ls: No match.")
return;
$slices_array = explode(" ", $slices);
return $slices_array;
}
function get_disks() {
global $g, $debug;
$disks_array = array();
$disks_s = explode(" ", get_single_sysctl("kern.disks"));
foreach($disks_s as $disk)
if(trim($disk))
$disks_array[] = $disk;
return $disks_array;
}
function discover_config($mountpoint) {
global $g, $debug;
$locations_to_check = array("/", "/config");
foreach($locations_to_check as $ltc) {
$tocheck = "/tmp/mnt/cf{$ltc}config.xml";
if($debug) {
echo "\nChecking for $tocheck";
if(file_exists($tocheck))
echo " -> found!";
}
if(file_exists($tocheck))
return $tocheck;
}
return "";
}
function test_config($file_location) {
global $g, $debug;
if(!$file_location)
return;
// config.xml was found. ensure it is sound.
$root_obj = trim("<{$g['xml_rootobj']}>");
$xml_file_head = exec("/usr/bin/head -2 " . escapeshellarg($file_location) . " | /usr/bin/tail -n1");
if($debug) {
echo "\nroot obj = $root_obj";
echo "\nfile head = $xml_file_head";
}
if($xml_file_head == $root_obj) {
// Now parse config to make sure
$config_status = config_validate($file_location);
if($config_status)
return true;
}
return false;
}
// Probes all disks looking for config.xml
function find_config_xml() {
global $g, $debug;
$disks = get_disks();
// Safety check.
if(!is_array($disks))
return;
$boot_disk = get_boot_disk();
$swap_disks = get_swap_disks();
exec("/bin/mkdir -p /tmp/mnt/cf");
foreach($disks as $disk) {
$slices = get_disk_slices($disk);
if(is_array($slices)) {
foreach($slices as $slice) {
if($slice == "")
continue;
if(stristr($slice, $boot_disk)) {
if($debug)
echo "\nSkipping boot device slice $slice";
continue;
}
if(in_array($slice, $swap_disks)) {
if($debug)
echo "\nSkipping swap device slice $slice";
continue;
}
echo " $slice";
// First try msdos fs
if($debug)
echo "\n/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
$result = exec("/sbin/mount -t msdosfs /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
// Next try regular fs (ufs)
if(!$result) {
if($debug)
echo "\n/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null \n";
$result = exec("/sbin/mount /dev/{$slice} /tmp/mnt/cf 2>/dev/null");
}
$mounted = trim(exec("/sbin/mount | /usr/bin/grep -v grep | /usr/bin/grep '/tmp/mnt/cf' | /usr/bin/wc -l"));
if($debug)
echo "\nmounted: $mounted ";
if(intval($mounted) > 0) {
// Item was mounted - look for config.xml file
$config_location = discover_config($slice);
if($config_location) {
if(test_config($config_location)) {
// We have a valid configuration. Install it.
echo " -> found config.xml\n";
echo "Backing up old configuration...\n";
backup_config();
echo "Restoring [{$slice}] {$config_location}...\n";
restore_backup($config_location);
echo "Cleaning up...\n";
exec("/sbin/umount /tmp/mnt/cf");
exit;
}
}
exec("/sbin/umount /tmp/mnt/cf");
}
}
}
}
}
echo "External config loader 1.0 is now starting...";
find_config_xml();
echo "\n";
?>
......@@ -63,7 +63,6 @@ $g = array(
"product_website" => "www.opnsense.org",
"product_website_footer" => "https://www.opnsense.org/?gui22",
"product_email" => "coreteam@opnsense.org",
"hideplatform" => false,
"hidedownloadbackup" => false,
"hidebackupbeforeupgrade" => false,
"disablethemeselection" => false,
......
#!/bin/sh
# part of pfSense by Scott Ullrich
# Copyright (C) 2004-2010 Scott Ullrich, All rights reserved.
# originally based on m0n0wall (http://neon1.net/m0n0wall)
# Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
# Copyright (C) 2014 Franco Fichtner <franco@opnsense.org>
# All rights reserved.
stty status '^T' 2> /dev/null
......@@ -18,18 +17,15 @@ HOME=/
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin
export HOME PATH
# Set our operating platform
PLATFORM=`/bin/cat /usr/local/etc/platform`
# Set our current version
version=`/bin/cat /usr/local/etc/version`
if [ -e /root/force_fsck ]; then
echo "Forcing filesystem check..."
/sbin/fsck -y -t ufs /
if [ "$PLATFORM" = "nanobsd" ]; then
/sbin/fsck -y -t ufs /cf
fi
/bin/rm -f /root/force_fsck
fi
if [ "${PLATFORM}" = "nanobsd" ]; then
......@@ -150,10 +146,6 @@ if [ ! -f /conf/config.xml ]; then
echo " done."
fi
/bin/rm -f /root/force_fsck
/bin/rm -f /root/TRIM_set
/bin/rm -f /root/TRIM_unset
# Disable APM on ATA drives. Leaving this on will kill drives long-term, especially laptop drives, by generating excessive Load Cycles.
if [ -f /usr/local/etc/rc.disable_hdd_apm ]; then
/usr/local/etc/rc.disable_hdd_apm
......@@ -170,24 +162,10 @@ fi
rm -f /etc/spwd.db.tmp
/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd
product=`/usr/bin/grep product_name /usr/local/etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
hideplatform=`/usr/bin/grep hideplatform /usr/local/etc/inc/globals.inc | /usr/bin/wc -l`
varrunpath=`/usr/bin/grep varrun_path /usr/local/etc/inc/globals.inc | /usr/bin/cut -d'"' -f4`
if [ "$PLATFORM" = "pfSense" ] && [ ${USE_MFS_TMPVAR} -eq 0 ]; then
/sbin/mdmfs -S -M -s 4m md $varrunpath
fi
if [ "$hideplatform" -gt "0" ]; then
platformbanner="" # hide the platform
else
platformbanner=" on the '${PLATFORM}' platform"
/sbin/mdmfs -S -M -s 4m md /var/run
fi
echo
echo "Welcome to ${product} ${version} ${platformbanner} ..."
echo
if [ ! "$PLATFORM" = "jail" ]; then
# Enable console output if its muted.
/sbin/conscontrol mute off >/dev/null
......@@ -207,7 +185,6 @@ elif [ "$PLATFORM" = "nanobsd" ] || [ ${USE_MFS_TMPVAR} -gt 0 ]; then
elif [ "$PLATFORM" = "jail" ]; then
# do nothing for jail platform
else
SWAPDEVICE=`/bin/cat /etc/fstab | /usr/bin/grep swap | /usr/bin/cut -f1`
/sbin/swapon -a
/usr/local/etc/rc.savecore
......@@ -220,17 +197,9 @@ else
fi
fi
# Copy PBI keys
if ls /usr/local/share/pbi-keys/*.ssl >/dev/null 2>&1; then
if [ ! -d "/var/db/pbi/keys" ]; then
mkdir -p /var/db/pbi/keys
fi
cp -f /usr/local/share/pbi-keys/*.ssl /var/db/pbi/keys
fi
# make some directories in /var
/bin/mkdir -p $varrunpath /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
/bin/rm -rf $varrunpath/*
/bin/mkdir -p /var/run /var/log /var/etc /var/db/entropy /var/at/jobs/ /var/empty 2>/dev/null
/bin/rm -rf /var/run/*
if [ "$PLATFORM" != "pfSense" ]; then
/bin/rm /var/log/* 2>/dev/null
fi
......@@ -278,10 +247,7 @@ if [ ! -h /tmp/tmp ]; then
/bin/ln -hfs / /tmp/tmp
fi
# Make sure our /tmp is 777 + Sticky
if [ ! "$PLATFORM" = "cdrom" ] ; then
/bin/rm -rf /tmp/*
fi
/bin/rm -rf /tmp/*
/bin/chmod 1777 /tmp
if [ ! "$PLATFORM" = "cdrom" ] ; then
......@@ -351,7 +317,7 @@ if [ ! "$PLATFORM" = "jail" ]; then
fi
# Create an initial utmp file
cd $varrunpath && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
cd /var/run && /bin/cp /dev/null utmp && /bin/chmod 644 utmp
echo -n "."
/sbin/ldconfig -elf /usr/lib /usr/local/lib /lib
......@@ -378,14 +344,8 @@ echo "done."
# Recreate capabilities DB
/usr/bin/cap_mkdb /etc/login.conf
# Run the php.ini setup file and populate
# /usr/local/etc/php.ini and /usr/local/lib/php.ini
/usr/local/etc/rc.php_ini_setup 2>/tmp/php_errors.txt
# Launch external configuration loader for supported platforms
if [ "$PLATFORM" = "nanobsd" -o "$PLATFORM" = "pfSense" ]; then
/usr/local/bin/php -q /usr/local/etc/ecl.php
fi
# Run the php.ini setup file
/usr/local/etc/rc.php_ini_setup
chmod u+rx /usr/local/opnsense/service/check_reload_status.py
/usr/bin/nice -n20 /usr/local/opnsense/service/check_reload_status.py
......@@ -395,11 +355,11 @@ sleep 1 # give check_reload_status some time to load to prevent missing socket
echo -n "Launching the init system..."
/bin/rm -f /cf/conf/backup/backup.cache
/bin/rm -f /root/lighttpd*
/usr/bin/touch $varrunpath/booting
/usr/bin/touch /var/run/booting
/usr/local/etc/rc.bootup
# rc.bootup unset $g['booting'], remove file right now to be consistent
/bin/rm $varrunpath/booting
/bin/rm /var/run/booting
# If a shell was selected from recovery
# console then just drop to the shell now.
......@@ -412,16 +372,14 @@ echo -n "Starting CRON... "
cd /tmp && /usr/sbin/cron -s 2>/dev/null
echo "done."
/bin/rm -rf /usr/local/pkg/pf/CVS
# Start ping handler every 240 seconds
/usr/local/bin/minicron 240 $varrunpath/ping_hosts.pid /usr/local/bin/ping_hosts.sh
/usr/local/bin/minicron 240 /var/run/ping_hosts.pid /usr/local/bin/ping_hosts.sh
# Start account expire handler every hour
/usr/local/bin/minicron 3600 $varrunpath/expire_accounts.pid /usr/local/etc/rc.expireaccounts
/usr/local/bin/minicron 3600 /var/run/expire_accounts.pid /usr/local/etc/rc.expireaccounts
# Start alias url updater every 24 hours
/usr/local/bin/minicron 86400 $varrunpath/update_alias_url_data.pid /usr/local/etc/rc.update_alias_url_data
/usr/local/bin/minicron 86400 /var/run/update_alias_url_data.pid /usr/local/etc/rc.update_alias_url_data
/bin/chmod a+rw /tmp/.
......@@ -434,15 +392,13 @@ if [ "${GMIRROR_STATUS}" != "" ]; then
/usr/local/bin/minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
fi
# Log product version to syslog
ARCH=`uname -m`
echo "$product ($PLATFORM) $version $ARCH"
echo "Bootup complete"
/usr/local/bin/beep.sh start 2>&1 >/dev/null
# Reset the cache. read-only requires this.
/bin/rm -f /tmp/config.cache
echo
/usr/local/etc/rc.initial.banner
exit 0
......@@ -35,15 +35,7 @@ fi
# endless loop
while : ; do
if [ -f /tmp/ttybug ]; then
rm /tmp/ttybug
exit && exit && logout
fi
/usr/local/etc/rc.banner
product=`grep product_name /usr/local/etc/inc/globals.inc | cut -d'"' -f4`
hidebanner=`grep hidebanner /usr/local/etc/inc/globals.inc | cut -d'"' -f4`
# Check to see if SSH is running.
if pgrep -q -a -F /var/run/sshd.pid sshd >/dev/null 2>&1; then
......@@ -52,20 +44,12 @@ else
sshd_option="14) Enable Secure Shell (sshd)";
fi
for i in /var/db/pfi/capable_*; do
if [ -f $i -a ! -L /cf/conf ]; then
option98="98) Move configuration file to removable device"
break
fi
done
if [ "$PLATFORM" = "cdrom" ]; then
option99="99) Install ${product} to a hard drive, etc."
fi
# display a cheap menu
echo ""
echo " 0) Logout (SSH only) 8) Shell"
echo " 0) Logout 8) Shell"
echo " 1) Assign Interfaces 9) pfTop"
echo " 2) Set interface(s) IP address 10) Filter Logs"
echo " 3) Reset webConfigurator password 11) Restart webConfigurator"
......@@ -73,8 +57,6 @@ echo " 4) Reset to factory defaults 12) ${product} Developer Shell"
echo " 5) Reboot system 13) Upgrade from console"
echo " 6) Halt system ${sshd_option}"
echo " 7) Ping host 15) Restore recent configuration"
echo " ${option98} "
if [ "${option99}" != "" ]; then
/bin/echo "${option99}"
fi
......@@ -86,7 +68,7 @@ echo
# see what the user has chosen
case ${opmode} in
0)
logout
exit
;;
1)
/usr/local/etc/rc.initial.setports
......@@ -144,5 +126,8 @@ case ${opmode} in
;;
esac
done
/usr/local/etc/rc.initial.banner
echo
done
......@@ -2,7 +2,6 @@
<?php
/*
part of pfSense
Copyright (C) 2005 Scott Ullrich and Colin Smith
Copyright (C) 2009 Ermal Luçi
All rights reserved
......@@ -29,93 +28,86 @@
POSSIBILITY OF SUCH DAMAGE.
*/
/* parse the configuration and include all functions used below */
require_once("config.inc");
require_once("gwlb.inc");
require_once("interfaces.inc");
/* parse the configuration and include all functions used below */
require_once("config.inc");
require_once("gwlb.inc");
require_once("interfaces.inc");
$version = trim(file_get_contents("/usr/local/etc/version"));
$platform = trim(file_get_contents("/usr/local/etc/platform"));
$hostname = $config['system']['hostname'];
$product = $g['product_name'];
$machine = trim(`uname -m`);
$hideplatform = $g['hideplatform'];
if(!$hideplatform)
$platformbanner = "-{$platform}";
print "*** Welcome to {$product} {$version}{$platformbanner} ({$machine}) on {$hostname} ***\n";
$version = trim(file_get_contents("/usr/local/etc/version"));
$hostname = $config['system']['hostname'];
$product = $g['product_name'];
$machine = trim(`uname -m`);
$iflist = get_configured_interface_with_descr(false, true);
foreach($iflist as $ifname => $friendly) {
/* point to this interface's config */
$ifconf = $config['interfaces'][$ifname];
/* look for 'special cases' */
switch($ifconf['ipaddr']) {
case "dhcp":
$class = "/DHCP4";
break;
case "pppoe":
$class = "/PPPoE";
break;
case "pptp":
$class = "/PPTP";
break;
case "l2tp":
$class = "/L2TP";
break;
default:
$class = "";
break;
}
switch($ifconf['ipaddrv6']) {
case "dhcp6":
$class6 = "/DHCP6";
break;
case "slaac":
$class6 = "/SLAAC";
break;
case "6rd":
$class6 = "/6RD";
break;
case "6to4":
$class6 = "/6to4";
break;
case "track6":
$class6 = "/t6";
break;
}
$ipaddr = get_interface_ip($ifname);
$subnet = get_interface_subnet($ifname);
$ipaddr6 = get_interface_ipv6($ifname);
$subnet6 = get_interface_subnetv6($ifname);
$realif = get_real_interface($ifname);
$tobanner = "{$friendly} ({$ifname})";
print "*** Welcome to {$product} {$version} ({$machine}) on {$hostname} ***\n";
$iflist = get_configured_interface_with_descr(false, true);
foreach($iflist as $ifname => $friendly) {
/* point to this interface's config */
$ifconf = $config['interfaces'][$ifname];
/* look for 'special cases' */
switch($ifconf['ipaddr']) {
case "dhcp":
$class = "/DHCP4";
break;
case "pppoe":
$class = "/PPPoE";
break;
case "pptp":
$class = "/PPTP";
break;
case "l2tp":
$class = "/L2TP";
break;
default:
$class = "";
break;
}
switch($ifconf['ipaddrv6']) {
case "dhcp6":
$class6 = "/DHCP6";
break;
case "slaac":
$class6 = "/SLAAC";
break;
case "6rd":
$class6 = "/6RD";
break;
case "6to4":
$class6 = "/6to4";
break;
case "track6":
$class6 = "/t6";
break;
}
$ipaddr = get_interface_ip($ifname);
$subnet = get_interface_subnet($ifname);
$ipaddr6 = get_interface_ipv6($ifname);
$subnet6 = get_interface_subnetv6($ifname);
$realif = get_real_interface($ifname);
$tobanner = "{$friendly} ({$realif})";
printf("\n %-15s -> %-10s -> ",
$tobanner,
$realif
printf("\n %-15s -> ", $tobanner);
$v6first = false;
if (!empty($ipaddr) && !empty($subnet)) {
printf("v4%s: %s/%s",
$class,
$ipaddr,
$subnet
);
$v6first = false;
if (!empty($ipaddr) && !empty($subnet)) {
printf("v4%s: %s/%s",
$class,
$ipaddr,
$subnet
);
} else {
$v6first = true;
}
if (!empty($ipaddr6) && !empty($subnet6)) {
if (!$v6first) {
printf("\n%s", str_repeat(" ",34));
}
printf("v6%s: %s/%s",
$class6,
$ipaddr6,
$subnet6
);
} else {
$v6first = true;
}
if (!empty($ipaddr6) && !empty($subnet6)) {
if (!$v6first) {
printf("\n%s", str_repeat(" ", 20));
}
printf("v6%s: %s/%s",
$class6,
$ipaddr6,
$subnet6
);
}
}
?>
printf("\n");
......@@ -135,7 +135,6 @@ $filesystems = get_mounted_filesystems();
<?php endif; ?>
</td>
</tr>
<?php if(!$g['hideplatform']): ?>
<tr>
<td width="25%" class="vncellt"><?=gettext("Platform");?></td>
<td width="75%" class="listr">
......@@ -145,7 +144,6 @@ $filesystems = get_mounted_filesystems();
} ?>
</td>
</tr>
<?php endif; ?>
<?php if ($g['platform'] == "nanobsd"): ?>
<?
global $SLICE, $OLDSLICE, $TOFLASH, $COMPLETE_PATH, $COMPLETE_BOOT_PATH;
......
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