plex/ 0000755 0001750 0001750 00000000000 11222146226 010500 5 ustar scio scio plex/Plex.pm 0000644 0000000 0000000 00000000163 11222146063 011767 0 ustar root root package Plex;
my $VERSION = "2.7";
our ($WEBSERVER, $USER_DIR, $ROOT, %SERVER);
$SERVER{VERSION} = $VERSION;
1;
plex/Plex/ 0000755 0000000 0000000 00000000000 11222146124 011427 5 ustar root root plex/Plex/Compiler.pm 0000644 0000000 0000000 00000001666 11222146124 013550 0 ustar root root package Plex::Compiler;
use Plex::Compiler::Lexer;
my $debug = 1;
@ISA = ( Plex::Compiler::Lexer );
my @comp;
sub new {
my ($class, @tokens) = @_;
my $self = {};
@{$self->{tokens}} = @tokens;
bless ($self, $class);
return $self;
}
sub compile {
my $self = shift;
foreach my $token_ref (@{$self->{tokens}}) {
my $to = $token_ref->[1];
$to =~ s/\?/$token_ref->[0]/;
push(@comp, qq[$to\n]);
}
my $comp = join('', @comp);
$self->{comp} = $comp;
#$cache->cache_code( $comp );
@comp = ();
$comp = undef;
return $self;
}
sub execute {
my ($self, %ARGS) = @_;
if (defined %ARGS) {
local %ENV;
foreach my $arg (keys %ARGS) {
$ENV{$arg} = $ARGS{$arg};
}
}
my $code = $self->{comp};
eval($code) or die "error: $!";
my @buffer = getbuf();
my $buffer = join('', @buffer);
$self->{buffer} = $buffer;
return $self;
}
1;
plex/Plex/HTTP.pm 0000644 0000000 0000000 00000003617 11222146124 012553 0 ustar root root package Plex::HTTP;
use IO::Socket;
use HTTP::Status;
use Plex::HTTP::Call;
use HTTP::Request;
use HTTP::Date;
use URI::Escape;
use Plex::Text;
local $/ = undef;
@ISA = ( Plex::HTTP::Cache, Plex::HTTP::Call );
my $CRLF = "\015\012";
my %cfg = (
'version' => '1.1',
'server' => 'plex/2.7',
);
sub new ($%) {
my ($class, %args) = @_;
$args{Listen} ||= 10;
$args{Proto} ||= 'tcp';
$args{Reuse} ||= 1;
$args{LocalPort} ||= 80;
my $s = IO::Socket::INET->new(%args)
or die "Couldn't set up socket: $!";
my $self = {};
$self->{server} = $s;
bless($self, $class);
return $self;
}
sub accept ($) {
my $self = shift;
my $c = $self->{server}->accept();
$self->{client} = $c;
return $self;
}
sub get_request ($) {
my $self = shift;
my %data;
my $c = $self->{client};
my $req;
while (<$c>) {
$req = $req.$_;
if ($_ eq $CRLF) { last; }
}
my $http = HTTP::Request->parse($req);
$self->{req} = $http;
return $self;
}
sub make ($$$$) {
my ($self, $status, $type, $content) = @_;
my $c = $self->{client};
print $c "HTTP/$cfg{version} $status ".status_message($status).$CRLF;
print $c "Date: ".time2str(localtime()).$CRLF;
print $c "Server: $cfg{server}".$CRLF;
print $c "Content-Type: $type".$CRLF;
print $c "Content-Length: ".length($content).$CRLF.$CRLF;
print $c $content;
}
sub make_error {
my ($self, $status, $message) = @_;
my $c = $self->{client};
my $content = "$status ".status_message($status)."
$message
".$cfg{server}.$CRLF;
print $c "HTTP/$cfg{version} $status ".status_message($status).$CRLF;
print $c "Date: ".time2str(localtime()).$CRLF;
print $c "Server: $cfg{server}".$CRLF;
print $c "Content-Type: text/html".$CRLF;
print $c "Content-Length: ".length($content).$CRLF.$CRLF;
print $c $content;
}
1;
plex/Plex/Language.pm 0000644 0000000 0000000 00000000451 11222146124 013510 0 ustar root root package Plex::Language;
use Filter::Util::Call;
sub import {
my ($type) = @_;
my ($status);
if (($status = filter_read() > 0)) {
s/\/\*(.*?)\*\//MultiLineComment($1)/seg;
}
$status;
}
sub MultiLineComment {
my $comment = shift;
while (<$comment>) {
chomp;
}
return $comment;
}
1; plex/Plex/Template.pm 0000644 0000000 0000000 00000000304 11222146124 013535 0 ustar root root package Plex::Template;
local $/ = undef;
sub display {
my $display = shift;
}
sub compile {
my $file = shift;
open(FILE, "<$file");
my $text = ;
close(FILE);
}
1;
plex/Plex/Text.pm 0000644 0000000 0000000 00000000314 11222146124 012707 0 ustar root root package Plex::Text;
sub html_escape ($) {
my $string = shift;
$string =~ s/</g;
$string =~ s/>/>/g;
$string =~ s/&/&/g;
$string =~ s/"/"/g;
return $string;
}
1;
plex/Plex/View.pm 0000644 0000000 0000000 00000003130 11222146124 012674 0 ustar root root package Plex::View;
use Plex::Compiler;
our %cache;
our @need;
our $need_as_string;
my @buffer;
sub exec {
my $file = shift;
eval($cache{$file}) or die $!;
my $buffer = join('', @buffer);
@buffer = ();
return $buffer;
}
sub out {
my $string = shift;
push(@buffer, $string);
return 1;
}
sub show_cached {
foreach (keys %cache) {
print "$_ => [$cache{$_}]\n";
}
}
sub compile_all {
my $root = $Plex::ROOT;
traversedir($root);
if ($Plex::USER_DIR) {
traversedir("/home/");
}
foreach my $need (@need) {
my $lexer = Plex::Compiler::Lexer->new();
$lexer->read_file( $need );
$lexer->lex;
my $compiler = Plex::Compiler->new( @{$lexer->{tokens}} );
$compiler->compile;
print "after compiling it is ".$compiler->{comp};
my $code = $compiler->{comp};
$cache{$need} = $code;
$code = undef;
$compiler->{comp} = undef;
$lexer = undef;
$compiler = undef;
print "after deleting it is ".$compiler->{comp};
}
$need_as_string = join('', @need);
}
sub traversedir {
my $path = shift;
opendir(my $dhl,"$path") || die "Can't open directory: $!";
my @files = grep {!/^\.{1,2}$/ } readdir($dhl);
foreach my $file (@files) {
if(-d "$path$file") {
traversedir("$path$file");
} else {
my $absolute = "$path/$file";
if ($absolute =~ /\./) {
if ($absolute =~ /\.view/i) {
push(@need, $absolute);
}
} else {
push(@need, $absolute);
}
}
}
closedir($dhl);
}
1;
plex/Plex/YAML.pm 0000644 0000000 0000000 00000000030 11222146124 012520 0 ustar root root package Plex::YAML;
1;
plex/Plex/Compiler/ 0000755 0000000 0000000 00000000000 11222146124 013201 5 ustar root root plex/Plex/Compiler/Cache.pm 0000644 0000000 0000000 00000000057 11222146124 014544 0 ustar root root package Plex::Compiler::Cache;
my %Cache;
1;
plex/Plex/Compiler/Lexer.pm 0000644 0000000 0000000 00000003445 11222146124 014624 0 ustar root root package Plex::Compiler::Lexer;
my %default = (
STANDARD => {
START => '<%',
END => '%>',
TO => '?',
},
);
my %rules = (
COMMENT => {
START => '<\#',
END => '\#>',
TO => '# ?\n',
},
);
my %interpolations = (
PRINT => {
TAG => '=',
TO => 'out qq[?];',
},
);
my $text;
my @tokens;
sub new {
my $class = shift;
my $self = {};
bless ($self, $class);
return $self;
}
sub read {
my ($self, $text_r) = @_;
$text = $text_r;
return 1;
}
sub read_file {
my ($self, $file) = @_;
local $/ = undef;
open(FILE, "<$file");
$text = ;
close(FILE);
return 1;
}
sub lex {
my $self = shift;
while (1) {
last if $text =~ m/\G\z/;
if ($text =~ m/ \G $default{STANDARD}{START}(.+?)$default{STANDARD}{END} /sgcx) {
push @tokens, [$1, $default{STANDARD}{TO}];
}
foreach my $type (keys %rules) {
if ($text =~ m/ \G $rules{$type}{START}(.+?)$rules{$type}{END} /sgcx) {
push @tokens, [$1, $rules{$type}{TO}];
}
}
foreach my $interpolation (keys %interpolations) {
if ($text =~ m/ \G $default{STANDARD}{START}$interpolations{$interpolation}{START}(.+?)$default{STANDARD}{END} /sgcx) {
push @tokens, [$1, $interpolations{$interpolation}{TO}];
}
}
match_text() or
die "Syntax error!";
}
@{$self->{tokens}} = @tokens;
@tokens = undef;
return $self;
}
sub match_text {
if ($text =~ m/ \G (.+?) (?= <\/?[%#] | \z) /sgcx) {
push @tokens, [$1, 'out qq[?];'];
return 1;
}
return 0;
}
1;
plex/Plex/Compiler/Simple.pm 0000644 0000000 0000000 00000001657 11222146124 015001 0 ustar root root package Plex::Compiler::Simple;
use Exporter;
use Plex::Compiler::Cache;
@ISA = ( Exporter );
use Plex::Compiler;
my $lexer = Plex::Compiler::Lexer->new();
@EXPORT = (compile_file);
@EXPORT_OK = (compile_file);
sub compile_file {
my (undef, $file) = @_;
$lexer->read_file( $file );
$lexer->lex;
my $compiler = Plex::Compiler->new( @{$lexer->{tokens}} );
$compiler->compile;
$compiler->execute;
return $compiler->{buffer};
}
sub cache_compile {
my (undef, $file) = @_;
$lexer->read_file( $file );
$lexer->lex;
my $compilr = Plex::Compiler->new( @{$lexer->{tokens}} );
$compiler->compile;
$compiler->execute;
$Plex::Compiler::Cache{$file} = sub { $compiler->{buffer} };
}
sub compile {
my (undef, $str) = @_;
$lexer->read( $str );
$lexer->lex;
my $compiler = Plex::Compiler->new( @{$lexer->{tokens}} );
$compiler->compile;
$compiler->execute;
return $compiler->{buffer};
}
1;
plex/Plex/HTTP/ 0000755 0000000 0000000 00000000000 11222146124 012206 5 ustar root root plex/Plex/HTTP/Cache.pm 0000644 0000000 0000000 00000000452 11222146124 013550 0 ustar root root package Plex::HTTP::Cache;
my %cache;
sub new {
my $class = shift;
return $class;
}
sub cache_code {
my ($self, $file, $code) = @_;
$cache{$file}{Code} = $code;
return 1;
}
sub cache_out {
my ($self, $file, $out) = @_;
$cache{$file}{Out} = $out;
return 1;
}
1;
plex/Plex/HTTP/Call.pm 0000644 0000000 0000000 00000005332 11222146124 013422 0 ustar root root package Plex::HTTP::Call;
use File::MMagic;
use Plex::Compiler::Simple;
my $mm = new File::MMagic;
my %obj;
sub new {
my ($class, $root) = @_;
my $self = {};
$self->{root} = $root;
bless($self, $class);
return $self;
}
sub handle {
my ($self, $host, $file, $http) = @_;
my $absolute = $Plex::ROOT."/".$host."/".$file;
if ($file =~ /\/~(.*?)\/(.*)/) {
$absolute = "/home/$1/$2";
}
$absolute =~ s/\/\//\//g;
if (-d $absolute) {
if(is_index_in_dir($absolute)) {
my $path = $absolute."index.view";
print "Called index file of $absolute\n";
$http->make(200, "text/html", &Plex::View::exec($path));
} else {
$http->make_error(404, "No index file. LOL. You thought i'll give YOU directory listing!? :D");
}
} elsif (-e $absolute) {
my $type = $mm->checktype_filename( $absolute );
print "Type: $type :: $file\n";
$type =~ /(.*?)\/(.*)/;
if ($file =~ /\./) {
if ($file =~ /\/(.*?)\.view$/i) {
print "Call $absolute\n";
$http->make(200, "text/html", &Plex::View::exec($absolute) );
} elsif ($file =~ /\/(.*?)\.css/i) {
local $/ = undef;
open(CSS, "<$absolute");
my $css = ;
close(CSS);
$http->make(200, "text/css", $css);
} elsif ($file =~ /\/(.*?)\.gif/) {
local $/ = undef;
open(GIF, "<$absolute");
my $gif = ;
close(GIF);
$http->make(200, "image/gif", $gif);
} elsif ($file =~ /\.jpg/) {
local $/ = undef;
open(JPG, "<$absolute");
my $jpg = ;
close(JPG);
$http->make(200, "image/jpg", $jpg);
}
} elsif ($file =~ /\/(.*?)$/) {
print "Call $absolute\n";
$http->make(200, "text/html", &Plex::View::exec($absolute) );
} else {
local $/ = undef;
print "Delivering $file as $type\n";
open(FILE, "<$absolute");
my $file = ;
close(FILE);
$http->make(200, $type, $file);
}
} else {
if (-e $absolute.".view") {
print "Call $absolute".".view";
$http->make(200, "text/html", &Plex::View::exec($absolute.".view"));
} else {
$http->make_error(404, "No such file or directory.");
}
}
}
sub is_index_in_dir {
my $dir = shift;
opendir(DIR, $dir);
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
if ($file eq "index.view") {
return 1;
}
}
return 0;
}
1;
plex/Plex/loesung.pl 0000644 0000000 0000000 00000000522 11222146124 013437 0 ustar root root sub traversedir {
my $path = shift;
opendir(my $dhl,"$path") || die "Can't open directory: $!";
my @files = grep {!/^\.{1,2}$/ } readdir($dhl);
foreach my $file (@files) {
if(-d "$path$file") {
traversedir("$path$file");
} else {
print "$path/$file\n";
}
}
closedir($dhl);
}
traversedir("/var/www/");
plex/Plex/Plex.pm 0000644 0000000 0000000 00000000054 11222146124 012674 0 ustar root root package Plex;
our ($WEBSERVER, $ROOT);
1;
plex/plex 0000755 0000000 0000000 00000005002 11222146133 011412 0 ustar root root #!/usr/bin/perl
use Plex;
use Plex::View;
use Plex::HTTP;
use Getopt::Long;
use Proc::Daemon;
use Symbol;
use POSIX;
my $PREFORK = 8;
my $MAX_CLIENTS_PER_CHILD = 8;
my %children = ();
my $children = 0;
my ($port, $config, $root, $dbeug, $dev, $vhosts, $user_dir) = undef;
GetOptions( 'port=s' => \$port,
'root=s' => \$root,
'vhosts' => \$vhosts,
'debug' => \$debug,
'dev' => \$dev,
'user_dir' => \$user_dir,
'config' => \$config);
if ($config) {
use YAML::Syck;
}
$Plex::ROOT = $root;
$Plex::USER_DIR = 1 if $user_dir;
Plex::View::compile_all();
print "Plex/3.0 Application Server with PSL\n-----------------------\n";
print "Port => $port\n";
print "Root => $root\n";
print "Vhosts => $vhosts\n";
print "Debug => $dev\n";
print "Devel => $dev\n";
print "Compiled => $Plex::View::need_as_string\n";
print "-----------------------\n";
Proc::Daemon::Init if !$dev;
my $http = Plex::HTTP->new( LocalPort => $port );
my $call = Plex::HTTP::Call->new( $root );
my $server = $http->{server};
$Plex::WEBSERVER = $http;
for (1 .. $PREFORK) {
spawn();
}
$SIG{CHLD} = \&REAPER;
$SIG{INT} = \&HUNTSMAN;
while (1) {
sleep;
for ($i = $children; $i < $PREFORK; $i++) {
$Plex::SERVER{spawned} = $children;
$Plex::SERVER{to_spawn} = $PREFORK;
spawn();
}
}
sub spawn {
my $pid;
my $sigset;
$sigset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $sigset)
or die "Can't block SIGINT for fork: $!\n";
die "fork: $!" unless defined ($pid = fork);
if ($pid) {
sigprocmask(SIG_UNBLOCK, $sigset)
or die "Can't unblock SIGINT for fork: $!\n";
$children{$pid} = 1;
$children++;
return;
} else {
$SIG{INT} = 'DEFAULT';
sigprocmask(SIG_UNBLOCK, $sigset)
or die "Can't unblock SIGINT for fork: $!\n";
for ($i=0; $i < $MAX_CLIENTS_PER_CHILD; $i++) {
$http->accept() or last;
my $client = $http->{client};
$http->get_request();
my $host = $http->{req}->header('Host');
my $file = $http->{req}->url->path;
$call->handle( $host, $file, $http );
$client->close();
exit;
}
exit;
}
}
sub REAPER {
$SIG{CHLD} = \&REAPER;
my $pid = wait;
$children --;
delete $children{$pid};
}
sub HUNTSMAN {
local($SIG{CHLD}) = 'IGNORE';
kill 'INT' => keys %children;
exit;
}
plex/INSTALL 0000644 0001750 0001750 00000000201 11222146226 011522 0 ustar scio scio INSTALL
---
No install script yet. Just run plex to daemonize.
Run:
plex --port=80 --root=/var/www/ --user_dir --vhosts [--dev]