Commit d7915262 authored by Alex Ne's avatar Alex Ne

add files

parent b1819600
<?php
/*
НЕ ТРОЖ!!! :)
*/
class X_DB_MySQLi
{
static $DBC_LIST = [];
static $LINK = [];
private $DBLN = false;
private $DBHOST = "localhost";
private $DBNAME = "test";
private $DBUSER = "root";
private $DBPASS = "";
private $DBCHARSET = "utf8";
// ARGV:
// array( "DBHOST" => , "DBNAME" => , "DBUSER" => , "DBPASS" => , "DBCHARSET" => )
// OR:
// $DBNAME, $DBUSER, $DBPASS | Defauts: $DBHOST = "localhost"; $DBCHARSET = "utf8";
// OR:
// $DBHOST, $DBNAME, $DBUSER, $DBPASS | Defauts: $DBCHARSET = "utf8";
// OR:
// $DBHOST, $DBNAME, $DBUSER, $DBPASS, $DBCHARSET
// OR:
// $DBC - name of configured database
function __construct()
{ $cfg = func_get_args();
if( !(count($cfg)>0) ) throw new Exception("DB_MySQLi_NULL_CONSTRUCT_ARGUMENT", X_Exception_List::DB_MySQLi_NULL_CONSTRUCT_ARGUMENT);
if(is_array($cfg[0])) {
if(isset($cfg[0]["DBHOST"])) $this->DBHOST = $cfg[0]["DBHOST"];
if(isset($cfg[0]["DBNAME"])) $this->DBNAME = $cfg[0]["DBNAME"];
if(isset($cfg[0]["DBUSER"])) $this->DBUSER = $cfg[0]["DBUSER"];
if(isset($cfg[0]["DBPASS"])) $this->DBPASS = $cfg[0]["DBPASS"];
if(isset($cfg[0]["DBCHARSET"])) $this->DBCHARSET = $cfg[0]["DBCHARSET"];
} else if( count($cfg) == 1 ) {
if(isset(X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBHOST"])) $this->DBHOST = X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBHOST"];
if(isset(X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"])) $this->DBNAME = X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"];
if(isset(X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"])) $this->DBUSER = X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"];
if(isset(X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"])) $this->DBPASS = X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"];
if(isset(X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBCHARSET"])) $this->DBCHARSET = X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBCHARSET"];
} else if( count($cfg) == 3 )
{ $this->DBNAME = $cfg[0]; $this->DBUSER = $cfg[1]; $this->DBPASS = $cfg[2]; }
else if( count($cfg) == 4 )
{ $this->DBHOST = $cfg[0]; $this->DBNAME = $cfg[1]; $this->DBUSER = $cfg[2]; $this->DBPASS = $cfg[3]; }
else if( count($cfg) == 5 )
{ $this->DBHOST = $cfg[0]; $this->DBNAME = $cfg[1]; $this->DBUSER = $cfg[2]; $this->DBPASS = $cfg[3]; $this->DBCHARSET = $cfg[4]; }
else throw new Exception("DB_MySQLi_WRONG_CONSTRUCT_ARGUMENT", X_Exception_List::DB_MySQLi_WRONG_CONSTRUCT_ARGUMENT);
$this->DBLN = md5($this->DBHOST.$this->DBNAME.$this->DBUSER.$this->DBPASS.$this->DBCHARSET);
}
// ARGV:
// $DBC, array( "DBHOST" => , "DBNAME" => , "DBUSER" => , "DBPASS" => , "DBCHARSET" => )
// OR:
// $DBC, $DBNAME, $DBUSER, $DBPASS | Defauts: $DBHOST = "localhost"; $DBCHARSET = "utf8";
// OR:
// $DBC, $DBHOST, $DBNAME, $DBUSER, $DBPASS | Defauts: $DBCHARSET = "utf8";
// OR:
// $DBC, $DBHOST, $DBNAME, $DBUSER, $DBPASS, $DBCHARSET
static function SetConfig()
{ $cfg = func_get_args();
if(isset($cfg[1]) && is_array($cfg[1])) {
if(isset($cfg[1]["DBHOST"])) X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBHOST"] = $cfg[1]["DBHOST"];
if(isset($cfg[1]["DBNAME"])) X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"] = $cfg[1]["DBNAME"];
if(isset($cfg[1]["DBUSER"])) X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"] = $cfg[1]["DBUSER"];
if(isset($cfg[1]["DBPASS"])) X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"] = $cfg[1]["DBPASS"];
if(isset($cfg[1]["DBCHARSET"])) X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBCHARSET"] = $cfg[1]["DBCHARSET"];
} else if( count($cfg) == 4 ) { X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"] = $cfg[1]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"] = $cfg[2]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"] = $cfg[3];
} else if( count($cfg) == 5 ) { X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBHOST"] = $cfg[1]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"] = $cfg[2];
X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"] = $cfg[3]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"] = $cfg[4];
} else if( count($cfg) == 6 ) { X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBHOST"] = $cfg[1]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBNAME"] = $cfg[2]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBUSER"] = $cfg[3];
X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBPASS"] = $cfg[4]; X_DB_MySQLi::$DBC_LIST[$cfg[0]]["DBCHARSET"] = $cfg[5]; }
}
public function Connect()
{
if(!isset(X_DB_MySQLi::$LINK[$this->DBLN]) || !X_DB_MySQLi::$LINK[$this->DBLN]->ping() )
{
X_DB_MySQLi::$LINK[$this->DBLN] = new mysqli( $this->DBHOST, $this->DBUSER, $this->DBPASS, $this->DBNAME );
X_DB_MySQLi::$LINK[$this->DBLN]->set_charset( $this->DBCHARSET );
if ( X_DB_MySQLi::$LINK[$this->DBLN]->connect_errno )
throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->connect_error, X_DB_MySQLi::$LINK[$this->DBLN]->connect_errno);
}
return $this;
}
public function add($tableName, $arrayParams, $replace=false)
{
$link_id = $this->Connect()->DBLN;
$values = array_map( function($string) use ($link_id) {
return X_DB_MySQLi::$LINK[$link_id]->real_escape_string($string);
}, array_values($arrayParams));
$keys = array_keys($arrayParams);
if($replace) $type = "REPLACE";
else $type = "INSERT";
return $this->insert($type.' INTO `'.$tableName.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');
}
public function insert($SQL)
{
if( X_DB_MySQLi::$LINK[$this->Connect()->DBLN]->real_query($SQL) ) return X_DB_MySQLi::$LINK[$this->DBLN]->insert_id;
else throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->error, X_DB_MySQLi::$LINK[$this->DBLN]->errno);
}
public function rq( $SQL )
{
if( X_DB_MySQLi::$LINK[$this->Connect()->DBLN]->real_query($SQL) ) return true;
else throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->error, X_DB_MySQLi::$LINK[$this->DBLN]->errno);
}
public function get($SQL,$ID_COL=false,$ID_COL2=false,$ID_COL3=false)
{
if($this->rq($SQL))
{
$result = X_DB_MySQLi::$LINK[$this->DBLN]->store_result();
if($result)
{
if( $result->num_rows > 0 )
{
$DATA = array();
while ( $row = $result->fetch_assoc() )
{
if(isset($row[$ID_COL]) && $ID_COL)
{
if(isset($row[$ID_COL2]) && $ID_COL2)
{
if(isset($row[$ID_COL3]) && $ID_COL3) $DATA[$row[$ID_COL]][$row[$ID_COL2]][$row[$ID_COL3]] = $row;
else $DATA[$row[$ID_COL]][$row[$ID_COL2]] = $row;
}
else $DATA[$row[$ID_COL]] = $row;
}
else $DATA[] = $row;
}
$result->close();
return $DATA;
} else {
$result->close();
return array();
}
} else {
//throw new Exception(X_DB_MySQLi::$LINK[$this->DBLN]->error, X_DB_MySQLi::$LINK[$this->DBLN]->errno);
return false;
}
}
else return false;
}
function __destruct()
{
if ( isset( X_DB_MySQLi::$LINK[$this->DBLN] ) && X_DB_MySQLi::$LINK[$this->DBLN]->ping() )
X_DB_MySQLi::$LINK[$this->DBLN]->close();
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_ErrorWriter
{
static $AllErrorList = [];
public $ErrorList = [];
function __construct($Type, $Message, $File, $Line, $StackTrace=false)
{
$this->fixError($Type, $Message, $File, $Line, $StackTrace);
}
public function fixError($Type, $Message, $File, $Line, $StackTrace=false)
{
$File = str_replace(ROOT_DIR, "", $File);
$Message = str_replace(ROOT_DIR, "", $Message);
$StackTrace = str_replace(ROOT_DIR, "", $StackTrace);
$ErrorIndex = md5($Type.$Message.$File.$Line);
if(isset($this->ErrorList[$ErrorIndex])) $this->ErrorList[$ErrorIndex]['count']++;
else
{
$this->ErrorList[$ErrorIndex]['id'] = $ErrorIndex;
$this->ErrorList[$ErrorIndex]['count'] = 1;
$this->ErrorList[$ErrorIndex]['number'] = $Type;
$this->ErrorList[$ErrorIndex]['message'] = $StackTrace?$Message."\n".$StackTrace:$Message;
$this->ErrorList[$ErrorIndex]['file'] = $File;
$this->ErrorList[$ErrorIndex]['line'] = $Line;
$this->ErrorList[$ErrorIndex]['time'] = time();
}
X_ErrorWriter::$AllErrorList[$ErrorIndex] = $this->ErrorList[$ErrorIndex];
return $this;
}
public function tryWriteErrorToDB()
{
if(count($this->ErrorList)>0)
{
$DB = ( new X_DB_MySQLi("sw") )->Connect();
$lastErrors = $DB->get("SELECT * from `error_log` where `id` in ('".implode( "','", array_keys($this->ErrorList) )."') order by `time` desc","id");
if(count($lastErrors)>0)
{
foreach ($lastErrors as $key => $value)
{
$this->ErrorList[$key]['count'] = $this->ErrorList[$key]['count'] + $value['count'];
}
}
foreach ($this->ErrorList as $key => $data)
{
if( $DB->add("error_log", $data, true) )
unset($this->ErrorList[$key]);
}
}
}
function __destruct(){}
}
?>
\ No newline at end of file
<?php
class X_Exception_List
{
const DB_MySQLi_NULL_CONSTRUCT_ARGUMENT = 11020;
const DB_MySQLi_WRONG_CONSTRUCT_ARGUMENT = 11021;
static function GetList()
{
$Reflection = X_Exception_List::Reflection();
return $Reflection->getConstants();
}
static function Reflection()
{
return new ReflectionClass('X_Exception_List');
}
}
?>
\ No newline at end of file
<?php
/**
*
*/
class X_HTTP_Client
{
public $UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:41.0) Gecko/20100101 Firefox/41.0";
public $HEADERS = array();
public $Cookies = array();
public $Proxy = false;
public $Timeout = 60;
function __construct($cfg=[])
{
foreach ($cfg as $key => $value)
{
switch (strtolower($key))
{
case 'proxy': $this->Proxy = $value; break;
case 'useragent': $this->UserAgent = $value; break;
case 'cookies': $this->Cookies = $value; break;
case 'headers': $this->HEADERS = $value; break;
case 'timeout': $this->Timeout = $value; break;
}
}
}
public function GET($URL)
{
$this->HEADERS[] = "User-Agent: ".$this->UserAgent;
$cookies_arr = array();
foreach( $this->Cookies as $k => $v ) { $cookies_arr[] = $k."=".$v; }
$result = false;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $URL);
//curl_setopt($curl, CURLOPT_HEADER, true);
if( count($cookies_arr) > 0 ) curl_setopt($curl, CURLOPT_COOKIE, implode("; ",$cookies_arr));
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->HEADERS);
if( $this->Proxy ) curl_setopt($curl, CURLOPT_PROXY, $this->Proxy);
curl_setopt($curl, CURLOPT_TIMEOUT, $this->Timeout);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
public function POST($URL)
{
# NOT YET
}
}
?>
\ No newline at end of file
<?php
class X_HTTP_ProxyList
{
public $check_url = "http://test.arhat.tv/ok";
public $check_resp = "ok";
public $data_dir = "./";
private $reject_list = [];
private $fail_list = [];
private $used_list = [];
private $database = [];
private $service_list = [];
private $offset = 0;
function __construct($data_dir)
{
if(is_dir($data_dir)) $this->data_dir = $data_dir;
$this->database = $this->load_database();
$this->reject_list = $this->load_reject();
$this->fail_list = $this->load_fail();
foreach ($this->fail_list as $IP => $value)
{
if($value < time() - (60*60*24*20)) unset($this->fail_list[$IP]);
}
}
public function set_fail($IP)
{
$this->database = array_merge($this->database, $this->load_database());
$this->fail_list = array_merge($this->fail_list, $this->load_fail());
$this->fail_list[$IP] = time();
unset($this->database[$IP]);
$this->save_database();
$this->save_fail();
}
public function set_reject($IP)
{
$this->database = array_merge($this->database, $this->load_database());
$this->reject_list = array_merge($this->reject_list, $this->load_reject());
$this->reject_list[$IP] = time();
$this->database = array_merge($this->database, $this->load_database());
$this->database[$IP]["status"] = "REJECT";
$this->database[$IP]["time"] = time();
$this->save_database();
$this->save_reject();
}
public function unset_reject($IP)
{
$this->reject_list = array_merge($this->reject_list, $this->load_reject());
$this->database = array_merge($this->database, $this->load_database());
$this->database[$IP]["status"] = "REJECT";
$this->database[$IP]["time"] = time();
$this->save_database();
unset($this->reject_list[$IP]);
$this->save_reject();
}
public function get_next($R=false)
{
if($R) $this->get_list();
if(count($this->database) == 0) $this->get_list();
shuffle_assoc($this->database);
foreach ($this->database as $IP => $DATA)
{
if(isset($this->fail_list[$IP])) $this->set_fail($IP);
if(isset($this->reject_list[$IP]) && $this->reject_list[$IP] < (time()-(60*60*24*10))) $this->unset_reject($IP);
if(
isset($this->database[$IP]) &&
!isset($this->used_list[$IP]) &&
!isset($this->reject_list[$IP]) &&
!isset($this->fail_list[$IP])
)
{
if($this->database[$IP]["status"] == "NEW")
{
$this->database[$IP]["status"] = $this->check_proxy($IP)?"OK":"FAIL";
//ec("Proxy > ".$IP." > ".$this->database[$IP]["status"]);
}
if($this->database[$IP]["status"] == "OK" )
{
//ec("Use proxy > ".$IP);
$this->database[$IP]["time"] = time();
$this->used_list[$IP] = true;
$this->save_database();
return $IP;
}
if($this->database[$IP]["status"] == "FAIL") $this->set_fail($IP);
}
}
if($R) return false; else return $this->get_next(true);
}
##############################
public function load_database()
{
if(is_file($this->data_dir."proxyList.txt"))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList.txt"));
while (!is_array($data))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList.txt"));
sleep(1);
}
return $data;
}
else return array();
}
public function save_database()
{
file_put_contents($this->data_dir."proxyList.txt", serialize($this->database));
}
##############################
public function load_fail()
{
if(is_file($this->data_dir."proxyList-fail.txt"))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList-fail.txt"));
while (!is_array($data))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList-fail.txt"));
sleep(1);
}
return $data;
}
else return array();
}
public function save_fail()
{
file_put_contents($this->data_dir."proxyList-fail.txt", serialize($this->fail_list));
}
##############################
public function load_reject()
{
if(is_file($this->data_dir."proxyList-reject.txt"))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList-reject.txt"));
while (!is_array($data))
{
$data = unserialize(file_get_contents($this->data_dir."proxyList-reject.txt"));
sleep(1);
}
return $data;
}
else return array();
}
public function save_reject()
{
file_put_contents($this->data_dir."proxyList-reject.txt", serialize($this->reject_list));
}
##############################
public function get_list()
{
foreach ($this->service_list as $Service)
{
$list = $Service->get();
shuffle($list);
foreach ($list as $value)
{
if(
!isset($this->database[$value]) &&
!isset($this->fail_list[$value]) //&& !isset($this->reject_list[$value])
)
$this->database[$value] = ["IP" => $value, "status" => "NEW", "time" => time()];
}
}
}
public function add_service()
{
$arg_list = func_get_args();
foreach ($arg_list as $key => $value)
{
$this->service_list[] = new $value();
}
}
public function check_proxy($proxy)
{
if( trim( (new X_HTTP_Client(["Proxy" => $proxy, "timeout" => 5]))->GET($this->check_url) ) == $this->check_resp )
return true;
else return false;
}
}
?>
\ No newline at end of file
<?php
class X_HTTP_ProxyParser_MultiproxyOrg
{
public $URL = "http://multiproxy.org/txt_all/proxy.txt";
public $IPs = array();
private $body = false;
function __construct()
{
}
public function get()
{
$this->body = file_get_contents($this->URL);
while(preg_match('/([0-9]+).([0-9]+).([0-9]+).([0-9]+):([0-9]+)/', $this->body, $o))
{
$this->IPs[] = $o[0];
$this->body = str_replace($o[0], "", $this->body);
}
return $this->IPs;
}
public function get_next()
{
return false;
}
public function get_all()
{
return $this->get();
}
}
?>
\ No newline at end of file
<?php
class X_HTTP_ProxyParser_PrimeSpeedRu
{
public $URL = "http://www.prime-speed.ru/proxy/free-proxy-list/all-working-proxies.php";
public $IPs = array();
private $body = false;
function __construct()
{
}
public function get()
{
$this->body = file_get_contents($this->URL);
while(preg_match('/([0-9]+).([0-9]+).([0-9]+).([0-9]+):([0-9]+)/', $this->body, $o))
{
$this->IPs[] = $o[0];
$this->body = str_replace($o[0], "", $this->body);
}
return $this->IPs;
}
public function get_next()
{
return false;
}
public function get_all()
{
return $this->get();
}
}
?>
\ No newline at end of file
<?php
class X_HTTP_ProxyParser_WebanetlabsNet
{
public $URL = "http://webanetlabs.net/publ/24";
public $IPs = array();
private $body = "";
function __construct()
{
}
public function get()
{
$page = file_get_contents($this->URL);
while(preg_match('/freeproxy\/proxylist_at_([0-9]+).([0-9]+).([0-9]+).txt/', $page, $o))
{
$this->body .= file_get_contents("http://webanetlabs.net/".$o[0]);
$page = str_replace($o[0], "", $page);
}
while(preg_match('/([0-9]+).([0-9]+).([0-9]+).([0-9]+):([0-9]+)/', $this->body, $o))
{
$this->IPs[] = $o[0];
$this->body = str_replace($o[0], "", $this->body);
}
return $this->IPs;
}
public function get_next()
{
return false;
}
public function get_all()
{
return $this->get();
}
}
?>
\ No newline at end of file
<?php
class X_Proc_Stats
{
private $CPU_COUNT = 1;
private $CMD = "/bin/ps -auxw";
private $DATABASE = array();
private $RAW;
private $RAW_LINES;
function __construct($CPU_COUNT)
{
$this->CPU_COUNT = $CPU_COUNT;
$this->RAW = `$this->CMD`;
$this->RAW_LINES = explode("\n", $this->RAW);
foreach ($this->RAW_LINES as $key => $value)
{
$line = str_replace(" ", " ", $value);
$line = str_replace(" ", " ", $line);
$line = str_replace(" ", " ", $line);
$line = str_replace(" ", " ", $line);
$line = str_replace(" ", " ", $line);
$line = str_replace(" ", " ", $line);
$cols["data"] = explode(" ", $line);
$cols["raw"] = $line;
$this->DATABASE[] = $cols;
}
}
public function get_pcpu()
{
$programs = func_get_args();
$pcpu = 0;
foreach ($this->DATABASE as $key => $item) {
foreach ($item as $key => $coll) {
foreach ($programs as $program) {
if( isset($coll[10]) && $coll[10] == $program) $pcpu += $coll[2];
}
}
}
return $pcpu / $this->CPU_COUNT;
}
public function count()
{
return count($this->DATABASE);
}
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment