Manually edit parameters.
[gnucomo.git] / src / web / page.class.php
1 <?php
2 /**************************************************************************
3 **  (c) Copyright 2003, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : page.class.php
10 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
11 **      VERSION NUMBER : $Revision: 1.8 $
12 **
13 **  DESCRIPTION      : Base class for Gnucomo web interface pages.
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Jan 22, 2003
23 **      LAST UPDATE     : Feb 19, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: page.class.php,v $
29    Revision 1.8  2007-01-11 13:44:29  arjen
30    Manually edit parameters.
31    View logs from abusing IP addresses.
32
33    Revision 1.7  2003/12/24 07:41:23  arjen
34    Changed version number
35
36    Revision 1.6  2003/09/04 06:53:40  arjen
37    Prepared for release 0.0.8
38
39    Revision 1.5  2003/08/14 10:37:04  arjen
40    Prepared for release 0.0.7
41
42    Revision 1.4  2003/07/15 11:05:32  arjen
43    Chnaged version number to 0.0.6 in login form.
44
45    Revision 1.3  2003/02/19 09:12:27  arjen
46    Added the 'form' class on table and td elements. This class is intended
47    for borderless tables that are used to layout HTML forms.
48
49    Revision 1.2  2003/02/13 08:59:52  arjen
50    Use our own error handler for PHP errors and warnings
51
52    Revision 1.1  2003/02/05 09:38:42  arjen
53    A base class for all web interface pages
54
55 ******************************/
56
57 // RCSID = "$Id: page.class.php,v 1.8 2007-01-11 13:44:29 arjen Exp $";
58
59
60 require_once('gnucomo_config.php');
61
62 $last_error = "&nbsp;";
63
64 function error($errno, $errstr, $errfile, $errline)
65 {
66    global $last_error;
67
68    $last_error = $errstr;
69 }
70
71 function login_form()
72 {
73    global $last_error;
74
75 ?>
76    <div class='login'>
77    <h1 align="center">GNU Computer Monitoring</h1>
78    <h4 align="center"><i>Version 0.0.9, December 24, 2003</i></h4>
79    <p>
80       <h2 class='error'><?php echo $last_error?></h2>
81    </p>
82    <center><table class='form'>
83    <tr>
84    <td width='50%' class='form'>
85       <a href='http://gnucomo.org/' target='_top'><img src='logo.png' alt='GnoCoMo logo'></a></td>
86    <td class='form'><form name="login" method="POST">
87        <table class='form'>
88        <tr>
89        <td class='form'>Username</td>
90        <td class='form'><input type="text" name="username"></td>
91        </tr>
92        <tr>
93        <td class='form'>Password</td>
94        <td class='form'><input type="password" name="password"></td>
95        </tr>
96        <tr>
97        <td class='form'>&nbsp;</td>
98        <td align="right" class='form'><input type="submit" value="signin"></td>
99        </tr>
100        </table>
101        </form>
102    </td>
103    </tr>
104    </table></center>
105    </div>
106 <?php
107 }
108
109 class page
110 {
111    var  $the_title;       //  The title used on the page.
112    var  $database;        //  Connection to the database server.
113    var  $path;            //  Directory path to stylesheets and images.
114    var  $config;          //  The XML configuration object.
115
116    //   Page constructor.
117
118    function page($title, $path = "")
119    {
120       $this->the_title = $title;
121       $this->database = false;
122       $this->path = $path;
123       session_start();
124       //set_error_handler("error");
125    }
126
127    function Head()
128    {
129 ?>
130       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
131                     "http://www.w3.org/TR/html4/loose.dtd">
132       <html>
133       <head>
134       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
135       <meta name="author" content="Arjen Baart">
136       <meta name="expires" content="0">
137
138       <link rel='stylesheet' href='<?php echo $this->path ?>gnucomo.css' type='text/css'>
139       <title><?php echo $this->the_title ?></title>
140       </head>
141       <body>
142 <?php
143    }
144
145    function Body()
146    {
147       echo "The default body.";
148    }
149
150    function Tail()
151    {
152       if ($this->database)
153       {
154          pg_close($this->database);
155       }
156       echo "</body>";
157       echo "</html>";
158    }
159
160    function Showpage()
161    {
162       $this->config = new gnucomo_config;
163
164       $this->config->read("gnucomo");
165
166       $this->Head();
167       if (empty($_SESSION['username']))
168       {
169          //  Nobody logged in yet.
170
171          if (isset($_POST['username']) && isset($_POST['password']))
172          {
173             //  Login form submitted. Try to start a new session.
174
175             $name   = $_POST['username'];   // PostgreSQL username
176             $passw  = $_POST['password'];   // PostgreSQL user password
177
178             //  Connect to the database
179             $this->database = pg_connect($this->config->Database($name, $passw));
180             if ($this->database == false)
181             {
182                login_form();
183             }
184             else
185             {
186                session_register('username');
187                $_SESSION['username'] = $name;
188                session_register('password');
189                $_SESSION['password'] = $passw;
190                $this->Body();
191             }
192
193          }
194          else
195          {
196             //  Nobody tried to login yet. Present the login form.
197             login_form();
198          }
199       }
200       else
201       {
202          $name   = $_SESSION['username'];   // PostgreSQL username
203          $passw  = $_SESSION['password'];   // PostgreSQL user password
204
205          //  Connect to the database
206          $this->database = pg_connect($this->config->Database($name, $passw));
207          $this->Body();
208       }
209       $this->Tail();
210    }
211 }