package DashboardScripts::DashboardScripts; # File: DashboardScripts/DashboardScripts.pm use strict; use Apache2::RequestRec (); # for $r->content_type use Apache2::RequestIO (); # for $r->puts use Apache2::Const -compile => qw(OK DECLINED M_GET HTTP_METHOD_NOT_ALLOWED); BEGIN { $| } use Data::Dumper; sub handler { my $r = shift; my $ref; my $post; #my $host = $r->get_remote_host; unless ($r->method_number == Apache2::Const::M_GET) { $r->allowed($r->allowed | (1<content_type('text/html'); map { $_ =~ s/\+/ /g; my ($key, $val) = split(/=/,$_,2); foreach ($key, $val) {$_ =~ s/%([A-Fa-f0-9]{2})/pack("c",hex($1))/ge}; $$ref{$key} .= (defined($ref->{$key})) ? "\0$val" : $val; } split/[&;]/,$r->args(); #mysql> desc defaultscripts; #+----------+-------------+------+-----+---------+-------+ #| Field | Type | Null | Key | Default | Extra | #+----------+-------------+------+-----+---------+-------+ #| name | varchar(25) | NO | PRI | | | #| script | text | YES | | NULL | | #+----------+-------------+------+-----+---------+-------+ #2 rows in set (0.01 sec) exit Apache2::Const::DECLINED if ($ref->{name} eq ""); my @Raw_DB_Data; my $dbh = DBI->connect("DBI:mysql:dashboards", 'id', 'passwd', { PrintError => 0, # warn( ) on errors RaiseError => 0, # don't die on error AutoCommit => 1, # commit executes immediately } ); my $sql = "SELECT script FROM scripts where name='$ref->{name}'"; my $script; my $sth = $dbh->prepare("$sql"); if ($sth->execute) { while(my $row_hash = $sth->fetchrow_hashref) { $script = "$row_hash->{script}"; } $post .= "$script"; $post .= eval "$script; 1" or warn $@; $sth->finish(); } ################################################ $r->puts(<<"END"); $post END undef $post; undef $r; undef $sth; undef $dbh; return Apache2::Const::OK; } END { } 1;