New version number and release date.
[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.11 $
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.11  2007-11-21 14:40:48  arjen
30    New version number and release date.
31
32    Revision 1.10  2007/11/21 14:38:06  arjen
33    The buttonbar at the top of each page is now a fixed 'div' element
34    instead of a framed page.
35    Contributed by Edwin Nadorp.
36
37    Revision 1.9  2007/10/23 14:47:42  arjen
38    Prepared for release 0.0.10
39
40    Revision 1.8  2007/01/11 13:44:29  arjen
41    Manually edit parameters.
42    View logs from abusing IP addresses.
43
44    Revision 1.7  2003/12/24 07:41:23  arjen
45    Changed version number
46
47    Revision 1.6  2003/09/04 06:53:40  arjen
48    Prepared for release 0.0.8
49
50    Revision 1.5  2003/08/14 10:37:04  arjen
51    Prepared for release 0.0.7
52
53    Revision 1.4  2003/07/15 11:05:32  arjen
54    Chnaged version number to 0.0.6 in login form.
55
56    Revision 1.3  2003/02/19 09:12:27  arjen
57    Added the 'form' class on table and td elements. This class is intended
58    for borderless tables that are used to layout HTML forms.
59
60    Revision 1.2  2003/02/13 08:59:52  arjen
61    Use our own error handler for PHP errors and warnings
62
63    Revision 1.1  2003/02/05 09:38:42  arjen
64    A base class for all web interface pages
65
66 ******************************/
67
68 // RCSID = "$Id: page.class.php,v 1.11 2007-11-21 14:40:48 arjen Exp $";
69
70
71 require_once('gnucomo_config.php');
72
73 $last_error = "&nbsp;";
74
75 function error($errno, $errstr, $errfile, $errline)
76 {
77    global $last_error;
78
79    $last_error = $errstr;
80 }
81
82 function login_form()
83 {
84    global $last_error;
85
86 ?>
87    <div class='login'>
88    <h1 align="center">GNU Computer Monitoring</h1>
89    <h4 align="center"><i>Version 0.0.11, November 22, 2007</i></h4>
90    <h2 class='error'><?php echo $last_error?></h2>
91    <center><table class='form'>
92    <tr>
93    <td width='50%' class='form'>
94       <a href='http://gnucomo.org/' target='_top'><img src='logo.png' alt='GnuCoMo logo'></a></td>
95    <td class='form'><form name="login" method="POST" action="index.php">
96        <table class='form'>
97        <tr>
98        <td class='form'>Username</td>
99        <td class='form'><input type="text" name="username"></td>
100        </tr>
101        <tr>
102        <td class='form'>Password</td>
103        <td class='form'><input type="password" name="password"></td>
104        </tr>
105        <tr>
106        <td class='form'>&nbsp;</td>
107        <td align="right" class='form'><input type="submit" value="signin"></td>
108        </tr>
109        </table>
110        </form>
111    </td>
112    </tr>
113    </table></center>
114    </div>
115 <?php
116 }
117
118 class page
119 {
120    var  $the_title;       //  The title used on the page.
121    var  $database;        //  Connection to the database server.
122    var  $path;            //  Directory path to stylesheets and images.
123    var  $config;          //  The XML configuration object.
124
125    //   Page constructor.
126
127    function page($title, $path = "")
128    {
129       $this->the_title = $title;
130       $this->database = false;
131       $this->path = $path;
132       session_start();
133       //set_error_handler("error");
134    }
135
136    function Head()
137    {
138 ?>
139       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
140                     "http://www.w3.org/TR/html4/loose.dtd">
141       <html>
142       <head>
143       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
144       <meta name="author" content="Arjen Baart">
145       <meta name="expires" content="0">
146
147       <link rel='stylesheet' href='<?php echo $this->path ?>gnucomo.css' type='text/css'>
148       <title><?php echo $this->the_title ?></title>
149       </head>
150       <body>
151         <div id="header">
152            <a href='index.php'><img src='small-logo.png' title='Gnucomo' alt='Gnucomo'></a>
153            <a href='objects.php'><img src='server.png' title='Objects' alt='Objects'></a>
154            <a href='users.php'><img src='user.png' title='Users' alt='Users'></a>
155            <a href='services.php'><img src='service.png' title='Services' alt='Services'></a>
156            <a href='issues.php'><img src='bell.png' title='Issues' alt='Issues'></a>
157            <a href='classes.php'><img src='change.png' title='Classes' alt='Classes'></a>
158            <!-- a href='notification2.php'>N2</a -->
159            <a href='logout.php'><img src='exit.png' title='Logout' alt='Logout'></a>
160         </div>
161
162         <div id="menu_title">&nbsp;</div>
163
164         <div id="content">
165 <?php
166    }
167
168    function Body()
169    {
170       //echo "The default body.";
171       echo "<div id='content'>
172                  <img src='logo.png' alt='GnuCoMo'>
173             </div>";
174    }
175
176    function Tail()
177    {
178       if ($this->database)
179       {
180          pg_close($this->database);
181       }
182       echo "<br></div>
183             <div id='footer'>
184             &copy; <a href='http://www.gnucomo.org'>GnuCoMo</a>
185             </div>";
186       echo "</body>";
187       echo "</html>";
188    }
189
190    function Showpage()
191    {
192       $this->config = new gnucomo_config;
193
194       $this->config->read("gnucomo");
195
196       $this->Head();
197       if (empty($_SESSION['username']))
198       {
199          //  Nobody logged in yet.
200
201          if (isset($_POST['username']) && isset($_POST['password']))
202          {
203             //  Login form submitted. Try to start a new session.
204
205             $name   = $_POST['username'];   // PostgreSQL username
206             $passw  = $_POST['password'];   // PostgreSQL user password
207
208             //  Connect to the database
209             $this->database = pg_connect($this->config->Database($name, $passw));
210             if ($this->database == false)
211             {
212                login_form();
213             }
214             else
215             {
216                session_register('username');
217                $_SESSION['username'] = $name;
218                session_register('password');
219                $_SESSION['password'] = $passw;
220                $this->Body();
221             }
222
223          }
224          else
225          {
226             //  Nobody tried to login yet. Present the login form.
227             login_form();
228          }
229       }
230       else
231       {
232          $name   = $_SESSION['username'];   // PostgreSQL username
233          $passw  = $_SESSION['password'];   // PostgreSQL user password
234
235          //  Connect to the database
236          $this->database = pg_connect($this->config->Database($name, $passw));
237          $this->Body();
238       }
239       $this->Tail();
240    }
241 }