From d3f4d86e26aa297416e85a8e99dd926e7e3a78af Mon Sep 17 00:00:00 2001 From: mcrane Date: Sat, 19 Dec 2009 16:22:57 -0700 Subject: Introducing vHosts web server package. It uses lighttp that is already installed but runs another instance of it with its own config. Also supports PHP5, and PHP PDO and SQLite --- config/vhosts/lighty-vhosts.conf | 179 +++++++++++++++++++++++++++++ config/vhosts/vhosts.inc | 228 +++++++++++++++++++++++++++++++++++++ config/vhosts/vhosts.xml | 132 ++++++++++++++++++++++ config/vhosts/vhosts_php.tmp | 191 +++++++++++++++++++++++++++++++ config/vhosts/vhosts_php_edit.tmp | 231 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 961 insertions(+) create mode 100644 config/vhosts/lighty-vhosts.conf create mode 100644 config/vhosts/vhosts.inc create mode 100644 config/vhosts/vhosts.xml create mode 100644 config/vhosts/vhosts_php.tmp create mode 100644 config/vhosts/vhosts_php_edit.tmp (limited to 'config') diff --git a/config/vhosts/lighty-vhosts.conf b/config/vhosts/lighty-vhosts.conf new file mode 100644 index 00000000..b3178771 --- /dev/null +++ b/config/vhosts/lighty-vhosts.conf @@ -0,0 +1,179 @@ +# +# lighttpd configuration file +# +# use a it as base for lighttpd 1.0.0 and above +# +############ Options you really have to take care of #################### + +## FreeBSD! +server.event-handler = "freebsd-kqueue" +server.network-backend = "writev" ## Fixes 7.x upload issues + + + +## modules to load +server.modules = ( + "mod_accesslog", + "mod_access", "mod_accesslog", + "mod_fastcgi", "mod_cgi","mod_rewrite" + ) + +## Unused modules +# "mod_setenv", +# "mod_compress" +# "mod_redirect", +# "mod_rewrite", +# "mod_ssi", +# "mod_usertrack", +# "mod_expire", +# "mod_secdownload", +# "mod_rrdtool", +# "mod_auth", +# "mod_status", +# "mod_alias", +# "mod_proxy", +# "mod_simple_vhost", +# "mod_evhost", +# "mod_userdir", +# "mod_cgi", +# "mod_accesslog" + +## a static document-root, for virtual-hosting take look at the +## server.virtual-* options +server.document-root = "/usr/local/vhosts/" + + +# Maximum idle time with nothing being written (php downloading) +server.max-write-idle = 999 + +## where to send error-messages to +server.errorlog = "/var/log/lighttpd.error.log" + +# files to check for if .../ is requested +server.indexfiles = ( "index.php", "index.html", + "index.htm", "default.htm" ) + +# mimetype mapping +mimetype.assign = ( + ".pdf" => "application/pdf", + ".sig" => "application/pgp-signature", + ".spl" => "application/futuresplash", + ".class" => "application/octet-stream", + ".ps" => "application/postscript", + ".torrent" => "application/x-bittorrent", + ".dvi" => "application/x-dvi", + ".gz" => "application/x-gzip", + ".pac" => "application/x-ns-proxy-autoconfig", + ".swf" => "application/x-shockwave-flash", + ".tar.gz" => "application/x-tgz", + ".tgz" => "application/x-tgz", + ".tar" => "application/x-tar", + ".zip" => "application/zip", + ".mp3" => "audio/mpeg", + ".m3u" => "audio/x-mpegurl", + ".wma" => "audio/x-ms-wma", + ".wax" => "audio/x-ms-wax", + ".ogg" => "audio/x-wav", + ".wav" => "audio/x-wav", + ".gif" => "image/gif", + ".jpg" => "image/jpeg", + ".jpeg" => "image/jpeg", + ".png" => "image/png", + ".xbm" => "image/x-xbitmap", + ".xpm" => "image/x-xpixmap", + ".xwd" => "image/x-xwindowdump", + ".css" => "text/css", + ".html" => "text/html", + ".htm" => "text/html", + ".js" => "text/javascript", + ".asc" => "text/plain", + ".c" => "text/plain", + ".conf" => "text/plain", + ".text" => "text/plain", + ".txt" => "text/plain", + ".dtd" => "text/xml", + ".xml" => "text/xml", + ".mpeg" => "video/mpeg", + ".mpg" => "video/mpeg", + ".mov" => "video/quicktime", + ".qt" => "video/quicktime", + ".avi" => "video/x-msvideo", + ".asf" => "video/x-ms-asf", + ".asx" => "video/x-ms-asf", + ".wmv" => "video/x-ms-wmv", + ".bz2" => "application/x-bzip", + ".tbz" => "application/x-bzip-compressed-tar", + ".tar.bz2" => "application/x-bzip-compressed-tar" + ) + +# Use the "Content-Type" extended attribute to obtain mime type if possible +#mimetypes.use-xattr = "enable" + +#### accesslog module +#accesslog.filename = "/dev/null" + +## deny access the file-extensions +# +# ~ is for backupfiles from vi, emacs, joe, ... +# .inc is often used for code includes which should in general not be part +# of the document-root +url.access-deny = ( "~", ".db" ) + + +######### Options that are good to be but not neccesary to be changed ####### + +## bind to port (default: 80) +server.port = 8001 + +## error-handler for status 404 +#server.error-handler-404 = "/error-handler.html" +#server.error-handler-404 = "/error-handler.php" + +## to help the rc.scripts +server.pid-file = "/var/run/lighty-vhosts.pid" + +## virtual directory listings +server.dir-listing = "disable" + +## enable debugging +debug.log-request-header = "disable" +debug.log-response-header = "disable" +debug.log-request-handling = "disable" +debug.log-file-not-found = "disable" + +#### compress module +#compress.cache-dir = "/tmp/lighttpd/cache/compress/" +#compress.filetype = ("text/plain", "text/html") + +#server.network-backend = "writev" + +server.upload-dirs = ( "/root/", "/tmp/", "/var/" ) + + +server.max-request-size = 2097152 + +#### fastcgi module +## read fastcgi.txt for more info +fastcgi.server = ( ".php" => + ( "localhost" => + ( + "socket" => "/tmp/php5-fastcgi.socket", + "min-procs" => 1, + "max-procs" => 1, + "idle-timeout" => 0, + "bin-environment" => ( + "PHP_FCGI_MAX_REQUESTS" => "500", + "PHP_FCGI_CHILDREN" => "1" + ), + "bin-path" => "/usr/local/php5/php-cgi" + ) + ) +) + +#### CGI module +cgi.assign = ( ".cgi" => "" ) + + + + + diff --git a/config/vhosts/vhosts.inc b/config/vhosts/vhosts.inc new file mode 100644 index 00000000..0cb88064 --- /dev/null +++ b/config/vhosts/vhosts.inc @@ -0,0 +1,228 @@ +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]; +} + + +function vhosts_sync_package_php() +{ + + global $config; + if($config['installedpackages']['vhosts']['config'] != "") { + + conf_mount_rw(); + config_unlock(); + + $tmp = "\\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']['vhosts']['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 .= 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/vhosts.php","w"); + fwrite($fout, $tmp); + unset($tmp); + fclose($fout); + + conf_mount_ro(); + + } +} + + +function php_sync_package() +{ + + global $config; + vhosts_sync_package_php(); + +} + + +function php_install_command() +{ + + global $config; + conf_mount_rw(); + config_lock(); + + if (!is_dir('/usr/local/www/packages/')) { + exec("mkdir /usr/local/www/packages/"); + } + + if (!is_dir('/usr/local/www/packages/vhosts/')) { + exec("mkdir /usr/local/www/packages/vhosts/"); + } + + //rename PHP files from .tmp to .php + exec("cp /tmp/vhosts_php.tmp /usr/local/www/packages/vhosts/vhosts_php.php"); + unlink_if_exists("/tmp/vhosts_php.tmp"); + + exec("cp /tmp/vhosts_php_edit.tmp /usr/local/www/packages/vhosts/vhosts_php_edit.php"); + unlink_if_exists("/tmp/vhosts_php_edit.tmp"); + + //extract php5 + exec("cp /tmp/vhosts_php_edit.tmp /usr/local/www/packages/vhosts/vhosts_php_edit.php"); + unlink_if_exists("/tmp/php5.tar.gz"); + + //write_config(); + + write_rcfile(array( + "file" => "vhosts.sh", + "start" => "/usr/local/sbin/lighttpd -f /var/etc/lighty-vhosts.conf", + "stop" => "rm /tmp/phpmonitor.pid" + ) + ); + + php_sync_package(); + //$handle = popen("/usr/local/etc/rc.d/vhosts.sh start", "r"); + //pclose($handle); + + //if (pkg_is_service_running('vhosts')) { + //documentation purposes + //} + + conf_mount_ro(); + config_unlock(); + +} + + +function deinstall_command() +{ + conf_mount_rw(); + config_lock(); + $handle = popen("/usr/local/etc/rc.d/vhosts.sh stop", "r"); + unlink_if_exists("/usr/local/pkg/vhosts.xml"); + unlink_if_exists("/usr/local/pkg/vhosts.inc"); + unlink_if_exists("/usr/local/www/vhosts.inc"); + unlink_if_exists("/usr/local/etc/rc.d/vhosts.sh"); + exec("rm -R /usr/local/php5"); + conf_mount_ro(); + config_unlock(); +} + +?> \ No newline at end of file diff --git a/config/vhosts/vhosts.xml b/config/vhosts/vhosts.xml new file mode 100644 index 00000000..cbb01582 --- /dev/null +++ b/config/vhosts/vhosts.xml @@ -0,0 +1,132 @@ + + + + + + + + PHP Service + Describe your package requirements here + Currently there are no FAQ items provided. + vHosts Settings + 0.1 + Settings + /usr/local/pkg/vhosts.inc + + vhosts + vHosts Service settings. +
Services
+ vhosts.xml + /packages/vhosts/vhosts_php.php +
+ + vhosts + vhosts.sh + vhosts + Lighttpd web server service. + + + + Settings + /pkg_edit.php?xml=vhosts.xml&id=0 + + + + Settings + /packages/vhosts_php.php + + + + installedpackages->package->$packagename->configuration->vhosts + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/vhosts/vhosts.xml + + + /usr/local/pkg/ + 0755 + http://www.pfsense.com/packages/config/vhosts/vhosts.inc + + + /tmp/ + 0755 + http://www.pfsense.com/packages/config/vhosts/vhosts_php.tmp + + + /tmp/ + 0755 + http://www.pfsense.com/packages/config/vhosts/vhosts_php_edit.tmp + + + /var/etc/ + 0755 + http://www.pfsense.com/packages/config/vhosts/lighty-vhosts.conf + + + /tmp/ + 0755 + http://www.pfsense.com/packages/config/vhosts/php5.tar.gz + + + + + Variable One + var1 + Enter the variable one here. + input + + + Variable Two + var1 + Enter the variable one here. + input + + + + + + php_sync_package(); + + + php_sync_package(); + + + php_install_command(); + + + deinstall_command(); + +
\ No newline at end of file diff --git a/config/vhosts/vhosts_php.tmp b/config/vhosts/vhosts_php.tmp new file mode 100644 index 00000000..c77d50a3 --- /dev/null +++ b/config/vhosts/vhosts_php.tmp @@ -0,0 +1,191 @@ + + + + + +

