public function action_delete($id = null) { if ($proxy = Model_Proxy::find($id)) { $proxy->delete(); Session::set_flash('success', 'Deleted proxy #' . $id); } else { Session::set_flash('error', 'Could not delete proxy #' . $id); } Response::redirect('proxies'); }
public function action_create() { if (Input::method() == 'POST') { $val = Model_Proxy_Import::validate('create'); if ($val->run()) { $proxy_import = Model_Proxy_Import::forge(array('name' => Input::post('name'), 'proxylist' => Input::post('proxylist'))); if ($proxy_import and $proxy_import->save()) { // Run the importer foreach (explode("\r\n", Input::post('proxylist')) as $line) { $proxy_details = explode(':', $line); $check_proxy = Model_Proxy::find()->where('host', $proxy_details[0])->where('port', $proxy_details[1]); if ($check_proxy->count() < 1) { $proxy = Model_Proxy::forge(array('host' => $proxy_details[0], 'port' => $proxy_details[1], 'fail_count' => 0, 'use_count' => 0)); $proxy->save(); } else { /* $check_proxy->get_one(); $this_proxy = Model_Proxy::find($check_proxy->id); $this_proxy->fail_count = 0; $this_proxy->save(); */ } } Session::set_flash('success', 'Added proxy_import #' . $proxy_import->id . '.'); Response::redirect('proxy/import'); } else { Session::set_flash('error', 'Could not save proxy_import.'); } } else { Session::set_flash('error', $val->error()); } } $this->template->title = "Proxy_Imports"; $this->template->content = View::forge('proxy/import/create'); }
private function get_html_dom($surname, $town, $page_number = 1) { date_default_timezone_set('Europe/London'); $html = null; while (!is_object($html)) { $proxy_query = \Model_Proxy::find()->where('fail_count', '<', static::$current_max_count)->order_by('use_count', 'asc')->limit(1); while ($proxy_query->count() == 0) { static::$current_max_count++; echo "Proxy Count Now: " . static::$current_max_count; @ob_flush(); $proxy_query = \Model_Proxy::find()->where('fail_count', '<', static::$current_max_count); } if ($proxy_query->count() > 0) { $count = $proxy_query->count(); if ($count < 50 and static::$current_max_count == 1) { $previous_alerts = \Model_Adam_Announcement::find()->where('campaign', 'NULL')->where('alert_type', 'PROXY-50'); if ($previous_alerts->count() == 0) { Datascrape::send_push_message("Just so you know, there are less than 50 fresh proxies available to use!"); $adam_announcement = \Model_Adam_Announcement::forge(array('campaign' => "NULL", 'alert_type' => "PROXY-50", 'remove_date' => date("Y-m-d H:i:s", strtotime("+15 minutes")))); $adam_announcement->save(); } } $proxy = $proxy_query->get_one(); echo "Trying Proxy (from " . $count . ") - " . $proxy->host . ":" . $proxy->port; $html = \Simple_Html_Dom\helper::file_get_html('http://www.ukphonebook.com/telephone_directory/search?data_source=osis&name=' . $surname . '&place=' . $town . '&er_years%5B0%5D=pre-2013&er_years%5B1%5D=2013&page=' . $page_number, false, stream_context_create(array('http' => array('proxy' => $proxy->host . ":" . $proxy->port, 'request_fulluri' => true, 'timeout' => 10, 'method' => "GET", 'header' => "Accept-language: en\r\n" . "Cookie: foo=bar\r\n" . "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.107 Safari/534.13\r\n")))); if (!is_object($html)) { $proxy->use_count = $proxy->use_count + 1; $proxy->fail_count = $proxy->fail_count + 1; $proxy->save(); echo " - Failed\n"; @ob_flush(); } else { $proxy->use_count = $proxy->use_count + 1; $proxy->save(); echo " - Passed\n"; } } else { $html = "NOPROXY"; } } return $html; }