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
|
<?php
///////////////////////////////////////////////////////////////////////////////
//
// pgPhoneHome - Postgres Monitor for iPhone
// Copyright 2008, EnterpriseDB UK Ltd.
// Dave Page (dave.page@enterprisedb.com)
//
// info.php - Server information
//
///////////////////////////////////////////////////////////////////////////////
require "global.php";
// Get the server number
if (isset($_GET['s']))
$server = intval($_GET['s']);
else
$server = -1;
// Set the display panel
$panel = "info" . $server;
if ($server == -1 || $servers[$server]["description"] == "" || $servers[$server]["connstr"] == "")
www_error("Invalid server", "The specified server number ($server) does not have a valid configuration.");
// Connect the database
$db = @pg_connect($servers[$server]["connstr"]);
if ($db === FALSE)
www_error("Couldn't connect to the database.", html_entity_decode($php_errormsg, ENT_QUOTES));
// Get the server version
$sql = "SELECT version() AS version, current_user AS username, (SELECT count(*) FROM pg_stat_activity) AS connections;";
$res = @pg_query($db, $sql);
if ($res === false)
www_error("Query execution error", $php_errormsg);
$rows = pg_numrows($res);
if ($rows != 1)
www_error("Query execution error", "$rows rows were returned when retrieving server info when one row was expected!");
$version = www_clean(pg_fetch_result($res, 0, "version"));
$host = www_clean(pg_host($db));
$port = www_clean(pg_port($db));
$connections = www_clean(pg_fetch_result($res, 0, "connections"));
$database = www_clean(pg_dbname($db));
$username = www_clean(pg_fetch_result($res, 0, "username"));
$pid = www_clean(pg_get_pid($db));
pg_free_result($res);
$message = "Server: " . $servers[$server]["description"];
// Echo the HTML snippet
$text = <<<EOT
<div id="$panel" class="panel" title="Info">
<div class="dh">$message</div>
<h2>Server version</h2><div class="vb">$version</div>
<h2>Server host</h2><div class="vb">$host</div>
<h2>Server port</h2><div class="vb">$port</div>
<h2>Active connections</h2><div class="vb">$connections</div>
<h2>Current database</h2><div class="vb">$database</div>
<h2>Current username</h2><div class="vb">$username</div>
<h2>Current backend PID</h2><div class="vb">$pid</div>
</div>
EOT;
echo $text;
exit();
?>
|