--- /dev/null
+<?php
+/**************************************************************************
+** (c) Copyright 2003, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+** FILE NAME : page.class.php
+** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
+** VERSION NUMBER : $Revision: 1.1 $
+**
+** DESCRIPTION : Base class for Gnucomo web interface pages.
+**
+** EXPORTED OBJECTS :
+** LOCAL OBJECTS :
+** MODULES USED :
+***************************************************************************
+** ADMINISTRATIVE INFORMATION *
+********************************
+** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+** CREATION DATE : Jan 22, 2003
+** LAST UPDATE : Feb 03, 2003
+** MODIFICATIONS :
+**************************************************************************/
+
+/*****************************
+ $Log: page.class.php,v $
+ Revision 1.1 2003-02-05 09:38:42 arjen
+ A base class for all web interface pages
+
+******************************/
+
+// RCSID = "$Id: page.class.php,v 1.1 2003-02-05 09:38:42 arjen Exp $";
+
+
+require_once('gnucomo_config.php');
+
+function login_form()
+{
+?>
+ <div class='login'>
+ <h1 align="center">GNU Computer Monitoring</h1>
+ <h4 align="center"><i>Version 0.0.4, Februari 05, 2003</i></h4>
+ <center><table>
+ <tr>
+ <td width='50%'><img src='logo.png' alt='GnoCoMo logo'></td>
+ <td><form name="login" method="POST">
+ <table>
+ <tr>
+ <td>Username</td>
+ <td><input type="text" name="username"></td>
+ </tr>
+ <tr>
+ <td>Password</td>
+ <td><input type="password" name="password"></td>
+ </tr>
+ <tr>
+ <td> </td>
+ <td align="right"><input type="submit" value="signin"></td>
+ </tr>
+ </table>
+ </form>
+ </td>
+ </tr>
+ </table></center>
+ </div>
+<?php
+}
+
+class page
+{
+ var $the_title; // The title used on the page.
+ var $database; // Connection to the database server.
+ var $path; // Directory path to stylesheets and images.
+ var $config; // The XML configuration object.
+
+ // Page constructor.
+
+ function page($title, $path = "")
+ {
+ $this->the_title = $title;
+ $this->database = false;
+ $this->path = $path;
+ session_start();
+ }
+
+ function Head()
+ {
+?>
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+ <html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="author" content="Arjen Baart">
+ <meta name="expires" content="0">
+
+ <link rel='stylesheet' href='<?php echo $this->path ?>gnucomo.css' type='text/css'>
+ <title><?php echo $this->the_title ?></title>
+ </head>
+ <body>
+<?php
+ }
+
+ function Body()
+ {
+ echo "The default body.";
+ }
+
+ function Tail()
+ {
+ if ($this->database)
+ {
+ pg_close($this->database);
+ }
+ echo "</body>";
+ echo "</html>";
+ }
+
+ function Showpage()
+ {
+ $this->config = new gnucomo_config;
+
+ $this->config->read("gnucomo");
+
+ $this->Head();
+ if (empty($_SESSION['username']))
+ {
+ // Nobody logged in yet.
+
+ if (isset($_POST['username']) && isset($_POST['password']))
+ {
+ // Login form submitted. Try to start a new session.
+
+ $name = $_POST['username']; // PostgreSQL username
+ $passw = $_POST['password']; // PostgreSQL user password
+
+ // Connect to the database
+ $this->database = pg_connect($this->config->Database($name, $passw));
+ if ($this->database == false)
+ {
+ login_form();
+ }
+ else
+ {
+ session_register('username');
+ $_SESSION['username'] = $name;
+ session_register('password');
+ $_SESSION['password'] = $passw;
+ $this->Body();
+ }
+
+ }
+ else
+ {
+ // Nobody tried to login yet. Present the login form.
+ login_form();
+ }
+ }
+ else
+ {
+ $name = $_SESSION['username']; // PostgreSQL username
+ $passw = $_SESSION['password']; // PostgreSQL user password
+
+ // Connect to the database
+ $this->database = pg_connect($this->config->Database($name, $passw));
+ $this->Body();
+ }
+ $this->Tail();
+ }
+}