-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.php
164 lines (145 loc) · 6.13 KB
/
index.php
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
require_once("config.inc.php");
require_once("functions.php");
require_once("class_zabbix.php");
/* Include the basic header/css/... */
require_once("template/header.php");
// Main Zabbix object
$zabbix = new Zabbix($arrSettings);
// Login
if (!$arrSettings["promptCredentials"]) {
// Login using supplied credentials from the config.php file
$zabbix->login();
}else {
// It's a hosted version, perhaps we can recover username & password from cookies?
$zabbixApi = "";
$zabbixUser = "";
$zabbixPass = "";
// Get the values
require_once("cookies.php");
// Populate our class
$zabbix->setUsername($zabbixUser);
$zabbix->setPassword($zabbixPass);
$zabbix->setZabbixApiUrl($zabbixApi);
// Login
if (strlen($zabbix->getUsername()) > 0 && strlen($zabbix->getPassword()) > 0 && strlen($zabbix->getZabbixApiUrl()) > 0) {
$zabbix->login();
}
}
//$zabbix->Login("mattias_api", "test");
if ($zabbix->isLoggedIn()) {
// Authenticated, save cookie
setcookie("zabbixUsername", $zabbix->getUsername(), $arrSettings["cookieExpire"]);
setcookie("zabbixPassword", $zabbix->getPassword(), $arrSettings["cookieExpire"]);
setcookie("zabbixApi", $zabbix->getZabbixApiUrl(), $arrSettings["cookieExpire"]);
setcookie("zabbixAuthHash", $zabbix->getAuthToken(), $arrSettings["cookieExpire"]);
}
// "templates"
require_once("template/header.php");
if ($zabbix->isLoggedIn()) {
// Retrieve the data in one go
$zabbix_auth = $zabbix->getAuthToken();
// Get all active triggers (for the counter on homepage);
$triggersActive = $zabbix->getTriggersActive($arrSettings["minimalSeverity"]);
if (!is_array($triggersActive))
$triggersActive = array();
?>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.php">MoZBX - Mobile Monitoring</a>
</div>
</div>
</div>
<div class="container">
<h2>Monitoring</h2>
<p>
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="hostgroups.php">Your hosts</a><br />
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="activetriggers.php">Active Triggers</a><br />
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="<?php echo $arrSettings["urlApplication"]?>">Refresh page</a> <br />
</p>
<h2>Options</h2>
<p>
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="logout.php">Logout</a><br />
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="feedback.php">Send Feedback</a><br />
<a class="btn btn-large" style='padding: 15px; width:250px; margin-top: 7px;' href="about.php">About version <?php echo $arrSettings["mZabbixVersion"]; ?></a><br />
</p>
</div>
<?php
} else {
// Show login screen
$zabbixUser = isset($_GET['username']) && strlen($_GET['username']) > 0 ? $_GET['username'] : $zabbixUser;
$zabbixApi = isset($_GET['api_url']) && strlen($_GET['api_url']) > 0 ? $_GET['api_url'] : $zabbixApi;
if (strpos($zabbixApi, 'api_jsonrpc.php') === false)
$zabbixApi .= "api_jsonrpc.php";
$zabbixHideApi = isset($_GET['hideapi']) ? 'hideapi' : 'donthideapi';
$zabbixPass = isset($_GET['password']) ? $_GET['password'] : $arrSettings["zabbixPassword"];
?>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">MoZBX</a>
</div>
</div>
</div>
<div class="container">
<h2>Login</h2>
<form method="post" action="index.php" class="form-horizontal" >
<fieldset>
<?php
if (isset($_POST['zabbixUsername'])) {
// POST variables set, but still showing the form. Invalid credentials?
if (count($zabbix->getLastError()) > 0) {
$arrError = $zabbix->getLastError();
$errormsg = $arrError["data"];
} else {
$errormsg = "invalid combination";
}
?>
<div class="alert alert-error">
<?php echo $errormsg; ?>
</div>
<?php
}
if ($arrSettings["isHosted"] && !isset($_GET['hideapi'])) {
// Hosted version, show input field for the JSON API
?>
<div class="control-group">
<label class="control-label" for="zabbixApi">API URL</label>
<div class="controls">
<input type="text" id="zabbixApi" name="zabbixApi" value="<?php echo isset($_POST['zabbixApi']) ? $_POST['zabbixApi'] : $zabbixApi ?>" class="input-xlarge" />
<p class="help-block">The URL of your public Zabbix web interface.</p>
</div>
</div>
<?php
} else {
// Fixed setup. Enter JSON API as hidden field
?>
<input type="hidden" name="zabbixApi" value="<?php echo isset($_POST['zabbixApi']) ? $_POST['zabbixApi'] : $zabbixApi ?>" />
<?php
}
?>
<div class="control-group">
<label class="control-label" for="zabbixUsername">Username</label>
<div class="controls">
<input type="text" name="zabbixUsername" id="zabbixUsername" value="<?php echo isset($_POST['zabbixUsername']) ? $_POST['zabbixUsername'] : $zabbixUser?>" class="input-xlarge" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="zabbixPassword">Password</label>
<div class="controls">
<input type="password" name="zabbixPassword" id="zabbixPassword" value="<?php echo isset($_POST['zabbixPassword']) ? $_POST['zabbixPassword'] : $zabbixPass?>" class="input-xlarge" />
</div>
</div>
<div class="form-actions">
<button type="submit" name="mZabbixLogin" class="btn btn-primary">Login</button>
</div>
</fieldset>
</form>
<?php
}
?>
</div>
<?php
require_once("template/footer.php");
?>