summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brachold <vdr07@deltab.de>2009-05-04 18:30:04 +0000
committerAndreas Brachold <vdr07@deltab.de>2009-05-04 18:30:04 +0000
commitb54b6c95d599b4e0febff69ba47ed7ac9ca7e639 (patch)
tree15961904a3c11105da22dbd30a2368647ec8f1f4
parent04f030980f950eb8b8684d324d535ac06b539cbe (diff)
downloadxxv-b54b6c95d599b4e0febff69ba47ed7ac9ca7e639.tar.gz
xxv-b54b6c95d599b4e0febff69ba47ed7ac9ca7e639.tar.bz2
* WML: Backport changes from module HTTPD
-rw-r--r--lib/XXV/MODULES/EPG.pm3
-rw-r--r--lib/XXV/MODULES/WAPD.pm162
-rw-r--r--lib/XXV/OUTPUT/Wml.pm81
-rw-r--r--wml/now.tmpl10
-rw-r--r--wml/program.tmpl16
-rw-r--r--wml/search.tmpl4
-rw-r--r--wml/skin.cfg2
-rw-r--r--wml/tlist.tmpl4
l---------wml/widgets/textfield.tmpl1
9 files changed, 212 insertions, 71 deletions
diff --git a/lib/XXV/MODULES/EPG.pm b/lib/XXV/MODULES/EPG.pm
index c56f250..1db3e29 100644
--- a/lib/XXV/MODULES/EPG.pm
+++ b/lib/XXV/MODULES/EPG.pm
@@ -905,7 +905,8 @@ order by
my $info = {
rows => $rows
};
- if($console->typ eq 'HTML') {
+ if($console->typ eq 'HTML'
+ || $console->typ eq 'WML') {
$info->{channels} = $cmod->ChannelWithGroup('c.name,c.hash');
$info->{current} = $cid;
}
diff --git a/lib/XXV/MODULES/WAPD.pm b/lib/XXV/MODULES/WAPD.pm
index 6005202..f63c29b 100644
--- a/lib/XXV/MODULES/WAPD.pm
+++ b/lib/XXV/MODULES/WAPD.pm
@@ -171,6 +171,8 @@ sub init {
# read new line and report it
my $handle=$watcher->w->fd;
+ my $ip = getip($handle);
+
my $data = $self->parseRequest($handle,(defined $self->{LOGOUT} && $self->{LOGOUT} == 1 ));
unless($data) {
undef $self->{LOGOUT};
@@ -236,6 +238,25 @@ sub init {
$console->footer();
}
}
+
+ # make entry more readable
+ $data->{Query} =~ s/%([a-f0-9][a-f0-9])/pack("C", hex($1))/ieg
+ if($data->{Query});
+ $data->{Referer} =~ s/%([a-f0-9][a-f0-9])/pack("C", hex($1))/ieg
+ if($data->{Referer});
+ # Log like Apache Format ip, resolved hostname, user, method request, status, bytes, referer, useragent
+ lg sprintf('%s - %s "%s %s%s" %s %s "%s" "%s"',
+ $ip,
+ $data->{username} ? $data->{username} : "-",
+ $data->{Method},
+ $data->{Request} ? $data->{Request} : "",
+ $data->{Query} ? "?" . $data->{Query} : "",
+ $console->{'header'},
+ $console->{'sendbytes'},
+ $data->{Referer} ? $data->{Referer} : "-",
+ "-" #$data->{http_useragent} ? $data->{http_useragent} : ""
+ );
+
$watcher->w->cancel;
undef $watcher;
$handle->close();
@@ -250,41 +271,94 @@ sub init {
}
# ------------------
+sub _readline {
+# ------------------
+ my $fh = $_[0];
+ my $c='';
+ my $line='';
+ my $eof=0;
+
+ while ($c ne "\n" && ! $eof) {
+ if (sysread($fh, $c, 1) > 0) {
+ $line = $line . $c;
+ } else {
+ $eof=1;
+ }
+ }
+ return $line;
+}
+# ------------------
sub parseRequest {
# ------------------
my $self = shift || return error('No object defined!');
- my $hdl = shift || return error('No handle defined!');
+ my $socket = shift || return error('No handle defined!');
my $logout = shift || 0;
- my ($Req, $size) = getFromSocket($hdl);
-
- if($Req->[0] =~ /^GET (\/[\w\.\/-\:\%]*)([\?[\w=&\.\+\%-\:\!]*]*)[\#\d ]+HTTP\/1.\d$/) {
- my $data = {};
- ($data->{Request}, $data->{Query}) = ($1, $2 ? substr($2, 1, length($2)) : undef);
-
- # parse header
- foreach my $line (@$Req) {
- if($line =~ /Referer: (.*)/) {
+ binmode $socket;
+ my $data = {};
+ my $line;
+ while (defined($line = &_readline($socket))) {
+ if(!$line || $line eq "\r\n") {
+ last;
+ } elsif(!$data->{Method} && $line =~ /^(\w+) (\/[\w\.\/\-\:\%]*)([\?[\w=&\.\+\%-\:\!]*]*)[\#\d ]+HTTP\/1.\d/) {
+ ($data->{Method}, $data->{Request}, $data->{Query}) = ($1, $2, $3 ? substr($3, 1, length($3)) : undef);
+ } elsif($line =~ /Referer: (.*)/) {
$data->{Referer} = $1;
- }
- if($line =~ /Host: (.*)/) {
+ $data->{Referer} =~ s/(\r|\n)//g;
+ } elsif($line =~ /Host: (.*)/) {
$data->{HOST} = $1;
- }
- if($line =~ /Authorization: basic (.*)/i and not $logout) {
+ $data->{HOST} =~ s/(\r|\n)//g;
+ } elsif($line =~ /Authorization: basic (.*)/i and not $logout) {
($data->{username}, $data->{password}) = split(":", MIME::Base64::decode_base64($1), 2);
- }
- if($line =~ /User-Agent: (.*)/i) {
+ } elsif($line =~ /User-Agent: (.*)/i) {
$data->{http_useragent} = $1;
+ $data->{http_useragent} =~ s/(\r|\n)//g;
+ } elsif($line =~ /Accept-Encoding:.+?gzip/i) {
+ $data->{accept_gzip} = 1;
+ } elsif($line =~ /If-None-Match: (\S+)/i) {
+ $data->{Match} = $1;
+ } elsif($line =~ /Cookie: (\S+)=(\S+)/i) {
+ $data->{$1} = $2;
+ } elsif($line =~ /Content-Type: (\S+)/i) {
+ $data->{ContentType} = $1;
+ } elsif($line =~ /Content-Length: (\S+)/i) {
+ $data->{ContentLength} = $1;
}
- }
- $data->{Request} =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
+ $self->{STATUS}->{'readbytes'} += length($line);
+ }
+
+ $data->{Request} =~ s/%([a-f0-9][a-f0-9])/pack("C", hex($1))/ieg
+ if($data->{Request});
+ if($data->{Method}) {
+ if($data->{Method} eq 'GET'
+ or $data->{Method} eq 'HEAD') {
+ return $data;
+ } elsif($data->{Method} eq 'POST') {
+ if(int($data->{ContentLength})>0) {
+ my $post;
+ my $bytes = sysread($socket,$post,$data->{ContentLength});
+ $data->{Post} = $post
+ if($bytes && $data->{ContentLength} == $bytes);
+ $self->{STATUS}->{'readbytes'} += $bytes;
+ }
+ return $data;
+ } else {
+ lg sprintf("Unsupported HTTP Method : %s",$data->{Method});
+ }
+ }
+ return undef;
+}
- return $data;
- } else {
- error sprintf("Unknown Request: <%s>\n", join("\n", @$Req));
- return;
- }
+# ------------------
+sub ModulNotLoaded {
+# ------------------
+ my $self = shift || return error('No object defined!');
+ my $console = shift || return error('No console defined!');
+ my $module = shift || return error('No module defined!');
+ $console->statusmsg(500,
+ ,sprintf(gettext("Module '%s' is'nt loaded!"),$module),
+ ,gettext("Internal Server Error"));
}
# ------------------
@@ -292,7 +366,7 @@ sub handleInput {
# ------------------
my $self = shift || return error('No object defined!');
my $console = shift || return error('No console defined!');
- my $cgi = shift || return error ('No CGI Object');
+ my $cgi = shift || return error('No CGI object defined!');
my $ucmd = $cgi->param('cmd') || '<undef>';
my $udata = $cgi->param('data') || '';
@@ -318,15 +392,41 @@ sub handleInput {
# Test the command on exists, permissions and so on
my $u = main::getModule('USER');
- my ($cmdobj, $cmdname, $shorterr, $err) = $u->checkCommand($console, $ucmd);
- $console->{call} = $cmdname;
- if($cmdobj and not $shorterr) {
- $cmdobj->{callback}($console, $udata, $result );
- } elsif($shorterr eq 'noperm' or $shorterr eq 'noactive') {
- return $console->status403($err);
+ if($u) {
+ my ($cmdobj, $cmdname, $cmdModule, $shorterr, $err) = $u->checkCommand($console, $ucmd);
+ $console->setCall($cmdname);
+ if($cmdobj and not $shorterr) {
+
+ if($cmdobj->{binary}) {
+ $console->{nocache} = 1
+ if($cmdobj->{binary} eq 'nocache');
+ }
+ $cmdobj->{callback}($console, $console->{USER}->{config}->{$cmdModule}, $udata, $result );
+ } elsif($shorterr eq 'noperm' or $shorterr eq 'noactive') {
+ $console->status403($err);
+ } else {
+ $self->_usage($console, undef, $err);
+ }
+ } else {
+ $self->ModulNotLoaded($console,'USER');
+ }
+}
+
+# ------------------
+sub _usage {
+# ------------------
+ my $self = shift || return error('No object defined!');
+ my $console = shift || return error('No console defined!');
+ my $modulename = shift;
+ my $hint = shift;
+
+ my $m = main::getModule('CONFIG');
+ if ($m){
+ return $m->usage($console,undef, $modulename,$hint);
} else {
- return $self->usage($console, undef, $err);
+ $self->ModulNotLoaded($console,'CONFIG');
}
+
}
diff --git a/lib/XXV/OUTPUT/Wml.pm b/lib/XXV/OUTPUT/Wml.pm
index d2852d4..2168737 100644
--- a/lib/XXV/OUTPUT/Wml.pm
+++ b/lib/XXV/OUTPUT/Wml.pm
@@ -116,7 +116,6 @@ sub parseTemplate {
my $data = shift || return error('No data defined!');
my $params = shift || {};
- my $t = $self->{tt};
my $u = main::getModule('USER');
# you can use two templates, first is a user defined template
@@ -171,8 +170,8 @@ sub parseTemplate {
}
},
};
- $t->process($widget, $vars, \$output)
- or return error($t->error());
+ $self->{tt}->process($widget, $vars, \$output)
+ or return error($self->{tt}->error());
return $output;
}
@@ -185,14 +184,13 @@ sub out {
my $type = shift || 'text/vnd.wap.wml';
my %args = @_;
- my $q = $self->{cgi};
unless(defined $self->{header}) {
# HTTP Header
- $self->{handle}->print(
- $self->header($type, \%args)
- );
+ my $header = $self->header($type, \%args);
+ $self->{sendbytes}+= length($header);
+ $self->{handle}->print($header );
}
-
+ $self->{sendbytes}+= length($text)+ 2;
$self->{handle}->print( $text,"\r\n" );
}
@@ -203,7 +201,7 @@ sub header {
my $typ = shift || return error ('No Type!' );
my $arg = shift || {};
- $self->{header} = 1;
+ $self->{header} = 200;
return $self->{cgi}->header(
-type => $typ,
-status => "200 OK",
@@ -217,24 +215,60 @@ sub header {
sub statusmsg {
# ------------------
my $self = shift || return error('No object defined!');
- my $msg = shift || return error ('No Msg!');
- my $status = shift || return error ('No Status!');
+ my $state = shift || return error('No state defined!');
+ my $msg = shift;
+ my $title = shift;
+ my $typ = shift || 'text/vnd.wap.wml';
unless(defined $self->{header}) {
$self->{nopack} = 1;
- $self->{header} = 1;
+
+ my $s = {
+ 200 => '200 OK',
+ 204 => '204 No Response',
+ 301 => '301 Moved Permanently',
+ 302 => '302 Found',
+ 303 => '303 See Other',
+ 304 => '304 Not Modified',
+ 307 => '307 Temporary Redirect',
+ 400 => '400 Bad Request',
+ 401 => '401 Unauthorized',
+ 403 => '403 Forbidden',
+ 404 => '404 Not Found',
+ 405 => '405 Not Allowed',
+ 408 => '408 Request Timed Out',
+ 500 => '500 Internal Server Error',
+ 503 => '503 Service Unavailable',
+ 504 => '504 Gateway Timed Out',
+ };
+ my $status = $s->{200};
+ $status = $s->{$state}
+ if(exists $s->{$state});
+
+ my $arg = {};
+
+ $arg->{'Location'} = $msg
+ if($state == 301);
+
+ $arg->{'WWW-Authenticate'} = "Basic realm=\"xxvd\""
+ if($state == 401);
+
+ $arg->{'expires'} = (($state != 304) || (defined $self->{nocache} && $self->{nocache})) ? "now" : "+7d";
+
+ $self->{header} = $state;
my $data = $self->{cgi}->header(
- -type => 'text/vnd.wap.wml',
+ -type => $typ,
-status => $status,
- -expires => "now",
+ -charset => $self->{charset},
+ %{$arg},
);
$self->out($data);
}
-
- my @title = split ('\n', $status);
- $self->start(undef,{ title => $title[0] });
- $self->err($msg);
- $self->footer();
+ if($msg && $title) {
+ $self->start(undef,{ title => $title });
+ $self->err($msg);
+ $self->footer();
+ }
}
# ------------------
@@ -244,7 +278,7 @@ sub login {
my $self = shift || return error('No object defined!');
my $msg = shift || '';
- $self->statusmsg($msg,"401 Authorization Required\nWWW-Authenticate: Basic realm=\"xxvd\"");
+ $self->statusmsg(401,$msg,gettext("Authorization required"));
}
# ------------------
@@ -254,7 +288,7 @@ sub status403 {
my $self = shift || return error('No object defined!');
my $msg = shift || '';
- $self->statusmsg($msg,"403 Forbidden");
+ $self->statusmsg(403,$msg,gettext("Forbidden"));
}
@@ -266,11 +300,10 @@ sub status404 {
my $file = shift || return error('No file defined!');
my $why = shift || "";
- lg sprintf("Couldn't open file '%s' : %s!",$file,$why);
-
$file =~ s/$self->{wmldir}\///g; # Don't post wml root, avoid spy out
- $self->statusmsg(sprintf(gettext("Couldn't open file '%s' : %s!"),$file,$why),"404 File not found");
+ $self->statusmsg(404,sprintf(gettext("Couldn't open file '%s' : %s!"),$file,$why),
+ gettext("Not found"));
}
# ------------------
diff --git a/wml/now.tmpl b/wml/now.tmpl
index 9aa2caa..6ef28a0 100644
--- a/wml/now.tmpl
+++ b/wml/now.tmpl
@@ -2,7 +2,7 @@
<?% "<i>" IF param.timers.${id} %?>
<?% IF global.ShowCardTitle %?>
<a href="?cmd=p&amp;data=<?% channel %?>">
- <?% channel %?>. <?% sender | truncate(20) | html %?>
+ <?% sender | truncate(20) | html %?>
</a><br />
<?% END %?>
<?% start %?> - <?% stop %?><br />
@@ -26,14 +26,18 @@
<?% fields = data.shift %?>
<?% FOREACH zeile = data %?>
<?% IF loop.count < skip;NEXT;END %?>
- <?% title=zeile.1;subtitle=zeile.2;sender=zeile.3;channel=zeile.4;start=zeile.5;stop=zeile.6;duration=zeile.7;desc=zeile.8 %?>
+ <?% title=zeile.1;subtitle=zeile.2;sender=zeile.3;
+ channel=zeile.4;group=zeile.5;start=zeile.6;stop=zeile.7;
+ desc=zeile.8;duration=zeile.9;
+ timerid=zeile.10;recording=zeile.11;running=zeile.12;
+ pdc=zeile.13; %?>
<?% IF id.defined %?>
<a href="#n<?% loop.count %?>"><img src="images/forward.wbm" alt="<?% gettext("Forward") %?>" /></a>
<a href="#index"><img src="images/home.wbm" alt="<?% gettext("Menu") %?>" /></a>
</p>
</card>
<?% END %?>
-<card id="<?% IF loop.count > 1 %?>n<?% loop.count;ELSE %?>first<?% END %?>" title="<?% channel %?>.<?% sender | truncate(10)| html %?>">
+<card id="<?% IF loop.count > 1 %?>n<?% loop.count;ELSE %?>first<?% END %?>" title="<?% sender | truncate(10)| html %?>">
<?% id=zeile.0 %?>
<p>
<?% PROCESS item %?>
diff --git a/wml/program.tmpl b/wml/program.tmpl
index d3dcd37..5dae34d 100644
--- a/wml/program.tmpl
+++ b/wml/program.tmpl
@@ -1,10 +1,12 @@
<?% USE date %?>
-<?% ######################################################################################
- channelpos=0;;
+<?% channel1st = param.channels.0;
+ channel = channel1st.0;
+ channelhash = channel1st.1;
+ channelitem = 1;
FOREACH ch = param.channels;
IF cgi.param('data') == ch.1 || cgi.param('data') == ch.0 || param.current == ch.1;
channel = ch.0;
- channelpos = ch.1;
+ channelhash = ch.1;
channelitem = loop.count;
LAST;
END;
@@ -14,7 +16,7 @@
<p>
<select name="channel" ivalue="<?% channelitem %?>" >
<?% FOREACH ch = param.channels %?>
- <option value="<?% ch.1 %?>"><?% ch.0 | html %?></option>
+ <option value="<?% loop.count %?>"><?% ch.0 | html %?></option>
<?% IF loop.count >= global.MaxChannelsProgram;LAST;END %?>
<?% END %?>
</select><br />
@@ -29,10 +31,10 @@
<?% BLOCK item %?>
<?% "<i>" IF param.timers.${id} %?>
<?% IF global.ShowCardTitle %?>
- <?% channelpos %?>.<?% channel | truncate(15)| html %?>
+ <?% channel | truncate(15)| html %?>
<br />
<?% END %?>
- <?% date.format(datum, "%a, %x") | html %?><br />
+ <?% datum | html %?><br />
<?% start %?> - <?% stop %?><br />
<b><?% title | truncate(20) | html %?></b><?% IF subtitle %?><br /><?% subtitle | truncate(20) | html%?><?% END %?>
<br />
@@ -64,7 +66,7 @@
</p>
</card>
<?% END %?>
-<card id="p<?% loop.count %?>" title="<?% channelpos %?>.<?% channel | truncate(15)| html %?>">
+<card id="p<?% loop.count %?>" title="<?% channel | truncate(15)| html %?>">
<?% id=zeile.0 %?>
<p>
<?% PROCESS item %?>
diff --git a/wml/search.tmpl b/wml/search.tmpl
index e1dd782..7885fdd 100644
--- a/wml/search.tmpl
+++ b/wml/search.tmpl
@@ -3,7 +3,7 @@
<?% "<i>" IF param.timers.${id} %?>
<?% IF global.ShowCardTitle %?>
<a href="?cmd=p&amp;data=<?% channel %?>">
- <?% channel %?>. <?% sender | truncate(20) | html %?>
+ <?% sender | truncate(20) | html %?>
</a><br />
<?% END %?>
<?% date.format(datum, "%a, %x") | html %?><br />
@@ -36,7 +36,7 @@
</card>
<?% END %?>
<?% id=zeile.0 %?>
-<card id="<?% IF loop.count > 1 %?>s<?% loop.count;ELSE %?>first<?% END %?>" title="<?% channel %?>.<?% sender | truncate(10)| html %?>">
+<card id="<?% IF loop.count > 1 %?>s<?% loop.count;ELSE %?>first<?% END %?>" title="<?% sender | truncate(10)| html %?>">
<p>
<?% PROCESS item %?>
<?% count = loop.count + 1 %?>
diff --git a/wml/skin.cfg b/wml/skin.cfg
index bc2b5e7..85cef40 100644
--- a/wml/skin.cfg
+++ b/wml/skin.cfg
@@ -12,4 +12,4 @@
<?% SET global.ShowCardTitle = 0 %?>
<?% ######################################################################## %?>
<?% # Include EPG description inside card %?>
-<?% SET global.ShowDescription = 0 %?>
+<?% SET global.ShowDescription = 1 %?>
diff --git a/wml/tlist.tmpl b/wml/tlist.tmpl
index a3289c1..63cf300 100644
--- a/wml/tlist.tmpl
+++ b/wml/tlist.tmpl
@@ -23,7 +23,7 @@
<?% IF allow('tedit') %?>
<a href="?cmd=te&amp;data=<?% id %?>">
<?% END %?>
- <?% gettext("Timer") %?> <?% id %?>
+ <?% gettext("Timer") %?> <?% ' ';loop.count %?>
<?% "</a>" IF allow('tedit') %?>
<br />
<?% END %?>
@@ -64,7 +64,7 @@
</card>
<?% END %?>
<?% id=zeile.0 %?>
-<card id="t<?% loop.count %?>" title="<?% gettext("Timer") %?> <?% id %?>">
+<card id="t<?% loop.count %?>" title="<?% gettext("Timer") %?> <?% ' ';loop.count %?>">
<p>
<?% PROCESS item %?>
<?% count = loop.count + 1 %?>
diff --git a/wml/widgets/textfield.tmpl b/wml/widgets/textfield.tmpl
new file mode 120000
index 0000000..8ea271d
--- /dev/null
+++ b/wml/widgets/textfield.tmpl
@@ -0,0 +1 @@
+string.tmpl \ No newline at end of file