-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
152 lines (107 loc) · 3.27 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
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/tablesorter/jquery.tablesorter.js"></script>
<style>
body {
font-family: Verdana, Arial;
}
input {
padding-left: 5px;
}
</style>
<link href="js\tablesorter\themes\blue\style.css" rel="stylesheet" type="text/css"/>
<title>WHM/cPanel Server Account Locator</title>
</head>
<body>
<h1>Server Account Location</h1>
Search for an account: <input id="search" type="search" placeholder="Search" autocomplete="off" autofocus="true" align="middle"/>
<table id="accounts" class="tablesorter">
<thead>
<tr>
<th>Domain</th>
<th>Username</th>
<th>Plan</th>
<th>Server</th>
</tr>
</thead>
<tbody>
<?php
ini_set('max_execution_time', 90000); //300 seconds = 5 minutes
/* Change this part to ensure you list the data from a server which actually exists! */
$servers = array (
array("server" => "myserver.domain.com", "username" => "root", "password" => "CHANGEME",),
);
// No need to change anything else below
$server_counts = array();
foreach ($servers as $serverdetails) {
$server = $serverdetails["server"];
$username = $serverdetails["username"];
$password = $serverdetails["password"];
$server_count = 0;
$query = 'https://' . $server . ':2087/json-api/listaccts?api.version=1&want=domain';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_HEADER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header[0] = "Authorization: Basic " .
base64_encode($username.":".$password) . "\n\r";
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if ($result == false) {
error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query<br /><br />");
// log error if curl exec fails
}
curl_close($curl);
$result = json_decode($result, true);
foreach($result["data"]["acct"] as $apidata) {
echo '<tr data-state="accountlist"><td>';
print $apidata["domain"];
echo "</td><td>";
print $apidata["user"];
echo "</td><td>";
print $apidata["plan"];
echo "</td><td>";
echo $server;
echo "</td></tr>";
$server_count++;
}
$server_counts[] = array("server" => $server, "server_count" => $server_count);
}
?>
</tbody>
</table>
<?php
foreach ($server_counts as $servercount) {
echo "<b>User Count for: </b>" . $servercount["server"] . " = " . $servercount["server_count"] . "<br />";
}
?>
<script type="text/javascript">
$(document).ready(function()
{
$("#accounts").tablesorter({
sortList: [[0,0]]
});
}
);
$("input#search").keyup(function () {
var filter = $(this).val();
var regExPattern = "gi";
var regEx = new RegExp(filter, regExPattern);
$("table tr").each(function () {
if($(this).data('state'))
if (
$(this).text().search(new RegExp(filter, "i")) < 0
&& $(this).data('state').search(regEx) < 0
){
$(this).hide();
} else {
$(this).show();
}
});
});
</script>
</body>
</html>