vHosts Service:

+ +
+ + +
+ +
+ + + + + +
+ +
+ "; + //print_info_box_np("This is an info box."); + //echo"
"; + //endif; + + ?> + + + + +

+ 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"); +

+ For more information see: http://doc.pfsense.org/index.php/vhosts +

+
+ + + + + + + + + + + 0) { + + foreach ($a_vhosts as $ent) { + + ?> + + + + + + + + + + + + + + + + + +
NameEnabledDescription + + + + + + +
+ +
+   + +   + +   + + + + + + +
+
+ + + + + +
+
+ +
+ + +
+
+
+
+
+
+
+
+ +
+ +
+ + + + + diff --git a/config/vhosts/vhosts_php_edit.tmp b/config/vhosts/vhosts_php_edit.tmp new file mode 100644 index 00000000..db3235d6 --- /dev/null +++ b/config/vhosts/vhosts_php_edit.tmp @@ -0,0 +1,231 @@ + + + + + + +

PHP Service: Edit

+ + + +
+ + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name + +
Host + +
IP Address + +
Port + + Example: 8001 +
Enabled + \n"; + echo " \n"; + switch (htmlspecialchars($pconfig['enabled'])) { + case "true": + echo " \n"; + echo " \n"; + break; + case "false": + echo " \n"; + echo " \n"; + break; + default: + echo " \n"; + echo " \n"; + } + echo " \n"; + ?> +
Description + +
Enter the description here.
+
  + + + + +
+
+ +
+
+
+
+
+
+ +
+ +
+ + + + -- cgit v1.2.3