-<?
+<?php
/**************************************************************************
** 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.
$login = "<div class='login'>";
$login .= "<h1 align=\"center\">GNU Computer Monitoring</h1>";
+ $login .= "<h4 align=\"center\"><i>Version 0.0.3, December 6, 2003</i></h4>";
$login .= "<center><table>";
$login .= "<tr>";
- $login .= "<td width='50%'><img src='../doc/logo.png' alt='GnuCoMo logo'></td>";
+ $login .= "<td width='50%'><img src='logo.png' alt='GnuCoMo logo'></td>";
$login .= "<td><form name=\"login\" method=\"POST\" action=\"login.php\">";
$login .= " <table>";
$login .= " <tr>";
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+/*
+ *
+ * Objects Administration page.
+ * Input parameters: action (POST) : empty, 'Create'
+ * objname (POST) : name of the object to create or remove
+ */
+
+session_start();
+require_once('classes/gnucomo_config.php');
+?>
+
+<!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">
+<link rel='stylesheet' href='gnucomo.css' type='text/css'>
+<title>GNUCoMo login</title>
+
+<script language='JavaScript'>
+function CheckCreate(f)
+{
+ if (f.objectname.value == "")
+ {
+ alert("You must supply a name");
+ return false;
+ }
+ return true;
+}
+
+function CheckRemove(f)
+{
+ var message = "Are you sure you want to remove object ";
+ message += f.objectname.value;
+ message += " ?";
+
+ return confirm(message);
+}
+
+</script>
+
+</head>
+<body>
+<?php
+if (empty($_SESSION['username']))
+{
+ echo "Please log in first.";
+}
+else
+{
+
+ $config = new gnucomo_config;
+
+ $config->read("gnucomo");
+
+ // Connect to the database
+ $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+
+ if (!empty($_GET['oid']))
+ {
+ $res = pg_exec("SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
+ $obj = pg_fetch_object($res, 0);
+ echo "<h1>Log for " . $obj->objectname . "</h1><hr>";
+
+ $res = pg_exec("SELECT object_timestamp, servicecode, rawdata FROM log "
+ ."WHERE objectid=" . $_GET['oid']);
+
+ echo "<table>";
+ $row = 0;
+ while ($row < pg_numrows($res))
+ {
+ $log = pg_fetch_object($res, $row);
+ ?>
+ <tr><td align='center'>
+ <?php echo $log->object_timestamp?>
+ </td><td>
+ <?php echo $log->servicecode?>
+ </td><td>
+ <?php echo $log->rawdata?>
+ </td></tr>
+ <?php
+ $row++;
+ }
+ echo "</table>";
+ }
+}
+?>
+
+</body>
+</html>
<?php
session_start();
-require_once('gnucomo_config.php');
+require_once('classes/gnucomo_config.php');
include "functions.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
</head>
<body>
<?php
-if( isset($_POST["username"]) and isset($_POST["password"]) and isset($_SESSION['login']) ) {
- $name = $_POST["username"]; // PostgreSQL username
- $passw = $_POST["password"]; // PostgreSQL user password
+
+if (empty($_SESSION["username"]))
+{
+
+if( isset($_POST["username"]) and isset($_POST["password"]) and isset($_SESSION['login']) )
+{
+ $name = $_POST["username"]; // PostgreSQL username
+ $passw = $_POST["password"]; // PostgreSQL user password
$config = new gnucomo_config;
$config->read("gnucomo");
- //echo "Database Access string = " . $config->Database();
-
- $conn = pg_connect($config->Database());
- // connect to the database
- //$conn = pg_Connect( "host=$pgsqlhost port=$pgsqlport dbname=$dbname user=$name password=$passw" );
- if( !$conn ) {
- echo "Error connecting, try again.";
- echo login_form();
- $_SESSION["login"] = true;
- } else {
- $sql = "SELECT * FROM user_gnucomo WHERE username='$name' and password='$passw'";
- $res = query( $conn, $sql );
+ // connect to the database
+ //echo "Database connection = " . $config->Database($name, $passw) . "<br>";
+ $conn = pg_connect($config->Database($name, $passw));
- if( $res[0] ) {
- if ($res[2] == 1)
- {
- $arr = pg_fetch_array( $res[1], 0 );
- $_SESSION["login.ini"] = $arr;
- }
- else
- {
- echo "Login incorrect.<br>";
- }
+ if ( !$conn )
+ {
+ echo "Error connecting, try again.";
+ echo login_form();
+ }
+ else
+ {
+ $sql = "SELECT * FROM usr WHERE username='$name'";
+ $res = pg_exec( $conn, $sql );
+ if ($res && pg_numrows($res) == 1)
+ {
+ echo "<br> Database login OK.<br>";
+ session_register('username');
+ $_SESSION["username"] = $name;
+ session_register('password');
+ $_SESSION["password"] = $passw;
+ }
+ else
+ {
+ // User not found in database. Check if we have any users at all.
- // user is authorised, step to next page.
- echo "Ok!";
- } else {
- pgsql_error( "SQL: error.<br>" . $res[3] );
- }
- }
-} else {
- echo login_form();
- $_SESSION["login"] = true;
+ $res = pg_exec($conn, "SELECT count(username) FROM usr");
+ $nusers = pg_fetch_object($res, 0);
+ $nusers = $nusers->count;
+ if ($nusers == 0)
+ {
+ echo "<br>No users in database. Authentication granted.<br>";
+ session_register('username');
+ $_SESSION["username"] = $name;
+ session_register('password');
+ $_SESSION["password"] = $passw;
+ }
+ else
+ {
+ echo "<br>User $name not found in database.<br>";
+ }
+ }
+ }
+}
+else
+{
+ echo login_form();
+ $_SESSION["login"] = true;
+}
+}
+else
+{
+ echo "Logged in as " . $_SESSION['username'] . "<br>";
}
?>
</body>
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+session_start();
+require_once('classes/gnucomo_config.php');
+$_SESSION['username'] = '';
+
+include('login.php');
<title>GnuCoMo Web Interface</title>
</head>
<body>
- <img src='server.png' alt='Objects'>
- <img src='user.png' alt='Users'>
- <img src='closed_package.png' alt='Packages'>
+ <a href='objects.php' target='main'><img src='server.png' alt='Objects'></a>
+ <a href='users.php' target='main'><img src='user.png' alt='Users'></a>
<img src='password.png' alt='Change Password'>
- <img src='exit.png' alt='Logout'>
+ <a href='logout.php' target='main'><img src='exit.png' alt='Logout'></a>
<hr>
</body>
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+/*
+ *
+ * Objects Administration page.
+ * Input parameters: action (POST) : empty, 'Create'
+ * objname (POST) : name of the object to create or remove
+ */
+
+session_start();
+require_once('classes/gnucomo_config.php');
+?>
+
+<!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">
+<link rel='stylesheet' href='gnucomo.css' type='text/css'>
+<title>GNUCoMo login</title>
+
+<script language='JavaScript'>
+function CheckCreate(f)
+{
+ if (f.objectname.value == "")
+ {
+ alert("You must supply a name");
+ return false;
+ }
+ return true;
+}
+
+function CheckRemove(f)
+{
+ var message = "Are you sure you want to remove object ";
+ message += f.objectname.value;
+ message += " ?";
+
+ return confirm(message);
+}
+
+</script>
+
+</head>
+<body>
+<?php
+if (empty($_SESSION['username']))
+{
+ echo "Please log in first.";
+}
+else
+{
+ echo "<h1>Objects Administration</h1><hr>";
+
+ $config = new gnucomo_config;
+
+ $config->read("gnucomo");
+
+ // Connect to the database
+ $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+
+
+ if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
+ {
+ pg_exec($conn, "INSERT INTO object (objectname) VALUES ('"
+ . $_POST['objectname'] . "')");
+ }
+
+ if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
+ {
+ pg_exec($conn, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
+ }
+
+ $res = pg_exec($conn, "SELECT objectid,objectname FROM object");
+
+ echo "<table>";
+ $obj = 0;
+ while ($obj < pg_numrows($res))
+ {
+ $u = pg_fetch_object($res, $obj);
+ $r = pg_exec($conn, "SELECT count(logid) FROM log WHERE objectid='"
+ . $u->objectid . "'");
+ $r = pg_fetch_object($r, 0);
+
+ $nr_logs = $r->count;
+
+ $r = pg_exec ($conn, "SELECT count(paramid) FROM parameter WHERE objectid='"
+ . $u->objectid . "'");
+ $r = pg_fetch_object($r, 0);
+
+ $nr_params = $r->count;
+ ?>
+ <tr><td align='center'><img src='server.png'><br>
+ <b><?php echo $u->objectname ?></b>
+ </td><td>
+ <?php echo $nr_logs?> <a href='log.php?oid=<?php echo $u->objectid?>'>Log entries</a>
+ </td><td>
+ <?php echo $nr_params?> <a href='parameter.php?oid=<?php echo $u->objectid?>'>Parameters</a>
+ </td><td>
+ <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
+ <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
+ <input type='submit' name='action' value='Remove'>
+ </form>
+ </td></tr>
+ <?php
+ $obj++;
+ }
+ echo "</table>";
+
+}
+?>
+
+<h2>Create new object:</h2>
+<p>
+
+<form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
+Objects name (FQDN): <input name='objectname' type='text'>
+<br>
+<input type='submit' name='action' value='Create'>
+</form>
+</p>
+</body>
+</html>
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+/*
+ *
+ * Objects Administration page.
+ * Input parameters: action (POST) : empty, 'Create'
+ * objname (POST) : name of the object to create or remove
+ */
+
+session_start();
+require_once('classes/gnucomo_config.php');
+
+/* Local functions */
+
+function object_selection($db, $skip_oid)
+{
+ /* Create and print an HTML option list of objects */
+
+ $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid != " . $skip_oid);
+ for ($row = 0; $row < pg_numrows($res); $row++)
+ {
+ $obj = pg_fetch_object($res, $row);
+ echo "<option value='" . $obj->objectid . "'>";
+ echo $obj->objectname;
+ echo "</option>";
+ }
+}
+?>
+
+<!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">
+<link rel='stylesheet' href='gnucomo.css' type='text/css'>
+<title>GNUCoMo login</title>
+
+<script language='JavaScript'>
+function CheckCreate(f)
+{
+ if (f.objectname.value == "")
+ {
+ alert("You must supply a name");
+ return false;
+ }
+ return true;
+}
+
+function CheckRemove(f)
+{
+ var message = "Are you sure you want to remove object ";
+ message += f.objectname.value;
+ message += " ?";
+
+ return confirm(message);
+}
+
+</script>
+
+</head>
+<body>
+<?php
+if (empty($_SESSION['username']))
+{
+ echo "Please log in first.";
+}
+else
+{
+
+ $config = new gnucomo_config;
+
+ $config->read("gnucomo");
+
+ // Connect to the database
+ $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+
+ if (!empty($_GET['oid']))
+ {
+ $res = pg_exec($conn, "SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
+ $obj = pg_fetch_object($res, 0);
+ echo "<h1>Parameters for " . $obj->objectname . "</h1>";
+
+ $res = pg_exec("SELECT paramid, class, name, description FROM parameter "
+ ."WHERE objectid=" . $_GET['oid']);
+
+ ?>
+ <form action='parameter_compare.php' method='post'>
+ <input type='hidden' name='oid' value='<?php echo $_GET['oid'] ?>'>
+ Compare to object:
+ <select>
+ <?php object_selection($conn, $_GET['oid']); ?>
+ </select>
+ <input type='submit' value=' Show Difference'>
+ </form>
+ <?php
+ echo "<hr>";
+ echo "<table>";
+ $row = 0;
+ while ($row < pg_numrows($res))
+ {
+ $par = pg_fetch_object($res, $row);
+ ?>
+ <tr><td align='center'>
+ <?php echo $par->class?>
+ </td><td>
+ <?php echo $par->name?>
+ </td><td>
+ <?php echo $par->description?>
+ </td><td>
+ <?php
+ $r = pg_exec($conn, "SELECT name, value FROM property WHERE paramid='" . $par->paramid . "'");
+ for ($p = 0; $p < pg_numrows($r); $p++)
+ {
+ $prop = pg_fetch_object($r, $p);
+ echo $prop->name . "=" . $prop->value . " ";
+ }
+ ?>
+ </td></tr>
+ <?php
+ $row++;
+ }
+ echo "</table>";
+ }
+}
+?>
+
+</body>
+</html>
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+/*
+ *
+ * Objects Administration page.
+ * Input parameters: action (POST) : empty, 'Create'
+ * objname (POST) : name of the object to create or remove
+ */
+
+session_start();
+require_once('classes/gnucomo_config.php');
+?>
+
+<!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">
+<link rel='stylesheet' href='gnucomo.css' type='text/css'>
+<title>GNUCoMo login</title>
+
+<script language='JavaScript'>
+function CheckCreate(f)
+{
+ if (f.objectname.value == "")
+ {
+ alert("You must supply a name");
+ return false;
+ }
+ return true;
+}
+
+function CheckRemove(f)
+{
+ var message = "Are you sure you want to remove object ";
+ message += f.objectname.value;
+ message += " ?";
+
+ return confirm(message);
+}
+
+</script>
+
+</head>
+<body>
+<?php
+if (empty($_SESSION['username']))
+{
+ echo "Please log in first.";
+}
+else
+{
+
+ $config = new gnucomo_config;
+
+ $config->read("gnucomo");
+
+ // Connect to the database
+ $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+
+ if (!empty($_GET['oid']))
+ {
+ $res = pg_exec("SELECT objectname FROM object WHERE objectid=" . $_GET['oid']);
+ $obj = pg_fetch_object($res, 0);
+ echo "<h1>Parameters for " . $obj->objectname . "</h1><hr>";
+
+ $res = pg_exec("SELECT paramid, class, name, description FROM parameter "
+ ."WHERE objectid=" . $_GET['oid']);
+
+ ?>
+ <form action='parameter_compare.php' method='post'>
+ </form>
+ <?php
+ echo "<table>";
+ $row = 0;
+ while ($row < pg_numrows($res))
+ {
+ $par = pg_fetch_object($res, $row);
+ ?>
+ <tr><td align='center'>
+ <?php echo $par->class?>
+ </td><td>
+ <?php echo $par->name?>
+ </td><td>
+ <?php echo $par->description?>
+ </td><td>
+ <?php
+ $r = pg_exec($conn, "SELECT name, value FROM property WHERE paramid='" . $par->paramid . "'");
+ for ($p = 0; $p < pg_numrows($r); $p++)
+ {
+ $prop = pg_fetch_object($r, $p);
+ echo $prop->name . "=" . $prop->value . " ";
+ }
+ ?>
+ </td></tr>
+ <?php
+ $row++;
+ }
+ echo "</table>";
+ }
+}
+?>
+
+</body>
+</html>
--- /dev/null
+<?php
+
+/**************************************************************************
+** 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.
+***************************************************************************/
+
+/*
+ *
+ * User Administration page.
+ * Input parameters: action (POST) : empty, 'Create'
+ * username (POST) : name of the user to create or remove
+ */
+
+session_start();
+require_once('classes/gnucomo_config.php');
+?>
+
+<!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">
+<link rel='stylesheet' href='gnucomo.css' type='text/css'>
+<title>GNUCoMo login</title>
+
+<script language='JavaScript'>
+function CheckCreate(f)
+{
+ if (f.username.value == "")
+ {
+ alert("You must supply a username");
+ return false;
+ }
+ if (f.passwd.value == "")
+ {
+ alert("You must supply a password");
+ return false;
+ }
+ if (f.passwd.value != f.pwverify.value)
+ {
+ alert("Passwords don't match");
+ return false;
+ }
+ return true;
+}
+
+function CheckRemove(f)
+{
+ var message = "Are you sure you want to remove user ";
+ message += f.username.value;
+ message += " ?";
+
+ return confirm(message);
+}
+
+</script>
+
+</head>
+<body>
+<?php
+if (empty($_SESSION['username']))
+{
+ echo "Please log in first.";
+}
+else
+{
+ echo "<h1>User Administration</h1><hr>";
+
+ $config = new gnucomo_config;
+
+ $config->read("gnucomo");
+
+ // Connect to the database
+ $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
+
+
+ if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['username']))
+ {
+ pg_exec($conn, "CREATE USER " . $_POST['username'] . " PASSWORD '"
+ . $_POST['passwd'] . "'");
+ pg_exec($conn, "INSERT INTO usr (username, security_level) VALUES ('"
+ . $_POST['username'] . "','" . $_POST['seclevel'] . "')");
+ }
+
+ if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['username']))
+ {
+ pg_exec($conn, "DELETE FROM usr WHERE username='" . $_POST['username'] . "'");
+ pg_exec($conn, "DROP USER " . $_POST['username']);
+ }
+
+ $res = pg_exec($conn, "SELECT username, security_level FROM usr");
+
+ echo "<table>";
+ $usr = 0;
+ while ($usr < pg_numrows($res))
+ {
+ $u = pg_fetch_object($res, $usr);
+ ?>
+ <tr><td align='center'><img src='user.png'><br>
+ <b><?php echo $u->username ?></b>
+ </td><td>
+ Sec. Level <?php echo $u->security_level ?>
+ </td><td>
+ <?php if ($_SESSION['username'] != $u->username)
+ {
+ ?>
+ <form action='users.php' method='post' onSubmit='return CheckRemove(this)'>
+ <input type='hidden' name='username' value='<?php echo $u->username ?>'>
+ <input type='submit' name='action' value='Remove'>
+ </form>
+ <?php
+ }
+ ?>
+ </td></tr>
+ <?php
+ $usr++;
+ }
+ echo "</table>";
+
+}
+?>
+
+<h2>Create new user:</h2>
+<p>
+
+<form action='users.php' method='post' onSubmit='return CheckCreate(this)'>
+User name: <input name='username' type='text'>
+Security level: <select name='seclevel'>
+<option value='1'>1</option>
+<option value='2'>2</option>
+<option value='3'>3</option>
+<option value='4'>4</option>
+<option value='5'>5</option>
+</select>
+<br>
+Password: <input type='password' name='passwd'>
+Verify password: <input type='password' name='pwverify'>
+<br>
+<input type='submit' name='action' value='Create'>
+</form>
+</p>
+</body>
+</html>