summaryrefslogtreecommitdiff
path: root/index.php
blob: a644cbc88c5f7ea802c40a75126782a62bbf3a3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php

///////////////////////////////////////////////////////////////////////////////
//
// pgPhoneHome - Postgres Monitor for iPhone
// Copyright 2008, EnterpriseDB UK Ltd.
// Dave Page (dave.page@enterprisedb.com)
//
// index.php - Main app body 
//
///////////////////////////////////////////////////////////////////////////////

require "global.php";

$svrlist = "";
$svrcount = 0;

foreach ($servers as $key=>$server) {
	if (array_key_exists("description", $server) && array_key_exists("connstr", $server)) {

		// Get the image if there is one
		if (array_key_exists("icon", $server) && $server["icon"] != "")
			$icon = "<img src=\"" .  $server["icon"] . "\" class=\"mi\">";

		// Connect the database
		$db = @pg_connect($server["connstr"]);		

		// Can we connect?
		if ($db === false) {
			$svrlist .= "<li>" . $icon . "<s>" . $server["description"] . "</s><br /><span class=\"n\">" . html_entity_decode($php_errormsg, ENT_QUOTES) . "</span></li>";
		} else {
			// Valid server version?
			$res = @pg_query($db, "SHOW server_version_num;");
			if (@pg_fetch_result($res, 0, 0) < 80200) {
				$svrlist .= "<li>" . $icon . "<s>" . $server["description"] . "</s><br /><span class=\"n\">Server version is less than 8.2</span></li>";
			} else {
				// Have we got superuser privs?
				@pg_free_result($res);
				$res = @pg_query($db, "SELECT usesuper FROM pg_shadow WHERE usename = current_user;");
				if (pg_fetch_result($res, 0, 0) != "t") {
					$svrlist .= "<li>" . $icon . "<s>" . $server["description"] . "</s><br /><span class=\"n\">The connecting user is not a superuser</span></li>";
				} else {
					// Looks good - let's go!
					$svrlist .= "<li>" . $icon . "<a href=\"server.php?s=" . $key . "\">" . $server["description"] . "</a></li>";
				}
			}
			pg_free_result($res);
		}
		$svrcount++;
	}
}

if ($svrlist == "")
	www_error("No servers configured", "No configured servers could be found. Please edit the config.php file.");

// Set the message for the top of the page
$message = "Servers: $svrcount configured";

// Echo the main HTML body. Everything else is loaded a snippet at a time, via AJAX
$text = <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$APP_NAME v$APP_VERSION</title>
<meta name="viewport" content="width=devicewidth; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<link rel="apple-touch-icon" href="../../iui/iui-logo-touch-icon.png" />
<meta name="apple-touch-fullscreen" content="YES" />
<style type="text/css" media="screen">@import "iui/iui.css";</style>
<style type="text/css" media="screen">@import "css/iui-ext.css";</style>
<script type="application/x-javascript" src="iui/iui.js"></script>
</head>
<body>
<div class="toolbar">
<h1 id="pageTitle"></h1>
<a id="backButton" class="button" href="#"></a>
</div>
<ul id="servers" title="$APP_NAME" selected="true"> 
<li class="group">$message</li>
$svrlist
<li class="d"><a href="#about">About</a></li>
</ul>
<div id="about" class="panel" title="About">
<h2>$APP_NAME v$APP_VERSION</h2>
<p>$APP_NAME is a remote monitoring interface for your Postgres and Postgres Plus servers.</p>
<p>For support, please visit the EnterpriseDB <a href="http://forums.enterprisedb.com" target="_new">forums</a>.</p>
<p>$APP_NAME is released under the <a href="http://www.opensource.org/licenses/gpl-2.0.php" target="_new">GNU General Public Licence</a>.</p>
<p>$APP_COPYRIGHT</p>
<p>&nbsp;</p>
<center><a href="http://www.enterprisedb.com" target="_new"><img src="images/enterprisedb.png" alt="EnterpriseDB Logo" style="border-style: none" /></a></center>
</div>
</body>
</html>
EOT;

echo $text;
exit();

?>