Plex-2.7/0000755000175000017500000000000011224142602010740 5ustar scioscioPlex-2.7/Plex.pm0000644000175000017500000000016311222146063012211 0ustar sciosciopackage Plex; my $VERSION = "2.7"; our ($WEBSERVER, $USER_DIR, $ROOT, %SERVER); $SERVER{VERSION} = $VERSION; 1; Plex-2.7/Plex/0000755000175000017500000000000011223202030011637 5ustar scioscioPlex-2.7/Plex/Compiler.pm0000644000175000017500000000166611222146124013772 0ustar sciosciopackage 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-2.7/Plex/HTTP.pm0000644000175000017500000000361711222146124012775 0ustar sciosciopackage 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-2.7/Plex/Language.pm0000644000175000017500000000045111222146124013732 0ustar sciosciopackage 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-2.7/Plex/Template.pm0000644000175000017500000000030411222146124013757 0ustar sciosciopackage Plex::Template; local $/ = undef; sub display { my $display = shift; } sub compile { my $file = shift; open(FILE, "<$file"); my $text = ; close(FILE); } 1; Plex-2.7/Plex/Text.pm0000644000175000017500000000031411222146124013131 0ustar sciosciopackage Plex::Text; sub html_escape ($) { my $string = shift; $string =~ s//>/g; $string =~ s/&/&/g; $string =~ s/"/"/g; return $string; } 1; Plex-2.7/Plex/View.pm0000644000175000017500000000313011222146124013116 0ustar sciosciopackage 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-2.7/Plex/YAML.pm0000644000175000017500000000003011222146124012742 0ustar sciosciopackage Plex::YAML; 1; Plex-2.7/Plex/Compiler/0000755000175000017500000000000011222146124013423 5ustar scioscioPlex-2.7/Plex/Compiler/Cache.pm0000644000175000017500000000005711222146124014766 0ustar sciosciopackage Plex::Compiler::Cache; my %Cache; 1; Plex-2.7/Plex/Compiler/Lexer.pm0000644000175000017500000000344511222146124015046 0ustar sciosciopackage 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-2.7/Plex/Compiler/Simple.pm0000644000175000017500000000165711222146124015223 0ustar sciosciopackage 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-2.7/Plex/HTTP/0000755000175000017500000000000011222146124012430 5ustar scioscioPlex-2.7/Plex/HTTP/Cache.pm0000644000175000017500000000045211222146124013772 0ustar sciosciopackage 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-2.7/Plex/HTTP/Call.pm0000644000175000017500000000533211222146124013644 0ustar sciosciopackage 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-2.7/Plex/loesung.pl0000644000175000017500000000052211222146124013661 0ustar sciosciosub 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-2.7/plex0000755000175000017500000000500211222146133011634 0ustar scioscio#!/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-2.7/INSTALL0000644000175000017500000000020111222146226011766 0ustar scioscioINSTALL --- No install script yet. Just run plex to daemonize. Run: plex --port=80 --root=/var/www/ --user_dir --vhosts [--dev] Plex-2.7/Plex.pod0000644000175000017500000000001411224142602012347 0ustar scioscio=head1 Plex