From 528679c0f574d49aa184aefa723b36845b9ef723 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 9 Dec 2014 16:15:34 +0100 Subject: [PATCH] etc: move more files --- conf.default/config.xml | 2 +- etc/sshd | 204 ------------------ tmp/pre_upgrade_command | 2 +- usr/local/etc/inc/interfaces.inc | 6 +- usr/local/etc/inc/system.inc | 4 +- usr/local/etc/inc/upgrade_config.inc | 2 +- usr/local/etc/rc.bootup | 2 +- {etc => usr/local/etc}/rc.dyndns.update | 5 +- usr/local/etc/rc.firmware | 12 +- usr/local/etc/rc.initial | 2 +- usr/local/etc/rc.kill_states | 2 +- {etc => usr/local/etc}/rc.newwanip | 2 +- {etc => usr/local/etc}/rc.newwanipv6 | 0 {etc => usr/local/etc}/rc.notify_message | 2 +- {etc => usr/local/etc}/rc.reboot | 0 .../local/etc}/rc.resolv_conf_generate | 0 .../local/etc}/rc.restore_config_backup | 0 usr/local/etc/rc.sshd | 195 +++++++++++++++++ .../service/conf/actions_interface.conf | 4 +- .../service/conf/actions_service.conf | 8 +- usr/local/www/xmlrpc.php | 2 +- 21 files changed, 222 insertions(+), 234 deletions(-) delete mode 100755 etc/sshd rename {etc => usr/local/etc}/rc.dyndns.update (98%) rename {etc => usr/local/etc}/rc.newwanip (99%) rename {etc => usr/local/etc}/rc.newwanipv6 (100%) rename {etc => usr/local/etc}/rc.notify_message (98%) rename {etc => usr/local/etc}/rc.reboot (100%) rename {etc => usr/local/etc}/rc.resolv_conf_generate (100%) rename {etc => usr/local/etc}/rc.restore_config_backup (100%) create mode 100755 usr/local/etc/rc.sshd diff --git a/conf.default/config.xml b/conf.default/config.xml index 4a61a7dec..c95fac607 100644 --- a/conf.default/config.xml +++ b/conf.default/config.xml @@ -668,7 +668,7 @@ * * root - /usr/bin/nice -n20 /etc/rc.dyndns.update + /usr/bin/nice -n20 /usr/local/etc/rc.dyndns.update */60 diff --git a/etc/sshd b/etc/sshd deleted file mode 100755 index 90401698d..000000000 --- a/etc/sshd +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/local/bin/php -f -. - 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. -*/ - - require_once("globals.inc"); - require_once("config.inc"); - require_once("functions.inc"); - require_once("shaper.inc"); - - if (!isset($config['system']['enablesshd'])) { - return; - } - - /* are we already running? if not, do conf_mount_rw(), otherwise it should already be rw */ - if (!is_subsystem_dirty('sshdkeys')) { - conf_mount_rw(); - } - - $keys = array( - 'ssh_host_key', - 'ssh_host_key.pub', - 'ssh_host_dsa_key', - 'ssh_host_dsa_key.pub', - 'ssh_host_rsa_key', - 'ssh_host_rsa_key.pub', - 'ssh_host_ecdsa_key', - 'ssh_host_ecdsa_key.pub', - 'ssh_host_ed25519_key', - 'ssh_host_ed25519_key.pub' - ); - - /* restore ssh data for nanobsd platform */ - if($g['platform'] == "nanobsd" and file_exists("/conf/sshd/ssh_host_key") and !file_exists("/etc/ssh/ssh_host_key.pub")) { - echo "Restoring SSH from /conf/sshd/"; - exec("/bin/cp -p /conf/sshd/* /etc/ssh/"); - - /* make sure host private key permissions aren't too open so sshd won't complain */ - foreach($keys as $f2c) { - if(file_exists("/etc/ssh/{$f2c}")) - chmod("/etc/ssh/{$f2c}", 0600); - } - } - - /* if any of these files are 0 bytes then they are corrupted. - * remove them - */ - foreach($keys as $f2c) { - if (file_exists("/etc/ssh/{$f2c}") && filesize("/etc/ssh/{$f2c}") == 0) { - unlink_if_exists('/etc/ssh/ssh_host*'); - break; - } - } - - if (!is_dir("/var/empty")) { - /* make ssh home directory */ - mkdir("/var/empty", 0555); - } - - if(!file_exists("/var/log/lastlog")) { - /* Login related files. */ - @touch("/var/log/lastlog"); - } - - $sshConfigDir = "/etc/ssh"; - - if (is_array($config['system']['ssh']) && !empty($config['system']['ssh']['port'])) - $sshport = $config['system']['ssh']['port']; - else - $sshport = 22; - - /* Include default configuration for pfSense */ - $sshconf = "# This file is automatically generated at startup\n"; - $sshconf .= "Ciphers aes128-ctr,aes256-ctr,arcfour256,arcfour,aes128-cbc,aes256-cbc\n"; - $sshconf .= "PermitRootLogin yes\n"; - $sshconf .= "Compression yes\n"; - $sshconf .= "ClientAliveInterval 30\n"; - $sshconf .= "UseDNS no\n"; - $sshconf .= "X11Forwarding no\n"; - if (isset($config['system']['ssh']['sshdkeyonly'])) { - $sshconf .= "# Login via Key only\n"; - $sshconf .= "PasswordAuthentication no\n"; - $sshconf .= "ChallengeResponseAuthentication no\n"; - $sshconf .= "PubkeyAuthentication yes\n"; - } else { - $sshconf .= "# Login via Key and Password\n"; - $sshconf .= "PasswordAuthentication yes\n"; - $sshconf .= "ChallengeResponseAuthentication yes\n"; - $sshconf .= "PubkeyAuthentication yes\n"; - } - $sshconf .= "# override default of no subsystems\n"; - $sshconf .= "Subsystem sftp /usr/libexec/sftp-server\n"; - /* Only allow protocol 2, because we say so */ - $sshconf .= "Protocol 2\n"; - /* Run the server on another port if we have one defined */ - $sshconf .= "Port $sshport\n"; - /* Hide FreeBSD version */ - $sshconf .= "VersionAddendum \n"; - - /* Apply package SSHDCond settings if config file exists */ - if (file_exists("/etc/sshd_extra")) { - $fdExtra = fopen("/etc/sshd_extra", 'r'); - $szExtra = fread($fdExtra, 1048576); // Read up to 1MB from extra file - $sshconf .= $szExtra; - fclose($fdExtra); - } - - /* Write the new sshd config file */ - @file_put_contents("/etc/ssh/sshd_config", $sshconf); - - /* mop up from a badly implemented ssh keys -> cf backup */ - if($config['ssh']['dsa_key'] <> "") { - unset($config['ssh']['dsa_key']); - unset($config['ssh']['ecdsa_key']); - unset($config['ssh']['ed25519_key']); - unset($config['ssh']['rsa_key']); - unset($config['ssh']['rsa1_key']); - unset($config['ssh']['dsa']); - unset($config['ssh']['rsa']); - unset($config['ssh']['rsa1']); - unset($config['ssh']['ak']); - write_config("Clearing SSH keys from config.xml"); - } - - /* are we already running? if so exit */ - if(is_subsystem_dirty('sshdkeys')) { - unset($keys); - return; - } - - // Check for all needed key files. If any are missing, the keys need to be regenerated. - $generate_keys = false; - foreach ($keys as $f2c) { - if (!file_exists("/etc/ssh/{$f2c}")) { - $generate_keys = true; - break; - } - } - - if ($generate_keys) { - /* remove previous keys and regen later */ - file_notice("SSH", "{$g['product_name']} has started creating your SSH keys. SSH Startup will be delayed. Please note that reloading the filter rules and changes will be delayed until this operation is completed.", "SSH KeyGen", ""); - unlink_if_exists('/etc/ssh/ssh_host_*'); - mark_subsystem_dirty('sshdkeys'); - echo " Generating Keys:\n"; - $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t rsa1 -N '' -f $sshConfigDir/ssh_host_key"); - $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t rsa -N '' -f $sshConfigDir/ssh_host_rsa_key"); - $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t dsa -N '' -f $sshConfigDir/ssh_host_dsa_key"); - $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t ecdsa -N '' -f $sshConfigDir/ssh_host_ecdsa_key"); - $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t ed25519 -N '' -f $sshConfigDir/ssh_host_ed25519_key"); - clear_subsystem_dirty('sshdkeys'); - file_notice("SSH", "{$g['product_name']} has completed creating your SSH keys. SSH is now started.", "SSH Startup", ""); - } - - /* kill existing sshd process, server only, not the childs */ - $sshd_pid = exec("ps ax | egrep '/usr/sbin/[s]shd' | awk '{print $1}'"); - if($sshd_pid <> "") { - echo "stopping ssh process $sshd_pid \n"; - @posix_kill($sshd_pid, SIGTERM); - } - /* Launch new server process */ - $status = mwexec("/usr/sbin/sshd"); - if($status <> 0) { - file_notice("sshd_startup", "SSHD failed to start.", "SSHD Daemon", ""); - echo "error!\n"; - } else { - echo "done.\n"; - } - - // NanoBSD - if($g['platform'] == "nanobsd") { - if(!is_dir("/conf/sshd")) - mkdir("/conf/sshd", 0750); - $_gb = exec("/bin/cp -p /etc/ssh/ssh_host* /conf/sshd"); - } - conf_mount_ro(); - unset($keys); -?> diff --git a/tmp/pre_upgrade_command b/tmp/pre_upgrade_command index a06e017b4..82db587fb 100644 --- a/tmp/pre_upgrade_command +++ b/tmp/pre_upgrade_command @@ -7,7 +7,7 @@ PRIOR_VERSION=`uname -r | cut -d'.' -f1` echo $PRIOR_VERSION > /tmp/pre_upgrade_version # Hack to workaround ticket #3749 -if [ "${PRIOR_VERSION}" = "8" ] && grep -q 'sh /etc/rc.reboot' /usr/local/etc/rc.firmware; then +if [ "${PRIOR_VERSION}" = "8" ] && grep -q 'sh /usr/local/etc/rc.reboot' /usr/local/etc/rc.firmware; then PROC=$(ps axwww | grep '/usr/local/etc/rc.firmware *pfSenseupgrade') PID='' IMG='' diff --git a/usr/local/etc/inc/interfaces.inc b/usr/local/etc/inc/interfaces.inc index 74b05ec7e..00618cf90 100644 --- a/usr/local/etc/inc/interfaces.inc +++ b/usr/local/etc/inc/interfaces.inc @@ -1,6 +1,6 @@ /dev/null 2>&1 &"); + mwexec("nohup /usr/local/etc/rc.reboot > /dev/null 2>&1 &"); } function system_reboot_sync() { @@ -1690,7 +1690,7 @@ function system_reboot_sync() { system_reboot_cleanup(); - mwexec("/etc/rc.reboot > /dev/null 2>&1"); + mwexec("/usr/local/etc/rc.reboot > /dev/null 2>&1"); } function system_reboot_cleanup() { diff --git a/usr/local/etc/inc/upgrade_config.inc b/usr/local/etc/inc/upgrade_config.inc index 75c6d1b79..67c9e7c28 100644 --- a/usr/local/etc/inc/upgrade_config.inc +++ b/usr/local/etc/inc/upgrade_config.inc @@ -461,7 +461,7 @@ function upgrade_025_to_026() { $cron_item['month'] = "*"; $cron_item['wday'] = "*"; $cron_item['who'] = "root"; - $cron_item['command'] = "/usr/bin/nice -n20 /etc/rc.dyndns.update"; + $cron_item['command'] = "/usr/bin/nice -n20 /usr/local/etc/rc.dyndns.update"; $config['cron']['item'][] = $cron_item; diff --git a/usr/local/etc/rc.bootup b/usr/local/etc/rc.bootup index 209ebe1f1..52f92f7a9 100755 --- a/usr/local/etc/rc.bootup +++ b/usr/local/etc/rc.bootup @@ -66,7 +66,7 @@ function rescue_detect_keypress() { echo "\n\nInstaller mode selected...\n"; passthru("/usr/bin/env TERM=cons25 /bin/csh -c /usr/local/installer/lua_installer"); if(file_exists("/tmp/install_complete")) { - passthru("/etc/rc.reboot"); + passthru("/usr/local/etc/rc.reboot"); exit; } } elseif (in_array($key, array("!", "~"))) { diff --git a/etc/rc.dyndns.update b/usr/local/etc/rc.dyndns.update similarity index 98% rename from etc/rc.dyndns.update rename to usr/local/etc/rc.dyndns.update index ac56f3562..607b8000f 100755 --- a/etc/rc.dyndns.update +++ b/usr/local/etc/rc.dyndns.update @@ -1,8 +1,7 @@ #!/usr/local/bin/php -f diff --git a/usr/local/etc/rc.firmware b/usr/local/etc/rc.firmware index 27c4fd615..9695098c1 100755 --- a/usr/local/etc/rc.firmware +++ b/usr/local/etc/rc.firmware @@ -155,7 +155,7 @@ pfSenseNanoBSDupgrade) echo "NanoBSD Firmware upgrade in progress..." >> /conf/upgrade_log.txt 2>&1 echo "NanoBSD Firmware upgrade in progress..." | wall - /etc/rc.notify_message -e -g -m "NanoBSD Firmware upgrade in progress..." + /usr/local/etc/rc.notify_message -e -g -m "NanoBSD Firmware upgrade in progress..." # backup config /bin/mkdir -p /tmp/configbak @@ -367,13 +367,13 @@ pfSenseNanoBSDupgrade) echo "NanoBSD Firmware upgrade is complete. Rebooting in 10 seconds." >> /conf/upgrade_log.txt 2>&1 echo "NanoBSD Firmware upgrade is complete. Rebooting in 10 seconds." | wall - /etc/rc.notify_message -e -g -m "NanoBSD Firmware upgrade is complete. Rebooting in 10 seconds." + /usr/local/etc/rc.notify_message -e -g -m "NanoBSD Firmware upgrade is complete. Rebooting in 10 seconds." sleep 10 rm -f /var/run/firmwarelock.dirty rm -f /var/run/firmware.lock - . /etc/rc.reboot + . /usr/local/etc/rc.reboot ;; pfSenseupgrade) @@ -419,7 +419,7 @@ pfSenseupgrade) echo "Firmware upgrade in progress..." >> /conf/upgrade_log.txt 2>&1 echo "Firmware upgrade in progress..." | wall - /etc/rc.notify_message -e -g -m "Firmware upgrade in progress..." + /usr/local/etc/rc.notify_message -e -g -m "Firmware upgrade in progress..." # backup config [ -d /tmp/configbak ] && rm -rf /tmp/configbak @@ -489,7 +489,7 @@ pfSenseupgrade) echo "Firmware upgrade is complete. Rebooting in 10 seconds." >> /conf/upgrade_log.txt 2>&1 echo "Firmware upgrade is complete. Rebooting in 10 seconds." | wall - /etc/rc.notify_message -e -g -m "Firmware upgrade is complete. Rebooting in 10 seconds." + /usr/local/etc/rc.notify_message -e -g -m "Firmware upgrade is complete. Rebooting in 10 seconds." # Sleep and allow disks to catch up sleep 10 @@ -500,7 +500,7 @@ pfSenseupgrade) if [ -f /tmp/no_upgrade_reboot_required ]; then rm /tmp/no_upgrade_reboot_required else - . /etc/rc.reboot + . /usr/local/etc/rc.reboot fi ;; diff --git a/usr/local/etc/rc.initial b/usr/local/etc/rc.initial index f3c823b48..7641951d3 100755 --- a/usr/local/etc/rc.initial +++ b/usr/local/etc/rc.initial @@ -131,7 +131,7 @@ case ${opmode} in /usr/local/etc/rc.initial.toggle_sshd ;; 15) - /etc/rc.restore_config_backup + /usr/local/etc/rc.restore_config_backup ;; 99) if [ -e /dev/ukbd0 ]; then diff --git a/usr/local/etc/rc.kill_states b/usr/local/etc/rc.kill_states index 5db889253..aa55d4cef 100755 --- a/usr/local/etc/rc.kill_states +++ b/usr/local/etc/rc.kill_states @@ -1,7 +1,7 @@ #!/usr/local/bin/php -f All rights reserved. diff --git a/etc/rc.reboot b/usr/local/etc/rc.reboot similarity index 100% rename from etc/rc.reboot rename to usr/local/etc/rc.reboot diff --git a/etc/rc.resolv_conf_generate b/usr/local/etc/rc.resolv_conf_generate similarity index 100% rename from etc/rc.resolv_conf_generate rename to usr/local/etc/rc.resolv_conf_generate diff --git a/etc/rc.restore_config_backup b/usr/local/etc/rc.restore_config_backup similarity index 100% rename from etc/rc.restore_config_backup rename to usr/local/etc/rc.restore_config_backup diff --git a/usr/local/etc/rc.sshd b/usr/local/etc/rc.sshd new file mode 100755 index 000000000..4e7f2a000 --- /dev/null +++ b/usr/local/etc/rc.sshd @@ -0,0 +1,195 @@ +#!/usr/local/bin/php -f +. + 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. +*/ + +require_once("globals.inc"); +require_once("config.inc"); +require_once("functions.inc"); +require_once("shaper.inc"); + +if (!isset($config['system']['enablesshd'])) { + return; +} + +/* are we already running? if not, do conf_mount_rw(), otherwise it should already be rw */ +if (!is_subsystem_dirty('sshdkeys')) { + conf_mount_rw(); +} + +$keys = array( + 'ssh_host_key', + 'ssh_host_key.pub', + 'ssh_host_dsa_key', + 'ssh_host_dsa_key.pub', + 'ssh_host_rsa_key', + 'ssh_host_rsa_key.pub', + 'ssh_host_ecdsa_key', + 'ssh_host_ecdsa_key.pub', + 'ssh_host_ed25519_key', + 'ssh_host_ed25519_key.pub' +); + +/* restore ssh data for nanobsd platform */ +if($g['platform'] == "nanobsd" and file_exists("/conf/sshd/ssh_host_key") and !file_exists("/etc/ssh/ssh_host_key.pub")) { + echo "Restoring SSH from /conf/sshd/"; + exec("/bin/cp -p /conf/sshd/* /etc/ssh/"); + + /* make sure host private key permissions aren't too open so sshd won't complain */ + foreach($keys as $f2c) { + if(file_exists("/etc/ssh/{$f2c}")) + chmod("/etc/ssh/{$f2c}", 0600); + } +} + +/* if any of these files are 0 bytes then they are corrupted. + * remove them + */ +foreach($keys as $f2c) { + if (file_exists("/etc/ssh/{$f2c}") && filesize("/etc/ssh/{$f2c}") == 0) { + unlink_if_exists('/etc/ssh/ssh_host*'); + break; + } +} + +if (!is_dir("/var/empty")) { + /* make ssh home directory */ + mkdir("/var/empty", 0555); +} + +if(!file_exists("/var/log/lastlog")) { + /* Login related files. */ + @touch("/var/log/lastlog"); +} + +$sshConfigDir = "/etc/ssh"; + +if (is_array($config['system']['ssh']) && !empty($config['system']['ssh']['port'])) + $sshport = $config['system']['ssh']['port']; +else + $sshport = 22; + +/* Include default configuration for pfSense */ +$sshconf = "# This file is automatically generated at startup\n"; +$sshconf .= "Ciphers aes128-ctr,aes256-ctr,arcfour256,arcfour,aes128-cbc,aes256-cbc\n"; +$sshconf .= "PermitRootLogin yes\n"; +$sshconf .= "Compression yes\n"; +$sshconf .= "ClientAliveInterval 30\n"; +$sshconf .= "UseDNS no\n"; +$sshconf .= "X11Forwarding no\n"; +if (isset($config['system']['ssh']['sshdkeyonly'])) { + $sshconf .= "# Login via Key only\n"; + $sshconf .= "PasswordAuthentication no\n"; + $sshconf .= "ChallengeResponseAuthentication no\n"; + $sshconf .= "PubkeyAuthentication yes\n"; +} else { + $sshconf .= "# Login via Key and Password\n"; + $sshconf .= "PasswordAuthentication yes\n"; + $sshconf .= "ChallengeResponseAuthentication yes\n"; + $sshconf .= "PubkeyAuthentication yes\n"; +} +$sshconf .= "# override default of no subsystems\n"; +$sshconf .= "Subsystem sftp /usr/libexec/sftp-server\n"; +/* Only allow protocol 2, because we say so */ +$sshconf .= "Protocol 2\n"; +/* Run the server on another port if we have one defined */ +$sshconf .= "Port $sshport\n"; +/* Hide FreeBSD version */ +$sshconf .= "VersionAddendum \n"; + +/* Write the new sshd config file */ +@file_put_contents("/etc/ssh/sshd_config", $sshconf); + +/* mop up from a badly implemented ssh keys -> cf backup */ +if($config['ssh']['dsa_key'] <> "") { + unset($config['ssh']['dsa_key']); + unset($config['ssh']['ecdsa_key']); + unset($config['ssh']['ed25519_key']); + unset($config['ssh']['rsa_key']); + unset($config['ssh']['rsa1_key']); + unset($config['ssh']['dsa']); + unset($config['ssh']['rsa']); + unset($config['ssh']['rsa1']); + unset($config['ssh']['ak']); + write_config("Clearing SSH keys from config.xml"); +} + +/* are we already running? if so exit */ +if(is_subsystem_dirty('sshdkeys')) { + unset($keys); + return; +} + +// Check for all needed key files. If any are missing, the keys need to be regenerated. +$generate_keys = false; +foreach ($keys as $f2c) { + if (!file_exists("/etc/ssh/{$f2c}")) { + $generate_keys = true; + break; + } +} + +if ($generate_keys) { + /* remove previous keys and regen later */ + file_notice("SSH", "{$g['product_name']} has started creating your SSH keys. SSH Startup will be delayed. Please note that reloading the filter rules and changes will be delayed until this operation is completed.", "SSH KeyGen", ""); + unlink_if_exists('/etc/ssh/ssh_host_*'); + mark_subsystem_dirty('sshdkeys'); + echo " Generating Keys:\n"; + $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t rsa1 -N '' -f $sshConfigDir/ssh_host_key"); + $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t rsa -N '' -f $sshConfigDir/ssh_host_rsa_key"); + $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t dsa -N '' -f $sshConfigDir/ssh_host_dsa_key"); + $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t ecdsa -N '' -f $sshConfigDir/ssh_host_ecdsa_key"); + $_gb = exec("/usr/bin/nice -n20 /usr/bin/ssh-keygen -t ed25519 -N '' -f $sshConfigDir/ssh_host_ed25519_key"); + clear_subsystem_dirty('sshdkeys'); + file_notice("SSH", "{$g['product_name']} has completed creating your SSH keys. SSH is now started.", "SSH Startup", ""); +} + +/* kill existing sshd process, server only, not the childs */ +$sshd_pid = exec("ps ax | egrep '/usr/sbin/[s]shd' | awk '{print $1}'"); +if($sshd_pid <> "") { + echo "stopping ssh process $sshd_pid \n"; + @posix_kill($sshd_pid, SIGTERM); +} +/* Launch new server process */ +$status = mwexec("/usr/sbin/sshd"); +if($status <> 0) { + file_notice("sshd_startup", "SSHD failed to start.", "SSHD Daemon", ""); + echo "error!\n"; +} else { + echo "done.\n"; +} + +// NanoBSD +if($g['platform'] == "nanobsd") { + if(!is_dir("/conf/sshd")) + mkdir("/conf/sshd", 0750); + $_gb = exec("/bin/cp -p /etc/ssh/ssh_host* /conf/sshd"); +} +conf_mount_ro(); +unset($keys); diff --git a/usr/local/opnsense/service/conf/actions_interface.conf b/usr/local/opnsense/service/conf/actions_interface.conf index de98841b8..3f1475d9d 100644 --- a/usr/local/opnsense/service/conf/actions_interface.conf +++ b/usr/local/opnsense/service/conf/actions_interface.conf @@ -29,13 +29,13 @@ type:script message:Configuring interface %s [newip] -command:/etc/rc.newwanip +command:/usr/local/etc/rc.newwanip parameters:%s type:script message:rc.newwanip starting %s [newwanipv6] -command:/etc/rc.newwanipv6 +command:/usr/local/etc/rc.newwanipv6 parameters:%s type:script message:rc.newwanipv6 starting %s diff --git a/usr/local/opnsense/service/conf/actions_service.conf b/usr/local/opnsense/service/conf/actions_service.conf index 5bdb0bce9..8ec6b085d 100644 --- a/usr/local/opnsense/service/conf/actions_service.conf +++ b/usr/local/opnsense/service/conf/actions_service.conf @@ -5,7 +5,7 @@ type:script message:Reloading all [reload|restart.dns] -command:/etc/rc.resolv_conf_generate +command:/usr/local/etc/rc.resolv_conf_generate parameters: type:script message:Rewriting resolv.conf @@ -29,13 +29,13 @@ type:script message:Restarting OpenVPN tunnels/interfaces %s [reload|restart.dyndns] -command:/etc/rc.dyndns.update +command:/usr/local/etc/rc.dyndns.update parameters:%s type:script message:updating dyndns %s [reload|restart.dyndnsall] -command:/etc/rc.dyndns.update +command:/usr/local/etc/rc.dyndns.update parameters: type:script message:Updating all dyndns @@ -54,7 +54,7 @@ type:script message:Starting packages [reload|restart.sshd] -command:/etc/sshd +command:/usr/local/etc/rc.sshd parameters: type:script message:starting sshd diff --git a/usr/local/www/xmlrpc.php b/usr/local/www/xmlrpc.php index 93733cc87..3c12eef5f 100755 --- a/usr/local/www/xmlrpc.php +++ b/usr/local/www/xmlrpc.php @@ -464,7 +464,7 @@ function reboot_xmlrpc($raw_params) { xmlrpc_authfail(); return $xmlrpc_g['return']['authfail']; } - mwexec_bg("/etc/rc.reboot"); + mwexec_bg("/usr/local/etc/rc.reboot"); return $xmlrpc_g['return']['true']; }