|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||
See:
Description
| Packages | |
| com.lukasfeiler.httpd | The HTTP server daemon. |
| com.lukasfeiler.httpd.plugins | Contains the plugins loadable with the configuration option Plugins. |
joedoe:9uZ9B2 janedoe:ZUa23YExamples:
ListenPort 80 ListenAddress localhost ConnectionTimeout 50000 ConnectionLifetime 300000 ConnectionMaximum 10 ConnectionMaximumDelay 20000 ConnectionQueueLength 1 ServerBanner Apache DocumentRoot M:\ Plugins IPFilter HTTPAuth ExtensionFilter AutoIndex ParseM3U ReadFile IPFilterOrder allow deny IPFilterAllow 192.168.1.10/255.255.255.0 127.0.0.1 IPFilterDeny ALL ExtensionFilterOrder allow deny ExtensionFilterAllow .m3u .txt .mp3 ExtensionFilterDeny ALL HTTPAuthPasswordFile conf/logins.pwd HTTPAuthRealm This is a restricted area. LogAccess logs/access.log LogError logs/error.log LogSecure logs/secure.log
com.lukasfeiler.httpd.plugins.HTTPServerPlugin.
You will need to implement a constructor and the method run. run has to return false if the plugin
did not match and an different plugins should be run; if it returns true no other plugins will be
run.
package com.lukasfeiler.test;
import com.lukasfeiler.httpd.*;
import com.lukasfeiler.httpd.plugins.HTTPServerPlugin;
import java.io.*;
import java.util.Vector;
/**Parses PHP files using the the php CGI executable.
* You can use the configuration option PHPCgi to specify
* the path to the php executable. The default is "php".
*/
public class ParsePHP extends HTTPServerPlugin {
/**parent constructor is protected; we need a public constructor*/
public ParsePHP(HTTPServer server) {
super(server);
}
/**Is called by HTTPSocket to run the plugin for a specific request*/
public boolean run(HTTPSocket socket, File f, String requestedResource, Vector headers) {
//try another plugin if a directory was requested
if (f.isDirectory()) {
return false;
}
//try another plugin if the requested file does not have the extension .php
if (!server.getFileExtension(f).equals(".php")) {
return false;
}
try {
//read the value of the configuration option PHPCgi; use the "php" as a default
String php = server.getConfigurationOption("PHPCgi", "php");
//run the php CGI version with the filename as argument
Process cmdProcess = Runtime.getRuntime().exec(php + " " + f.getCanonicalPath());
//get the process output stream (an input stream form our perspective)
InputStream cmdProcessIn = cmdProcess.getInputStream();
//write standard HTTP headers and use text/html as content type
socket.writeStandardHTTPHeaders("text/html");
//read PHP output and write it to the socket stream
int c = 0;
while((c = cmdProcessIn.read()) != -1){
socket.getOut().write(
Character.toString((char)c).getBytes()
);
}
//everything went fine
server.logAccess(socket, f, requestedResource, headers, 200, (int)f.length());
} catch (IOException e) {
//log an error and send a "500 Internal error" to the client
socket.writeInternalError(socket, f, requestedResource, headers, e.getClass().getName() + ": " + e.getMessage());
}
//do not try to run another plugin for this request
return true;
}
}
|
||||||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||||