diff --git a/src/etc/inc/auth.inc b/src/etc/inc/auth.inc index e6e22ba47..fa84e5eb9 100644 --- a/src/etc/inc/auth.inc +++ b/src/etc/inc/auth.inc @@ -342,9 +342,8 @@ function local_sync_accounts() * If a crontab was created to user, pw userdel will be interactive and * can cause issues. Just remove crontab before run it when necessary */ - unlink_if_exists("/var/cron/tabs/{$line[0]}"); - $cmd = "/usr/sbin/pw userdel -n '{$line[0]}'"; - mwexec($cmd); + @unlink("/var/cron/tabs/{$line[0]}"); + mwexecf('/usr/sbin/pw userdel -n %s', $line[0]); } pclose($fd); } @@ -364,8 +363,7 @@ function local_sync_accounts() if ($line[2] > 65000) { continue; } - $cmd = "/usr/sbin/pw groupdel {$line[2]}"; - mwexec($cmd); + mwexecf('/usr/sbin/pw groupdel %s', $line[2]); } pclose($fd); } @@ -477,12 +475,11 @@ function local_user_set(&$user) $keys = base64_decode($user['authorizedkeys']); @file_put_contents("{$user_home}/.ssh/authorized_keys", $keys); @chown("{$user_home}/.ssh/authorized_keys", $user_name); - } else - unlink_if_exists("{$user_home}/.ssh/authorized_keys"); - - $un = $lock_account ? "" : "un"; - exec("/usr/sbin/pw {$un}lock {$user_name} -q"); + } else { + @unlink("{$user_home}/.ssh/authorized_keys"); + } + mwexecf('/usr/sbin/pw %s %s -q', array($lock_account ? 'lock' : 'unlock', $user_name)); } function local_user_del($user) @@ -622,23 +619,20 @@ function local_group_set($group, $reset = false) pclose($fd); /* determine add or mod */ - if (!strncmp($pwread, "pw:", 3)) + if (!strncmp($pwread, "pw:", 3)) { $group_op = "groupadd"; - else + } else { $group_op = "groupmod"; + } /* add or mod group db */ - $cmd = "/usr/sbin/pw {$group_op} {$group_name} -g {$group_gid} -M {$group_members} 2>&1"; - - mwexec($cmd); - + mwexecf('/usr/sbin/pw %s %s -g %s -M %s', array($group_op, $group_name, $group_gid, $group_members)); } function local_group_del($group) { /* delete from group db */ - $cmd = "/usr/sbin/pw groupdel {$group['name']}"; - mwexec($cmd); + mwexecf('/usr/sbin/pw groupdel %s', $group['name']); } function ldap_test_connection($authcfg) @@ -1462,5 +1456,3 @@ function http_basic_auth($http_auth_header) // not authenticated return false; } - -?> diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 81441c437..f030bdc93 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -2371,7 +2371,7 @@ function interface_wireless_configure($if, &$wl, &$wlcfg) { */ // Remove script file - unlink_if_exists("/tmp/{$if}_setup.sh"); + @unlink("/tmp/{$if}_setup.sh"); // Clone wireless nic if needed. interface_wireless_clone($if, $wl); @@ -5198,7 +5198,7 @@ EOD; chmod($cron_file, 0755); killbypid('/var/run/cron.pid', 'HUP'); } else { - unlink_if_exists($cron_file); + @unlink($cron_file); } } diff --git a/src/etc/inc/notices.inc b/src/etc/inc/notices.inc index 269d4a7d2..053a9b034 100644 --- a/src/etc/inc/notices.inc +++ b/src/etc/inc/notices.inc @@ -128,7 +128,7 @@ function close_notice($id) $ids = array(); if(!$notices = get_notices()) return; if($id == "all") { - unlink_if_exists('/tmp/notices'); + @unlink('/tmp/notices'); return; } foreach(array_keys($notices) as $time) { @@ -151,13 +151,10 @@ function close_notice($id) fwrite($queueout, serialize($notices)); fclose($queueout); } else { - unlink_if_exists('/tmp/notices'); + @unlink('/tmp/notices'); } - - return; } - /****f* notices/print_notices * NAME * print_notices @@ -360,5 +357,3 @@ function notify_all_remote($msg) { notify_via_smtp($msg); notify_via_growl($msg); } - -?> diff --git a/src/etc/inc/openvpn.inc b/src/etc/inc/openvpn.inc index 64a2ffdff..8c4c42faa 100644 --- a/src/etc/inc/openvpn.inc +++ b/src/etc/inc/openvpn.inc @@ -873,14 +873,9 @@ function openvpn_delete($mode, & $settings) @array_map('unlink', glob("{$g['varetc_path']}/openvpn/{$mode_id}.*")); } -function openvpn_cleanup_csc($common_name) { - global $g, $config; - if (empty($common_name)) - return; - $fpath = "{$g['varetc_path']}/openvpn-csc/" . basename($common_name); - if (is_file($fpath)) - unlink_if_exists($fpath); - return; +function openvpn_cleanup_csc($common_name) +{ + @unlink('/var/etc/openvpn-csc/' . basename($common_name)); } function openvpn_resync_csc(& $settings) { @@ -889,7 +884,7 @@ function openvpn_resync_csc(& $settings) { $fpath = $g['varetc_path']."/openvpn-csc/".$settings['common_name']; if (isset($settings['disable'])) { - unlink_if_exists($fpath); + @unlink($fpath); return; } openvpn_create_dirs(); @@ -941,20 +936,17 @@ function openvpn_resync_csc(& $settings) { chgrp($fpath, 'nobody'); } -function openvpn_delete_csc(& $settings) { - global $g, $config; - - $fpath = $g['varetc_path']."/openvpn-csc/".$settings['common_name']; - unlink_if_exists($fpath); +function openvpn_delete_csc(&$settings) +{ + @unlink("/var/etc/openvpn-csc/{$settings['common_name']}"); } -// Resync the configuration and restart the VPN -function openvpn_resync($mode, $settings) { +function openvpn_resync($mode, $settings) +{ openvpn_reconfigure($mode, $settings); openvpn_restart($mode, $settings); } -// Resync and restart all VPNs function openvpn_resync_all($interface = '') { global $g, $config; diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index dbe6dda39..d47f8577f 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -686,8 +686,8 @@ function reload_all_sync() { system_ntp_configure(); /* sync pw database */ - unlink_if_exists("/etc/spwd.db.tmp"); - mwexec("/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd"); + @unlink('/etc/spwd.db.tmp'); + mwexec('/usr/sbin/pwd_mkdb -d /etc/ /etc/master.passwd'); /* restart sshd */ mwexec_bg('/usr/local/etc/rc.sshd'); @@ -1657,18 +1657,19 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false) { || $forceupdate) { // Try to fetch the URL supplied - unlink_if_exists($urltable_filename . ".tmp"); + @unlink("{$urltable_filename}.tmp"); $verify_ssl = isset($config['system']['checkaliasesurlcert']); - if (download_file($url, $urltable_filename . ".tmp", $verify_ssl)) { + if (download_file($url, "{$urltable_filename}.tmp", $verify_ssl)) { mwexec("/usr/bin/sed -E 's/\;.*//g; /^[[:space:]]*($|#)/d' ". escapeshellarg($urltable_filename . ".tmp") . " > " . escapeshellarg($urltable_filename)); if (alias_get_type($name) == "urltable_ports") { $ports = explode("\n", file_get_contents($urltable_filename)); $ports = group_ports($ports); file_put_contents($urltable_filename, implode("\n", $ports)); } - unlink_if_exists($urltable_filename . ".tmp"); - } else + @unlink("{$urltable_filename}.tmp"); + } else { touch($urltable_filename); + } return true; } else { // File exists, and it doesn't need updated. diff --git a/src/etc/inc/rrd.inc b/src/etc/inc/rrd.inc index 670721c89..c99ae9053 100644 --- a/src/etc/inc/rrd.inc +++ b/src/etc/inc/rrd.inc @@ -30,7 +30,7 @@ function dump_rrd_to_xml($rrddatabase, $xmldumpfile) { $rrdtool = '/usr/local/bin/rrdtool'; - unlink_if_exists($xmldumpfile); + @unlink($xmldumpfile); exec("$rrdtool dump " . escapeshellarg($rrddatabase) . " {$xmldumpfile} 2>&1", $dumpout, $dumpret); if ($dumpret <> 0) { @@ -77,7 +77,7 @@ function restore_rrd() } /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ if (!isset($config['system']['use_mfs_tmpvar'])) { - unlink_if_exists('/conf/rrd.tgz'); + @unlink('/conf/rrd.tgz'); } return true; } diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index 14651eea0..db129402e 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -388,7 +388,7 @@ function services_dhcpdv4_configure() } /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ if (!isset($config['system']['use_mfs_tmpvar'])) { - unlink_if_exists('/conf/dhcpleases.tgz'); + @unlink('/conf/dhcpleases.tgz'); } } @@ -1008,7 +1008,7 @@ function services_dhcpdv6_configure($blacklist = array()) } /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ if (isset($config['system']['use_mfs_tmpvar'])) { - unlink_if_exists('/conf/dhcp6leases.tgz'); + @unlink('/conf/dhcp6leases.tgz'); } } diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 5732f8de8..8dd2c2d80 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -1264,7 +1264,7 @@ function system_ntp_setup_gps($serialport) { return false; // Create symlink that ntpd requires - unlink_if_exists($gps_device); + @unlink($gps_device); symlink($serialport, $gps_device); /* Send the following to the GPS port to initialize the GPS */ @@ -1306,23 +1306,22 @@ function system_ntp_setup_gps($serialport) { return true; } -function system_ntp_setup_pps($serialport) { - global $config, $g; - +function system_ntp_setup_pps($serialport) +{ $pps_device = '/dev/pps0'; - $serialport = '/dev/'.$serialport; + $serialport = "/dev/{$serialport}"; - if (!file_exists($serialport)) + if (!file_exists($serialport)) { return false; + } // Create symlink that ntpd requires - unlink_if_exists($pps_device); + @unlink($pps_device); @symlink($serialport, $pps_device); return true; } - function system_ntp_configure($start_ntpd = true) { global $config, $g; diff --git a/src/etc/inc/upgrade_config.inc b/src/etc/inc/upgrade_config.inc index 34ec202b9..6ccee0725 100644 --- a/src/etc/inc/upgrade_config.inc +++ b/src/etc/inc/upgrade_config.inc @@ -2030,7 +2030,6 @@ function upgrade_054_to_055() { echo "Updating configuration..."; } - function upgrade_055_to_056() { global $config; @@ -2526,10 +2525,10 @@ function upgrade_077_to_078() { $config['pptpd']['n_pptp_units'] = empty($config['pptpd']['n_pptp_units']) ? 16 : $config['pptpd']['n_pptp_units']; } } -function upgrade_078_to_079() { - global $g; +function upgrade_078_to_079() +{ /* Delete old and unused RRD file */ - unlink_if_exists("/var/db/rrd/captiveportal-totalusers.rrd"); + @unlink('/var/db/rrd/captiveportal-totalusers.rrd'); } function upgrade_079_to_080() { @@ -2692,8 +2691,8 @@ function upgrade_080_to_081() { mwexec("$rrdtool restore -f /tmp/{$xmldumpnew} {$rrddbpath}/{$database} 2>&1"); unset($xml); # Default /tmp tmpfs is ~40mb, do not leave temp files around - unlink_if_exists("/tmp/{$xmldump}"); - unlink_if_exists("/tmp/{$xmldumpnew}"); + @unlink("/tmp/{$xmldump}"); + @unlink("/tmp/{$xmldumpnew}"); } enable_rrd_graphing(); /* Let's save the RRD graphs after we run enable RRD graphing */ @@ -3254,13 +3253,13 @@ function upgrade_110_to_111() mwexec('/usr/sbin/pw useradd -n unbound -c "Unbound DNS Resolver" -d /var/unbound -s /usr/sbin/nologin -u 59 -g 59', true); /* cleanup old unbound package stuffs */ - unlink_if_exists("/usr/local/pkg/unbound.xml"); - unlink_if_exists("/usr/local/pkg/unbound.inc"); - unlink_if_exists("/usr/local/pkg/unbound_advanced.xml"); - unlink_if_exists("/usr/local/www/unbound_status.php"); - unlink_if_exists("/usr/local/www/unbound_acls.php"); - unlink_if_exists("/usr/local/bin/unbound_monitor.sh"); - unlink_if_exists("/usr/local/etc/rc.d/unbound.sh"); + @unlink('/usr/local/pkg/unbound.xml'); + @unlink('/usr/local/pkg/unbound.inc'); + @unlink('/usr/local/pkg/unbound_advanced.xml'); + @unlink('/usr/local/www/unbound_status.php'); + @unlink('/usr/local/www/unbound_acls.php'); + @unlink('/usr/local/bin/unbound_monitor.sh'); + @unlink('/usr/local/etc/rc.d/unbound.sh'); /* Remove old menu and service entries */ if (isset($config['installedpackages']['menu']) && is_array($config['installedpackages']['menu'])) { diff --git a/src/etc/inc/vpn.inc b/src/etc/inc/vpn.inc index 723bcff3a..9bcdf55d4 100644 --- a/src/etc/inc/vpn.inc +++ b/src/etc/inc/vpn.inc @@ -937,9 +937,9 @@ function vpn_pptpd_configure() { } /* remove mpd.conf, if it exists */ - unlink_if_exists("{$g['varetc_path']}/pptp-vpn/mpd.conf"); - unlink_if_exists("{$g['varetc_path']}/pptp-vpn/mpd.links"); - unlink_if_exists("{$g['varetc_path']}/pptp-vpn/mpd.secret"); + @unlink('/var/etc/pptp-vpn/mpd.conf'); + @unlink('/var/etc/pptp-vpn/mpd.links'); + @unlink('/var/etc/pptp-vpn/mpd.secret'); } if (empty($pptpdcfg['n_pptp_units'])) { diff --git a/src/etc/inc/vslb.inc b/src/etc/inc/vslb.inc index 65a4937f3..b209d9eeb 100644 --- a/src/etc/inc/vslb.inc +++ b/src/etc/inc/vslb.inc @@ -557,5 +557,5 @@ function cleanup_lb_marked() } } - unlink_if_exists($filename); + @unlink($filename); } diff --git a/src/pkg/openvpn-client-export.inc b/src/pkg/openvpn-client-export.inc index 35c894e64..04f44582b 100644 --- a/src/pkg/openvpn-client-export.inc +++ b/src/pkg/openvpn-client-export.inc @@ -63,9 +63,9 @@ function openvpn_client_export_deinstall() $ovpndir = "/usr/local/share/openvpn"; $workdir = "{$ovpndir}/client-export"; - unlink_if_exists("/usr/local/www/{$phpfile}"); - unlink_if_exists("/usr/local/www/{$phpfile2}"); - unlink_if_exists("/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz"); + @unlink("/usr/local/www/{$phpfile}"); + @unlink("/usr/local/www/{$phpfile2}"); + @unlink("/usr/local/pkg/openvpn-client-export-{$current_openvpn_version}.tgz"); exec("/bin/rm -r {$workdir}"); } diff --git a/src/www/diag_confbak.php b/src/www/diag_confbak.php index fdc7cf79f..5455adb1e 100644 --- a/src/www/diag_confbak.php +++ b/src/www/diag_confbak.php @@ -55,7 +55,7 @@ if (isset($_POST['backupcount'])) { $savemsg = gettext("Unable to revert to the selected configuration."); } if($_POST['rmver'] != "") { - unlink_if_exists('/conf/backup/config-' . $_POST['rmver'] . '.xml'); + @unlink('/conf/backup/config-' . $_POST['rmver'] . '.xml'); $savemsg = sprintf(gettext('Deleted backup with timestamp %1$s and description "%2$s".'), date(gettext("n/j/y H:i:s"), $_POST['rmver']),$confvers[$_POST['rmver']]['description']); } } diff --git a/src/www/firewall_aliases_edit.php b/src/www/firewall_aliases_edit.php index adb04fe80..47a337180 100755 --- a/src/www/firewall_aliases_edit.php +++ b/src/www/firewall_aliases_edit.php @@ -194,7 +194,7 @@ if ($_POST) { /* fetch down and add in */ $isfirst = 0; $temp_filename = tempnam('/tmp/', 'alias_import'); - unlink_if_exists($temp_filename); + @unlink($temp_filename); $verify_ssl = isset($config['system']['checkaliasesurlcert']); mkdir($temp_filename); download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl); diff --git a/src/www/status_rrd_graph_img.php b/src/www/status_rrd_graph_img.php index 1fef5476f..bbe3803a9 100644 --- a/src/www/status_rrd_graph_img.php +++ b/src/www/status_rrd_graph_img.php @@ -1236,14 +1236,14 @@ if(($graphcmdreturn <> 0) || (! $data)) { log_error(sprintf(gettext('Failed to create graph with error code %1$s, the error is: %2$s'),$graphcmdreturn,$graphcmdoutput)); if(strstr($curdatabase, "queues")) { log_error(sprintf(gettext("failed to create graph from %s%s, removing database"),$rrddbpath,$curdatabase)); - unlink_if_exists($rrddbpath . $curif . $queues); + @unlink($rrddbpath . $curif . $queues); flush(); usleep(500); enable_rrd_graphing(); } if(strstr($curdatabase, "queuesdrop")) { log_error(sprintf(gettext("failed to create graph from %s%s, removing database"),$rrddbpath,$curdatabase)); - unlink_if_exists($rrddbpath . $curdatabase); + @unlink($rrddbpath . $curdatabase); flush(); usleep(500); enable_rrd_graphing();