3 error_log("hosts loaded");
6 $URL_HANDLERS["hosts.*"] = "GLCASHosts";
7 global $BASE_URL, $MENU_ITEMS;
8 $MENU_ITEMS["30hosts"]["name"] = "Known Machines";
9 $MENU_ITEMS["30hosts"]["link"] = "$BASE_URL/hosts";
12 function __construct($config)
14 $this->config = $config;
15 error_log("constructor for GLCASHosts");
21 if(isset($_REQUEST["action"])) {
22 switch($_REQUEST["action"]) {
24 error_log("in updaterepo");
25 GLCASpageBuilder($this,"addHost");
28 error_log("in add group");
29 GLCASpageBuilder($this, "addGroup");
32 error_log("in add group");
33 GLCASpageBuilder($this, "deleteHost");
36 GLCASpageBuilder($this, "scanIPRange");
41 GLCASpageBuilder($this,"mainBody");
46 function scanIPRange($url)
48 $iprange = $_REQUEST["scanip"];
50 if(isset($_REQUEST["hostgroup"])) {
51 $hostgroup = $_REQUEST["hostgroup"];
54 // we just assume class c atm
55 $ips_v = explode(".", $iprange);
57 $ips = $ips_v[0].".".$ips_v[1].".".$ips_v[2];
59 for($i = 1; $i < 32; $i++) {
62 echo "Scanning $ips_me<br>";
63 error_log("Scanning $ips_me<br>");
65 $hostname = gethostbyaddr($ips_me);
66 if($hostname != $ips_me) {
67 echo "Found host on $ips_me as $hostname<br>";
68 error_log("Found host on $ips_me as $hostname");
70 $hosts = $this->config->getData("hosts");
72 foreach($hosts as $key => $val) {
73 if($val["category"] == $hostname && $val["name"] == $ips_me) {
74 echo "Host in db already<br>";
80 if(!$exists) $this->config->addData("hosts", "$hostname", "$ips_me", "$hostgroup");
88 function deleteHost($url)
90 $hostname = $_REQUEST["hostname"];
91 $this->config->delData("hosts", "$hostname");
92 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
93 header("Location: $BASE_URL/hosts");
96 function addHost($url)
98 $hg = $_REQUEST["hostgroup"];
99 $hostname = $_REQUEST["hostname"];
100 $ip = $_REQUEST["ipaddr"];
102 if($hostname == "" && $ip == "") {
103 echo "Error: must have either ip or hostname\n";
107 if($hostname == "") {
108 // try to lookup hostname from ip
109 $hostname = gethostbyaddr($ip);
113 // try to lookup ip from hostname
114 $ip = gethostbyname($hostname);
117 $hosts = $this->config->getData("hosts");
118 foreach($hosts as $key => $val) {
119 if($val["category"] == $hostname && $val["name"] == $ip) {
120 echo "Error: host already exists<br>";
125 $this->config->addData("hosts", "$hostname", "$ip", "$hg");
128 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
129 header("Location: $BASE_URL/hosts");
133 function addGroup($url)
135 $grpname = $_REQUEST["groupname"];
136 $groups = $this->config->getData("hostgroups");
138 foreach($groups as $key => $val) {
139 if($val["category"] == $grpname) {
140 echo "Error: gorup already exists";
145 $this->config->adddata("hostgroups", "$grpname", "", "");
146 global $WEB_ROOT_FS, $URL_HANDLERS, $BASE_URL;
147 header("Location: $BASE_URL/hosts");
151 function mainBody($url)
153 $hosts = $this->config->getData("hosts");
154 $groups = $this->config->getData("hostgroups");
156 echo "<h2>Hosts</h2>";
158 echo "<table border=\"1\"><tr><th>Host</th><th>IP</th><th>Host Group</th><th>Last Seen</th><th>Control</th></tr>";
159 foreach($hosts as $key => $val) {
160 $hname = $val["category"];
163 if($hg == "") $hg = "-";
164 echo "<tr><td>$hname</td><td>$hip</td><td>$hg</td><td>...</td><td><a href=\"?action=deletehost&hostname=$hname\">Delete</a></tr>";
168 echo "No hosts defined yet<br>";
173 echo "<h2>Host Groups</h2>";
175 echo "<table border=\"1\"><tr><th>Group Name</th></tr>";
176 foreach($groups as $key=>$val) {
177 $grpname = $val["category"];
178 echo "<tr><td>$grpname</td></tr>";
182 echo "No host groups defined yet<br>";
187 echo "<table><tr valign=\"top\"><td>";
189 // the add hosts dialog
190 echo "<h2>Add Host</h2>";
191 echo "<form method=\"post\" action=\"?action=addhost\">";
192 echo "Hostname: <input type=\"text\" name=\"hostname\"><br>";
193 echo "IP Address: <input type=\"text\" name=\"ipaddr\"><br>";
195 echo "Host Group: <select name=\"hostgroup\">";
196 echo "<option value=\"\">None</option>";
197 foreach($groups as $key => $val) {
198 $hgname = $val["category"];
199 echo "<option value=\"$hgname\">$hgname</option>";
201 echo "</select><br>";
203 echo "<input type=\"submit\" name=\"add\" value=\"Add\">";
208 // the add groups dialog
209 echo "<h2>Add Group</h2>";
210 echo "<form method=\"post\" action=\"?action=addgroup\">";
211 echo "Groupname: <input type=\"text\" name=\"groupname\"><br>";
212 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";
216 //scan ip range via dns
217 echo "<h2>Scan Range</h2>";
218 echo "<form method=\"post\" action=\"?action=scanrange\">";
219 echo "Range (i.e. 10.1.2.0): <input type=\"text\" name=\"scanip\"><br>";
221 echo "Host Group: <select name=\"hostgroup\">";
222 echo "<option value=\"\">None</option>";
223 foreach($groups as $key => $val) {
224 $hgname = $val["category"];
225 echo "<option value=\"$hgname\">$hgname</option>";
227 echo "</select><br>";
229 echo "<input type=\"submit\" name=\"Add\" value=\"Add\"><br>";