From 984ee342666877f8a3423be51c659fcc19cbc549 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 13 Feb 2005 23:45:00 +0000 Subject: [PATCH] Add first beginnings of web control system. --- html/.htaccess | 1 + html/ccbs.css | 80 ++++++++++++++++++++++++++++++++++++++ html/ccbs.pm | 81 +++++++++++++++++++++++++++++++++++++++ html/index.pl | 8 ++++ html/templates/index.tmpl | 4 ++ html/templates/main.tmpl | 16 ++++++++ 6 files changed, 190 insertions(+) create mode 100644 html/.htaccess create mode 100644 html/ccbs.css create mode 100755 html/ccbs.pm create mode 100755 html/index.pl create mode 100644 html/templates/index.tmpl create mode 100644 html/templates/main.tmpl diff --git a/html/.htaccess b/html/.htaccess new file mode 100644 index 0000000..21623ec --- /dev/null +++ b/html/.htaccess @@ -0,0 +1 @@ +DirectoryIndex index.pl diff --git a/html/ccbs.css b/html/ccbs.css new file mode 100644 index 0000000..f3f8f6f --- /dev/null +++ b/html/ccbs.css @@ -0,0 +1,80 @@ +body { + font-family: georgia, arial, sans-serif; + background-color: white; +} +* { +/* border: 1px solid black; */ +} +.header { + margin-bottom: 1em; +} +.menu { + border-top: 1px solid gray; + border-bottom: 1px solid gray; + padding-top: 0.5em; + padding-bottom: 0.5em; + margin-bottom: 1em; + text-align: center; + background-color: rgb(161,206,222); +} +h1 img { + vertical-align: middle; + margin-left: 1em; + margin-right: 1em; +} + +.main { + margin-left: 3em; +} +/* .main > div, but IE can't handle that :-/ */ +.main div { + border-left: 2px solid rgb(78,179,78); +} +.main div.msg, .main div.qotd { + border: 2px solid red; + background-color: rgb(161,206,222); + padding: 0.5em; + margin-bottom: 0.5em; +} +.msgfooter { + font-size: smaller; + text-align: right; +} +.msgfooter input { + margin-left: 0.5em; +} + +.main p, .main pre { + margin-left: 1em; +} +table { + border-collapse: collapse; + background-color: white; + margin-left: 2em; + font-size: smaller; +} +th, td { + border: 1px solid black; + padding: 2px; +} +th { background-color: rgb(128,229,128); } +tr.even td { background-color: #ffa; } +tr.total { border-top: 2px solid black; } +tr.own { border: 2px solid red; } + +a:link, a:hover, th a:link, th a:visited, th a:hover { + color: blue; +} +a:visited { + color: navy; +} + +/* IE sucks! */ +tr.own td, tr.own th { border-top: 2px solid red; border-bottom: 2px solid red; } + +.footer { + padding-top: 0.5em; + margin-top: 1em; + font-size: x-small; + border-top: 1px solid gray; +} diff --git a/html/ccbs.pm b/html/ccbs.pm new file mode 100755 index 0000000..6080078 --- /dev/null +++ b/html/ccbs.pm @@ -0,0 +1,81 @@ +package ccbs; +use Template; +use CGI; +use DBI; +use strict; +use warnings; + +our $ccbs_dbdebug = 0; + +sub print_header { + print CGI::header(-type=>'text/html; charset=utf-8'); +} + +sub db_connect { + $ccbs_dbdebug = defined(shift) ? 1 : 0; + + my $dbh = DBI->connect("dbi:Pg:dbname=ccbs;host=sql.samfundet.no", "ccbsmmeligaen", "Noohos8h") + or die "Couldn't connect to database"; + $dbh->{RaiseError} = 1; + return $dbh; +} + +sub db_fetch_all { + my ($dbh, $sql, @parms) = @_; + my $q = $dbh->prepare($sql) + or die "Could not prepare query: " . $dbh->errstr; + $q->execute(@parms) + or die "Could not execute query: " . $dbh->errstr; + + if ($ccbs_dbdebug) { + warn $sql; + warn "params=" . join(', ', @parms); + } + + my @ret = (); + while (my $ref = $q->fetchrow_hashref()) { + if ($ccbs_dbdebug) { + my $dbstr = ""; + for my $k (sort keys %$ref) { + $dbstr .= " " . $k . "=" . $ref->{$k}; + } + warn $dbstr; + } + push @ret, $ref; + } + + $q->finish; + return \@ret; +} + +sub process_template { + my ($page, $title, $vars) = @_; + $vars->{'page'} = $page; + $vars->{'title'} = $title; + + my $config = { + INCLUDE_PATH => 'templates/', + INTERPOLATE => 1, + POST_CHOMP => 1, + EVAL_PERL => 1, + }; + my $template = Template->new($config); + + my $output = ''; + $template->process('main.tmpl', $vars, \$output) + or die $template->error(); + + print $output; +} + +$SIG{__DIE__} = sub { + # Gosh! Net::Resolver::DNS is brain-damaged. + my $msg = shift; + return if $msg =~ m#Win32/Registry.pm#; + + ccbs::print_header(); + ccbs::process_template('error.tmpl', 'Internal Server Error', + { message => $msg }); +}; + +1; diff --git a/html/index.pl b/html/index.pl new file mode 100755 index 0000000..76ec1e8 --- /dev/null +++ b/html/index.pl @@ -0,0 +1,8 @@ +#! /usr/bin/perl + +use ccbs; +use strict; +use warnings; + +ccbs::print_header(); +ccbs::process_template('index.tmpl', 'Forside'); diff --git a/html/templates/index.tmpl b/html/templates/index.tmpl new file mode 100644 index 0000000..068631d --- /dev/null +++ b/html/templates/index.tmpl @@ -0,0 +1,4 @@ +[%# vim:set filetype=html: %] +
+

Velkommen. Tomt foreløpig. :-)

+
diff --git a/html/templates/main.tmpl b/html/templates/main.tmpl new file mode 100644 index 0000000..f9408ae --- /dev/null +++ b/html/templates/main.tmpl @@ -0,0 +1,16 @@ + + + + + [% title %] - CCBS + + + +

[% title %]

+ +
+[% INCLUDE $page %] +
+ + -- 2.39.2