mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Trying to swicth to new IRCScraper
This commit is contained in:
+30
-1
@@ -9,7 +9,7 @@ require_once(dirname(__FILE__) . "/../lib/showsleep.php");
|
||||
require_once(dirname(__FILE__) . "/../lib/functions.php");
|
||||
|
||||
|
||||
$version = "0.3r1141";
|
||||
$version = "0.3r1142";
|
||||
|
||||
$db = new DB();
|
||||
$functions = new Functions();
|
||||
@@ -174,6 +174,9 @@ $killed = "false";
|
||||
$getdate = gmDate("Ymd");
|
||||
|
||||
//get microtime
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
function microtime_float()
|
||||
{
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
@@ -181,6 +184,11 @@ function microtime_float()
|
||||
return ((float)$usec + (float)$sec);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $_time
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function relativeTime($_time)
|
||||
{
|
||||
$d[0] = array(1, "sec");
|
||||
@@ -209,6 +217,11 @@ function relativeTime($_time)
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cmd
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function command_exist($cmd)
|
||||
{
|
||||
$returnVal = shell_exec("which $cmd 2>/dev/null");
|
||||
@@ -216,6 +229,9 @@ function command_exist($cmd)
|
||||
return (empty($returnVal) ? false : true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
function get_color()
|
||||
{
|
||||
$from = 1;
|
||||
@@ -234,6 +250,11 @@ function get_color()
|
||||
return $number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $bytes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function decodeSize($bytes)
|
||||
{
|
||||
$types = array('B', 'KB', 'MB', 'GB', 'TB');
|
||||
@@ -243,6 +264,9 @@ function decodeSize($bytes)
|
||||
}
|
||||
|
||||
//get system load
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function get_load()
|
||||
{
|
||||
$load = sys_getloadavg();
|
||||
@@ -250,6 +274,11 @@ function get_load()
|
||||
return $load[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pane
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function writelog($pane)
|
||||
{
|
||||
$path = dirname(__FILE__) . "/../logs";
|
||||
|
||||
@@ -0,0 +1,722 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Basic IRC client for fetching IRCScraper.
|
||||
*
|
||||
* Class IRCClient
|
||||
*/
|
||||
class IRCClient
|
||||
{
|
||||
/**
|
||||
* Hostname IRC server used when connecting.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_host = '';
|
||||
|
||||
/**
|
||||
* Port number IRC server.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_port = 6667;
|
||||
|
||||
/**
|
||||
* Socket transport type for the IRC server.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_transport = 'tcp';
|
||||
|
||||
|
||||
/**
|
||||
* Hostname the IRC server sent us back.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_host_received = '';
|
||||
|
||||
/**
|
||||
* String used when creating the stream socket.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_socket_string = '';
|
||||
|
||||
/**
|
||||
* Are we using tls/ssl?
|
||||
*
|
||||
* @var bool
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_tls = false;
|
||||
|
||||
/**
|
||||
* Time in seconds to timeout on connect.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_remote_connection_timeout = 30;
|
||||
|
||||
/**
|
||||
* Time in seconds before we timeout when sending/receiving a command.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_socket_timeout = 180;
|
||||
|
||||
/**
|
||||
* How many times to retry when connecting to IRC.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_reconnectRetries = 3;
|
||||
|
||||
/**
|
||||
* Seconds to delay when reconnecting fails.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_reconnectDelay = 5;
|
||||
|
||||
/**
|
||||
* Stream socket client.
|
||||
*
|
||||
* @var resource
|
||||
* @access protected
|
||||
*/
|
||||
protected $_socket = null;
|
||||
|
||||
/**
|
||||
* Buffer contents.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_buffer = null;
|
||||
|
||||
/**
|
||||
* When someone types something into a channel, buffer it.
|
||||
* array(
|
||||
* 'nickname' => string(The nick name of the person who posted.),
|
||||
* 'channel' => string(The channel name.),
|
||||
* 'message' => string(The message the person posted.)
|
||||
* );
|
||||
*
|
||||
* @note Used with the processChannelMessages() function.
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $_channelData = array();
|
||||
|
||||
/**
|
||||
* Nick name when we log in.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_nickName;
|
||||
|
||||
/**
|
||||
* User name when we log in.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_userName;
|
||||
|
||||
/**
|
||||
* "Real" name when we log in.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_realName;
|
||||
|
||||
/**
|
||||
* Password when we log in.
|
||||
*
|
||||
* @var string
|
||||
* @access protected
|
||||
*/
|
||||
protected $_password;
|
||||
|
||||
/**
|
||||
* List of channels and passwords to join.
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
protected $_channels;
|
||||
|
||||
/**
|
||||
* Last time we received a ping or sent a ping to the server.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_lastPing;
|
||||
|
||||
/**
|
||||
* How many times we've tried to reconnect to IRC.
|
||||
*
|
||||
* @var int
|
||||
* @access protected
|
||||
*/
|
||||
protected $_currentRetries = 0;
|
||||
|
||||
/**
|
||||
* Turns on or off debugging.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_debug = true;
|
||||
|
||||
/**
|
||||
* Are we already logged in to IRC?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_alreadyLoggedIn = false;
|
||||
|
||||
/**
|
||||
* Disconnect from IRC.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->quit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Time before giving up when trying to read or write to the IRC server.
|
||||
* The default is fine, it will ping the server if the server does not ping us
|
||||
* within this time to keep the connection alive.
|
||||
*
|
||||
* @param int $timeout Seconds.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setSocketTimeout($timeout)
|
||||
{
|
||||
if (!is_numeric($timeout)) {
|
||||
echo 'ERROR: IRC socket timeout must be a number!' . PHP_EOL;
|
||||
} else {
|
||||
$this->_socket_timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of time to wait before giving up when connecting.
|
||||
*
|
||||
* @param int $timeout Seconds.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setConnectionTimeout($timeout)
|
||||
{
|
||||
if (!is_numeric($timeout)) {
|
||||
echo 'ERROR: IRC connection timeout must be a number!' . PHP_EOL;
|
||||
} else {
|
||||
$this->_remote_connection_timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of times to retry before giving up when connecting.
|
||||
*
|
||||
* @param int $retries
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setConnectionRetries($retries)
|
||||
{
|
||||
if (!is_numeric($retries)) {
|
||||
echo 'ERROR: IRC connection retries must be a number!' . PHP_EOL;
|
||||
} else {
|
||||
$this->_reconnectRetries = $retries;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of time to wait between failed connects.
|
||||
*
|
||||
* @param int $delay Seconds.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function setReConnectDelay($delay)
|
||||
{
|
||||
if (!is_numeric($delay)) {
|
||||
echo 'ERROR: IRC reconnect delay must be a number!' . PHP_EOL;
|
||||
} else {
|
||||
$this->_reconnectDelay = $delay;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a IRC server.
|
||||
*
|
||||
* @param string $hostname Host name of the IRC server (can be a IP or a name).
|
||||
* @param int $port Port number of the IRC server.
|
||||
* @param bool $tls Use encryption for the socket transport? (make sure the port is right).
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function connect($hostname, $port = 6667, $tls = false)
|
||||
{
|
||||
$this->_alreadyLoggedIn = false;
|
||||
$transport = ($tls === true ? 'tls' : 'tcp');
|
||||
|
||||
$socket_string = $transport . '://' . $hostname . ':' . $port;
|
||||
if ($socket_string !== $this->_remote_socket_string || !$this->_connected()) {
|
||||
if (!is_string($hostname) || $hostname == '') {
|
||||
echo 'ERROR: IRC host name must not be empty!' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_numeric($port)) {
|
||||
echo 'ERROR: IRC port must be a number!' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_remote_host = $hostname;
|
||||
$this->_remote_port = $port;
|
||||
$this->_remote_transport = $transport;
|
||||
$this->_remote_tls = $tls;
|
||||
$this->_remote_socket_string = $socket_string;
|
||||
|
||||
// Try to connect until we run out of retries.
|
||||
while ($this->_reconnectRetries >= $this->_currentRetries++) {
|
||||
$this->_initiateStream();
|
||||
if ($this->_connected()) {
|
||||
break;
|
||||
} else {
|
||||
// Sleep between retries.
|
||||
sleep($this->_reconnectDelay);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_alreadyLoggedIn = true;
|
||||
}
|
||||
|
||||
// Set last ping time to now.
|
||||
$this->_lastPing = time();
|
||||
// Reset retries.
|
||||
$this->_currentRetries = $this->_reconnectRetries;
|
||||
|
||||
return $this->_connected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in to a IRC server.
|
||||
*
|
||||
* @param string $nickName The nick name - visible in the channel.
|
||||
* @param string $userName The user name - visible in the host name.
|
||||
* @param string $realName The real name - visible in the WhoIs.
|
||||
* @param null $password The password - some servers require a password.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function login($nickName, $userName, $realName, $password = null)
|
||||
{
|
||||
if (!$this->_connected()) {
|
||||
echo 'ERROR: You must connect to IRC first!' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($nickName) || empty($userName) || empty($realName)) {
|
||||
echo 'ERROR: nick/user/real name must not be empty!' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_nickName = $nickName;
|
||||
$this->_userName = $userName;
|
||||
$this->_realName = $realName;
|
||||
$this->_password = $password;
|
||||
|
||||
if (($password !== null && !empty($password)) && !$this->_writeSocket('PASSWORD ' . $password)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_writeSocket('NICK ' . $nickName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->_writeSocket('USER ' . $userName . ' 0 * :' . $realName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Loop over socket buffer until we find "001".
|
||||
while (true) {
|
||||
$this->_readSocket();
|
||||
|
||||
// We got pinged, reply with a pong.
|
||||
if (preg_match('/^PING\s*:(.+?)$/', $this->_buffer, $matches)) {
|
||||
$this->_pong($matches[1]);
|
||||
|
||||
} else if (preg_match('/^:(.*?)\s*(\d+).*?(:.+?)?$/', $this->_buffer, $matches)) {
|
||||
// We found 001, which means we are logged in.
|
||||
if ($matches[2] == 001) {
|
||||
$this->_remote_host_received = $matches[1];
|
||||
break;
|
||||
|
||||
// We got 464, which means we need to send a password.
|
||||
} else if ($matches[2] == 464) {
|
||||
// Before the lower check, set the password : username:password
|
||||
$tempPass = $userName . ':' . $password;
|
||||
|
||||
// Check if the user has his password in this format: username/server:password
|
||||
if (preg_match('/^.+?\/.+?:.+?$/', $password)) {
|
||||
$tempPass = $password;
|
||||
}
|
||||
|
||||
if ($password !== null && !$this->_writeSocket('PASS ' . $tempPass)) {
|
||||
return false;
|
||||
} else if (isset($matches[3]) && strpos(strtolower($matches[3]), 'invalid password')) {
|
||||
echo 'Invalid password or username for (' . $this->_remote_host . ').';
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//ERROR :Closing Link: kevin123[100.100.100.100] (This server is full.)
|
||||
} else if (preg_match('/^ERROR\s*:/', $this->_buffer)) {
|
||||
echo $this->_buffer . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quit from IRC.
|
||||
*
|
||||
* @param string $message Optional disconnect message.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function quit($message = null)
|
||||
{
|
||||
if ($this->_connected()) {
|
||||
$this->_writeSocket('QUIT' . ($message === null ? '' : ' :' . $message));
|
||||
}
|
||||
$this->_closeStream();
|
||||
|
||||
return $this->_connected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the incoming buffer in a loop.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function readIncoming()
|
||||
{
|
||||
while (true) {
|
||||
|
||||
$this->_readSocket();
|
||||
|
||||
// If the server pings us, return it a pong.
|
||||
if (preg_match('/^PING\s*:(.+?)$/', $this->_buffer, $matches)) {
|
||||
if ($matches[1] === $this->_remote_host_received) {
|
||||
$this->_pong($matches[1]);
|
||||
}
|
||||
|
||||
// Check for a channel message.
|
||||
} else if (preg_match('/^:(?P<nickname>.+?)\!.+?\s+PRIVMSG\s+(?P<channel>#.+?)\s+:\s*(?P<message>.+?)\s*$/',
|
||||
$this->_stripControlCharacters($this->_buffer),
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
|
||||
$this->_channelData =
|
||||
array(
|
||||
'nickname' => $matches['nickname'],
|
||||
'channel' => $matches['channel'],
|
||||
'message' => $matches['message']
|
||||
);
|
||||
|
||||
$this->processChannelMessages();
|
||||
}
|
||||
|
||||
// Ping the server if it has not sent us a ping in a while.
|
||||
if ((time() - $this->_lastPing) > ($this->_socket_timeout / 2)) {
|
||||
$this->_ping($this->_remote_host_received);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a channel or multiple channels.
|
||||
*
|
||||
* @param array $channels Array of channels with their passwords (null if the channel doesn't need a password).
|
||||
* array( '#exampleChannel' => 'thePassword', '#exampleChan2' => null );
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function joinChannels($channels = array())
|
||||
{
|
||||
$this->_channels = $channels;
|
||||
|
||||
if (!$this->_connected()) {
|
||||
echo 'ERROR: You must connect to IRC first!' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($channels)) {
|
||||
foreach ($channels as $channel => $password) {
|
||||
$this->_joinChannel($channel, $password);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation.
|
||||
* Extended classes will use this function to parse the messages in the channel using $this->_channelData.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function processChannelMessages()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a channel.
|
||||
*
|
||||
* @param string $channel
|
||||
* @param string $password
|
||||
*
|
||||
* @access protected.
|
||||
*/
|
||||
protected function _joinChannel($channel, $password)
|
||||
{
|
||||
$this->_writeSocket('JOIN ' . $channel . ($password === null ? '' : ' ' . $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send PONG to a host.
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _pong($host)
|
||||
{
|
||||
if ($this->_writeSocket('PONG ' . $host) === false) {
|
||||
$this->_reconnect();
|
||||
}
|
||||
|
||||
// If we got a ping from the IRC server, set the last ping time to now.
|
||||
if ($host === $this->_remote_host_received) {
|
||||
$this->_lastPing = time();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send PING to a host.
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _ping($host)
|
||||
{
|
||||
$pong = $this->_writeSocket('PING ' . $host);
|
||||
|
||||
// Check if there's a connection error.
|
||||
if ($pong === false || ((time() - $this->_lastPing) > ($this->_socket_timeout / 2) && !preg_match('/^PONG/', $this->_buffer))) {
|
||||
$this->_reconnect();
|
||||
}
|
||||
|
||||
// If sent a ping from the IRC server, set the last ping time to now.
|
||||
if ($host === $this->_remote_host_received) {
|
||||
$this->_lastPing = time();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to reconnect to IRC.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _reconnect()
|
||||
{
|
||||
if (!$this->connect($this->_remote_host, $this->_remote_port, $this->_remote_tls)) {
|
||||
exit('FATAL: Could not reconnect to (' . $this->_remote_host . ') after (' . $this->_reconnectRetries . ') tries.' . PHP_EOL);
|
||||
}
|
||||
|
||||
if ($this->_alreadyLoggedIn === false) {
|
||||
if (!$this->login($this->_nickName, $this->_userName, $this->_realName, $this->_password)) {
|
||||
exit('FATAL: Could not log in to (' . $this->_remote_host . ')!' . PHP_EOL);
|
||||
}
|
||||
|
||||
$this->joinChannels($this->_channels);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read response from the IRC server.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _readSocket()
|
||||
{
|
||||
$buffer = '';
|
||||
do {
|
||||
stream_set_timeout($this->_socket, $this->_socket_timeout);
|
||||
$buffer .= fgets($this->_socket, 1024);
|
||||
} while (!empty($buffer) && !preg_match('/\v+$/', $buffer));
|
||||
$this->_buffer = trim($buffer);
|
||||
|
||||
if ($this->_debug && $this->_buffer !== '') {
|
||||
echo 'RECV ' . $this->_buffer . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a command to the IRC server.
|
||||
*
|
||||
* @param string $command
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _writeSocket($command)
|
||||
{
|
||||
$command .= "\r\n";
|
||||
for ($written = 0; $written < strlen($command); $written += $fWrite) {
|
||||
stream_set_timeout($this->_socket, $this->_socket_timeout);
|
||||
$fWrite = $this->_writeSocketChar(substr($command, $written));
|
||||
|
||||
// http://www.php.net/manual/en/function.fwrite.php#96951 | fwrite can return 0 causing an infinite loop.
|
||||
if ($fWrite === false || $fWrite <= 0) {
|
||||
|
||||
// If it failed, try a second time.
|
||||
$fWrite = $this->_writeSocketChar(substr($command, $written));
|
||||
if ($fWrite === false || $fWrite <= 0) {
|
||||
echo 'ERROR: Could no write to socket! (the IRC server might have closed the connection)' . PHP_EOL;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_debug) {
|
||||
echo 'SEND :' . $command;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a single character to the socket.
|
||||
*
|
||||
* @param string (char) $character A single character.
|
||||
*
|
||||
* @return int|bool Number of bytes written or false.
|
||||
*/
|
||||
protected function _writeSocketChar($character)
|
||||
{
|
||||
return @fwrite($this->_socket, $character);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate stream socket to IRC server.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _initiateStream()
|
||||
{
|
||||
$this->_closeStream();
|
||||
|
||||
$socket = stream_socket_client(
|
||||
$this->_remote_socket_string,
|
||||
$error_number,
|
||||
$error_string,
|
||||
$this->_remote_connection_timeout
|
||||
);
|
||||
|
||||
if ($socket === false) {
|
||||
echo 'ERROR: ' . $error_string . ' (' . $error_number . ')' . PHP_EOL;
|
||||
} else {
|
||||
$this->_socket = $socket;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the socket.
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _closeStream()
|
||||
{
|
||||
if (!is_null($this->_socket)) {
|
||||
$this->_socket = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are connected to the IRC server.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _connected()
|
||||
{
|
||||
return (is_resource($this->_socket) && !feof($this->_socket));
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips control characters from a IRC message.
|
||||
*
|
||||
* @param string $text
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function _stripControlCharacters($text)
|
||||
{
|
||||
return preg_replace(
|
||||
array(
|
||||
'/(\x03(?:\d{1,2}(?:,\d{1,2})?)?)/', // Color code
|
||||
'/\x02/', // Bold
|
||||
'/\x0F/', // Escaped
|
||||
'/\x16/', // Italic
|
||||
'/\x1F/', // Underline
|
||||
'/\x12/' // Device control 2
|
||||
),
|
||||
'',
|
||||
$text
|
||||
);
|
||||
}
|
||||
}
|
||||
+163
-742
File diff suppressed because it is too large
Load Diff
+16
-40
@@ -3,59 +3,35 @@ require_once(dirname(__FILE__) . "/../../bin/config.php");
|
||||
require_once(dirname(__FILE__) . '/../Net_SmartIRC/Net/SmartIRC.php');
|
||||
require_once(dirname(__FILE__) . "/../IRCScraper.php");
|
||||
require_once 'settings.php';
|
||||
|
||||
if (!is_file('/var/www/newznab/misc/update_scripts/nix_scripts/tmux/lib/IRCScraper/settings.php')) {
|
||||
exit('Copy settings_example.php to settings.php and change the settings.' . PHP_EOL);
|
||||
}
|
||||
|
||||
if (!isset($argv[1])) {
|
||||
if (!isset($argv[1]) || $argv[1] !== 'true') {
|
||||
exit(
|
||||
'Argument 1: cz|efnet ; Scrape efnet or corrupt/zenet.' . PHP_EOL .
|
||||
' ; Both zenet and corrupt pre the same, so pick one or the other in settings.php' . PHP_EOL .
|
||||
' ; You can run efnet at the same time as corrupt or zenet.' . PHP_EOL .
|
||||
'Argument 2: (optional) false|true ; True runs in silent mode (no text output)' . PHP_EOL .
|
||||
'Argument 3: (optional) false|true ; True turns on debug (not recommended)' . PHP_EOL .
|
||||
'Argument 4: (optional) false|true ; True uses real sockets(faster), false uses fsock. If you have issues with real sockets, try fsock.' . PHP_EOL .
|
||||
'ex:' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' efnet ; Scrapes efnet with text output.' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' cz true > /dev/null 2>&1 ; (unix) Scrapes corrupt/zenet with no text output, in the background (you can close your terminal window).' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' efnet true ; Scrapes efnet with no text output, keeps lock on terminal (closing terminal kills the scraping).' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' cz true true ; Scrapes corrupt/zenet with text output and debug output.' . PHP_EOL
|
||||
'Argument 1: false|true ; false prints this help screen, true runs the scraper.' . PHP_EOL .
|
||||
'Argument 2: (optional) false|true ; true runs in silent mode (no text output)' . PHP_EOL .
|
||||
'Argument 3: (optional) false|true ; true turns on debug (shows sent/received messages from the socket)' . PHP_EOL .
|
||||
'examples:' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true ; Scrapes PRE with text output.' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true true > /dev/null 2>&1 ; (unix) Scrapes PRE with no text output, in the background (you can close your terminal window).' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true false true ; Scrapes PRE with text output and debug output.' . PHP_EOL .
|
||||
'php ' . $argv[0] . ' true true true ; Scrapes PRE with debug but no text output.' . PHP_EOL
|
||||
);
|
||||
}
|
||||
|
||||
if (!in_array($argv[1], array('efnet', 'cz'))) {
|
||||
exit('Error, must be efnet or cz, you typed: ' . $argv[1] . PHP_EOL);
|
||||
require_once '/var/www/newznab/misc/update_scripts/nix_scripts/tmux/lib/IRCScraper/settings.php';
|
||||
|
||||
if (!defined('SCRAPE_IRC_NICKNAME')) {
|
||||
exit('ERROR! You must update settings.php using settings_example.php.');
|
||||
}
|
||||
|
||||
if (!defined('SCRAPE_IRC_EFNET_NICKNAME') ||
|
||||
!defined('SCRAPE_IRC_CORRUPT_NICKNAME') ||
|
||||
!defined('SCRAPE_IRC_ZENET_NICKNAME')
|
||||
) {
|
||||
exit ('ERROR! You must update your settings.php using settings_example.php' . PHP_EOL);
|
||||
}
|
||||
|
||||
if (SCRAPE_IRC_EFNET_NICKNAME == '' || SCRAPE_IRC_CORRUPT_NICKNAME == '' || SCRAPE_IRC_ZENET_NICKNAME == '') {
|
||||
if (SCRAPE_IRC_NICKNAME == '') {
|
||||
exit("ERROR! You must put a username in settings.php" . PHP_EOL);
|
||||
}
|
||||
|
||||
if ($argv[1] === 'cz') {
|
||||
if (SCRAPE_IRC_C_Z_BOOL === true) {
|
||||
$argv[1] = 'corrupt';
|
||||
} else {
|
||||
$argv[1] = 'zenet';
|
||||
}
|
||||
}
|
||||
|
||||
$silent = ((isset($argv[2]) && $argv[2] === 'true') ? true : false);
|
||||
$debug = ((isset($argv[3]) && $argv[3] === 'true') ? true : false);
|
||||
$socket = ((isset($argv[4]) && $argv[4] === 'false') ? false : true);
|
||||
|
||||
// Net_SmartIRC started here, or else globals are not properly set.
|
||||
new IRCScraper(
|
||||
new Net_SmartIRC(),
|
||||
$argv[1],
|
||||
$silent,
|
||||
$debug,
|
||||
$socket
|
||||
);
|
||||
// Start scraping.
|
||||
new IRCScraper($silent, $debug);
|
||||
@@ -3,33 +3,43 @@
|
||||
// MAKE SURE THIS IS UNIQUE, IF SOMEONE HAS THE USERNAME ALREADY YOU WILL GET A BUNCH OF ERRORS, YOU HAVE BEEN WARNED.
|
||||
$username = '';
|
||||
|
||||
// EFNET server details.
|
||||
define('SCRAPE_IRC_EFNET_SERVER', 'irc.Prison.NET'); // Efnet server address, change if you have issues connecting.
|
||||
define('SCRAPE_IRC_EFNET_PORT', '6667'); // Port for efnet server.
|
||||
define('SCRAPE_IRC_EFNET_NICKNAME', "$username"); // Nick name (this is the nickname everyone sees in the channel)
|
||||
define('SCRAPE_IRC_EFNET_REALNAME', "$username"); // This is a name that people see in /whois, you can set this to your nickname.
|
||||
define('SCRAPE_IRC_EFNET_USERNAME', "$username"); // This is part of your hostname, you can set this the same as nickname. This is also used to log in to ZNC.
|
||||
define('SCRAPE_IRC_EFNET_PASSWORD', false); // This is used for bouncers like ZNC, set this false or '' if you don't have a bouncer.
|
||||
define('SCRAPE_IRC_EFNET_ENCRYPTION', false); // Set to true to use TLS encryption (make sure you change the port to a SSL one).
|
||||
// List of ignored channels, separated by commas. ie '#alt.binaries.teevee,#alt.binaries.moovee' for a single channel : '#alt.binaries.teevee'
|
||||
define('SCRAPE_IRC_EFNET_IGNORED_CHANNELS', '');
|
||||
|
||||
define('SCRAPE_IRC_C_Z_BOOL', false); // True uses Corrupt, False uses Zenet. (they both PRE the same stuff). If you have trouble with one, use the other.
|
||||
|
||||
// Corrupt-Net server details.
|
||||
define('SCRAPE_IRC_CORRUPT_SERVER', 'irc.corrupt-net.org'); // This should not be changed, since this is the only address to corrupt.
|
||||
define('SCRAPE_IRC_CORRUPT_PORT', '6667');
|
||||
define('SCRAPE_IRC_CORRUPT_NICKNAME', "$username");
|
||||
define('SCRAPE_IRC_CORRUPT_REALNAME', "$username");
|
||||
define('SCRAPE_IRC_CORRUPT_USERNAME', "$username");
|
||||
define('SCRAPE_IRC_CORRUPT_PASSWORD', false);
|
||||
define('SCRAPE_IRC_CORRUPT_ENCRYPTION', false);
|
||||
|
||||
// Zenet server details.
|
||||
define('SCRAPE_IRC_ZENET_SERVER', 'irc.zenet.org');
|
||||
define('SCRAPE_IRC_ZENET_PORT', '6667');
|
||||
define('SCRAPE_IRC_ZENET_NICKNAME', "$username");
|
||||
define('SCRAPE_IRC_ZENET_REALNAME', "$username");
|
||||
define('SCRAPE_IRC_ZENET_USERNAME', "$username");
|
||||
define('SCRAPE_IRC_ZENET_PASSWORD', false);
|
||||
define('SCRAPE_IRC_ZENET_ENCRYPTION', false);
|
||||
// https://www.synirc.net/servers Try another server if you have issues.
|
||||
define('SCRAPE_IRC_SERVER', 'contego.ny.us.synirc.net');
|
||||
// Use Port 6697 or 7001 and set SCRAPE_IRC_TLS to true for encryption.
|
||||
define('SCRAPE_IRC_PORT', '6667');
|
||||
define('SCRAPE_IRC_TLS', false);
|
||||
define('SCRAPE_IRC_NICKNAME', "$username");
|
||||
define('SCRAPE_IRC_REALNAME', "$username");
|
||||
define('SCRAPE_IRC_USERNAME', "$username");
|
||||
// Set to false if you need no password. Use a string (quoted text) if you need a password.
|
||||
define('SCRAPE_IRC_PASSWORD', false);
|
||||
// Regex to ignore categories. Leave empty ('') to not exclude any category.
|
||||
// Case sensitive example: '/^(XXX|PDA|EBOOK|MP3)$/'
|
||||
// Case insensitive (note the i): '/^(X264|TV)$/i'
|
||||
define('SCRAPE_IRC_CATEGORY_IGNORE', '');
|
||||
// Set to true to ignore a source.
|
||||
define('SCRAPE_IRC_SOURCE_IGNORE',
|
||||
serialize(
|
||||
array(
|
||||
'#a.b.cd.image' => false,
|
||||
'#a.b.console.ps3' => false,
|
||||
'#a.b.dvd' => false,
|
||||
'#a.b.erotica' => false,
|
||||
'#a.b.flac' => false,
|
||||
'#a.b.foreign' => false,
|
||||
'#a.b.games.nintendods' => false,
|
||||
'#a.b.inner-sanctum' => false,
|
||||
'#a.b.moovee' => false,
|
||||
'#a.b.movies.divx' => false,
|
||||
'#a.b.sony.psp' => false,
|
||||
'#a.b.sounds.mp3.complete_cd' => false,
|
||||
'#a.b.teevee' => false,
|
||||
'#a.b.games.wii' => false,
|
||||
'#a.b.warez' => false,
|
||||
'#a.b.games.xbox360' => false,
|
||||
'#pre@corrupt' => false,
|
||||
'#scnzb' => false,
|
||||
'#tvnzb' => false
|
||||
)
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user