diff options
-rw-r--r-- | config/phpservice/phpservice.inc | 223 | ||||
-rw-r--r-- | config/phpservice/phpservice.xml | 127 | ||||
-rw-r--r-- | config/phpservice/phpservice_php.php | 151 | ||||
-rw-r--r-- | config/phpservice/phpservice_php.tmp | 192 | ||||
-rw-r--r-- | config/phpservice/phpservice_php_edit.php | 180 | ||||
-rw-r--r-- | config/phpservice/phpservice_php_edit.tmp | 225 | ||||
-rw-r--r-- | pkg_config.10.xml | 2 |
7 files changed, 440 insertions, 660 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(); - } ?> diff --git a/config/phpservice/phpservice.xml b/config/phpservice/phpservice.xml index eb7e670e..e437be20 100644 --- a/config/phpservice/phpservice.xml +++ b/config/phpservice/phpservice.xml @@ -1,47 +1,49 @@ <?xml version="1.0" encoding="utf-8" ?> -<!DOCTYPE packagegui SYSTEM "./schema/packages.dtd"> -<?xml-stylesheet type="text/xsl" href="./xsl/package.xsl"?> +<!DOCTYPE packagegui SYSTEM "../schema/packages.dtd"> +<?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?> <packagegui> - <copyright> - <![CDATA[ + <copyright> +<![CDATA[ /* $Id$ */ -/* ========================================================================== */ +/* ====================================================================================== */ /* - phpservice.xml - Copyright (C) 2008 Mark J Crane - All rights reserved. - */ -/* ========================================================================== */ + phpservice.xml + 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: + 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. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 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. - */ -/* ========================================================================== */ - ]]> - </copyright> - <description>PHP Service</description> - <requirements>Describe your package requirements here</requirements> - <faq>Currently there are no FAQ items provided.</faq> + 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. +*/ +/* ====================================================================================== */ + ]]> + </copyright> + <description>PHP Service</description> <name>PHP Service Settings</name> - <version>0.4.1</version> + <version>0.5.0</version> <title>Settings</title> <include_file>/usr/local/pkg/phpservice.inc</include_file> <menu> @@ -55,66 +57,27 @@ <name>phpservice</name> <rcfile>phpservice.sh</rcfile> <executable>phpservice</executable> - <description>PHP run from a command line as a service.</description> + <description>PHP script as a service</description> <custom_php_service_status_command> - exec("/bin/pgrep -f phpservice"); + exec("/bin/pgrep -fq phpservice"); </custom_php_service_status_command> </service> - <tabs> - <tab> - <text>Settings</text> - <url>/pkg_edit.php?xml=phpservice.xml&id=0</url> - <active/> - </tab> - <tab> - <text>Settings</text> - <url>/packages/phpservice_php.php</url> - <active/> - </tab> - </tabs> - <configpath>installedpackages->package->$packagename->configuration->phpservice</configpath> + <configpath>installedpackages->package->$packagename->configuration->phpservice</configpath> <additional_files_needed> <prefix>/usr/local/pkg/</prefix> - <chmod>0755</chmod> - <item>https://packages.pfsense.org/packages/config/phpservice/phpservice.xml</item> - </additional_files_needed> - <additional_files_needed> - <prefix>/usr/local/pkg/</prefix> - <chmod>0755</chmod> <item>https://packages.pfsense.org/packages/config/phpservice/phpservice.inc</item> </additional_files_needed> <additional_files_needed> - <prefix>/tmp/</prefix> - <chmod>0755</chmod> - <item>https://packages.pfsense.org/packages/config/phpservice/phpservice_php.tmp</item> + <prefix>/usr/local/www/packages/phpservice/</prefix> + <item>https://packages.pfsense.org/packages/config/phpservice/phpservice_php.php</item> </additional_files_needed> <additional_files_needed> - <prefix>/tmp/</prefix> - <chmod>0755</chmod> - <item>https://packages.pfsense.org/packages/config/phpservice/phpservice_php_edit.tmp</item> - </additional_files_needed> - <fields> - <field> - <fielddescr>Variable One</fielddescr> - <fieldname>var1</fieldname> - <description>Enter the variable one here.</description> - <type>input</type> - </field> - <field> - <fielddescr>Variable Two</fielddescr> - <fieldname>var1</fieldname> - <description>Enter the variable one here.</description> - <type>input</type> - </field> - </fields> - <custom_add_php_command> - </custom_add_php_command> + <prefix>/usr/local/www/packages/phpservice/</prefix> + <item>https://packages.pfsense.org/packages/config/phpservice/phpservice_php_edit.php</item> + </additional_files_needed> <custom_php_resync_config_command> phpservice_sync_package(); </custom_php_resync_config_command> - <custom_delete_php_command> - phpservice_sync_package(); - </custom_delete_php_command> <custom_php_install_command> phpservice_install_command(); </custom_php_install_command> diff --git a/config/phpservice/phpservice_php.php b/config/phpservice/phpservice_php.php new file mode 100644 index 00000000..582d2f41 --- /dev/null +++ b/config/phpservice/phpservice_php.php @@ -0,0 +1,151 @@ +<?php +/* + phpservice_php.php + 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: + + 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("guiconfig.inc"); +require("/usr/local/pkg/phpservice.inc"); + +$a_phpservice = &$config['installedpackages']['phpservice']['config']; + +if ($_GET['act'] == "del") { + if ($_GET['type'] == 'php') { + if ($a_phpservice[$_GET['id']]) { + unset($a_phpservice[$_GET['id']]); + write_config(); + header("Location: phpservice_php.php"); + exit; + } + } +} + +$pgtitle = "PHP Service"; +include("head.inc"); + +?> + + +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> + +<div id="mainlevel"> +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<tr><td class="tabnavtbl"> +<?php + + $tab_array = array(); + $tab_array[] = array(gettext("Settings"), false, "/packages/phpservice/phpservice_php.php"); + display_top_tabs($tab_array); + +?> +</td></tr> +</table> + +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<tr><td class="tabcont" > + <form action="phpservice_php.php" method="post" name="iform" id="iform"> +<?php +if ($config_change == 1) { + write_config(); + $config_change = 0; +} +?> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr><td> + <div> + The custom PHP code that is defined below is run over and over again inside a continuous loop. There are many possible uses such as monitoring CPU, Memory, File System Space, interacting with Snort, and many others uses that are yet to be discovered.<br /> + It can send events to the sylog that will can be viewed from the system log or remote syslog server. Example: <em>exec("logger This is a test");</em><br /><br /> + For more information see: <a href='https://doc.pfsense.org/index.php/PHPService'>https://doc.pfsense.org/index.php/PHPService</a> + </div> + </td></tr> + </table> + <br /> + + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr> + <td width="30%" class="listhdrr">Name</td> + <td width="20%" class="listhdrr">Enabled</td> + <td width="40%" class="listhdr">Description</td> + <td width="10%" class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td width="17"></td> + <td valign="middle"><a href="phpservice_php_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" /></a></td> + </tr> + </table> + </td> + </tr> + + <?php + $i = 0; + if (count($a_phpservice) > 0) { + foreach ($a_phpservice as $ent) { + ?> + <tr> + <td class="listr" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"><?=$ent['name'];?> </td> + <td class="listr" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"><?=$ent['enabled'];?> </td> + <td class="listbg" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"><?=htmlspecialchars($ent['description']);?> </td> + <td valign="middle" nowrap class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td valign="middle"><a href="phpservice_php_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="" /></a></td> + <td><a href="phpservice_php_edit.php?type=php&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="" /></a></td> + </tr> + </table> + </td> + </tr> + <?php $i++; + } + } + ?> + + <tr> + <td class="list" colspan="3"></td> + <td class="list"> + <table border="0" cellspacing="0" cellpadding="1"> + <tr> + <td width="17"></td> + <td valign="middle"><a href="phpservice_php_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="" /></a></td> + </tr> + </table> + </td> + </tr> + <tr> + <td class="list" colspan="3"></td> + <td class="list"></td> + </tr> + </table> + </form> +<br /> + +</td></tr> +</table> +</div> + +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/config/phpservice/phpservice_php.tmp b/config/phpservice/phpservice_php.tmp deleted file mode 100644 index 55de1ae8..00000000 --- a/config/phpservice/phpservice_php.tmp +++ /dev/null @@ -1,192 +0,0 @@ -<?php -/* $Id$ */ -/* - phpservice_php.php - Copyright (C) 2008 Mark J Crane - 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("guiconfig.inc"); -require("/usr/local/pkg/phpservice.inc"); - -$a_phpservice = &$config['installedpackages']['phpservice']['config']; - - -if ($_GET['act'] == "del") { - if ($_GET['type'] == 'php') { - if ($a_phpservice[$_GET['id']]) { - unset($a_phpservice[$_GET['id']]); - write_config(); - header("Location: phpservice_php.php"); - exit; - } - } -} - -include("head.inc"); - -?> - - -<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> -<?php include("fbegin.inc"); ?> -<p class="pgtitle">PHP Service:</p> - -<div id="mainlevel"> -<table width="100%" border="0" cellpadding="0" cellspacing="0"> -<tr><td class="tabnavtbl"> -<?php - - $tab_array = array(); - $tab_array[] = array(gettext("Settings"), false, "/packages/phpservice/phpservice_php.php"); - display_top_tabs($tab_array); - -?> -</td></tr> -</table> - -<table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td class="tabcont" > - -<form action="phpservice_php.php" method="post" name="iform" id="iform"> -<?php - -if ($config_change == 1) { - write_config(); - $config_change = 0; -} - -//if ($savemsg) print_info_box($savemsg); -//if (file_exists($d_hostsdirty_path)): echo"<p>"; -//print_info_box_np("This is an info box."); -//echo"<br />"; -//endif; - -?> - <table width="100%" border="0" cellpadding="6" cellspacing="0"> - <tr> - <td><p><!--<span class="vexpl"><span class="red"><strong>PHP Service<br></strong></span>--> - Is command line PHP designed to run PHP as a Service. The custom PHP code that is defined below is run over and over again inside a continuous loop. There are many possible uses such as monitoring CPU, Memory, File System Space, interacting with Snort, and many others uses that are yet to be discovered. - It can send events to the sylog that will can be viewed from the system log or remote syslog server. example: exec("logger This is a test"); - <br /><br /> - For more information see: <a href='https://doc.pfsense.org/index.php/PHPService'>https://doc.pfsense.org/index.php/PHPService</a> - </p></td> - </tr> - </table> - <br /> - - <table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td width="30%" class="listhdrr">Name</td> - <td width="20%" class="listhdrr">Enabled</td> - <td width="40%" class="listhdr">Description</td> - <td width="10%" class="list"> - - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="phpservice_php_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - - </td> - </tr> - - - <?php - - $i = 0; - if (count($a_phpservice) > 0) { - - foreach ($a_phpservice as $ent) { - - ?> - <tr> - <td class="listr" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"> - <?=$ent['name'];?> - </td> - <td class="listr" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"> - <?=$ent['enabled'];?> - </td> - <td class="listbg" ondblclick="document.location='phpservice_php_edit.php?id=<?=$i;?>';"> - <font color="#FFFFFF"><?=htmlspecialchars($ent['description']);?> - </td> - <td valign="middle" nowrap class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td valign="middle"><a href="phpservice_php_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td> - <td><a href="phpservice_php_edit.php?type=php&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - <?php - - $i++; - } - } - ?> - - <tr> - <td class="list" colspan="3"></td> - <td class="list"> - <table border="0" cellspacing="0" cellpadding="1"> - <tr> - <td width="17"></td> - <td valign="middle"><a href="phpservice_php_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td> - </tr> - </table> - </td> - </tr> - - - <tr> - <td class="list" colspan="3"></td> - <td class="list"></td> - </tr> - </table> - -</form> - - -<br> -<br> -<br> -<br> -<br> -<br> -<br> -<br> - -</td> -</tr> -</table> - -</div> - - -<?php include("fend.inc"); ?> -</body> -</html> diff --git a/config/phpservice/phpservice_php_edit.php b/config/phpservice/phpservice_php_edit.php new file mode 100644 index 00000000..9727add6 --- /dev/null +++ b/config/phpservice/phpservice_php_edit.php @@ -0,0 +1,180 @@ +<?php +/* + phpservice_php_edit.php + 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: + + 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("guiconfig.inc"); +require("/usr/local/pkg/phpservice.inc"); + +$a_phpservice = &$config['installedpackages']['phpservice']['config']; + +$id = $_GET['id']; +if (isset($_POST['id'])) { + $id = $_POST['id']; +} + +if ($_GET['act'] == "del") { + if ($_GET['type'] == 'php') { + if ($a_phpservice[$_GET['id']]) { + unset($a_phpservice[$_GET['id']]); + write_config(); + phpservice_sync_package(); + header("Location: phpservice_php.php"); + exit; + } + } +} + +if (isset($id) && $a_phpservice[$id]) { + $pconfig['name'] = $a_phpservice[$id]['name']; + $pconfig['php'] = base64_decode($a_phpservice[$id]['php']); + $pconfig['enabled'] = $a_phpservice[$id]['enabled']; + $pconfig['description'] = $a_phpservice[$id]['description']; +} + +if ($_POST) { + + unset($input_errors); + $pconfig = $_POST; + + if (!$input_errors) { + + $ent = array(); + $ent['name'] = $_POST['name']; + $ent['php'] = base64_encode($_POST['php']); + $ent['enabled'] = $_POST['enabled']; + $ent['description'] = $_POST['description']; + + if (isset($id) && $a_phpservice[$id]) { + //update + $a_phpservice[$id] = $ent; + } + else { + //add + $a_phpservice[] = $ent; + } + + write_config(); + phpservice_sync_package(); + + header("Location: phpservice_php.php"); + exit; + } +} + +$pgtitle = "PHP Service: Edit"; +include("head.inc"); + +?> + +<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> +<?php include("fbegin.inc"); ?> +<?php if ($input_errors) print_input_errors($input_errors); ?> +<script type="text/javascript"> +//<![CDATA[ +function show_advanced_config() { + document.getElementById("showadvancedbox").innerHTML=''; + aodiv = document.getElementById('showadvanced'); + aodiv.style.display = "block"; +//]]> +</script> + +<div id="mainlevel"> +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<tr><td class="tabnavtbl"> +<?php + $tab_array = array(); + $tab_array[] = array(gettext("Settings"), false, "/packages/phpservice/phpservice_php.php"); + display_top_tabs($tab_array); +?> +</td></tr> +</table> + +<table width="100%" border="0" cellpadding="0" cellspacing="0"> +<tr><td class="tabcont"><br /> + <form action="phpservice_php_edit.php" method="post" name="iform" id="iform"> + <table width="100%" border="0" cellpadding="6" cellspacing="0"> + <tr> + <td width="25%" valign="top" class="vncellreq">Name</td> + <td width="75%" class="vtable"><input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" /></td> + </tr> + <tr> + <td width="22%" valign="top" class="vncell">PHP</td> + <td width="78%" class="vtable"> + <?php + echo "<textarea name=\"php\" id=\"php\" cols=\"70\" rows=\"15\" wrap=\"off\">" . htmlspecialchars($pconfig['php']) . "</textarea>\n"; + ?> + </td> + </tr> + <tr> + <td width="22%" valign="top" class="vncellreq">Enabled</td> + <td width="78%" class="vtable"> + <?php + echo "\t\t<select name='enabled' class='formfld'>\n"; + echo "\t\t\t<option></option>\n"; + switch (htmlspecialchars($pconfig['enabled'])) { + case "true": + echo "\t\t\t<option value='true' selected='selected'>true</option>\n"; + echo "\t\t\t<option value='false'>false</option>\n"; + break; + case "false": + echo "\t\t\t<option value='true'>true</option>\n"; + echo "\t\t\t<option value='false' selected='selected'>false</option>\n"; + break; + default: + echo "\t\t\t<option value='true' selected='selected'>true</option>\n"; + echo "\t\t\t<option value='false'>false</option>\n"; + } + echo "\t\t</select>\n"; + ?> + </td> + </tr> + <tr> + <td width="25%" valign="top" class="vncellreq">Description</td> + <td width="75%" class="vtable"> + <input name="description" type="text" class="formfld" id="description" size="40" value="<?=htmlspecialchars($pconfig['description']);?>" /> + <br /><span class="vexpl">Enter the description here.<br /></span> + </td> + </tr> + <tr> + <td valign="top"> </td> + <td> + <input name="Submit" type="submit" class="formbtn" value="Save" /> <input class="formbtn" type="button" value="Cancel" onclick="history.back()" /> + <?php if (isset($id) && $a_phpservice[$id]): ?><input name="id" type="hidden" value="<?=$id;?>" /><?php endif; ?> + </td> + </tr> + </table> + </form> + <br /> + +</td></tr> +</table> +</div> + +<?php include("fend.inc"); ?> +</body> +</html> diff --git a/config/phpservice/phpservice_php_edit.tmp b/config/phpservice/phpservice_php_edit.tmp deleted file mode 100644 index 20a9998a..00000000 --- a/config/phpservice/phpservice_php_edit.tmp +++ /dev/null @@ -1,225 +0,0 @@ -<?php -/* $Id$ */ -/* - - phpservice_php_edit.php - Copyright (C) 2008 Mark J Crane - 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("guiconfig.inc"); -require("/usr/local/pkg/phpservice.inc"); - - -$a_phpservice = &$config['installedpackages']['phpservice']['config']; - -$id = $_GET['id']; -if (isset($_POST['id'])) { - $id = $_POST['id']; -} - -if ($_GET['act'] == "del") { - if ($_GET['type'] == 'php') { - if ($a_phpservice[$_GET['id']]) { - unset($a_phpservice[$_GET['id']]); - write_config(); - phpservice_sync_package(); - header("Location: phpservice_php.php"); - exit; - } - } -} - -if (isset($id) && $a_phpservice[$id]) { - - $pconfig['name'] = $a_phpservice[$id]['name']; - $pconfig['php'] = base64_decode($a_phpservice[$id]['php']); - $pconfig['enabled'] = $a_phpservice[$id]['enabled']; - $pconfig['description'] = $a_phpservice[$id]['description']; - -} - -if ($_POST) { - - unset($input_errors); - $pconfig = $_POST; - - if (!$input_errors) { - - $ent = array(); - $ent['name'] = $_POST['name']; - $ent['php'] = base64_encode($_POST['php']); - $ent['enabled'] = $_POST['enabled']; - $ent['description'] = $_POST['description']; - - if (isset($id) && $a_phpservice[$id]) { - //update - $a_phpservice[$id] = $ent; - } - else { - //add - $a_phpservice[] = $ent; - } - - write_config(); - phpservice_sync_package(); - - header("Location: phpservice_php.php"); - exit; - } -} - -include("head.inc"); - -?> - -<script type="text/javascript" language="JavaScript"> - -function show_advanced_config() { - document.getElementById("showadvancedbox").innerHTML=''; - aodiv = document.getElementById('showadvanced'); - aodiv.style.display = "block"; -</script> - -<body link="#0000CC" vlink="#0000CC" alink="#0000CC"> -<?php include("fbegin.inc"); ?> -<p class="pgtitle">PHP Service: Edit</p> -<?php if ($input_errors) print_input_errors($input_errors); ?> - - -<div id="mainlevel"> -<table width="100%" border="0" cellpadding="0" cellspacing="0"> -<tr><td class="tabnavtbl"> -<?php - - $tab_array = array(); - $tab_array[] = array(gettext("Settings"), false, "/packages/phpservice/phpservice_php.php"); - display_top_tabs($tab_array); - -?> -</td></tr> -</table> -<table width="100%" border="0" cellpadding="0" cellspacing="0"> - <tr> - <td class="tabcont" > - - <!-- - <table width="100%" border="0" cellpadding="6" cellspacing="0"> - <tr> - <td><p><span class="vexpl"><span class="red"><strong>PHP<br> - </strong></span> - </p></td> - </tr> - </table> - --> - <br /> - - <form action="phpservice_php_edit.php" method="post" name="iform" id="iform"> - <table width="100%" border="0" cellpadding="6" cellspacing="0"> - - <tr> - <td width="25%" valign="top" class="vncellreq">Name</td> - <td width="75%" class="vtable"> - <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>"> - </td> - </tr> - - <tr> - <td width="22%" valign="top" class="vncell">PHP</td> - <td width="78%" class="vtable"> - <?php - echo "<textarea name=\"php\" id=\"php\" cols=\"70\" rows=\"15\" wrap=\"off\">".htmlspecialchars($pconfig['php'])."</textarea>\n"; - ?> - <!-- - <br> - <select name='dialplan_expression_select' id='dialplan_expression_select' onchange="document.getElementById('dialplan_expression').value += document.getElementById('dialplan_expression_select').value + '\n';" class='formfld'> - <option></option> - <option value='snortkillsessions'>snort kill sessions</option> - </select> - <span class="vexpl"> - <br /> - </span> - --> - </td> - </tr> - <tr> - <td width="22%" valign="top" class="vncellreq">Enabled</td> - <td width="78%" class="vtable"> - <?php - echo " <select name='enabled' class='formfld'>\n"; - echo " <option></option>\n"; - switch (htmlspecialchars($pconfig['enabled'])) { - case "true": - echo " <option value='true' selected='yes'>true</option>\n"; - echo " <option value='false'>false</option>\n"; - break; - case "false": - echo " <option value='true'>true</option>\n"; - echo " <option value='false' selected='yes'>false</option>\n"; - - break; - default: - echo " <option value='true' selected='yes'>true</option>\n"; - echo " <option value='false'>false</option>\n"; - } - echo " </select>\n"; - ?> - </td> - </tr> - <tr> - <td width="25%" valign="top" class="vncellreq">Description</td> - <td width="75%" class="vtable"> - <input name="description" type="text" class="formfld" id="description" size="40" value="<?=htmlspecialchars($pconfig['description']);?>"> - <br><span class="vexpl">Enter the description here.<br></span> - </td> - </tr> - - <tr> - <td valign="top"> </td> - <td> - <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()"> - <?php if (isset($id) && $a_phpservice[$id]): ?> - <input name="id" type="hidden" value="<?=$id;?>"> - <?php endif; ?> - </td> - </tr> - </table> - </form> - - <br> - <br> - <br> - <br> - <br> - <br> - - </td> - </tr> -</table> - -</div> - -<?php include("fend.inc"); ?> -</body> -</html> diff --git a/pkg_config.10.xml b/pkg_config.10.xml index dad9fc88..8e9fd82a 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -337,7 +337,7 @@ <category>Services</category> <pkginfolink>https://doc.pfsense.org/index.php/PHPService</pkginfolink> <config_file>https://packages.pfsense.org/packages/config/phpservice/phpservice.xml</config_file> - <version>0.4.2</version> + <version>0.5.0</version> <status>Beta</status> <required_version>2.2</required_version> <maintainer>markjcrane@gmail.com</maintainer> |