aboutsummaryrefslogtreecommitdiffstats
path: root/config/phpservice
diff options
context:
space:
mode:
authordoktornotor <notordoktor@gmail.com>2015-08-16 01:24:10 +0200
committerdoktornotor <notordoktor@gmail.com>2015-08-16 01:24:10 +0200
commiteec73129b5697ce70c89099d8555d0a56289c887 (patch)
treeaa373d5f975f0d678517c93f5db9c116bf433201 /config/phpservice
parentf91da286bb0edbabf22df53ea88c6b7e8ccc8b41 (diff)
downloadpfsense-packages-eec73129b5697ce70c89099d8555d0a56289c887.tar.gz
pfsense-packages-eec73129b5697ce70c89099d8555d0a56289c887.tar.bz2
pfsense-packages-eec73129b5697ce70c89099d8555d0a56289c887.zip
phpservice - rewrite garbage package
Diffstat (limited to 'config/phpservice')
-rw-r--r--config/phpservice/phpservice.inc223
1 files changed, 63 insertions, 160 deletions
diff --git a/config/phpservice/phpservice.inc b/config/phpservice/phpservice.inc
index ec2b9bef..cffdb09f 100644
--- a/config/phpservice/phpservice.inc
+++ b/config/phpservice/phpservice.inc
@@ -1,14 +1,11 @@
<?php
-/* $Id$ */
-/*
-/* ========================================================================== */
-/*
- phpservice.inc
- Copyright (C) 2008 Mark J Crane
- All rights reserved.
- */
-/* ========================================================================== */
/*
+ phpservice.inc
+ part of pfSense (https://www.pfSense.org/)
+ Copyright (C) 2008 Mark J Crane
+ Copyright (C) 2015 ESF, LLC
+ All rights reserved.
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
@@ -30,194 +27,100 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
+function phpservice_sync_package() {
+ global $config;
+
+ if ($config['installedpackages']['phpservice']['config'] != "") {
+
+ conf_mount_rw();
+ $tmp = <<<EOF
+<?php
+
+// Set time limit to indefinite execution
+set_time_limit (0);
-if (!function_exists("pkg_is_service_running")) {
- function pkg_is_service_running($servicename)
- {
- exec("/bin/ps ax | awk '{ print $5 }'", $psout);
- array_shift($psout);
- foreach($psout as $line) {
- $ps[] = trim(array_pop(explode(' ', array_pop(explode('/', $line)))));
- }
- if(is_service_running($servicename, $ps) or is_process_running($servicename) ) {
- return true;
- }
- else {
- return false;
- }
+//run this program as long as the pid file exists
+$filename = '/tmp/phpmonitor.pid';
+$fp = fopen($filename, 'w');
+fwrite($fp, "If this file is deleted then phpmonitor will stop.");
+fclose($fp);
+unset($filename);
+
+function send_to_syslog($syslogaddress, $syslogport, $syslogmsg) {
+
+ $syslogaddress = "127.0.0.1";
+ $syslogport = 514;
+
+ $fp = fsockopen("udp://".$syslogaddress, $syslogport, $errno, $errstr);
+ if (!$fp) {
+ return;
+ } else {
+ fwrite($fp, $syslogmsg);
+ fclose($fp);
}
}
-if (!function_exists("byte_convert")) {
- function byte_convert( $bytes ) {
- if ($bytes<=0)
- return '0 Byte';
+$x = 0;
+while ($x == 0) {
- $convention=1000; //[1000->10^x|1024->2^x]
- $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB');
- $e=floor(log($bytes,$convention));
- return round($bytes/pow($convention,$e),2).' '.$s[$e];
- }
+// If the pid file does not exist then close the program.
+if (!file_exists('/tmp/phpmonitor.pid')) {
+ return;
}
-
-function phpservice_sync_package_php()
-{
-
- global $config;
- if($config['installedpackages']['phpservice']['config'] != "") {
-
- conf_mount_rw();
-
- $tmp = "<?php\n";
- $tmp .= "\n";
- $tmp .= "// Set time limit to indefinite execution\n";
- $tmp .= "set_time_limit (0);\n";
- $tmp .= "\n";
- $tmp .= "//run this program as long as the pid file exists\n";
- $tmp .= "\$filename = '/tmp/phpmonitor.pid';\n";
- $tmp .= "\$fp = fopen(\$filename, 'w');\n";
- $tmp .= "fwrite(\$fp, \"If this file is deleted then phpmonitor will stop.\");\n";
- $tmp .= "fclose(\$fp);\n";
- $tmp .= "unset(\$filename);\n";
- $tmp .= "\n";
- $tmp .= "//require_once(\"config.inc\");\n";
- $tmp .= "//global \$config;\n";
- $tmp .= "//\$syslogaddress = \$config['syslog']['remoteserver'];\n";
- $tmp .= "\$syslogaddress = \"127.0.0.1\";\n";
- $tmp .= "\$syslogport = 514;\n";
- $tmp .= "echo \"syslog server: \".\$syslogaddress.\"\\n\";\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "function send_to_syslog(\$syslogaddress, \$syslogport, \$syslogmsg) {\n";
- $tmp .= "\n";
- $tmp .= " \$fp = fsockopen(\"udp://\".\$syslogaddress, \$syslogport, \$errno, \$errstr);\n";
- $tmp .= " if (!\$fp) {\n";
- $tmp .= " //echo \"ERROR: \$errno - \$errstr<br />\\n\";\n";
- $tmp .= " } else {\n";
- $tmp .= " fwrite(\$fp, \$syslogmsg);\n";
- $tmp .= " fclose(\$fp);\n";
- $tmp .= " }\n";
- $tmp .= "\n";
- $tmp .= "}\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "//\$msg = \"1.begin loop. \".date('r').\"\\n\";\n";
- $tmp .= "//\$fp = fopen('/tmp/phpmonitor.txt', 'a');\n";
- $tmp .= "//fwrite(\$fp, \$msg.\"\\n\");\n";
- $tmp .= "//fclose(\$fp);\n";
- $tmp .= "\n";
- $tmp .= "\$x = 0;\n";
- $tmp .= "while(\$x == 0) {\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= " if(!file_exists('/tmp/phpmonitor.pid')) {\n";
- $tmp .= " //if the file does not exist then close the program.\n";
- $tmp .= " echo \"program closing\\n\";\n";
- $tmp .= " return;\n";
- $tmp .= " }\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "\n";
-
- foreach($config['installedpackages']['phpservice']['config'] as $rowhelper) {
+
+EOF;
+
+ foreach ($config['installedpackages']['phpservice']['config'] as $rowhelper) {
if ($rowhelper['enabled'] != "false") {
$tmp_php = base64_decode($rowhelper['php']);
if (strlen($tmp_php) > 0) {
$tmp .= "// name: ".$rowhelper['name']." \n";
- $tmp .= "// description: ".$rowhelper['description']." \n\n";
+ $tmp .= "// description: ".$rowhelper['description']." \n\n";
$tmp .= base64_decode($rowhelper['php']);
$tmp .= "\n";
}
}
-
}
-
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= " //usleep(100000); //micro seconds //2 seconds 2000000\n";
- $tmp .= " sleep(1); //in seconds\n";
- $tmp .= " //if (\$x > 60){ exit; } //exit after 60 seconds for testing\n";
- $tmp .= "} //emd while\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "?>";
-
- $fout = fopen("/usr/local/pkg/phpservice.php","w");
- fwrite($fout, $tmp);
- unset($tmp);
- fclose($fout);
-
- conf_mount_ro();
-
- }
-}
+ $tmp .= <<< EOF
-function phpservice_sync_package()
-{
-
- global $config;
- phpservice_sync_package_php();
+sleep(1);
}
-
+?>
-function phpservice_install_command()
-{
+EOF;
- global $config;
- conf_mount_rw();
+ $fout = fopen("/usr/local/pkg/phpservice.php", "w");
+ fwrite($fout, $tmp);
+ unset($tmp);
+ fclose($fout);
- if (!is_dir('/usr/local/www/packages/')) {
- exec("mkdir /usr/local/www/packages/");
- }
-
- if (!is_dir('/usr/local/www/packages/phpservice/')) {
- exec("mkdir /usr/local/www/packages/phpservice/");
+ restart_service("phpservice");
+ conf_mount_ro();
+ } else {
+ stop_service("phpservice");
}
+}
-
- //rename PHP files from .tmp to .php
- exec("cp /tmp/phpservice_php.tmp /usr/local/www/packages/phpservice/phpservice_php.php");
- unlink_if_exists("/tmp/phpservice_php.tmp");
-
- exec("cp /tmp/phpservice_php_edit.tmp /usr/local/www/packages/phpservice/phpservice_php_edit.php");
- unlink_if_exists("/tmp/phpservice_php_edit.tmp");
-
- //write_config();
-
+function phpservice_install_command() {
+ conf_mount_rw();
write_rcfile(array(
"file" => "phpservice.sh",
"start" => "/usr/local/bin/php /usr/local/pkg/phpservice.php >> /var/log/phpservice.log &",
- "stop" => "rm /tmp/phpmonitor.pid"
+ "stop" => "/bin/rm -f /tmp/phpmonitor.pid; sleep 3"
)
);
-
phpservice_sync_package();
- //$handle = popen("/usr/local/etc/rc.d/phpservice.sh start", "r");
- //pclose($handle);
-
- //if (pkg_is_service_running('phpservice')) {
- //documentation purposes
- //}
-
conf_mount_ro();
-
}
-function phpservice_deinstall_command()
-{
-
+function phpservice_deinstall_command() {
conf_mount_rw();
- $handle = popen("/usr/local/etc/rc.d/phpservice.sh stop", "r");
- unlink_if_exists("/usr/local/pkg/phpservice.xml");
- unlink_if_exists("/usr/local/pkg/phpservice.inc");
- unlink_if_exists("/usr/local/www/phpservice.inc");
+ stop_service("phpservice");
unlink_if_exists("/usr/local/etc/rc.d/phpservice.sh");
conf_mount_ro();
-
}
?>