init
This commit is contained in:
436
standalone/cerberus.php
Executable file
436
standalone/cerberus.php
Executable file
@@ -0,0 +1,436 @@
|
||||
<?php
|
||||
|
||||
/* Main (Exemple) */
|
||||
|
||||
session_start();
|
||||
//session_destroy();
|
||||
|
||||
pre($_COOKIE, 'Cookie');
|
||||
pre($_SESSION, 'Session');
|
||||
pre($_REQUEST, 'Request');
|
||||
|
||||
//default values of reserved POST keys
|
||||
$sLogin = array_key_exists('login', $_POST)?$_POST['login']:'';
|
||||
$sPass = array_key_exists('pass', $_POST)?$_POST['pass']:'';
|
||||
$sPage = array_key_exists('p', $_REQUEST)?$_REQUEST['p']:'';
|
||||
$sAction = array_key_exists('a', $_POST)?$_POST['a']:'';
|
||||
$sPostToken = array_key_exists('post_token', $_POST)?$_POST['post_token']:'';
|
||||
|
||||
$oMySql = new MySqlManager();
|
||||
$oCerberus = new Cerberus($oMySql, array(Cerberus::OPTION_AUTO_LOGON=>true, Cerberus::OPTION_RENEW_TOKEN=>true));
|
||||
|
||||
//logging In / Out
|
||||
if($sAction=='logout')
|
||||
{
|
||||
$oCerberus->logMeOut();
|
||||
}
|
||||
else/*if(($sLogin=='' && $sPass=='') || $oCerberus->checkPostToken($sPostToken))*/
|
||||
{
|
||||
$oCerberus->logMeIn($sLogin, $sPass);
|
||||
}
|
||||
/*else
|
||||
{
|
||||
echo 'pouet';
|
||||
}*/
|
||||
|
||||
$sLayout = $sMenu = '';
|
||||
if($oCerberus->isLogguedIn())
|
||||
{
|
||||
$sMenu = '<form method="post"><input type="submit" name="a" value="logout">Log out</a><hr /></form>';
|
||||
$sLayout = 'Loggued In. '.$oCerberus->getNewPostToken();
|
||||
}
|
||||
else
|
||||
{
|
||||
$sLayout = '<form name="login" method="post">
|
||||
Login <input type="text" name="login" />
|
||||
pass <input type="text" name="pass" />
|
||||
<input type="hidden" name="post_token" value="'.$oCerberus->getNewPostToken().'" />
|
||||
<input type="submit" value="ok" />
|
||||
</form>';
|
||||
}
|
||||
|
||||
$sErrors = $oCerberus->getCleanMessages();
|
||||
|
||||
echo '<html><head><title>Cerberus</title></head><body>'.$sMenu."\n".$sLayout.'<br />'.$sErrors.'</body></html>';
|
||||
pre('new session post token : '.$_SESSION[Cerberus::SESSION_POST_TOKEN]);
|
||||
|
||||
/* Class */
|
||||
|
||||
/* Requirements */
|
||||
require_once 'functions.php';
|
||||
require_once 'php_object.php';
|
||||
require_once 'mysql_manager.php';
|
||||
|
||||
/**
|
||||
* Cerberus
|
||||
* Access control class
|
||||
* @author FranzZ
|
||||
*
|
||||
* Requirements:
|
||||
* Database with DB_TABLE_USER table and fields:
|
||||
* - DB_FIELD_ID_USER
|
||||
* - DB_FIELD_LOGIN
|
||||
* - DB_FIELD_PASS
|
||||
* - DB_FIELD_TOKEN
|
||||
*
|
||||
* Setup:
|
||||
* - Replace required tables and fields names with the mysql manager constants
|
||||
* - Set options :
|
||||
* - Cerberus::OPTION_AUTO_LOGON
|
||||
* - Cerberus::OPTION_RENEW_TOKEN
|
||||
*/
|
||||
class Cerberus extends PhpObject
|
||||
{
|
||||
// Database
|
||||
private $oMySql;
|
||||
const DB_TABLE_USER = MySqlManager::USER_TABLE;
|
||||
const DB_FIELD_ID_USER = 'id_user';
|
||||
const DB_FIELD_LOGIN = 'user';
|
||||
const DB_FIELD_PASS = 'pass';
|
||||
const DB_FIELD_TOKEN = 'token';
|
||||
|
||||
//Session
|
||||
const SESSION_ID_USER = self::DB_FIELD_ID_USER;
|
||||
const SESSION_LOGIN = self::DB_FIELD_LOGIN;
|
||||
const SESSION_TOKEN = self::DB_FIELD_TOKEN;
|
||||
const SESSION_POST_TOKEN = 'post_token';
|
||||
|
||||
//Cookie
|
||||
const COOKIE_ID_USER = self::DB_FIELD_ID_USER;
|
||||
const COOKIE_TOKEN = self::DB_FIELD_TOKEN;
|
||||
const COOKIE_POST_TOKEN = self::SESSION_POST_TOKEN;
|
||||
|
||||
//Options
|
||||
const OPTION_AUTO_LOGON = 'auto_logon';
|
||||
const OPTION_RENEW_TOKEN = 'renew_token';
|
||||
public $abOptions;
|
||||
|
||||
//Session Variables
|
||||
private $iUserId;
|
||||
private $sLogin;
|
||||
private $sToken;
|
||||
private $sPostToken;
|
||||
|
||||
public function __construct(&$oMySql, $abOptions)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->iUserId = $this->sLogin = $this->sToken = $this->sPostToken = false;
|
||||
$this->oMySql = $oMySql;
|
||||
$this->setOptions($abOptions);
|
||||
$this->syncSession();
|
||||
}
|
||||
|
||||
private function setOptions($abOptions)
|
||||
{
|
||||
//default values
|
||||
$this->abOptions = array(self::OPTION_AUTO_LOGON=>false, self::OPTION_RENEW_TOKEN=>true);
|
||||
$this->abOptions = array_merge($this->abOptions, $abOptions);
|
||||
}
|
||||
|
||||
private function getOption($sOptionName)
|
||||
{
|
||||
return $this->abOptions[$sOptionName];
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->iUserId;
|
||||
}
|
||||
|
||||
private function syncSession()
|
||||
{
|
||||
if(isset($_SESSION[self::SESSION_ID_USER]))
|
||||
{
|
||||
$this->iUserId = $_SESSION[self::SESSION_ID_USER];
|
||||
}
|
||||
if(isset($_SESSION[self::SESSION_LOGIN]))
|
||||
{
|
||||
$this->sLogin = $_SESSION[self::SESSION_LOGIN];
|
||||
}
|
||||
if(isset($_SESSION[self::SESSION_TOKEN]))
|
||||
{
|
||||
$this->sToken = $_SESSION[self::SESSION_TOKEN];
|
||||
}
|
||||
if(isset($_SESSION[self::SESSION_POST_TOKEN]))
|
||||
{
|
||||
$this->sPostToken = $_SESSION[self::SESSION_POST_TOKEN];
|
||||
}
|
||||
}
|
||||
|
||||
public function register($asData)
|
||||
{
|
||||
//data to register
|
||||
//TODO To be customized
|
||||
$sLogin = strtolower(trim($asData[self::DB_FIELD_LOGIN]));
|
||||
$sPass = $asData[self::DB_FIELD_PASS];
|
||||
|
||||
if($sLogin=='' || $sPass=='')
|
||||
{
|
||||
$this->addError('Empty mandatory fields (Nickname or password)');
|
||||
}
|
||||
elseif(htmlspecialchars($sLogin, ENT_QUOTES)!=$sLogin)
|
||||
{
|
||||
$this->addError('Nickname: HTML characters are forbidden');
|
||||
}
|
||||
elseif($this->checkAccount($sLogin))
|
||||
{
|
||||
$this->addError('Nickname: There is already a user called by that name, choose a different one');
|
||||
}
|
||||
else
|
||||
{
|
||||
$asData[self::DB_FIELD_LOGIN] = $sLogin;
|
||||
$asData[self::DB_FIELD_PASS] = self::encryptPassword($sPass);
|
||||
$this->oMySql->insertRow(self::DB_TABLE_USER, $asData);
|
||||
return $this->logMeIn($sLogin, $sPass);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function logMeIn($sLogin='', $sPass='')
|
||||
{
|
||||
$bResult = false;
|
||||
$bFirstLogin = true;
|
||||
if($sLogin=='' || $sPass=='')
|
||||
{
|
||||
$bFirstLogin = false;
|
||||
if($this->iUserId && $this->sLogin && $this->sToken && $this->checkToken())
|
||||
{
|
||||
//log in with session variables
|
||||
$iUserId = $this->iUserId;
|
||||
$sLogin = $this->sLogin;
|
||||
$sToken = $this->sToken;
|
||||
$bResult = true;
|
||||
}
|
||||
elseif($this->getOption(self::OPTION_AUTO_LOGON) && $this->checkToken(true))
|
||||
{
|
||||
//log in with cookies
|
||||
$iUserId = $_COOKIE[self::COOKIE_ID_USER];
|
||||
$sLogin = $this->oMySql->selectValue(self::DB_TABLE_USER, self::DB_FIELD_LOGIN, $iUserId);
|
||||
$sToken = $_COOKIE[self::COOKIE_TOKEN];
|
||||
$bResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addWarning('No login info (cookie / session)');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$asUser = $this->getUser($sLogin);
|
||||
if(!$asUser)
|
||||
{
|
||||
$this->addError('Unknown user');
|
||||
}
|
||||
elseif(!$this->checkPassword($sPass, $asUser[self::DB_FIELD_PASS]))
|
||||
{
|
||||
$this->addError('Incorrect password');
|
||||
}
|
||||
else
|
||||
{
|
||||
$iUserId = $asUser[self::DB_FIELD_ID_USER];
|
||||
$sToken = $asUser[self::DB_FIELD_TOKEN];
|
||||
$bResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($bResult)
|
||||
{
|
||||
//Class
|
||||
$this->iUserId = $iUserId;
|
||||
$this->sLogin = $sLogin;
|
||||
$this->sToken = $sToken;
|
||||
|
||||
//Session
|
||||
$_SESSION[self::SESSION_ID_USER] = $iUserId;
|
||||
$_SESSION[self::SESSION_LOGIN] = $sLogin;
|
||||
$_SESSION[self::SESSION_TOKEN] = $sToken;
|
||||
|
||||
//Cookie (doesn't leave any password nor login on user's computer)
|
||||
self::setCookie(self::COOKIE_ID_USER, $iUserId);
|
||||
self::setCookie(self::COOKIE_TOKEN, $sToken);
|
||||
|
||||
//reset pass
|
||||
if($bFirstLogin || $this->getOption(self::OPTION_RENEW_TOKEN))
|
||||
{
|
||||
$this->resetToken();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->logMeOut();
|
||||
}
|
||||
|
||||
return $bResult;
|
||||
}
|
||||
|
||||
public function isLogguedIn()
|
||||
{
|
||||
$bLogguedIn = false;
|
||||
if($this->iUserId && $this->sLogin && $this->sToken)
|
||||
{
|
||||
//check if token is set and valid
|
||||
if($this->checkToken())
|
||||
{
|
||||
//Check if user got a actual account in the database
|
||||
$bLogguedIn = $this->checkAccount($this->sLogin, $this->iUserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->addError('Authentication problem, please sign in again');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
echo "[TEST]<br />check token :
|
||||
<br />db token ", $this->iUserId." - ".$this->getDbToken($this->iUserId),"
|
||||
<br />session token ", $_SESSION[self::SESSION_TOKEN], "
|
||||
<br />class token ", $this->sToken, "
|
||||
<br />cookie token ", $_COOKIE[self::COOKIE_TOKEN], '<br />[/TEST]';
|
||||
*/
|
||||
|
||||
return $bLogguedIn;
|
||||
}
|
||||
|
||||
public function logMeOut()
|
||||
{
|
||||
//Database
|
||||
if($this->iUserId)
|
||||
{
|
||||
$this->oMySql->updateRow(self::DB_TABLE_USER, $this->iUserId, array(self::DB_FIELD_TOKEN=>''));
|
||||
}
|
||||
|
||||
//Class variables
|
||||
$this->iUserId = $this->sLogin = $this->sToken = $this->sPostToken = false;
|
||||
|
||||
//Cookie
|
||||
self::setCookie(self::COOKIE_TOKEN, '', -1);
|
||||
self::setCookie(self::COOKIE_ID_USER, '', -1);
|
||||
|
||||
//Server session
|
||||
$_SESSION = array();
|
||||
return session_destroy();
|
||||
}
|
||||
|
||||
private function checkAccount($sUserName, $iUserId=0)
|
||||
{
|
||||
$asConstraints = array(self::DB_FIELD_LOGIN=>$sUserName);
|
||||
if($iUserId>0)
|
||||
{
|
||||
$asConstraints[self::DB_FIELD_ID_USER] = $iUserId;
|
||||
}
|
||||
return $this->oMySql->selectValue(self::DB_TABLE_USER, 'COUNT(1)', $asConstraints);
|
||||
}
|
||||
|
||||
private function getUser($oUser)
|
||||
{
|
||||
$sField = is_numeric($oUser)?self::DB_FIELD_ID_USER:self::DB_FIELD_LOGIN;
|
||||
return $this->oMySql->selectRow(self::DB_TABLE_USER, array($sField=>$oUser));
|
||||
}
|
||||
|
||||
public static function encryptPassword($sPass)
|
||||
{
|
||||
$sRandomText = 'F_RA-1H"2{bvj)5f?0sd3r#fP,K]U|w}hGiN@(sZ.sDe!7*x/:Mq+&';
|
||||
for($iIndex=0; $iIndex < strlen($sPass); $iIndex++)
|
||||
{
|
||||
$sPass[$iIndex] = $sRandomText[$iIndex%strlen($sRandomText)] ^ $sPass[$iIndex];
|
||||
}
|
||||
return md5($sPass);
|
||||
}
|
||||
|
||||
private static function createToken()
|
||||
{
|
||||
return self::encryptPassword( $_SERVER['HTTP_USER_AGENT'].
|
||||
$_SERVER['REMOTE_ADDR'].
|
||||
$_SERVER['REQUEST_TIME'].
|
||||
strstr(microtime(), ' ', true).
|
||||
$_SERVER['SERVER_SIGNATURE'].
|
||||
$_SERVER['SERVER_ADMIN']);
|
||||
}
|
||||
|
||||
private function resetToken()
|
||||
{
|
||||
//new token
|
||||
$sToken = $this->createToken();
|
||||
|
||||
//set database token
|
||||
$this->oMySql->updateRow(self::DB_TABLE_USER, $this->iUserId, array(self::DB_FIELD_TOKEN=>$sToken));
|
||||
|
||||
//set session token
|
||||
$_SESSION[self::SESSION_TOKEN] = $sToken;
|
||||
$this->sToken = $sToken;
|
||||
|
||||
//set cookie token
|
||||
self::setCookie(self::COOKIE_TOKEN, $sToken);
|
||||
}
|
||||
|
||||
public static function setCookie($sCookieName, $oCookieValue, $iTime=1)
|
||||
{
|
||||
setcookie($sCookieName, $oCookieValue, time()+60*60*24*$iTime);
|
||||
$_COOKIE[$sCookieName] = $oCookieValue;
|
||||
}
|
||||
|
||||
private function checkToken($bCookieCheck=false)
|
||||
{
|
||||
$bTokenOk = $iUserId = $sToken = false;
|
||||
|
||||
//Cookie check
|
||||
if($bCookieCheck && array_key_exists(self::COOKIE_ID_USER, $_COOKIE) && array_key_exists(self::COOKIE_TOKEN, $_COOKIE))
|
||||
{
|
||||
$iUserId = $_COOKIE[self::COOKIE_ID_USER];
|
||||
$sToken = $_COOKIE[self::COOKIE_TOKEN];
|
||||
}
|
||||
//Session check
|
||||
elseif(!$bCookieCheck && $this->iUserId && $this->sToken !== false)
|
||||
{
|
||||
$iUserId = $this->iUserId;
|
||||
$sToken = $this->sToken;
|
||||
}
|
||||
|
||||
if($iUserId && $sToken)
|
||||
{
|
||||
$sDbPass = $this->getDbToken($bCookieCheck?$_COOKIE[self::COOKIE_ID_USER]:$this->iUserId);
|
||||
$bTokenOk = ($sDbPass == $_COOKIE[self::COOKIE_TOKEN] && ($sDbPass == $this->sToken || $bCookieCheck));
|
||||
}
|
||||
|
||||
return $bTokenOk;
|
||||
}
|
||||
|
||||
private function getDbToken($iUserId)
|
||||
{
|
||||
$sPass = false;
|
||||
if($iUserId !== false)
|
||||
{
|
||||
$sPass = $this->oMySql->selectValue(self::DB_TABLE_USER, self::DB_FIELD_TOKEN, $iUserId);
|
||||
}
|
||||
return $sPass;
|
||||
}
|
||||
|
||||
public function getNewPostToken()
|
||||
{
|
||||
$sToken = self::createToken();
|
||||
$this->sPostToken = $sToken;
|
||||
$_SESSION[self::SESSION_POST_TOKEN] = $sToken;
|
||||
return $sToken;
|
||||
}
|
||||
|
||||
public function checkPostToken($sPostToken)
|
||||
{
|
||||
pre(array('Posted'=>$sPostToken, 'Class'=>$this->sPostToken, 'Session'=>$_SESSION[self::SESSION_POST_TOKEN]), 'check posted token');
|
||||
$bPostTokenOk = ($this->sPostToken && $sPostToken!='' && $sPostToken == $this->sPostToken);
|
||||
$this->sPostToken = '';
|
||||
$_SESSION[self::SESSION_POST_TOKEN] = '';
|
||||
return $bPostTokenOk;
|
||||
}
|
||||
|
||||
private static function checkPassword($sClearPass, $sEncodedPass)
|
||||
{
|
||||
return self::encryptPassword($sClearPass) == $sEncodedPass;
|
||||
}
|
||||
|
||||
public function getCleanMessages($sType=parent::ALL_TAB)
|
||||
{
|
||||
return $this->getCleanMessageStacks(array($this->oMySql), $sType);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
21
standalone/colors.php
Executable file
21
standalone/colors.php
Executable file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
$iMin = 0;
|
||||
$iMax = 256;
|
||||
$iStep = 20;
|
||||
$iBoxWidth = 10;
|
||||
|
||||
echo '<html><head><title>Colors</title></head><body><table style="border:0;">';
|
||||
for($i=$iMin;$i<$iMax;$i+=$iStep)
|
||||
{
|
||||
for($j=$iMin;$j<$iMax;$j+=$iStep)
|
||||
{
|
||||
echo '<tr>';
|
||||
for($k=$iMin;$k<$iMax;$k+=$iStep)
|
||||
{
|
||||
echo '<td style="width:'.$iBoxWidth.'px;height:'.$iBoxWidth.'px;background:rgb('.$i.','.$j.','.$k.')"></td>';
|
||||
}
|
||||
echo '</tr>';
|
||||
}
|
||||
}
|
||||
echo '</table><body></html>';
|
||||
14
standalone/image.php
Executable file
14
standalone/image.php
Executable file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
header("Content-type: image/png");
|
||||
|
||||
$iHeight = 150;
|
||||
$iWidth = 200;
|
||||
|
||||
$im = @imagecreate($iWidth, $iHeight) or die("Cannot Initialize new GD image stream");
|
||||
$background_color = imagecolorallocate($im, 145, 145, 145);
|
||||
$text_color = imagecolorallocate($im, 255, 255, 255);
|
||||
imagestring($im, 4, 5, $iHeight-20, "Picture 12", $text_color);
|
||||
imagepng($im);
|
||||
imagedestroy($im);
|
||||
?>
|
||||
0
standalone/rssbinsearch/bl_desc
Normal file
0
standalone/rssbinsearch/bl_desc
Normal file
3
standalone/rssbinsearch/bl_title
Normal file
3
standalone/rssbinsearch/bl_title
Normal file
@@ -0,0 +1,3 @@
|
||||
german
|
||||
xxx
|
||||
pr0n
|
||||
119
standalone/rssbinsearch/rssbinsearch.php
Executable file
119
standalone/rssbinsearch/rssbinsearch.php
Executable file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
//Anti Spam List
|
||||
$sMovieList = '';
|
||||
if(file_exist('movie_list')) $sMovieList = file_get_contents('movie_list');
|
||||
if(substr($sMovieList, 0, 8) != date('Ymd')) file_put_contents('movie_list', '');
|
||||
$asMovieList = array_shift(explode("\n", $sMovieList));
|
||||
|
||||
//Black List
|
||||
$sBlTitleContent = file_get_contents('bl_title');
|
||||
$sBlDescContent = file_get_contents('bl_desc');
|
||||
$asBlTitle = explode("\n", $sBlTitleContent);
|
||||
$asBlDesc = explode("\n", $sBlTitleContent);
|
||||
|
||||
$asChannels = array('alt.binaries.hdtv.x264', 'alt.binaries.movies', 'alt.binaries.sleazemovies');
|
||||
foreach($asChannels as $iChanKey=>$sChannel)
|
||||
{
|
||||
//Extract file
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://rss.binsearch.net/rss.php?max=300&g='.$sChannel);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
|
||||
$sRssIn = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
//Rss Feed Input
|
||||
$sRssIn = str_replace("\n", '', $sRssIn);
|
||||
|
||||
//Rss Feed Output
|
||||
$sRssOut = '';
|
||||
|
||||
//Slice Rss feed into items
|
||||
preg_match_all("/\<item\>(.+)\<\/item\>/U", $sRssIn, $asItems);
|
||||
//print_r($asItems);die();
|
||||
foreach($asItems[1] as $iItemKey=>$sItem)
|
||||
{
|
||||
//Slice item into tags
|
||||
preg_match_all("/\<(?P<tag>\w+)\>(?P<text>.+)\<\/(?P<tag_fin>\w+)\>/U", $sItem, $asTags);
|
||||
//print_r($asTags);die();
|
||||
/*
|
||||
[0] => Array
|
||||
(
|
||||
[0] => <title>dc96773fb88f2f75d581194a4320fedc[76/79] - "15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f.0" yEnc (1/1)</title>
|
||||
[1] => <description><table border width="75%" style="border: solid 1px"><tr><td width="25%">Group:<td>alt.binaries.hdtv.x264<tr><td>Subject:<td>dc96773fb88f2f75d581194a4320fedc[76/79] - "15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f.0" yEnc (1/1)<tr><td>Poster:<td>Yenc@power-post.org (Yenc-PP-A&amp;A)<tr><td>Details:<td><span class="d"><br><a href="http://www.binsearch.info/?b=15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f&amp;g=alt.binaries.hdtv.x264&amp;p=Yenc%40power-post.org+%28Yenc-PP-A%26A%29&amp;max=250">collection</a> size: 2.35&nbsp;MB, parts available: 7 / 7<br>- 2 par2 files<br>- 1 split file<br>- 1 other file<br></span></table></description>
|
||||
[2] => <pubDate>Thu, 03 Jan 2013 15:31:53 GMT</pubDate>
|
||||
[3] => <link>http://www.binsearch.info/?action=nzb&97515747=1</link>
|
||||
)
|
||||
|
||||
[tag] => Array
|
||||
(
|
||||
[0] => title
|
||||
[1] => description
|
||||
[2] => pubDate
|
||||
[3] => link
|
||||
)
|
||||
|
||||
[text] => Array
|
||||
(
|
||||
[0] => dc96773fb88f2f75d581194a4320fedc[76/79] - "15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f.0" yEnc (1/1)
|
||||
[1] => <table border width="75%" style="border: solid 1px"><tr><td width="25%">Group:<td>alt.binaries.hdtv.x264<tr><td>Subject:<td>dc96773fb88f2f75d581194a4320fedc[76/79] - "15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f.0" yEnc (1/1)<tr><td>Poster:<td>Yenc@power-post.org (Yenc-PP-A&amp;A)<tr><td>Details:<td><span class="d"><br><a href="http://www.binsearch.info/?b=15321568f277a26d326baddfb33d62621fe93693187c474f8cac0fb13a0d5b8f&amp;g=alt.binaries.hdtv.x264&amp;p=Yenc%40power-post.org+%28Yenc-PP-A%26A%29&amp;max=250">collection</a> size: 2.35&nbsp;MB, parts available: 7 / 7<br>- 2 par2 files<br>- 1 split file<br>- 1 other file<br></span></table>
|
||||
[2] => Thu, 03 Jan 2013 15:31:53 GMT
|
||||
[3] => http://www.binsearch.info/?action=nzb&97515747=1
|
||||
*/
|
||||
|
||||
//Extract item's tag names
|
||||
foreach($asTags['tag'] as $iTagKey=>$sTageName)
|
||||
{
|
||||
$asTagIndex[$sTageName] = $iTagKey;
|
||||
}
|
||||
$sTitle = $asTags['text'][$asTagIndex['title']];
|
||||
$sDesc = $asTags['text'][$asTagIndex['description']];
|
||||
|
||||
//Validator
|
||||
$bValid = true;
|
||||
|
||||
//Check Poster
|
||||
//preg_match('/Poster\:\<\;td\>\;(?P<address>\S*)\ \((?P<user>\S*)\)/i', $sTitle, $as);
|
||||
foreach($asBlTitle as $sBlWord)
|
||||
{
|
||||
preg_match('/'.preg_quote($sBlWord).'/i', $sTitle, $asFoundBlWord);
|
||||
if(count($asFoundBlWord) != 0) $bValid = false;
|
||||
}
|
||||
|
||||
foreach($asBlDesc as $sBlWord)
|
||||
{
|
||||
preg_match('/'.preg_quote($sBlWord).'/i', $sDesc, $asFoundBlWord);
|
||||
if(count($asFoundBlWord) != 0) $bValid = false;
|
||||
}
|
||||
|
||||
//Check movie quality
|
||||
preg_match('/1080p/i', $sTitle, $asQuality);
|
||||
if(count($asQuality) == 0) $bValid = false;
|
||||
|
||||
//Jul - Remove German movies
|
||||
//preg_match('/german/i', $sTitle, $asLang);
|
||||
//if(count($asLang) != 0) $bValid = false;
|
||||
|
||||
//Check Series
|
||||
preg_match('/s([0-9]{1,2})e([0-9]{2})/i', $sTitle, $asSeries);
|
||||
if(count($asSeries) != 0) $bValid = false;
|
||||
|
||||
if($bValid) $asValidItems[] = $asItems[0][$iItemKey];
|
||||
}
|
||||
}
|
||||
|
||||
//rebuild RSS feed
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
echo '<?xml version="1.0" encoding="utf-8"?><rss version="2.0">'.
|
||||
'<channel>'.
|
||||
'<title>'.implode(', ', $asChannels).'</title>'.
|
||||
'<link>http://www.binsearch.info/</link>'.
|
||||
'<description>Latest newsgroup posts as indexed by BinSearch.info</description>'.
|
||||
'<copyright>This RSS collection is copyright (c) BinSearch team. Commercial use prohibited. This collection is generated by an automated process based on the posts found in global Usenet newsgroups. The posters retain copyright over their individual posts.</copyright>'.
|
||||
'<lastBuildDate>'.date('r').'</lastBuildDate>'.
|
||||
implode("\n\t\t", $asValidItems).
|
||||
'</channel>'.
|
||||
'</rss>';
|
||||
?>
|
||||
110
standalone/send_mail.php
Executable file
110
standalone/send_mail.php
Executable file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
ini_set('default_charset', 'UTF-8');
|
||||
header('Content-Type: text/html; charset='.'UTF-8');
|
||||
mb_internal_encoding('UTF-8');
|
||||
mb_http_output('UTF-8');
|
||||
mb_http_input('UTF-8');
|
||||
mb_language('uni');
|
||||
mb_regex_encoding('UTF-8');
|
||||
|
||||
//Main
|
||||
$sApiKey = isset($_POST['api_key'])?$_POST['api_key']:'';
|
||||
$sApp = isset($_POST['app'])?$_POST['app']:'lutran.fr';
|
||||
$sFromName = isset($_POST['from_name'])?$_POST['from_name']:'';
|
||||
$sFromEmail = isset($_POST['from_email'])?$_POST['from_email']:'www-data@lutran.fr';
|
||||
$sSubject = isset($_POST['subject'])?$_POST['subject']:'';
|
||||
$sMsg = isset($_POST['msg'])?$_POST['msg']:'';
|
||||
$sToEmail = isset($_POST['to_email'])?$_POST['to_email']:'';
|
||||
$asCc = isset($_POST['cc_email'])?json_decode($_POST['cc_email'], true):'';
|
||||
$bSelfMail = isset($_POST['self'])?$_POST['self']:true;
|
||||
|
||||
$asAuthorizedApi = array('Wedding'=>'8D98B36BB558BC6771324AEFB9E37');
|
||||
if(array_key_exists($sApp, $asAuthorizedApi) && $sApiKey = $asAuthorizedApi[$sApp])
|
||||
{
|
||||
$sResult = sendEmail($sApp, $sFromName, $sFromEmail, $sSubject, $sMsg, $sToEmail, $asCc, $bSelfMail);
|
||||
}
|
||||
else $sResult = 1;
|
||||
|
||||
echo $sResult;
|
||||
|
||||
//Functions
|
||||
function sendEmail($sApp, $sFromName, $sFromEmail, $sSubject, $sMsg, $sToEmail, $asCc, $bSelfMail)
|
||||
{
|
||||
$sResult = 0;
|
||||
if($sFromName!='' && $sFromEmail!='' && $sSubject!='' && $sMsg!='' && $sToEmail!='')
|
||||
{
|
||||
//Message
|
||||
$sHtmlMessage = '';
|
||||
if($bSelfMail)
|
||||
{
|
||||
$sHtmlMessage = 'From: '.$sFromName."<br />".
|
||||
'Email: '.$sFromEmail."<br /><br />".
|
||||
'Subject: '.$sSubject."<br />".
|
||||
'Message: <br /><br />';
|
||||
$sFromName = $sApp;
|
||||
$sSubject = $sApp.' - Contact';
|
||||
}
|
||||
$sHtmlMessage .= str_replace("\n", '<br />', $sMsg);
|
||||
$sPlainMessage = strip_tags(str_replace('<br />', "\n", $sHtmlMessage));
|
||||
|
||||
//Email
|
||||
$iBoundary = uniqid("HTMLEMAIL");
|
||||
$sCc = empty($asCc)?'':('Cc: '.implodeAll($asCc, ' <', "\r\n, ", '', '>')."\r\n");
|
||||
$sHeaders = 'From: '.$sFromName.' <www-data@lutran.fr>'."\r\n".
|
||||
'Reply-To: '.$sFromName.' <www-data@lutran.fr>'."\r\n".
|
||||
$sCc.
|
||||
'MIME-Version: 1.0'."\r\n".
|
||||
'Content-Type: multipart/alternative;'.
|
||||
'boundary = '.$iBoundary."\r\n\r\n".
|
||||
'MIME encoded Message'.
|
||||
'--'.$iBoundary."\r\n".
|
||||
'Content-Type: text/plain; charset=UTF-8'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n\r\n".
|
||||
chunk_split(base64_encode($sPlainMessage)).
|
||||
'--'.$iBoundary."\r\n".
|
||||
'Content-Type: text/html; charset=UTF-8'."\r\n".
|
||||
'Content-Transfer-Encoding: base64'."\r\n\r\n".
|
||||
chunk_split(base64_encode($sHtmlMessage));
|
||||
|
||||
//Store in case email fails
|
||||
//@file_put_contents('log.html', '<br />----<br /><br />'.$sHtmlMessage, FILE_APPEND);
|
||||
|
||||
//Send
|
||||
if(mail($sToEmail, $sSubject, '', $sHeaders))
|
||||
{
|
||||
$sResult = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sResult = 3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sResult = 4;
|
||||
}
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
function implodeAll($asText, $asKeyValueSeparator='', $sRowSeparator='', $sKeyPre='', $sValuePost=false)
|
||||
{
|
||||
if($sValuePost===false)
|
||||
{
|
||||
$sValuePost = $sKeyPre;
|
||||
}
|
||||
$asCombinedText = array();
|
||||
|
||||
//if unique value for key value separator
|
||||
if(!is_array($asKeyValueSeparator) && !empty($asText))
|
||||
{
|
||||
$asKeyValueSeparator = array_combine(array_keys($asText), array_fill(0, count($asText), $asKeyValueSeparator));
|
||||
}
|
||||
|
||||
foreach($asText as $sKey=>$sValue)
|
||||
{
|
||||
$asCombinedText[] = $sKeyPre.$sKey.$asKeyValueSeparator[$sKey].(is_array($sValue)?implode($sValue):$sValue).$sValuePost;
|
||||
}
|
||||
return implode($sRowSeparator, $asCombinedText);
|
||||
}
|
||||
?>
|
||||
78
standalone/test.php
Executable file
78
standalone/test.php
Executable file
File diff suppressed because one or more lines are too long
83
standalone/upload.php
Normal file
83
standalone/upload.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
function combinedImplode($asPieces, $sKeyValGlue='', $sRowGlue='')
|
||||
{
|
||||
$asResult = array();
|
||||
foreach($asPieces as $sKey=>$sValue)
|
||||
{
|
||||
$asResult[] = is_array($sValue)?combinedImplode($sValue, $sKeyValGlue, $sRowGlue):$sKey.$sKeyValGlue.$sValue;
|
||||
}
|
||||
return implode($sRowGlue, $asResult);
|
||||
}
|
||||
|
||||
function getSabContent($sSabServer, $asParams)
|
||||
{
|
||||
$sQueueUrl = $sSabServer.'?'.combinedImplode($asParams, '=', '&');
|
||||
return json_decode(file_get_contents($sQueueUrl), true);
|
||||
}
|
||||
|
||||
$sUploadResult = $sQueueResult = $sHistoryResult = '';
|
||||
if(isset($_GET['api']) && $_GET['api']=='123456')
|
||||
{
|
||||
|
||||
$sSabServer = 'http://192.168.0.2:8085/sabnzbd/api';
|
||||
$asCommonParams = array('output'=>'json', 'apikey'=>'d93d02d23510871b0252fe282a0f591c');
|
||||
$asQueueParams = $asCommonParams + array('mode'=>'queue', 'start'=>0, 'limit'=>1);
|
||||
$asHistoryParams = $asCommonParams + array('mode'=>'history', 'start'=>0, 'limit'=>3);
|
||||
|
||||
//Displaying current download
|
||||
$asQueueResult = getSabContent($sSabServer, $asQueueParams);
|
||||
if(count($asQueueResult['queue']['slots'])==0) $sQueueResult = 'Empty queue';
|
||||
else
|
||||
{
|
||||
$asFile = $asQueueResult['queue']['slots'][0];
|
||||
$sQueueResult = 'Downloading '.$asFile['filename'].' ('.$asFile['size'].') ';
|
||||
$sQueueResult.= 'at '.$asQueueResult['queue']['speed'].'. File expected at ';
|
||||
$sQueueResult.= $asFile['eta'].' ('.$asFile['sizeleft'].' / '.$asFile['timeleft'].' left)';
|
||||
}
|
||||
|
||||
//Displaying history
|
||||
$asHistoryResult = getSabContent($sSabServer, $asHistoryParams);
|
||||
if(count($asHistoryResult['history']['slots'])==0) $asHistoryResult = 'Empty history';
|
||||
else
|
||||
{
|
||||
foreach($asHistoryResult['history']['slots'] as $asFile)
|
||||
{
|
||||
$sHistoryResult .= '<li>'.$asFile['name'].' ('.$asFile['size'].') ';
|
||||
if($asFile['status']=='Failed') $sHistoryResult.= 'failed to be downloaded ("'.$asFile['fail_message'].'")';
|
||||
else $sHistoryResult.= 'has been downloaded with success';
|
||||
$sHistoryResult .= '</li>';
|
||||
}
|
||||
}
|
||||
|
||||
//Uploading file
|
||||
$sUploadResult = '';
|
||||
if(array_key_exists('upload', $_FILES) && strtolower(substr($_FILES['upload']['name'], -4))=='.nzb')
|
||||
{
|
||||
$sWatchDir = "/tmp/downloads/watchdir/";
|
||||
$sPath = $sWatchDir.basename($_FILES['upload']['name']);
|
||||
$ok=1;
|
||||
if(move_uploaded_file($_FILES['upload']['tmp_name'], $sPath))
|
||||
{
|
||||
$sUploadResult = "The file ". basename( $_FILES['upload']['name']). " has been uploaded";
|
||||
}
|
||||
else $sUploadResult = "Sorry, there was a problem copying your file.";
|
||||
}
|
||||
}
|
||||
else $sUploadResult = 'Missing API key';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Add to NZB</title>
|
||||
</head>
|
||||
<body>
|
||||
<form enctype="multipart/form-data" action="upload.php" method="POST">
|
||||
Add to NZB: <input name="upload" type="file" /> <input type="submit" value="Upload" />
|
||||
</form>
|
||||
<p class="result"><?php echo $sUploadResult; ?></p>
|
||||
<p class="queue"><?php echo $sQueueResult; ?></p>
|
||||
<p class="history"><ul><?php echo $sHistoryResult; ?></ul></p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user