diff options
author | David Walter Seikel | 2013-03-15 01:06:16 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-03-15 01:06:16 +1000 |
commit | 4515cca57d6a5248114b03954fe7984ba477fcce (patch) | |
tree | 2aedb44fd103effbb6c7d6870b6c2cf4b9c19c1b /web/parser.php | |
parent | Add the SQL update scripts. (diff) | |
download | opensim-SC-4515cca57d6a5248114b03954fe7984ba477fcce.zip opensim-SC-4515cca57d6a5248114b03954fe7984ba477fcce.tar.gz opensim-SC-4515cca57d6a5248114b03954fe7984ba477fcce.tar.bz2 opensim-SC-4515cca57d6a5248114b03954fe7984ba477fcce.tar.xz |
Add grid server web scripts.
Diffstat (limited to 'web/parser.php')
-rw-r--r-- | web/parser.php | 317 |
1 files changed, 317 insertions, 0 deletions
diff --git a/web/parser.php b/web/parser.php new file mode 100644 index 0000000..4783148 --- /dev/null +++ b/web/parser.php | |||
@@ -0,0 +1,317 @@ | |||
1 | <?php | ||
2 | include("../config/os_modules_mysql.php"); | ||
3 | |||
4 | |||
5 | //Supress all Warnings/Errors | ||
6 | //error_reporting(0); | ||
7 | |||
8 | $now = time(); | ||
9 | |||
10 | // | ||
11 | // Search DB | ||
12 | // | ||
13 | mysql_connect ($DB_HOST, $DB_USER, $DB_PASSWORD); | ||
14 | mysql_select_db ($DB_NAME); | ||
15 | |||
16 | function GetURL($host, $port, $url) | ||
17 | { | ||
18 | $url = "http://$host:$port/$url"; | ||
19 | |||
20 | $ch = curl_init(); | ||
21 | curl_setopt($ch, CURLOPT_URL, $url); | ||
22 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
23 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); | ||
24 | curl_setopt($ch, CURLOPT_TIMEOUT, 30); | ||
25 | |||
26 | $data = curl_exec($ch); | ||
27 | if (curl_errno($ch) == 0) | ||
28 | { | ||
29 | curl_close($ch); | ||
30 | return $data; | ||
31 | } | ||
32 | |||
33 | curl_close($ch); | ||
34 | return ""; | ||
35 | } | ||
36 | |||
37 | function CheckHost($hostname, $port) | ||
38 | { | ||
39 | global $now; | ||
40 | |||
41 | $xml = GetURL($hostname, $port, "?method=collector"); | ||
42 | if ($xml == "") //No data was retrieved? (CURL may have timed out) | ||
43 | $failcounter = "failcounter + 1"; | ||
44 | else | ||
45 | $failcounter = "0"; | ||
46 | |||
47 | //Update nextcheck to be 10 minutes from now. The current OS instance | ||
48 | //won't be checked again until at least this much time has gone by. | ||
49 | $next = $now + 600; | ||
50 | |||
51 | mysql_query("UPDATE hostsregister SET nextcheck = $next," . | ||
52 | " checked = 1, failcounter = " . $failcounter . | ||
53 | " WHERE host = '" . mysql_real_escape_string($hostname) . "'" . | ||
54 | " AND port = '" . mysql_real_escape_string($port) . "'"); | ||
55 | |||
56 | if ($xml != "") | ||
57 | parse($hostname, $port, $xml); | ||
58 | } | ||
59 | |||
60 | function parse($hostname, $port, $xml) | ||
61 | { | ||
62 | global $now; | ||
63 | |||
64 | /////////////////////////////////////////////////////////////////////// | ||
65 | // | ||
66 | // Search engine sim scanner | ||
67 | // | ||
68 | |||
69 | // | ||
70 | // Load XML doc from URL | ||
71 | // | ||
72 | $objDOM = new DOMDocument(); | ||
73 | $objDOM->resolveExternals = false; | ||
74 | |||
75 | //Don't try and parse if XML is invalid or we got an HTML 404 error. | ||
76 | if ($objDOM->loadXML($xml) == False) | ||
77 | return; | ||
78 | |||
79 | // | ||
80 | // Get the region data to update | ||
81 | // | ||
82 | $regiondata = $objDOM->getElementsByTagName("regiondata"); | ||
83 | |||
84 | //If returned length is 0, collector method may have returned an error | ||
85 | if ($regiondata->length == 0) | ||
86 | return; | ||
87 | |||
88 | $regiondata = $regiondata->item(0); | ||
89 | |||
90 | // | ||
91 | // Update nextcheck so this host entry won't be checked again until after | ||
92 | // the DataSnapshot module has generated a new set of data to be parsed. | ||
93 | // | ||
94 | $expire = $regiondata->getElementsByTagName("expire")->item(0)->nodeValue; | ||
95 | $next = $now + $expire; | ||
96 | |||
97 | $updater = mysql_query("UPDATE hostsregister SET nextcheck = $next " . | ||
98 | "WHERE host = '" . mysql_real_escape_string($hostname) . "' AND " . | ||
99 | "port = '" . mysql_real_escape_string($port) . "'"); | ||
100 | |||
101 | // | ||
102 | // Get the region data to be saved in the database | ||
103 | // | ||
104 | $regionlist = $regiondata->getElementsByTagName("region"); | ||
105 | |||
106 | foreach ($regionlist as $region) | ||
107 | { | ||
108 | $regioncategory = $region->getAttributeNode("category")->nodeValue; | ||
109 | |||
110 | // | ||
111 | // Start reading the Region info | ||
112 | // | ||
113 | $info = $region->getElementsByTagName("info")->item(0); | ||
114 | |||
115 | $regionuuid = $info->getElementsByTagName("uuid")->item(0)->nodeValue; | ||
116 | |||
117 | $regionname = $info->getElementsByTagName("name")->item(0)->nodeValue; | ||
118 | |||
119 | $regionhandle = $info->getElementsByTagName("handle")->item(0)->nodeValue; | ||
120 | |||
121 | $url = $info->getElementsByTagName("url")->item(0)->nodeValue; | ||
122 | |||
123 | // | ||
124 | // First, check if we already have a region that is the same | ||
125 | // | ||
126 | $check = mysql_query("SELECT * FROM osregions WHERE regionuuid = '" . | ||
127 | mysql_real_escape_string($regionuuid) . "'"); | ||
128 | |||
129 | if (mysql_num_rows($check) > 0) | ||
130 | { | ||
131 | mysql_query("DELETE FROM osregions WHERE regionuuid = '" . | ||
132 | mysql_real_escape_string($regionuuid) . "'"); | ||
133 | mysql_query("DELETE FROM parcels WHERE regionuuid = '" . | ||
134 | mysql_real_escape_string($regionuuid) . "'"); | ||
135 | mysql_query("DELETE FROM allparcels WHERE regionUUID = '" . | ||
136 | mysql_real_escape_string($regionuuid) . "'"); | ||
137 | mysql_query("DELETE FROM parcelsales WHERE regionUUID = '" . | ||
138 | mysql_real_escape_string($regionuuid) . "'"); | ||
139 | mysql_query("DELETE FROM objects WHERE regionuuid = '" . | ||
140 | mysql_real_escape_string($regionuuid) . "'"); | ||
141 | } | ||
142 | |||
143 | $data = $region->getElementsByTagName("data")->item(0); | ||
144 | $estate = $data->getElementsByTagName("estate")->item(0); | ||
145 | |||
146 | $username = $estate->getElementsByTagName("name")->item(0)->nodeValue; | ||
147 | $useruuid = $estate->getElementsByTagName("uuid")->item(0)->nodeValue; | ||
148 | |||
149 | $estateid = $estate->getElementsByTagName("id")->item(0)->nodeValue; | ||
150 | |||
151 | // | ||
152 | // Second, add the new info to the database | ||
153 | // | ||
154 | $sql = "INSERT INTO osregions VALUES('" . | ||
155 | mysql_real_escape_string($regionname) . "','" . | ||
156 | mysql_real_escape_string($regionuuid) . "','" . | ||
157 | mysql_real_escape_string($regionhandle) . "','" . | ||
158 | mysql_real_escape_string($url) . "','" . | ||
159 | mysql_real_escape_string($username) ."','" . | ||
160 | mysql_real_escape_string($useruuid) ."')"; | ||
161 | |||
162 | mysql_query($sql); | ||
163 | |||
164 | // | ||
165 | // Start reading the parcel info | ||
166 | // | ||
167 | $parcel = $data->getElementsByTagName("parcel"); | ||
168 | |||
169 | foreach ($parcel as $value) | ||
170 | { | ||
171 | $parcelname = $value->getElementsByTagName("name")->item(0)->nodeValue; | ||
172 | |||
173 | $parceluuid = $value->getElementsByTagName("uuid")->item(0)->nodeValue; | ||
174 | |||
175 | $infouuid = $value->getElementsByTagName("infouuid")->item(0)->nodeValue; | ||
176 | |||
177 | $parcellanding = $value->getElementsByTagName("location")->item(0)->nodeValue; | ||
178 | |||
179 | $parceldescription = $value->getElementsByTagName("description")->item(0)->nodeValue; | ||
180 | |||
181 | $parcelarea = $value->getElementsByTagName("area")->item(0)->nodeValue; | ||
182 | |||
183 | $parcelcategory = $value->getAttributeNode("category")->nodeValue; | ||
184 | |||
185 | $parcelsaleprice = $value->getAttributeNode("salesprice")->nodeValue; | ||
186 | |||
187 | $dwell = $value->getElementsByTagName("dwell")->item(0)->nodeValue; | ||
188 | |||
189 | $owner = $value->getElementsByTagName("owner")->item(0); | ||
190 | |||
191 | $owneruuid = $owner->getElementsByTagName("uuid")->item(0)->nodeValue; | ||
192 | |||
193 | // Adding support for groups | ||
194 | |||
195 | $group = $value->getElementsByTagName("group")->item(0); | ||
196 | |||
197 | if ($group != "") | ||
198 | { | ||
199 | $groupuuid = $group->getElementsByTagName("groupuuid")->item(0)->nodeValue; | ||
200 | } | ||
201 | else | ||
202 | { | ||
203 | $groupuuid = "00000000-0000-0000-0000-000000000000"; | ||
204 | } | ||
205 | |||
206 | // | ||
207 | // Check bits on Public, Build, Script | ||
208 | // | ||
209 | $parcelforsale = $value->getAttributeNode("forsale")->nodeValue; | ||
210 | $parceldirectory = $value->getAttributeNode("showinsearch")->nodeValue; | ||
211 | $parcelbuild = $value->getAttributeNode("build")->nodeValue; | ||
212 | $parcelscript = $value->getAttributeNode("scripts")->nodeValue; | ||
213 | $parcelpublic = $value->getAttributeNode("public")->nodeValue; | ||
214 | |||
215 | // | ||
216 | // Save | ||
217 | // | ||
218 | $sql = "INSERT INTO allparcels VALUES('" . | ||
219 | mysql_real_escape_string($regionuuid) . "','" . | ||
220 | mysql_real_escape_string($parcelname) . "','" . | ||
221 | mysql_real_escape_string($owneruuid) . "','" . | ||
222 | mysql_real_escape_string($groupuuid) . "','" . | ||
223 | mysql_real_escape_string($parcellanding) . "','" . | ||
224 | mysql_real_escape_string($parceluuid) . "','" . | ||
225 | mysql_real_escape_string($infouuid) . "','" . | ||
226 | mysql_real_escape_string($parcelarea) . "' )"; | ||
227 | |||
228 | mysql_query($sql); | ||
229 | |||
230 | if ($parceldirectory == "true") | ||
231 | { | ||
232 | $sql = "INSERT INTO parcels VALUES('" . | ||
233 | mysql_real_escape_string($regionuuid) . "','" . | ||
234 | mysql_real_escape_string($parcelname) . "','" . | ||
235 | mysql_real_escape_string($parceluuid) . "','" . | ||
236 | mysql_real_escape_string($parcellanding) . "','" . | ||
237 | mysql_real_escape_string($parceldescription) . "','" . | ||
238 | mysql_real_escape_string($parcelcategory) . "','" . | ||
239 | mysql_real_escape_string($parcelbuild) . "','" . | ||
240 | mysql_real_escape_string($parcelscript) . "','" . | ||
241 | mysql_real_escape_string($parcelpublic) . "','". | ||
242 | mysql_real_escape_string($dwell) . "','" . | ||
243 | mysql_real_escape_string($infouuid) . "','" . | ||
244 | mysql_real_escape_string($regioncategory) . "')"; | ||
245 | |||
246 | mysql_query($sql); | ||
247 | } | ||
248 | |||
249 | if ($parcelforsale == "true") | ||
250 | { | ||
251 | $sql = "INSERT INTO parcelsales VALUES('" . | ||
252 | mysql_real_escape_string($regionuuid) . "','" . | ||
253 | mysql_real_escape_string($parcelname) . "','" . | ||
254 | mysql_real_escape_string($parceluuid) . "','" . | ||
255 | mysql_real_escape_string($parcelarea) . "','" . | ||
256 | mysql_real_escape_string($parcelsaleprice) . "','" . | ||
257 | mysql_real_escape_string($parcellanding) . "','" . | ||
258 | mysql_real_escape_string($infouuid) . "', '" . | ||
259 | mysql_real_escape_string($dwell) . "', '" . | ||
260 | mysql_real_escape_string($estateid) . "', '" . | ||
261 | mysql_real_escape_string($regioncategory) . "')"; | ||
262 | |||
263 | mysql_query($sql); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | // | ||
268 | // Handle objects | ||
269 | // | ||
270 | $objects = $data->getElementsByTagName("object"); | ||
271 | |||
272 | foreach ($objects as $value) | ||
273 | { | ||
274 | $uuid = $value->getElementsByTagName("uuid")->item(0)->nodeValue; | ||
275 | |||
276 | $regionuuid = $value->getElementsByTagName("regionuuid")->item(0)->nodeValue; | ||
277 | |||
278 | $parceluuid = $value->getElementsByTagName("parceluuid")->item(0)->nodeValue; | ||
279 | |||
280 | $location = $value->getElementsByTagName("location")->item(0)->nodeValue; | ||
281 | |||
282 | $title = $value->getElementsByTagName("title")->item(0)->nodeValue; | ||
283 | |||
284 | $description = $value->getElementsByTagName("description")->item(0)->nodeValue; | ||
285 | |||
286 | $flags = $value->getElementsByTagName("flags")->item(0)->nodeValue; | ||
287 | |||
288 | mysql_query("INSERT INTO objects VALUES('" . | ||
289 | mysql_real_escape_string($uuid) . "','" . | ||
290 | mysql_real_escape_string($parceluuid) . "','" . | ||
291 | mysql_real_escape_string($location) . "','" . | ||
292 | mysql_real_escape_string($title) . "','" . | ||
293 | mysql_real_escape_string($description) . "','" . | ||
294 | mysql_real_escape_string($regionuuid) . "')"); | ||
295 | } | ||
296 | } | ||
297 | } | ||
298 | |||
299 | $sql = "SELECT host, port FROM hostsregister " . | ||
300 | "WHERE nextcheck < $now AND checked = 0 LIMIT 0,10"; | ||
301 | |||
302 | $jobsearch = mysql_query($sql); | ||
303 | |||
304 | // | ||
305 | // If the sql query returns no rows, all entries in the hostsregister | ||
306 | // table have been checked. Reset the checked flag and re-run the | ||
307 | // query to select the next set of hosts to be checked. | ||
308 | // | ||
309 | if (mysql_num_rows($jobsearch) == 0) | ||
310 | { | ||
311 | mysql_query("UPDATE hostsregister SET checked = 0"); | ||
312 | $jobsearch = mysql_query($sql); | ||
313 | } | ||
314 | |||
315 | while ($jobs = mysql_fetch_row($jobsearch)) | ||
316 | CheckHost($jobs[0], $jobs[1]); | ||
317 | ?> | ||