Commit 94ec1de5 authored by Franco Fichtner's avatar Franco Fichtner

src: no hay pcntl

parent fb97ab7c
...@@ -986,7 +986,7 @@ function exec_command($command) { ...@@ -986,7 +986,7 @@ function exec_command($command) {
} }
/* wrapper for mwexec() ;) */ /* wrapper for mwexec() ;) */
function mwexecf($format, $args = array(), $mute = false, $clearsigmask = false) function mwexecf($format, $args = array(), $mute = false)
{ {
if (!is_array($args)) { if (!is_array($args)) {
/* just in case there's only one argument */ /* just in case there's only one argument */
...@@ -997,27 +997,18 @@ function mwexecf($format, $args = array(), $mute = false, $clearsigmask = false) ...@@ -997,27 +997,18 @@ function mwexecf($format, $args = array(), $mute = false, $clearsigmask = false)
$args[$id] = escapeshellarg($arg); $args[$id] = escapeshellarg($arg);
} }
return mwexec(vsprintf($format, $args), $mute, $clearsigmask); return mwexec(vsprintf($format, $args), $mute);
} }
/* wrapper for exec() */ /* wrapper for exec() */
function mwexec($command, $mute = false, $clearsigmask = false) function mwexec($command, $mute = false)
{ {
$oarr = array(); $oarr = array();
$retval = 0; $retval = 0;
if ($clearsigmask) {
$oldset = array();
pcntl_sigprocmask(SIG_SETMASK, array(), $oldset);
}
$garbage = exec("{$command} 2>&1", $oarr, $retval); $garbage = exec("{$command} 2>&1", $oarr, $retval);
unset($garbage); unset($garbage);
if ($clearsigmask) {
pcntl_sigprocmask(SIG_SETMASK, $oldset);
}
if ($retval != 0 && $mute == false) { if ($retval != 0 && $mute == false) {
$output = implode(' ', $oarr); $output = implode(' ', $oarr);
log_error(sprintf(gettext("The command '%s' returned exit code '%d', the output was '%s'"), $command, $retval, $output)); log_error(sprintf(gettext("The command '%s' returned exit code '%d', the output was '%s'"), $command, $retval, $output));
...@@ -1030,9 +1021,9 @@ function mwexec($command, $mute = false, $clearsigmask = false) ...@@ -1030,9 +1021,9 @@ function mwexec($command, $mute = false, $clearsigmask = false)
} }
/* wrapper for exec() in background */ /* wrapper for exec() in background */
function mwexec_bg($command, $mute = false, $clearsigmask = false) function mwexec_bg($command, $mute = false)
{ {
mwexec("/usr/sbin/daemon -f {$command}", $mute, $clearsigmask); mwexec("/usr/sbin/daemon -f {$command}", $mute);
} }
/* make a global alias table (for faster lookups) */ /* make a global alias table (for faster lookups) */
......
...@@ -42,7 +42,7 @@ PHPMODULES="$PHPMODULES curl" ...@@ -42,7 +42,7 @@ PHPMODULES="$PHPMODULES curl"
# Internationalization # Internationalization
PHPMODULES="$PHPMODULES gettext" PHPMODULES="$PHPMODULES gettext"
# User manager # User manager
PHPMODULES="$PHPMODULES ldap openssl pcntl" PHPMODULES="$PHPMODULES ldap openssl"
PHPMODULES="$PHPMODULES hash mcrypt" PHPMODULES="$PHPMODULES hash mcrypt"
# Login sessions # Login sessions
PHPMODULES="$PHPMODULES session" PHPMODULES="$PHPMODULES session"
......
<?php <?php
/** /**
* Copyright (C) 2015 Deciso B.V. * Copyright (C) 2015 Deciso B.V.
* *
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
namespace OPNsense\Core; namespace OPNsense\Core;
use \Phalcon\DI\FactoryDefault; use \Phalcon\DI\FactoryDefault;
...@@ -65,30 +67,27 @@ class Shell ...@@ -65,30 +67,27 @@ class Shell
* *
* @param string/Array() $command command to execute * @param string/Array() $command command to execute
* @param bool $mute * @param bool $mute
* @param bool $clearsigmask
* @param Array() &$output * @param Array() &$output
*/ */
public function exec($command, $mute = false, $clearsigmask = false, &$output = null) public function exec($command, $mute = false, &$output = null)
{ {
if (is_array($command)) { if (!is_array($command)) {
foreach ($command as $comm) { $command = array($command);
$this->execSingle($comm, $mute, $clearsigmask, $output);
}
} else {
$this->execSingle($command, $mute, $clearsigmask, $output);
} }
foreach ($command as $comm) {
$this->execSingle($comm, $mute, $output);
}
} }
/** /**
* execute shell command * execute shell command
* @param string $command command to execute * @param string $command command to execute
* @param bool $mute * @param bool $mute
* @param bool $clearsigmask
* @param Array() &$output * @param Array() &$output
* @return int * @return int
*/ */
private function execSingle($command, $mute = false, $clearsigmask = false, &$output = null) private function execSingle($command, $mute = false, &$output = null)
{ {
$oarr = array(); $oarr = array();
$retval = 0; $retval = 0;
...@@ -100,11 +99,6 @@ class Shell ...@@ -100,11 +99,6 @@ class Shell
// only execute actual command if not in simulation mode // only execute actual command if not in simulation mode
if (!$this->simulate) { if (!$this->simulate) {
if ($clearsigmask) {
$oldset = array();
pcntl_sigprocmask(SIG_SETMASK, array(), $oldset);
}
exec("$command 2>&1", $output, $retval); exec("$command 2>&1", $output, $retval);
if (($retval <> 0) && ($mute === false)) { if (($retval <> 0) && ($mute === false)) {
...@@ -114,11 +108,6 @@ class Shell ...@@ -114,11 +108,6 @@ class Shell
unset($output); unset($output);
} }
if ($clearsigmask) {
pcntl_sigprocmask(SIG_SETMASK, $oldset);
}
unset($oarr); unset($oarr);
return $retval; return $retval;
} }
......
...@@ -86,7 +86,7 @@ class ARP ...@@ -86,7 +86,7 @@ class ARP
$result = array(); $result = array();
$shell_output = array(); $shell_output = array();
// execute arp shell command and collect (only valid) info into named array // execute arp shell command and collect (only valid) info into named array
if ($this->shell->exec("arp -an", false, false, $shell_output) == 0) { if ($this->shell->exec('arp -an', false, $shell_output) == 0) {
foreach ($shell_output as $line) { foreach ($shell_output as $line) {
$line_parts = explode(" ", $line); $line_parts = explode(" ", $line);
if (sizeof($line_parts) >= 4) { if (sizeof($line_parts) >= 4) {
......
<?php <?php
/** /**
* Copyright (C) 2015 Deciso B.V. * Copyright (C) 2015 Deciso B.V.
* *
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
namespace OPNsense\CaptivePortal; namespace OPNsense\CaptivePortal;
use \Phalcon\Logger\Adapter\Syslog; use \Phalcon\Logger\Adapter\Syslog;
...@@ -183,7 +185,7 @@ class CPClient ...@@ -183,7 +185,7 @@ class CPClient
); );
// execute all ipfw actions // execute all ipfw actions
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// update administration // update administration
$db->upsertFixedIP($ip, $pipeno_in, $pipeno_out); $db->upsertFixedIP($ip, $pipeno_in, $pipeno_out);
// save bandwidth data // save bandwidth data
...@@ -211,7 +213,7 @@ class CPClient ...@@ -211,7 +213,7 @@ class CPClient
); );
// execute all ipfw actions // execute all ipfw actions
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// TODO : cleanup $record->pipeno_in, $record->pipeno_out ; // TODO : cleanup $record->pipeno_in, $record->pipeno_out ;
$db->dropFixedIP($ip); $db->dropFixedIP($ip);
} }
...@@ -311,7 +313,7 @@ class CPClient ...@@ -311,7 +313,7 @@ class CPClient
); );
// execute all ipfw actions // execute all ipfw actions
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// update administration // update administration
$db->upsertPassthruMAC( $db->upsertPassthruMAC(
$tagcontent->mac, $tagcontent->mac,
...@@ -334,7 +336,7 @@ class CPClient ...@@ -334,7 +336,7 @@ class CPClient
"/sbin/ipfw table ". $ipfw_tables["out"] . "/sbin/ipfw table ". $ipfw_tables["out"] .
" add " . $arp_maclist[$mac]['ip']. " " . $pipeno_out, " add " . $arp_maclist[$mac]['ip']. " " . $pipeno_out,
); );
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
$db->upsertPassthruMAC( $db->upsertPassthruMAC(
$tagcontent->mac, $tagcontent->mac,
...@@ -364,7 +366,7 @@ class CPClient ...@@ -364,7 +366,7 @@ class CPClient
"/sbin/ipfw table ". $ipfw_tables["out"] . "/sbin/ipfw table ". $ipfw_tables["out"] .
" delete ". $db_maclist[$mac]->ip, " delete ". $db_maclist[$mac]->ip,
); );
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// TODO : cleanup $record->pipeno_in, $record->pipeno_out ; // TODO : cleanup $record->pipeno_in, $record->pipeno_out ;
$db->dropPassthruMAC($mac); $db->dropPassthruMAC($mac);
} }
...@@ -410,7 +412,7 @@ class CPClient ...@@ -410,7 +412,7 @@ class CPClient
// TODO: check processing speed, this might need some improvement // TODO: check processing speed, this might need some improvement
// check if our ip is already in the list and collect first free rule number to place it there if necessary // check if our ip is already in the list and collect first free rule number to place it there if necessary
$shell_output=array(); $shell_output=array();
$this->shell->exec("/sbin/ipfw show", false, false, $shell_output); $this->shell->exec('/sbin/ipfw show', false, $shell_output);
$prev_id = 0; $prev_id = 0;
$new_id = null; $new_id = null;
foreach ($shell_output as $line) { foreach ($shell_output as $line) {
...@@ -442,7 +444,7 @@ class CPClient ...@@ -442,7 +444,7 @@ class CPClient
); );
// execute all ipfw actions // execute all ipfw actions
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
} }
} }
...@@ -559,7 +561,7 @@ class CPClient ...@@ -559,7 +561,7 @@ class CPClient
// add commands for access tables, and execute all collected // add commands for access tables, and execute all collected
$exec_commands[] = "/sbin/ipfw table ". $ipfw_tables["in"] ." add ". $clientip . " ".$pipeno_in; $exec_commands[] = "/sbin/ipfw table ". $ipfw_tables["in"] ." add ". $clientip . " ".$pipeno_in;
$exec_commands[] = "/sbin/ipfw table ". $ipfw_tables["out"] ." add ". $clientip . " ".$pipeno_out; $exec_commands[] = "/sbin/ipfw table ". $ipfw_tables["out"] ." add ". $clientip . " ".$pipeno_out;
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// lock the user/ip to it's MAC address using arp // lock the user/ip to it's MAC address using arp
$arp->setStatic($clientip, $clientmac); $arp->setStatic($clientip, $clientmac);
...@@ -633,7 +635,7 @@ class CPClient ...@@ -633,7 +635,7 @@ class CPClient
"/sbin/ipfw -f table ".$this->rules->getAuthMACTables($zoneid)["out"]." flush", "/sbin/ipfw -f table ".$this->rules->getAuthMACTables($zoneid)["out"]." flush",
"/sbin/ipfw delete set ".$zoneid, "/sbin/ipfw delete set ".$zoneid,
); );
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
} }
} }
} }
...@@ -725,7 +727,7 @@ class CPClient ...@@ -725,7 +727,7 @@ class CPClient
$filter_cmd =" | /usr/bin/grep ' " . $ipaddr ." '" ; $filter_cmd =" | /usr/bin/grep ' " . $ipaddr ." '" ;
} }
if ($this->shell->exec("/sbin/ipfw -aT list ".$filter_cmd, false, false, $shell_output) == 0) { if ($this->shell->exec("/sbin/ipfw -aT list ".$filter_cmd, false, $shell_output) == 0) {
foreach ($shell_output as $line) { foreach ($shell_output as $line) {
if (strpos($line, ' count ip from') !== false) { if (strpos($line, ' count ip from') !== false) {
$parts = preg_split('/\s+/', $line); $parts = preg_split('/\s+/', $line);
...@@ -790,7 +792,7 @@ class CPClient ...@@ -790,7 +792,7 @@ class CPClient
// only handle disconnect if we can find a client in our database // only handle disconnect if we can find a client in our database
$exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["in"] . " delete " . $db_clients[0]->ip; $exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["in"] . " delete " . $db_clients[0]->ip;
$exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["out"] . " delete " . $db_clients[0]->ip; $exec_commands[] = "/sbin/ipfw table " . $ipfw_tables["out"] . " delete " . $db_clients[0]->ip;
$this->shell->exec($exec_commands, false, false); $this->shell->exec($exec_commands);
// TODO: cleanup dummynet pipes $db_clients[0]->pipeno_in/out // TODO: cleanup dummynet pipes $db_clients[0]->pipeno_in/out
// TODO: log removal // TODO: log removal
// ( was : captiveportal_logportalauth($cpentry[4], $cpentry[3], $cpentry[2], "DISCONNECT");) // ( was : captiveportal_logportalauth($cpentry[4], $cpentry[3], $cpentry[2], "DISCONNECT");)
......
...@@ -55,13 +55,13 @@ if (file_exists($file_pkg_status)) { ...@@ -55,13 +55,13 @@ if (file_exists($file_pkg_status)) {
if ($_POST['action'] == 'pkg_upgrade') { if ($_POST['action'] == 'pkg_upgrade') {
// execute shell command and collect (only valid) info into named array // execute shell command and collect (only valid) info into named array
$cmd = '/usr/sbin/daemon -f /usr/local/opnsense/scripts/pkg_upgrade.sh ' . escapeshellarg($package); $cmd = '/usr/sbin/daemon -f /usr/local/opnsense/scripts/pkg_upgrade.sh ' . escapeshellarg($package);
$shell->exec($cmd, false, false, $shell_output); $shell->exec($cmd, false, $shell_output);
exit; exit;
} }
if ($_POST['action'] == 'pkg_update') { if ($_POST['action'] == 'pkg_update') {
// execute shell command and collect (only valid) info into named array // execute shell command and collect (only valid) info into named array
$shell->exec('/usr/local/opnsense/scripts/pkg_updatecheck.sh', false, false, $shell_output); $shell->exec('/usr/local/opnsense/scripts/pkg_updatecheck.sh', false, $shell_output);
} }
if ($_POST['action'] == 'update_status') { if ($_POST['action'] == 'update_status') {
......
...@@ -42,7 +42,7 @@ if ($_POST['action'] == 'pkg_update') { ...@@ -42,7 +42,7 @@ if ($_POST['action'] == 'pkg_update') {
$shell_output = array(); $shell_output = array();
$shell = new OPNsense\Core\Shell(); $shell = new OPNsense\Core\Shell();
// execute shell command and collect (only valid) info into named array // execute shell command and collect (only valid) info into named array
$shell->exec("/usr/local/opnsense/scripts/pkg_updatecheck.sh", false, false, $shell_output); $shell->exec('/usr/local/opnsense/scripts/pkg_updatecheck.sh', false, $shell_output);
} }
if (file_exists($file_pkg_status)) { if (file_exists($file_pkg_status)) {
......
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