Guest User

search

a guest
Mar 9th, 2016
127
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Search_model extends CI_Model {
  3.  
  4. public function __construct()
  5. {
  6. $zsite = $this->load->database('default', TRUE);
  7.  
  8. $this->load->helper('url');
  9. $this->load->helper('file');
  10.  
  11.  
  12. }
  13. function GetURL($host, $port, $url)
  14. {
  15. $url = "http://$host:$port/$url";
  16.  
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_URL, $url);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  21. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  22.  
  23. $data = curl_exec($ch);
  24. if (curl_errno($ch) == 0)
  25. {
  26. curl_close($ch);
  27. return $data;
  28. }
  29.  
  30. curl_close($ch);
  31. return "";
  32. }
  33.  
  34. function CheckHost($hostname, $port)
  35. {
  36. global $now;
  37.  
  38. $xml = GetURL($hostname, $port, "?method=collector");
  39. if ($xml == "") //No data was retrieved? (CURL may have timed out)
  40. $failcounter = "failcounter + 1";
  41. else
  42. $failcounter = "0";
  43.  
  44. //Update nextcheck to be 10 minutes from now. The current OS instance
  45. //won't be checked again until at least this much time has gone by.
  46. $next = $now + 600;
  47.  
  48. $zgrid->query("UPDATE hostsregister SET nextcheck = $next," .
  49. " checked = 1, failcounter = " . $failcounter .
  50. " WHERE host = '" . mysql_real_escape_string($hostname) . "'" .
  51. " AND port = '" . mysql_real_escape_string($port) . "'");
  52.  
  53. if ($xml != "")
  54. parse($hostname, $port, $xml);
  55. }
  56. function parse($hostname, $port, $xml)
  57. {
  58. global $now;
  59.  
  60. ///////////////////////////////////////////////////////////////////////
  61. //
  62. // Search engine sim scanner
  63. //
  64.  
  65. //
  66. // Load XML doc from URL
  67. //
  68. $objDOM = new DOMDocument();
  69. $objDOM->resolveExternals = false;
  70.  
  71. //Don't try and parse if XML is invalid or we got an HTML 404 error.
  72. if ($objDOM->loadXML($xml) == False)
  73. return;
  74.  
  75. //
  76. // Get the region data to update
  77. //
  78. $regiondata = $objDOM->getElementsByTagName("regiondata");
  79.  
  80. //If returned length is 0, collector method may have returned an error
  81. if ($regiondata->length == 0)
  82. return;
  83.  
  84. $regiondata = $regiondata->item(0);
  85.  
  86. //
  87. // Update nextcheck so this host entry won't be checked again until after
  88. // the DataSnapshot module has generated a new set of data to be parsed.
  89. //
  90. $expire = $regiondata->getElementsByTagName("expire")->item(0)->nodeValue;
  91. $next = $now + $expire;
  92.  
  93. $updater = $zgrid->query("UPDATE hostsregister SET nextcheck = $next " .
  94. "WHERE host = '" . mysql_real_escape_string($hostname) . "' AND " .
  95. "port = '" . mysql_real_escape_string($port) . "'");
  96.  
  97. //
  98. // Get the region data to be saved in the database
  99. //
  100. $regionlist = $regiondata->getElementsByTagName("region");
  101.  
  102. foreach ($regionlist as $region)
  103. {
  104. $regioncategory = $region->getAttributeNode("category")->nodeValue;
  105.  
  106. //
  107. // Start reading the Region info
  108. //
  109. $info = $region->getElementsByTagName("info")->item(0);
  110.  
  111. $regionuuid = $info->getElementsByTagName("uuid")->item(0)->nodeValue;
  112.  
  113. $regionname = $info->getElementsByTagName("name")->item(0)->nodeValue;
  114.  
  115. $regionhandle = $info->getElementsByTagName("handle")->item(0)->nodeValue;
  116.  
  117. $url = $info->getElementsByTagName("url")->item(0)->nodeValue;
  118.  
  119. //
  120. // First, check if we already have a region that is the same
  121. //
  122. $check = $zgrid->query("SELECT * FROM regions WHERE regionuuid = '" .
  123. mysql_real_escape_string($regionuuid) . "'");
  124. if ($check->num_rows() > 0) {
  125.  
  126. $zgrid->query("DELETE FROM regions WHERE regionuuid = '" .
  127. mysql_real_escape_string($regionuuid) . "'");
  128. $zgrid->query("DELETE FROM parcels WHERE regionuuid = '" .
  129. mysql_real_escape_string($regionuuid) . "'");
  130. $zgrid->query("DELETE FROM allparcels WHERE regionUUID = '" .
  131. mysql_real_escape_string($regionuuid) . "'");
  132. $zgrid->query("DELETE FROM parcelsales WHERE regionUUID = '" .
  133. mysql_real_escape_string($regionuuid) . "'");
  134. $zgrid->query("DELETE FROM objects WHERE regionuuid = '" .
  135. mysql_real_escape_string($regionuuid) . "'");
  136. }
  137.  
  138. $data = $region->getElementsByTagName("data")->item(0);
  139. $estate = $data->getElementsByTagName("estate")->item(0);
  140.  
  141. $username = $estate->getElementsByTagName("name")->item(0)->nodeValue;
  142. $useruuid = $estate->getElementsByTagName("uuid")->item(0)->nodeValue;
  143.  
  144. $estateid = $estate->getElementsByTagName("id")->item(0)->nodeValue;
  145.  
  146. //
  147. // Second, add the new info to the database
  148. //
  149. $sql = "INSERT INTO regions VALUES('" .
  150. mysql_real_escape_string($regionname) . "','" .
  151. mysql_real_escape_string($regionuuid) . "','" .
  152. mysql_real_escape_string($regionhandle) . "','" .
  153. mysql_real_escape_string($url) . "','" .
  154. mysql_real_escape_string($username) ."','" .
  155. mysql_real_escape_string($useruuid) ."')";
  156.  
  157. $zgrid->query($sql);
  158.  
  159. //
  160. // Start reading the parcel info
  161. //
  162. $parcel = $data->getElementsByTagName("parcel");
  163.  
  164. foreach ($parcel as $value)
  165. {
  166. $parcelname = $value->getElementsByTagName("name")->item(0)->nodeValue;
  167.  
  168. $parceluuid = $value->getElementsByTagName("uuid")->item(0)->nodeValue;
  169.  
  170. $infouuid = $value->getElementsByTagName("infouuid")->item(0)->nodeValue;
  171.  
  172. $parcellanding = $value->getElementsByTagName("location")->item(0)->nodeValue;
  173.  
  174. $parceldescription = $value->getElementsByTagName("description")->item(0)->nodeValue;
  175.  
  176. $parcelarea = $value->getElementsByTagName("area")->item(0)->nodeValue;
  177.  
  178. $parcelcategory = $value->getAttributeNode("category")->nodeValue;
  179.  
  180. $parcelsaleprice = $value->getAttributeNode("salesprice")->nodeValue;
  181.  
  182. $dwell = $value->getElementsByTagName("dwell")->item(0)->nodeValue;
  183.  
  184. $owner = $value->getElementsByTagName("owner")->item(0);
  185.  
  186. $owneruuid = $owner->getElementsByTagName("uuid")->item(0)->nodeValue;
  187.  
  188. // Adding support for groups
  189.  
  190. $group = $value->getElementsByTagName("group")->item(0);
  191.  
  192. if ($group != "")
  193. {
  194. $groupuuid = $group->getElementsByTagName("groupuuid")->item(0)->nodeValue;
  195. }
  196. else
  197. {
  198. $groupuuid = "00000000-0000-0000-0000-000000000000";
  199. }
  200.  
  201. //
  202. // Check bits on Public, Build, Script
  203. //
  204. $parcelforsale = $value->getAttributeNode("forsale")->nodeValue;
  205. $parceldirectory = $value->getAttributeNode("showinsearch")->nodeValue;
  206. $parcelbuild = $value->getAttributeNode("build")->nodeValue;
  207. $parcelscript = $value->getAttributeNode("scripts")->nodeValue;
  208. $parcelpublic = $value->getAttributeNode("public")->nodeValue;
  209.  
  210. //
  211. // Save
  212. //
  213. $sql = "INSERT INTO allparcels VALUES('" .
  214. mysql_real_escape_string($regionuuid) . "','" .
  215. mysql_real_escape_string($parcelname) . "','" .
  216. mysql_real_escape_string($owneruuid) . "','" .
  217. mysql_real_escape_string($groupuuid) . "','" .
  218. mysql_real_escape_string($parcellanding) . "','" .
  219. mysql_real_escape_string($parceluuid) . "','" .
  220. mysql_real_escape_string($infouuid) . "','" .
  221. mysql_real_escape_string($parcelarea) . "' )";
  222.  
  223. $zgrid->query($sql);
  224.  
  225. if ($parceldirectory == "true")
  226. {
  227. $sql = "INSERT INTO parcels VALUES('" .
  228. mysql_real_escape_string($regionuuid) . "','" .
  229. mysql_real_escape_string($parcelname) . "','" .
  230. mysql_real_escape_string($parceluuid) . "','" .
  231. mysql_real_escape_string($parcellanding) . "','" .
  232. mysql_real_escape_string($parceldescription) . "','" .
  233. mysql_real_escape_string($parcelcategory) . "','" .
  234. mysql_real_escape_string($parcelbuild) . "','" .
  235. mysql_real_escape_string($parcelscript) . "','" .
  236. mysql_real_escape_string($parcelpublic) . "','".
  237. mysql_real_escape_string($dwell) . "','" .
  238. mysql_real_escape_string($infouuid) . "','" .
  239. mysql_real_escape_string($regioncategory) . "')";
  240.  
  241. mysql_query($sql);
  242. }
  243.  
  244. if ($parcelforsale == "true")
  245. {
  246. $sql = "INSERT INTO parcelsales VALUES('" .
  247. mysql_real_escape_string($regionuuid) . "','" .
  248. mysql_real_escape_string($parcelname) . "','" .
  249. mysql_real_escape_string($parceluuid) . "','" .
  250. mysql_real_escape_string($parcelarea) . "','" .
  251. mysql_real_escape_string($parcelsaleprice) . "','" .
  252. mysql_real_escape_string($parcellanding) . "','" .
  253. mysql_real_escape_string($infouuid) . "', '" .
  254. mysql_real_escape_string($dwell) . "', '" .
  255. mysql_real_escape_string($estateid) . "', '" .
  256. mysql_real_escape_string($regioncategory) . "')";
  257.  
  258. $zgrid->query($sql);
  259. }
  260. }
  261.  
  262. //
  263. // Handle objects
  264. //
  265. $objects = $data->getElementsByTagName("object");
  266.  
  267. foreach ($objects as $value)
  268. {
  269. $uuid = $value->getElementsByTagName("uuid")->item(0)->nodeValue;
  270.  
  271. $regionuuid = $value->getElementsByTagName("regionuuid")->item(0)->nodeValue;
  272.  
  273. $parceluuid = $value->getElementsByTagName("parceluuid")->item(0)->nodeValue;
  274.  
  275. $location = $value->getElementsByTagName("location")->item(0)->nodeValue;
  276.  
  277. $title = $value->getElementsByTagName("title")->item(0)->nodeValue;
  278.  
  279. $description = $value->getElementsByTagName("description")->item(0)->nodeValue;
  280.  
  281. $flags = $value->getElementsByTagName("flags")->item(0)->nodeValue;
  282.  
  283. $zgrid->query("INSERT INTO objects VALUES('" .
  284. mysql_real_escape_string($uuid) . "','" .
  285. mysql_real_escape_string($parceluuid) . "','" .
  286. mysql_real_escape_string($location) . "','" .
  287. mysql_real_escape_string($title) . "','" .
  288. mysql_real_escape_string($description) . "','" .
  289. mysql_real_escape_string($regionuuid) . "')");
  290. }
  291. }
  292. }
  293.  
  294. public function parser()
  295. {
  296. $zgrid = $this->load->database('grid', TRUE);
  297. $now = time();
  298. $sql = "SELECT host, port FROM hostsregister " .
  299. "WHERE nextcheck < $now AND checked = 0 LIMIT 0,10";
  300.  
  301. $jobsearch = $zgrid->query($sql);
  302.  
  303. //
  304. // If the sql query returns no rows, all entries in the hostsregister
  305. // table have been checked. Reset the checked flag and re-run the
  306. // query to select the next set of hosts to be checked.
  307. //
  308. if ($jobsearch->num_rows() == 0)
  309. {
  310. $zgrid->query("UPDATE hostsregister SET checked = 0");
  311. $jobsearch = $zgrid->query($sql);
  312. }
  313. $r = $jobsearch->row();
  314. while ($jobs = $r)
  315. $this->CheckHost($jobs[0], $jobs[1])->result_array();
  316.  
  317.  
  318. }
  319.  
  320. public function register($hostname,$port,$service)
  321. {
  322. $zgrid = $this->load->database('grid', TRUE);
  323.  
  324. if ($hostname != "" && $port != "" && $service == "online")
  325. {
  326. $checkhost = $zgrid->query("SELECT register FROM hostsregister WHERE " .
  327. "host = '" .$zgrid->escape_str($hostname). "' AND " .
  328. "port = '" .$zgrid->escape_str($port). "'");
  329.  
  330. $timestamp = $_SERVER['REQUEST_TIME'];
  331.  
  332. if ($checkhost->num_rows() > 0)
  333. {
  334. $update = $zgrid->query("UPDATE hostsregister SET " .
  335. "register = '" .$zgrid->escape_str($timestamp). "', " .
  336. "nextcheck = '0', checked = '0', " .
  337. "failcounter = '0' " .
  338. "WHERE host = '" .$zgrid->escape_str($hostname). "' AND " .
  339. "port = '" .$zgrid->escape_str($port). "'");
  340.  
  341.  
  342.  
  343. }
  344. else
  345. {
  346. $register = $zgrid->query("INSERT INTO hostsregister VALUES ".
  347. "('" .$zgrid->escape_str($hostname) . "', " .
  348. "'" .$zgrid->escape_str($port) . "', " .
  349. "'" .$zgrid->escape_str($timestamp) . "', 0, 0, 0)");
  350.  
  351. }
  352.  
  353. }
  354. elseif ($hostname != "" && $port != "" && $service = "offline")
  355. {
  356. $delete = $zgrid->query("DELETE FROM hostsregister " .
  357. "WHERE host = '" .$zgrid->escape_str($hostname) . "' AND " .
  358. "port = '" .$zgrid->escape_str($port) . "'");
  359.  
  360.  
  361.  
  362. }
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370. }
  371. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×