Merge pull request #1519 from phil-davis/Code-style-etc-misc

This commit is contained in:
Renato Botelho 2015-02-26 09:37:47 -03:00
commit 9c8e788cc9
9 changed files with 149 additions and 112 deletions

View File

@ -4,7 +4,7 @@ require_once("interfaces.inc");
require_once("util.inc");
set_single_sysctl("net.inet.carp.allow", "0");
if(is_array($config['virtualip']['vip'])) {
if (is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
switch ($vip['mode']) {

View File

@ -3,18 +3,19 @@ require_once("config.inc");
require_once("interfaces.inc");
require_once("util.inc");
if(is_array($config['virtualip']['vip'])) {
if (is_array($config['virtualip']['vip'])) {
$viparr = &$config['virtualip']['vip'];
foreach ($viparr as $vip) {
switch ($vip['mode']) {
case "carp":
interface_carp_configure($vip);
sleep(1);
break;
case "ipalias":
if (strpos($vip['interface'], '_vip'))
interface_ipalias_configure($vip);
break;
case "carp":
interface_carp_configure($vip);
sleep(1);
break;
case "ipalias":
if (strpos($vip['interface'], '_vip')) {
interface_ipalias_configure($vip);
}
break;
}
}
}

View File

@ -10,7 +10,7 @@ require_once("filter.inc");
require_once("shaper.inc");
require_once("rrd.inc");
require_once("pfsense-utils.inc");
$GIT_PKG = "git"; // Either "git" or the full package URL
$GIT_BIN= "/usr/pbi/bin/git";
$GIT_REPO = "git://github.com/pfsense/pfsense.git";
@ -32,27 +32,29 @@ global $g;
global $argv;
global $command_split;
if(is_array($command_split))
if (is_array($command_split)) {
$temp_args = array_slice($command_split, 2);
else
} else {
$temp_args = array_slice($argv, 3);
}
$valid_args = array(
"--minimal" => "\tPerform a minimal copy of only the updated files.\n" .
"\tNot recommended if the system has files modified by any method other\n" .
"\tthan gitsync.\n",
"\tNot recommended if the system has files modified by any method other\n" .
"\tthan gitsync.\n",
"--help" => "\tDisplay this help list.\n"
);
$args = array();
$arg_count = 0;
while(!empty($temp_args)) {
while (!empty($temp_args)) {
$arg = array_shift($temp_args);
if($arg[0] == '-') {
switch($arg) {
if ($arg[0] == '-') {
switch ($arg) {
case "--help":
echo "Usage: playback gitsync [options] [[repository] <branch>]\nOptions:\n";
foreach($valid_args as $arg_name => $arg_desc)
foreach($valid_args as $arg_name => $arg_desc) {
echo $arg_name . "\n" . $arg_desc;
}
exit;
case "--upgrading":
// Disables all interactive functions and neither PHP
@ -73,7 +75,7 @@ while(!empty($temp_args)) {
unlink_if_exists("/tmp/config.cache");
conf_mount_rw();
if(!file_exists($GIT_BIN)) {
if (!file_exists($GIT_BIN)) {
echo "Cannot find git, fetching...\n";
require_once("config.inc");
require_once("util.inc");
@ -94,8 +96,9 @@ if(!file_exists($GIT_BIN)) {
if (($g['platform'] == "nanobsd")) {
$pkgtmpdir = "/usr/bin/env PKG_TMPDIR=/root/ ";
$pkgstagingdir = "/root/tmp";
if (!is_dir($pkgstagingdir))
if (!is_dir($pkgstagingdir)) {
mkdir($pkgstagingdir);
}
$pkgstaging = "-t {$pkgstagingdir}/instmp.XXXXXX";
}
system("{$pkgtmpdir}/usr/sbin/pkg_add {$pkgstaging} -r {$GIT_PKG}");
@ -107,34 +110,38 @@ if(!file_exists($GIT_BIN)) {
}
# Remove mainline if exists (older)
if(is_dir("/root/pfsense/mainline"))
if (is_dir("/root/pfsense/mainline")) {
exec("rm -rf /root/pfsense/mainline");
}
# Remove RELENG_1_2 if exists (older)
if(is_dir("/root/pfsense/RELENG_1_2"))
if (is_dir("/root/pfsense/RELENG_1_2")) {
exec("rm -rf /root/pfsense/RELENG_1_2");
}
# Remove HEAD if exists (older)
if(is_dir("/root/pfsense/HEAD"))
if (is_dir("/root/pfsense/HEAD")) {
exec("rm -rf /root/pfsense/HEAD");
}
if(file_exists("/root/cvssync_backup.tgz")) {
if (file_exists("/root/cvssync_backup.tgz")) {
$backup_date = `ls -lah /root/cvssync_backup.tgz | awk '{ print $6,$7,$8 }'`;
$tmp = array("RESTORE" => "Restores prior CVSSync backup data performed at {$backup_date}");
$branches = array_merge($branches, $tmp);
}
if(is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
if (is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} config remote.origin.url", $output_str, $ret);
if(is_array($output_str) && !empty($output_str[0]))
if (is_array($output_str) && !empty($output_str[0])) {
$GIT_REPO = $output_str[0];
}
unset($output_str);
}
if(!$args[0] && !$upgrading) {
if (!$args[0] && !$upgrading) {
echo "\nCurrent repository is $GIT_REPO\n";
echo "\nPlease select which branch you would like to sync against:\n\n";
foreach($branches as $branchname => $branchdesc) {
foreach ($branches as $branchname => $branchdesc) {
echo "{$branchname} \t {$branchdesc}\n";
}
echo "\nOr alternatively you may enter a custom RCS branch URL (Git or HTTP).\n\n";
@ -144,51 +151,55 @@ if(!$args[0] && !$upgrading) {
$branch = $args[0];
}
if($args[1] == "NOBACKUP")
if ($args[1] == "NOBACKUP") {
$nobackup = true;
else
} else {
$nobackup = false;
}
// If the repository has been fetched before, build a list of its branches.
if(is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
if (is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} branch -r", $branch_list, $ret);
if($ret == 0 && is_array($branch_list)) {
if ($ret == 0 && is_array($branch_list)) {
foreach ($branch_list as $branch_item) {
$branch_item = substr(strrchr($branch_item, "/"), 1);
if (!isset($branches[$branch_item]))
if (!isset($branches[$branch_item])) {
$branches[$branch_item] = " ";
}
}
}
}
$found = false;
foreach($branches as $branchname => $branchdesc) {
if($branchname == $branch)
foreach ($branches as $branchname => $branchdesc) {
if ($branchname == $branch) {
$found = true;
}
}
if(!$found) {
if(isURL($branch) && !$upgrading) {
if($args[1]) {
if (!$found) {
if (isURL($branch) && !$upgrading) {
if ($args[1]) {
$GIT_REPO = $branch;
$branch = $args[1];
$found = true;
}
else {
} else {
echo "\n";
echo "NOTE: $branch was not found.\n\n";
$command = readline("Is this a custom GIT URL? [y]? ");
if(strtolower($command) == "y" or $command == "") {
if (strtolower($command) == "y" or $command == "") {
$GIT_REPO = $branch;
$command = readline("Checkout which branch [${DEFAULT_BRANCH}]? ");
if($command == "")
if ($command == "") {
$branch = $DEFAULT_BRANCH;
if($command)
}
if ($command) {
$branch = $command;
}
$found = true;
}
}
}
if(!$found) {
if (!$found) {
echo "\nNo valid branch found. Exiting.\n\n";
conf_mount_ro();
exit;
@ -196,17 +207,18 @@ if(!$found) {
}
$merge_repos = array();
if(file_exists($GITSYNC_MERGE)) {
if (file_exists($GITSYNC_MERGE)) {
$gitsync_merges = file($GITSYNC_MERGE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if(!empty($gitsync_merges) && is_array($gitsync_merges)) {
if (!empty($gitsync_merges) && is_array($gitsync_merges)) {
echo "\n===> Automatic merge list read from ${GITSYNC_MERGE}\n";
foreach($gitsync_merges as $merge_line_num => $merge_line) {
foreach ($gitsync_merges as $merge_line_num => $merge_line) {
$merge_comments = explode("#", trim($merge_line));
if(empty($merge_comments[0]))
if (empty($merge_comments[0])) {
continue;
}
$merge_line = explode(" ", trim($merge_comments[0]));
if(count($merge_line) != 2 || empty($merge_line[0]) || empty($merge_line[1])) {
if (count($merge_line) != 2 || empty($merge_line[0]) || empty($merge_line[1])) {
echo "\nLine " . ($merge_line_num + 1) . " does not have the correct parameter count or has improper spacing.\n";
echo "Expected parameters: repository_url branch\n";
echo "Line read: " . implode(" ", $merge_line) . "\n\n";
@ -218,22 +230,23 @@ if(file_exists($GITSYNC_MERGE)) {
}
}
}
if(!$args[0] && !$upgrading) {
if (!$args[0] && !$upgrading) {
do {
echo "\nAdd a custom RCS branch URL (Git or HTTP) to merge in or press enter if done.\n\n";
$merge_repo = readline("> ");
if(!empty($merge_repo)) {
if (!empty($merge_repo)) {
$merge_branch = readline("Merge which branch [${DEFAULT_BRANCH}]? ");
if($merge_branch == "")
if ($merge_branch == "") {
$merge_repos[] = array('repo' => $merge_repo, 'branch' => $DEFAULT_BRANCH);
else if($merge_branch)
} else if ($merge_branch) {
$merge_repos[] = array('repo' => $merge_repo, 'branch' => $merge_branch);
}
}
} while(!empty($merge_repo));
} while (!empty($merge_repo));
}
if($branch == "RESTORE" && $g['platform'] == "pfSense") {
if(!file_exists("/root/cvssync_backup.tgz")) {
if ($branch == "RESTORE" && $g['platform'] == "pfSense") {
if (!file_exists("/root/cvssync_backup.tgz")) {
echo "Sorry, we could not find a previous CVSSync backup file.\n";
conf_mount_ro();
exit();
@ -247,7 +260,7 @@ if($branch == "RESTORE" && $g['platform'] == "pfSense") {
$nobackup = true; // do not backup embedded, livecd
}
if($nobackup == false) {
if ($nobackup == false) {
echo "===> Backing up current pfSense information...\n";
echo "===> Please wait... ";
exec("tar czPf /root/cvssync_backup.tgz --exclude /root --exclude /dev --exclude /tmp --exclude /var/run --exclude /var/empty /");
@ -259,7 +272,7 @@ if($nobackup == false) {
echo "===> Checking out $branch\n";
// Git commands for resetting to the specified branch
if($branch == "build_commit") {
if ($branch == "build_commit") {
$git_cmd = array(
"cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} branch " . escapeshellarg($branch) . " 2>/dev/null",
"cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} checkout -f " . escapeshellarg($branch) . " 2>/dev/null",
@ -274,28 +287,30 @@ if($branch == "build_commit") {
}
// Git 'er done!
if(is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
if (is_dir("$CODIR/pfSenseGITREPO/pfSenseGITREPO")) {
echo "===> Fetching updates...\n";
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} config remote.origin.url " . escapeshellarg($GIT_REPO));
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} fetch");
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} clean -f -f -x -d");
run_cmds($git_cmd);
} else {
exec("mkdir -p $CODIR/pfSenseGITREPO");
echo "Executing cd $CODIR/pfSenseGITREPO && {$GIT_BIN} clone $GIT_REPO pfSenseGITREPO\n";
exec("mkdir -p $CODIR/pfSenseGITREPO");
echo "Executing cd $CODIR/pfSenseGITREPO && {$GIT_BIN} clone $GIT_REPO pfSenseGITREPO\n";
exec("cd $CODIR/pfSenseGITREPO && {$GIT_BIN} clone " . escapeshellarg($GIT_REPO) . " pfSenseGITREPO");
if(is_dir("$CODIR/pfSenseGITREPO/pfSense"))
if (is_dir("$CODIR/pfSenseGITREPO/pfSense")) {
exec("mv $CODIR/pfSenseGITREPO/pfSense $CODIR/pfSenseGITREPO/pfSenseGITREPO");
if(is_dir("$CODIR/pfSenseGITREPO/mainline"))
}
if (is_dir("$CODIR/pfSenseGITREPO/mainline")) {
exec("mv $CODIR/pfSenseGITREPO/mainline $CODIR/pfSenseGITREPO/pfSenseGITREPO");
}
run_cmds($git_cmd);
}
foreach($merge_repos as $merge_repo) {
foreach ($merge_repos as $merge_repo) {
echo "===> Merging branch {$merge_repo['branch']} from {$merge_repo['repo']}\n";
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} pull " . escapeshellarg($merge_repo['repo']) . " " . escapeshellarg($merge_repo['branch']), $output_str, $ret);
unset($output_str);
if($ret <> 0) {
if ($ret <> 0) {
echo "\nMerge failed. Aborting sync.\n\n";
run_cmds($git_cmd);
conf_mount_ro();
@ -303,14 +318,16 @@ foreach($merge_repos as $merge_repo) {
}
}
if(isset($args["--minimal"])) {
if(file_exists("/etc/version.gitsync"))
if (isset($args["--minimal"])) {
if (file_exists("/etc/version.gitsync")) {
$old_revision = trim(file_get_contents("/etc/version.gitsync"));
else if(file_exists("/etc/version.lastcommit"))
} else if (file_exists("/etc/version.lastcommit")) {
$old_revision = trim(file_get_contents("/etc/version.lastcommit"));
}
$files_to_copy = strtr(shell_exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} diff --name-only " . escapeshellarg($old_revision)), "\n", " ");
} else
} else {
$files_to_copy = '--exclude .git .';
}
// Save new commit ID for later minimal file copies
exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} rev-parse -q --verify HEAD > /etc/version.gitsync");
@ -321,7 +338,7 @@ exec("mkdir -p /tmp/lighttpd/cache/compress/");
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name CVS -exec rm -rf {} \; 2>/dev/null");
exec("cd ${CODIR}/pfSenseGITREPO/pfSenseGITREPO && find . -name pfSense.tgz -exec rm {} \; 2>/dev/null");
// Remove files that we do not want to overwrite the system with
// Remove files that we do not want to overwrite the system with
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/crontab 2>/dev/null");
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/master.passwd 2>/dev/null");
exec("rm ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/passwd 2>/dev/null");
@ -341,13 +358,15 @@ exec("rm -f ${CODIR}/pfSenseGITREPO/pfSenseGITREPO/etc/syslog.conf 2>/dev/null")
echo "===> Installing new files...\n";
if($g['platform'] == "pfSense")
if ($g['platform'] == "pfSense") {
$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - {$files_to_copy} | (cd / ; tar -Uxpf -)";
else
} else {
$command = "cd $CODIR/pfSenseGITREPO/pfSenseGITREPO ; tar -cpf - {$files_to_copy} | (cd / ; tar -xpf -) 2>/dev/null";
if(!empty($files_to_copy))
}
if (!empty($files_to_copy)) {
exec($command);
else {
} else {
echo "Already up-to-date.\n";
$upgrading = true;
}
@ -357,19 +376,23 @@ exec("cd $CODIR/pfSenseGITREPO/pfSenseGITREPO && {$GIT_BIN} reset --hard >/dev/n
// Remove obsolete files
$files_to_remove = file("/etc/pfSense.obsoletedfiles");
foreach($files_to_remove as $file_to_remove)
if(file_exists($file_to_remove))
foreach ($files_to_remove as $file_to_remove) {
if (file_exists($file_to_remove)) {
exec("/bin/rm -f $file_to_remove");
}
}
if(!$upgrading)
if (!$upgrading) {
post_cvssync_commands();
}
echo "===> Checkout complete.\n";
echo "\n";
if(!$upgrading)
if (!$upgrading) {
echo "Your system is now sync'd and PHP and Lighty will be restarted in 5 seconds.\n\n";
else
} else {
echo "Your system is now sync'd.\n\n";
}
function post_cvssync_commands() {
echo "===> Removing FAST-CGI temporary files...\n";
@ -386,7 +409,7 @@ function post_cvssync_commands() {
exec("pfctl -f /tmp/rules.debug");
echo "\n";
if(file_exists("/etc/rc.php_ini_setup")) {
if (file_exists("/etc/rc.php_ini_setup")) {
echo "===> Running /etc/rc.php_ini_setup...";
exec("/etc/rc.php_ini_setup");
echo "\n";
@ -395,14 +418,15 @@ function post_cvssync_commands() {
/* lock down console if necessary */
echo "===> Locking down the console if needed...\n";
reload_ttys();
echo "===> Signaling PHP and Lighty restart...";
$fd = fopen("/tmp/restart_lighty", "w");
fwrite($fd, "#!/bin/sh\n");
fwrite($fd, "sleep 5\n");
fwrite($fd, "/usr/local/sbin/pfSctl -c 'service restart webgui'\n");
if(file_exists("/var/etc/lighty-CaptivePortal.conf"))
if (file_exists("/var/etc/lighty-CaptivePortal.conf")) {
fwrite($fd, "/usr/local/sbin/lighttpd -f /var/etc/lighty-CaptivePortal.conf\n");
}
fclose($fd);
mwexec_bg("sh /tmp/restart_lighty");
echo "\n";
@ -410,19 +434,23 @@ function post_cvssync_commands() {
}
function isUrl($url = "") {
if($url)
if(strstr($url, "rcs.pfsense.org") or
strstr($url, "mainline") or
strstr($url, ".git") or strstr($url, "git://"))
return true;
if ($url) {
if (strstr($url, "rcs.pfsense.org") or
strstr($url, "mainline") or
strstr($url, ".git") or
strstr($url, "git://")) {
return true;
}
}
return false;
}
function run_cmds($cmds) {
global $debug;
foreach($cmds as $cmd) {
if($debug)
foreach ($cmds as $cmd) {
if ($debug) {
echo "Running $cmd";
}
exec($cmd);
}
}

View File

@ -4,10 +4,11 @@ require_once("pkg-utils.inc");
global $g, $config, $argv, $command_split;
if(is_array($command_split))
if (is_array($command_split)) {
$args = array_slice($command_split, 2);
else
} else {
$args = array_slice($argv, 3);
}
$pkg_name = $args[0];
$install_type = empty($args[1]) ? "normal" : $args[1];
@ -27,13 +28,14 @@ if ($pkg_info) {
$static_output = "";
$pkg_interface = "console";
if (empty($pkg_info[$pkg_name]))
if (empty($pkg_info[$pkg_name])) {
echo "\nPackage not found.\n";
elseif ($install_type == "normal")
} elseif ($install_type == "normal") {
install_package($pkg_name, $pkg_info[$pkg_name], true);
elseif ($install_type == "xmlonly")
} elseif ($install_type == "xmlonly") {
install_package_xml($pkg_name);
else
} else {
echo "Invalid install type. Valid values are: normal, xmlonly.\n";
}
echo "\nDone.\n";

View File

@ -5,11 +5,12 @@ global $g, $config;
echo "Installed packages:\n";
foreach($config['installedpackages']['package'] as $package) {
foreach ($config['installedpackages']['package'] as $package) {
$name = str_pad("{$package['name']}-{$package['version']}", 30);
$descr = $package['descr'];
$line = "{$name} {$descr}";
if (strlen($line) > 80)
if (strlen($line) > 80) {
$line = substr($line, 0, 77) . "...";
}
echo "{$line}\n";
}

View File

@ -13,8 +13,9 @@ unset($queue);
unset($altq);
foreach ($config['filter']['rule'] as $key => $rule) {
if (isset($rule['wizard']) && $rule['wizard'] == "yes")
if (isset($rule['wizard']) && $rule['wizard'] == "yes") {
unset($config['filter']['rule'][$key]);
}
}
if (write_config()) {
echo gettext("Shaper Successfully Removed.\n");

View File

@ -13,10 +13,11 @@ function usage() {
global $g, $config, $argv, $command_split;
if(is_array($command_split))
if (is_array($command_split)) {
$args = array_slice($command_split, 2);
else
} else {
$args = array_slice($argv, 3);
}
if (empty($args[0])) {
usage();

View File

@ -4,10 +4,11 @@ require_once("pkg-utils.inc");
global $g, $config, $argv, $command_split;
if(is_array($command_split))
if (is_array($command_split)) {
$args = array_slice($command_split, 2);
else
} else {
$args = array_slice($argv, 3);
}
$pkg_name = $args[0];
$remove_type = empty($args[1]) ? "normal" : $args[1];
@ -15,21 +16,23 @@ $pkg_info = array();
echo "Removing package \"{$pkg_name}\"...\n";
foreach($config['installedpackages']['package'] as $package) {
if ($pkg_name == $package['name'])
foreach ($config['installedpackages']['package'] as $package) {
if ($pkg_name == $package['name']) {
$pkg_info = $package;
}
}
$static_output = "";
$pkg_interface = "console";
if (empty($pkg_info))
if (empty($pkg_info)) {
echo "\nPackage not installed.\n";
elseif ($remove_type == "normal")
} elseif ($remove_type == "normal") {
uninstall_package($pkg_name);
elseif ($remove_type == "xmlonly")
} elseif ($remove_type == "xmlonly") {
delete_package_xml($pkg_name);
else
} else {
echo "Invalid removal type. Valid values are: normal, xmlonly.\n";
}
echo "\nDone.\n";

View File

@ -44,7 +44,7 @@ certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
#unique_subject = no # Set to 'no' to allow creation of
# several ctificates with same subject.
# several certificates with same subject.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
@ -55,7 +55,7 @@ crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
x509_extensions = usr_cert # The extensions to add to the cert
# Comment out the following two lines for the "traditional"
# (and highly broken) format.
@ -111,7 +111,7 @@ default_bits = 2048
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert
x509_extensions = v3_ca # The extensions to add to the self signed cert
# Passwords for private keys if not present they will be prompted for
#input_password=""