summaryrefslogtreecommitdiff
path: root/gucs.php
blob: f7c44e94c5966636600f62d5c66a0070a28a9cbc (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
<?php

///////////////////////////////////////////////////////////////////////////////
//
// pgPhoneHome - Postgres Monitor for iPhone
// Copyright 2008, EnterpriseDB UK Ltd.
// Dave Page (dave.page@enterprisedb.com)
//
// gucs.php - Server GUCs
//
///////////////////////////////////////////////////////////////////////////////

require "global.php";

// Get the server number
if (isset($_GET['s']))
	$server = intval($_GET['s']);
else
	$server = -1;

// Set the display panel
$panel = "gucs" . $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 GUCs
$sql = "SHOW all;";
$res = @pg_query($db, $sql);

if ($res === false)
		www_error("Query execution error", $php_errormsg);

$gucs = "";

$rows = pg_numrows($res);

for ($x=0; $x < $rows; $x++) {
	$guc_name = www_clean(pg_fetch_result($res, $x, "name"));
	$guc_value = www_clean(pg_fetch_result($res, $x, "setting"));

	$gucs .= "<h2>" . $guc_name . "</h2><div class=\"vb\">" . $guc_value . "</div>";
}

pg_free_result($res);

$message = "Server: " . $servers[$server]["description"];

// Echo the HTML snippet
$text = <<<EOT
<div id="$panel" class="panel" title="GUCs">
<div class="dh">$message</div>
$gucs
</div>
EOT;

echo $text;
exit();

?>