Changeset 93
- Timestamp:
- 10/12/08 19:53:45 (1 year ago)
- Files:
-
- trunk/wtorrent/alter_table.sql (deleted)
- trunk/wtorrent/cls/install.cls.php (added)
- trunk/wtorrent/cls/rtorrent.cls.php (modified) (4 diffs)
- trunk/wtorrent/create_cookie.sql (deleted)
- trunk/wtorrent/install.php (modified) (1 diff)
- trunk/wtorrent/install2.php (deleted)
- trunk/wtorrent/lib/cls/PDOe.cls.php (added)
- trunk/wtorrent/lib/cls/Web.cls.php (modified) (4 diffs)
- trunk/wtorrent/lib/inc/includes.inc.php (modified) (1 diff)
- trunk/wtorrent/lib/inc/string.inc.php (modified) (1 diff)
- trunk/wtorrent/sqlite_migration.sh (added)
- trunk/wtorrent/wt/cls/AddT.cls.php (modified) (3 diffs)
- trunk/wtorrent/wt/cls/Admin.cls.php (modified) (1 diff)
- trunk/wtorrent/wt/cls/Cookie.cls.php (modified) (3 diffs)
- trunk/wtorrent/wt/cls/Feeds.cls.php (modified) (5 diffs)
- trunk/wtorrent/wt/cls/ListT.cls.php (modified) (1 diff)
- trunk/wtorrent/wt/css/estil.css (modified) (1 diff)
- trunk/wtorrent/wt/lang/en.txt (modified) (1 diff)
- trunk/wtorrent/wt/tpl/ajax.tpl.php (modified) (1 diff)
- trunk/wtorrent/wt/tpl/index.tpl.php (modified) (3 diffs)
- trunk/wtorrent/wt/tpl/install (added)
- trunk/wtorrent/wt/tpl/install/index.tpl.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/wtorrent/cls/rtorrent.cls.php
r91 r93 67 67 protected function construct( ){} 68 68 69 public function registrado( ) 70 { 71 return !is_null( $this->_sesion->id_user ); 72 } 73 public function compLogin($user, $passwd) 74 { 75 $passwd = md5($passwd); 76 $sql = "select id from tor_passwd where user = '$user' and passwd = '$passwd'"; 77 $result = $this->_db->query( $sql ); 78 if(is_object($result)) 79 { 80 $num = $result->numRows(); 81 82 if($num > 0) 83 $return = $result->current(); 84 else 85 $return = false; 86 } else { 87 $return = false; 88 } 89 return $return; 69 public function isRegistered( ) 70 { 71 return !is_null( $this->_session->id_user ); 90 72 } 91 73 public function getUser( ) 92 74 { 93 return $this->_ses ion->user;75 return $this->_session->user; 94 76 } 95 77 public function getIdUser( ) 96 78 { 97 return $this->_ses ion->id_user;79 return $this->_session->id_user; 98 80 } 99 81 public function getMenu() 100 82 { 101 if($this->_ses ion->admin === true)83 if($this->_session->admin === true) 102 84 $return = $this->menu_admin; 103 85 else … … 114 96 return floor($total/(count($menu_items)+1)) - 1; 115 97 } 116 public function Admin($id)117 {118 $sql = "select admin from tor_passwd where id = '" . $this->_sesion->id_user . "'";119 $result = $this->_db->query( $sql );120 $admin = $result->current();121 if($admin['admin'] == 1)122 $return = true;123 else124 $return = false;125 126 return $return;127 }128 98 public function login( $user, $password ) 129 99 { 130 $id = $this->compLogin($user, $password); 131 if($id != false) 132 { 133 $this->_sesion->id_user = $id['id']; 134 $this->_sesion->user = $user; 135 $this->_sesion->admin = $this->Admin($id['id']); 136 $return = true; 137 } else { 138 $return = false; 139 $this->addMessage($this->_str['err_login']); 140 } 141 return $return; 100 $record = $this->_db->query( 101 'SELECT id, admin FROM tor_passwd WHERE user = ? AND passwd = ?', 102 $user, 103 md5($password) 104 ); 105 if($record !== false) 106 { 107 $this->_session->id_user = $record['id']; 108 $this->_session->admin = !!$record['admin']; 109 $this->_session->user = $user; 110 return true; 111 } 112 return false; 142 113 } 143 114 public function isAdmin() 144 115 { 145 return $this->_ses ion->admin;146 } 147 public function logout( )148 { 149 if($this-> registrado())150 { 151 $this->_ses ion = null;116 return $this->_session->admin; 117 } 118 public function logout() 119 { 120 if($this->isRegistered()) 121 { 122 $this->_session = null; 152 123 $this->addMessage($this->_str['info_logout']); 153 124 } … … 155 126 private function getPrivate() 156 127 { 157 $tt = array(); 158 $sql = "select hash, user from torrents"; 159 $result = $this->_db->query($sql); 160 $torr = $result->fetchAll(); 161 foreach($torr as $torrent) 162 $tt[$torrent['hash']] = $torrent['user']; 163 164 return $tt; 128 $rv = array(); 129 foreach ($this->_db->queryAll('SELECT hash, user FROM torrents') as $torrent) 130 { 131 $rv[$torrent['hash']] = $torrent['user']; 132 } 133 return $rv; 165 134 } 166 135 public function setClient() … … 248 217 protected function erase_db($hash) 249 218 { 250 $sql = "delete from torrents where hash = '" . $hash . "'"; 251 $this->_db->query($sql); 219 $this->_db->modify('DELETE FROM torrents WHERE hash = ?', $hash); 252 220 } 253 221 protected function setPerm() trunk/wtorrent/install.php
r77 r93 1 1 <?php 2 require_once( 'conf/user.conf.php' ); 2 /* 3 This file is part of wTorrent. 4 5 wTorrent is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 wTorrent is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 Modified version of class done by David Marco Martinez 19 */ 20 require_once("lib/cls/Web.cls.php"); 21 require_once("cls/install.cls.php"); 22 error_reporting(E_ALL); 23 // Record the start time of execution 24 $mtime = microtime( true ); 25 // Start php session BEFORE ANY output 26 session_start(); 27 // Load conf 28 //require_once( 'conf/user.conf.php' ); 29 install::setDefines(); 3 30 require_once( 'conf/system.conf.php' ); 31 // Build the base of the app 32 $web = Web::getClass( 'install' ); 33 // Page specific operations and display 34 $web->display( 'install/index' ); 35 36 // Record end time 37 $ftime = microtime( true ); 38 $total = $ftime -$mtime; 39 //echo "total: " . $total . 's<br />'; 40 // If end time is shorter than 0.5 segons sleep untill then 41 if($total < MIN_TIME) { 42 usleep(floor((MIN_TIME - $total)*1000000)); 43 //echo 'lost time: ' . (MIN_TIME - $total) . 's<br />'; 44 } 45 // REAL end time (Should be about MIN_TIME + 0.1s) 46 $fftime = microtime( true ); 47 $total = $fftime - $mtime; 4 48 ?> 5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">6 7 <html xmlns="http://www.w3.org/1999/xhtml">8 9 <head>10 <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-15" />11 <title><?=TITLE?></title>12 <link rel="stylesheet" type="text/css" href="<?=DIR_CSS_ESTIL?>" media="all" />13 </head>14 15 <body>16 <div style="font-family: georgia; font-size: 20px; text-align: center; font-weight: bold; padding-top: 8px; margin: 0px auto; background-color: #ffffff; width: 300px; height: 30px; top: 0px; border-bottom: 1px solid #d4d4d4; border-left: 1px solid #d4d4d4; border-right: 1px solid #d4d4d4;">17 Install18 </div>19 <?php20 if(file_exists(DB_FILE))21 {22 echo '<div id="principal" class="principal" style="width: 500px;"><div style="font-size: 11px; margin-bottom: 12px; font-weight: bold;">';23 echo 'wTorrent has already been configured.<br /> If you wish to re-run the install, please delete or move your db file.';24 echo '</div></div></body></html>';25 die();26 }27 if(isset($_REQUEST['create']))28 {29 echo '<div class="messages" style="display: block; margin-bottom: 10px;">';30 if($_REQUEST['userf'] != '' && $_REQUEST['passwdf'] != '')31 {32 $db = new SQLiteDatabase(DB_FILE);33 if(is_object($db))34 {35 $sql_create = "CREATE TABLE tor_passwd(id integer primary key, user text, passwd text, admin integer, dir text, force_dir integer);";36 $sql_insert = "INSERT INTO tor_passwd VALUES(1,'" . $_REQUEST['userf'] . "','" . md5($_REQUEST['passwdf']) . "',1, '', 0);";37 $sql_create_torrents = "create table torrents(hash string, user int, private int);";38 $sql_create_feeds = "CREATE TABLE feeds(id integer primary key, url text, user integer);";39 $sql_create_cookies = "CREATE TABLE cookie(id integer primary key, userid integer, value text, hostname text);";40 $res1 = $db->query($sql_create);41 $res2 = $db->query($sql_insert);42 $res3 = $db->query($sql_create_torrents);43 $res4 = $db->query($sql_create_feeds);44 $res5 = $db->query($sql_create_cookies);45 if($res1 !== false && $res2 !== false)46 echo 'Database succesfully created, please delete install.php and enjoy wTorrent';47 else48 echo 'Error during creation/insertion of user into the database, please check that the dir has correct permisions';49 50 } else {51 echo 'Error trying to access database, plase check that you have compiled php with sqlite support';52 }53 } else {54 echo 'Error, you must fill the form';55 }56 echo '</div>';57 die();58 }59 else if(isset($_REQUEST['update']))60 {61 echo '<div class="messages">';62 $db = new SQLiteDatabase(DB_FILE);63 if(is_object($db))64 {65 $sql_create_torrents = "CREATE TABLE feeds(id integer primary key, url text, user integer);";66 $res = $db->query($sql_create_torrents);67 if($res !== false)68 echo 'Update complete, please delete install.php';69 else70 echo 'Error performing update, please check wTorrent for correct installation and/or reinstall';71 } else72 echo 'Could not connect to database, please check configuration';73 echo '</div>';74 }75 ?>76 <div id="principal" class="principal" style="width: 500px;">77 <div id="contingut" class="contingut" style="width:450px; padding: 20px; padding-bottom: 0px; margin-top: 5px;">78 <div style="font-size: 11px; margin-bottom: 12px; font-weight: bold;">79 Welcome to wTorrent!<br />80 Please input your desired username/password81 </div>82 <form action="install.php" method="POST">83 <div style="height: 20px; width: 100%;"><div style="height: 20px; padding-top: 6px; font-size:12px; width: 80px; float: left; text-align: left;"><b>User:</b></div><div style="float: left;"><input type="text" name="userf" /></div></div><br />84 <div style="height: 20px; width: 100%;"><div style="height: 20px; padding-top: 6px; font-size: 12px; width: 80px; float: left; text-align: left;"><b>Password:</b></div><div style="float: left;"> <input type="text" name="passwdf" /></div></div><br />85 <div style="padding-bottom: 10px;"><input type="submit" value="Create" name="create" /></div>86 <!-- <div style="padding-bottom: 10px;"><input type="submit" value="Update (only 20071014 and previous versions users)" name="update" /></div> -->87 </form>88 </div>89 </div>90 </body>91 92 </html>trunk/wtorrent/lib/cls/Web.cls.php
r91 r93 30 30 31 31 protected $_str = array( ); 32 protected $_ses ion = null;32 protected $_session = null; 33 33 protected $_request = null; 34 34 protected $_post = null; … … 44 44 protected $_ajax = false; 45 45 46 public function __construct( )46 public function __construct($install = false) 47 47 { 48 48 // Connect to DB (mysqli) 49 $this->_db = new SQLiteDatabase(DB_FILE); 50 49 50 // Compat: if DB_FILE instead of the DSN is defined then assume SQLITE and make a DSN out of it 51 if(!$install) 52 { 53 if (!defined('DB_DSN') && defined('DB_FILE')) 54 { 55 define('DB_DSN', 'sqlite:' . DIR_EXEC . DB_FILE); 56 } 57 $this->_db = new PDOe(DB_DSN, null, null, array(PDO::ERRMODE_EXCEPTION)); 58 } 51 59 // Instance of Smarty templates system 52 60 $this->_smarty = new Smarty( ); … … 62 70 foreach( $this->_getConstants( ) as $k => $v ) $this->smartyAssign( $k, $v ); 63 71 64 $this->_sesion = &$_SESSION[APP]; 65 $this->_request = escape( $_REQUEST ); 66 $this->_post = escape( $_POST ); 67 $this->_get = escape( $_GET ); 68 $this->_cookie = escape( $_COOKIE ); 69 $this->_globals = escape( $_GLOBALS ); 70 $this->_server = escape( $_SERVER ); 71 $this->_files = escape( $_FILES ); 72 $this->_env = escape( $_ENV ); 72 $this->_session = &$_SESSION[APP]; 73 $this->_request = unescape($_REQUEST); 74 $this->_post = unescape($_POST); 75 $this->_get = unescape($_GET); 76 $this->_cookie = unescape($_COOKIE); 77 $this->_files = unescape($_FILES); 78 $this->_server = &$_SERVER; 79 $this->_env = &$_ENV; 73 80 74 81 // Create json class 75 82 $this->_json = new Services_JSON(); 76 83 if($install) 84 { 85 $this->_lang = 'en'; 86 } 77 87 $this->loadLanguage( $this->getLang( ) ); 78 88 if(isset($this->_request['ajax'])) $this->_ajax = true; … … 110 120 111 121 // Subclass constructor 112 if($this-> registrado())122 if($this->isRegistered()) 113 123 { 114 124 $this->setPerm(); 115 if($this->_sesion->admin && $this->admin) // Avoid execution of orders by unregistered users 116 $this->construct( ); 117 elseif($this->admin !== true) 118 $this->construct( ); 125 $this->construct(); 119 126 } 120 127 trunk/wtorrent/lib/inc/includes.inc.php
r91 r93 24 24 require_once( 'cls/torrent.cls.php' ); 25 25 require_once( 'cls/multicall.cls.php' ); 26 //require_once( 'cls/install.cls.php' ); 26 27 require_once( 'lib/xmlrpc/xmlrpc.inc.php' ); 27 28 require_once( 'lib/inc/utils.inc.php' ); trunk/wtorrent/lib/inc/string.inc.php
r4 r93 37 37 } 38 38 39 /** 40 * Escapa todos los caracteres conflictivos de la variable mixta $var 41 * 42 * @param mixed $var 43 * @return mixed 44 */ 45 function escape( $var ) 46 { 47 if( get_magic_quotes_gpc( ) ) return $var; 48 49 $var = is_array( $var) ? array_map( 'escape', $var ) : addslashes( $var ); 50 return $var; 39 function _unescape_internal($var) 40 { 41 switch (gettype($var)) { 42 case 'array': 43 return array_map('_unescape_internal', $var); 44 case 'string': 45 return stripslashes($var); 46 default: 47 return $var; 48 } 49 } 50 function unescape( $var ) 51 { 52 if (!get_magic_quotes_gpc()) 53 { 54 return; 55 } 56 return _unescape_internal($var); 51 57 } 52 58 function html( $str ) trunk/wtorrent/wt/cls/AddT.cls.php
r84 r93 21 21 public function construct() 22 22 { 23 if(!$this->setClient()) 24 return false; 25 26 if ( isset( $this->_files['uploadedfile'] ) and ! $this->_request['torrenturl'] ) 27 { 28 $this->uploadTorrent( $this->_files['uploadedfile'], $this->_request['download_dir'], $this->_request['start_now'], $this->_request['private'] ); 29 } elseif ( $this->_request['torrenturl'] ) { 30 $this->addRemoteTorrent( $this->_request['torrenturl'], $this->_request['download_dir'], $this->_request['start_now'], $this->_request['private'] ); 31 } 32 } 33 // Add remote torrent 34 private function addRemoteTorrent( $url, $dir, $start_now, $private ) 35 { 36 // Get Dir if user can only download to a certain directory 37 if($this->getForceDir() == 1) 38 $dir = $this->getDir(); 39 // Parsing url 40 $purl = parse_url( $url ); 41 $uploadfile = DIR_EXEC . DIR_TORRENTS . sha1( $url ) . md5($url) . ".torrent"; 42 // Get sha1/md5 for avoid filename problems & Multiple torrents 43 if ( file_exists( $uploadfile ) ) 44 { 45 $this->addMessage( $this->_str['err_add_file'] ); 46 return false; 47 } 48 $fh = fopen( $uploadfile, 'w' ); 49 // Open a filehandle and check for curl function in php 50 if ( !function_exists("curl_init") ) { 51 $this->addMessage( $this->_str['no_curl_function'] ); 52 return; 53 } 54 $ua = curl_init(); 55 $cookie = $this->getCookie( $url ); 56 if ( ! empty($cookie) ) 57 { 58 curl_setopt($ua, CURLOPT_COOKIE, $cookie); 59 } 60 curl_setopt($ua, CURLOPT_PORT, $purl["port"] ); 61 curl_setopt($ua, CURLOPT_URL, $url); 62 curl_setopt($ua, CURLOPT_VERBOSE, FALSE); 63 curl_setopt($ua, CURLOPT_HEADER, FALSE); 64 // Dont put the header into the file 65 curl_setopt($ua, CURLOPT_USERAGENT, "Mozilla/5.0 (U; en-US; rv) Gecko Firefox (compatible wtorrent)"); 66 // Avoid problems with user agent sniffing 67 curl_setopt($ua, CURLOPT_RETURNTRANSFER, TRUE); 68 curl_setopt($ua, CURLOPT_SSL_VERIFYHOST, FALSE); 69 curl_setopt($ua, CURLOPT_SSL_VERIFYPEER, FALSE); 70 // Avoid ssl problems 71 curl_setopt($ua, CURLOPT_FOLLOWLOCATION, TRUE); 72 // Follow the location 73 curl_setopt($ua, CURLOPT_AUTOREFERER, TRUE); 74 curl_setopt($ua, CURLOPT_REFERER, $url); 75 // Avoid referrer problems 76 curl_setopt($ua, CURLOPT_FILE, $fh); 77 $file = curl_exec( $ua ); 78 // Execute the query 79 curl_close($ua); 80 fclose($fh); 81 chmod( $uploadfile, PERM_TORRENTS); 82 // Setting up the permissions 83 $torrent = new BDECODE($uploadfile); 84 // Try to load the torrent, and check is it valid or not 85 if ($torrent->result['error']) { 86 $this->addMessage($torrent->result['error']); 87 @unlink($uploadfile); 88 return false; 89 } 90 $message = new xmlrpcmsg("set_directory", array(new xmlrpcval($dir , 'string'))); 91 $result1 = $this->client->send($message); 92 if($start_now == 'on') 93 $method = 'load_start'; 94 else 95 $method = 'load'; 96 if($private == 'on') 97 { 98 $bencode = new BEncodeLib(); 99 $hash = strtoupper(bin2hex(sha1($bencode->bencode($torrent->result['info']), true))); 100 $sql = "insert into torrents values('" . $hash . "', '" . $this->getIdUser() . "', '1');"; 101 $this->_db->query($sql); 102 } 103 // sha.new( bencode ( bdecode( open('file.torrent', 'rb').read() )['info'] ) ).hexdigest() 104 105 $message = new xmlrpcmsg($method, array(new xmlrpcval($uploadfile , 'string'))); 106 $result2 = $this->client->send($message); 107 108 109 if(($result1->errno == 0) && ($result2->errno == 0) && ($res[0] !== false)) 110 $this->addMessage($this->_str['info_add_torrent']); 111 else 112 { 113 $this->addMessage($this->_str['err_add_torrent']); 23 if(!$this->setClient()) 24 { 25 return false; 26 } 27 28 if (!empty($this->_files['uploadedfile']) && !$this->_files['uploadedfile']['error']) 29 { 30 $this->uploadTorrent( 31 $this->_files['uploadedfile'], 32 $this->_request['download_dir'], 33 $this->_request['start_now'], 34 $this->_request['private'] 35 ); 36 } 37 else if(!empty($this->_request['torrenturl'])) 38 { 39 $this->addRemoteTorrent( 40 $this->_request['torrenturl'], 41 $this->_request['download_dir'], 42 $this->_request['start_now'], 43 $this->_request['private'] 44 ); 45 } 46 } 47 // Add remote torrent 48 private function addRemoteTorrent( $url, $dir, $start_now, $private ) 49 { 50 // Get Dir if user can only download to a certain directory 51 if($this->getForceDir() == 1) 52 { 53 $dir = $this->getDir(); 54 } 55 56 // Parsing url 57 $purl = parse_url($url); 58 $uploadfile = DIR_EXEC . DIR_TORRENTS . sha1( $url ) . md5($url) . ".torrent"; 59 // Get sha1/md5 for avoid filename problems & Multiple torrents 60 if (file_exists($uploadfile)) 61 { 62 $this->addMessage($this->_str['err_add_file']); 63 return false; 64 } 65 $fh = fopen($uploadfile, 'w'); 66 // Open a filehandle and check for curl function in php 67 if (!function_exists("curl_init")) 68 { 69 $this->addMessage( $this->_str['no_curl_function'] ); 70 return; 71 } 72 $ua = curl_init(); 73 $cookie = $this->getCookie( $url ); 74 if (!empty($cookie)) 75 { 76 curl_setopt($ua, CURLOPT_COOKIE, $cookie); 77 } 78 curl_setopt($ua, CURLOPT_PORT, $purl["port"] ); 79 curl_setopt($ua, CURLOPT_URL, $url); 80 curl_setopt($ua, CURLOPT_VERBOSE, FALSE); 81 curl_setopt($ua, CURLOPT_HEADER, FALSE); 82 // Dont put the header into the file 83 curl_setopt($ua, CURLOPT_USERAGENT, "Mozilla/5.0 (U; en-US; rv) Gecko Firefox (compatible wtorrent)"); 84 // Avoid problems with user agent sniffing 85 curl_setopt($ua, CURLOPT_RETURNTRANSFER, TRUE); 86 curl_setopt($ua, CURLOPT_SSL_VERIFYHOST, FALSE); 87 curl_setopt($ua, CURLOPT_SSL_VERIFYPEER, FALSE); 88 // Avoid ssl problems 89 curl_setopt($ua, CURLOPT_FOLLOWLOCATION, TRUE); 90 // Follow the location 91 curl_setopt($ua, CURLOPT_AUTOREFERER, TRUE); 92 curl_setopt($ua, CURLOPT_REFERER, $url); 93 // Avoid referrer problems 94 curl_setopt($ua, CURLOPT_FILE, $fh); 95 $file = curl_exec( $ua ); 96 // Execute the query 97 curl_close($ua); 98 fclose($fh); 99 chmod( $uploadfile, PERM_TORRENTS); 100 // Setting up the permissions 101 $torrent = new BDECODE($uploadfile); 102 // Try to load the torrent, and check is it valid or not 103 if ($torrent->result['error']) 104 { 105 $this->addMessage($torrent->result['error']); 114 106 @unlink($uploadfile); 107 return false; 108 } 109 $message = new xmlrpcmsg("set_directory", array(new xmlrpcval($dir , 'string'))); 110 $result1 = $this->client->send($message); 111 if($start_now == 'on') 112 { 113 $method = 'load_start'; 114 } 115 else 116 { 117 $method = 'load'; 118 } 119 if ($private == 'on') 120 { 121 $bencode = new BEncodeLib(); 122 $hash = strtoupper(bin2hex(sha1($bencode->bencode($torrent->result['info']), true))); 123 $this->_db->modify('INSERT INTO torrents VALUES(?, ?, 1)', $hash, $this->getIdUser()); 124 } 125 126 $message = new xmlrpcmsg($method, array(new xmlrpcval($uploadfile , 'string'))); 127 $result2 = $this->client->send($message); 128 129 130 if (($result1->errno == 0) && ($result2->errno == 0) && ($res[0] !== false)) 131 { 132 $this->addMessage($this->_str['info_add_torrent']); 133 } 134 else 135 { 136 $this->addMessage($this->_str['err_add_torrent']); 137 @unlink($uploadfile); 115 138 } 116 139 $message = new xmlrpcmsg("set_directory", array(new xmlrpcval(DIR_DOWNLOAD, 'string'))); 117 $result1 = $this->client->send($message); 118 } 119 private function getCookie($url) 120 { 121 // Getting cookie depends on hostname 122 $purl = parse_url( $url ); 123 $sql = "SELECT id,value, hostname FROM cookie where userid = " . $this->getIdUser() . " and hostname like '%".$purl['host']."%';"; 124 $res = $this->_db->query( $sql ); 125 $result = $res->fetchAll(); 126 // Return the first even there are more than one, FIXTHIS 127 return $result[0]['value']; 128 } 140 $this->client->send($message); 141 } 142 private function getCookie($url) 143 { 144 // Getting cookie depends on hostname 145 $purl = parse_url( $url ); 146 return implode( 147 '; ', 148 $this->_db->queryColumnAll( 149 'SELECT id, value, hostname FROM cookie WHERE userid = ? AND hostname LIKE ?', 150 $this->getIdUser(), 151 "%{$purl['host']}%" 152 ) 153 ); 154 } 129 155 public function getDir() 130 156 { 131 $sql = "SELECT dir FROM tor_passwd WHERE id = '" . $this->getIdUser() . "';"; 132 $res = $this->_db->query( $sql ); 133 $result = $res->fetch(); 134 return $result['dir']; 157 return $this->_db->queryColumn('SELECT dir FROM tor_passwd WHERE id = ?', $this->getIdUser()); 135 158 } 136 159 public function getForceDir() 137 160 { 138 $sql = "SELECT force_dir FROM tor_passwd WHERE id = '" . $this->getIdUser() . "';"; 139 $res = $this->_db->query( $sql ); 140 $result = $res->fetch(); 141 return $result['force_dir']; 161 return $this->_db->queryColumn('SELECT force_dir FROM tor_passwd WHERE id = ?', $this->getIdUser()); 142 162 } 143 163 private function uploadTorrent($fileU, $dir, $start_now, $private) 144 164 { 145 if($this->getForceDir() == 1) 165 if ($this->getForceDir() == 1) 166 { 146 167 $dir = $this->getDir(); 168 } 147 169 $uploadfile = DIR_EXEC . DIR_TORRENTS . time() . basename($fileU['name']); 148 if (!is_writable(DIR_EXEC . DIR_TORRENTS))170 if (!is_writable(DIR_EXEC . DIR_TORRENTS)) 149 171 { 150 172 $this->addMessage($this->_str['err_add_dir']); … … 164 186 165 187 if($start_now == 'on') 188 { 166 189 $method = 'load_start'; 167 else 190 } 191 else 192 { 168 193 $method = 'load'; 194 } 169 195 if($private == 'on') 170 196 { … … 172 198 $bencode = new BEncodeLib(); 173 199 $hash = strtoupper(bin2hex(sha1($bencode->bencode($torrent->result['info']), true))); 174 $sql = "insert into torrents values('" . $hash . "', '" . $this->getIdUser() . "', '1');"; 175 $this->_db->query($sql); 176 } 177 // sha.new( bencode ( bdecode( open('file.torrent', 'rb').read() )['info'] ) ).hexdigest() 200 $this->_db->modify('INSERT INTO torrents VALUES(?, ?, 1)', $hash, $this->getIdUser()); 201 } 178 202 179 203 $message = new xmlrpcmsg($method, array(new xmlrpcval($uploadfile , 'string'))); 180 204 $result2 = $this->client->send($message); 181 205 182 /*print_r($result1);183 print_r($result2);*/184 185 206 if(($result1->errno == 0) && ($result2->errno == 0) && ($res[0] !== false)) 186 207 $this->addMessage($this->_str['info_add_torrent']); trunk/wtorrent/wt/cls/Admin.cls.php
r74 r93 44 44 public function showUsers() 45 45 { 46 $sql = "SELECT user, id, admin, dir, force_dir FROM tor_passwd"; 47 $res = $this->_db->query( $sql ); 48 $result = $res->fetchAll(); 49 $num = count($result); 50 //print_r($result); 51 return $result; 46 return $this->_db->queryAll('SELECT user, id, admin, dir, force_dir FROM tor_passwd'); 52 47 } 53 48 public function deleteUsers($users) 54 49 { 55 if (count($users) > 0)50 if (!count($users) > 0) 56 51 { 57 $list=array_keys($users);58 $sql = "DELETE FROM tor_passwd where id IN (".implode(',',$list).")";59 $res = $this->_db->query( $sql );60 $this->addMessage($this->_str['info_users_deleted']);61 } else {62 52 $this->addMessage($this->_str['err_users_nosel']); 53 return; 63 54 } 55 $list = array_keys($users); 56 $this->_db->modifyMany('DELETE FROM tor_passwd WHERE id = ?', $list); 57 $this->addMessage($this->_str['info_users_deleted']); 64 58 } 65 59 public function addUser($user, $passwd, $admin, $dir, $force_dir) 66 60 { 67 if($user != '' && $passwd != '') 68 { 69 if($admin == 'on') $admin = 1; 70 if($force_dir == 'on') $force_dir = 1; 71 $sql = "insert into tor_passwd(user, passwd, admin, dir, force_dir) values('$user', '" . md5($passwd) . "', '" . $admin . "', '$dir', '$force_dir')"; 72 $this->_db->query( $sql ); 73 $this->addMessage($this->_str['info_users_added']); 74 } else { 61 if (empty($user) || empty($passwd)) 62 { 75 63 $this->addMessage($this->_str['err_users_add']); 64 return; 76 65 } 77 66 67 $admin = $admin == 'on' ? 1 : 0; 68 $force_dir = $force_dir == 'on' ? 1 : 0; 69 $this->db->modify( 70 'INSERT INTO tor_passwd (user, passwd, admin, dir, force_dir', 71 $user, 72 md5($passwd), 73 $admin, 74 $dir, 75 $force_dir 76 ); 77 $this->addMessage($this->_str['info_users_added']); 78 78 } 79 79 protected function setPerm() trunk/wtorrent/wt/cls/Cookie.cls.php
r91 r93 35 35 } 36 36 37 $this->info = $this->_db-> arrayQuery("SELECT * FROM cookie WHERE userid = {$this->getIdUser()}", SQLITE_ASSOC);37 $this->info = $this->_db->queryAll('SELECT * FROM cookie WHERE userid = ?', $this->getIdUser()); 38 38 } 39 39 public function getCookies() … … 48 48 return; 49 49 } 50 $sql = sprintf( 51 "INSERT INTO cookie (userid, hostname, value) VALUES(%d, '%s', '%s')", 50 51 $this->_db->modify( 52 'INSERT INTO cookie (userid, hostname, value) VALUES (?, ?, ?)', 52 53 $this->getIdUser(), 53 sqlite_escape_string($this->_post['cookie_host']),54 sqlite_escape_string($this->_post['cookie_value'])54 $this->_post['cookie_host'], 55 $this->_post['cookie_value'] 55 56 ); 56 $this->_db->queryExec($sql); 57 57 58 $this->addMessage($this->_str['info_add_cookie']); 58 59 } … … 65 66 } 66 67 67 $ sql = sprintf(68 "DELETE FROM cookie WHERE userid = %d AND id = %d",68 $this->_db->modify( 69 'DELETE FROM cookie WHERE userid = ? AND id = ?', 69 70 $this->getIdUser(), 70 $this->_post['cookie_id']71 intval($this->_post['cookie_id']) 71 72 ); 72 $this->_db->query($sql);73 73 $this->addMessage($this->_str['info_erase_cookie']); 74 74 } trunk/wtorrent/wt/cls/Feeds.cls.php
r51 r93 37 37 $this->setFeeds(); 38 38 $this->fetchFeeds(); 39 /*if(isset($this->_request['stop'])) $this->stop($this->_request['stop']);40 if(isset($this->_request['erase'])) $this->erase($this->_request['erase']);41 if(isset($this->_request['ch_dw'])) $this->setDownLimit($this->_request['down_rate']);42 if(isset($this->_request['ch_up'])) $this->setUploadLimit($this->_request['up_rate']);*/43 39 } 44 40 } … … 46 42 { 47 43 $this->view_feed = $id; 48 $sql = "SELECT url FROM feeds where user = " . $this->getIdUser() . " AND id = '$id';"; 49 $res = $this->_db->query( $sql ); 50 $result = $res->fetchAll(); 51 44 $url = $this->_db->queryColumn( 45 'SELECT url FROM feeds WHERE user = ? AND id = ?', 46 $this->getIdUser(), 47 $id 48 ); 52 49 $this->feeds = new SimplePie(); 53 $this->feeds->set_feed_url($ result[0]['url']);50 $this->feeds->set_feed_url($url); 54 51 $this->feeds->set_cache_location(DIR_TPL_COMPILE); 55 52 $this->feeds->init(); 56 53 $this->feeds->handle_content_type(); 57 58 /*$this->info['title'] = $this->feeds->get_title();59 $this->info['description'] = $this->feeds->get_description();60 $this->info['items'] = $this->feeds->get_items();*/61 54 } 62 55 private function setFeeds() 63 56 { 64 $sql = "SELECT id, url FROM feeds where user = " . $this->getIdUser() . ";"; 65 $res = $this->_db->query( $sql ); 66 $result = $res->fetchAll(); 67 $num_feeds = count($result); 68 /*$sql = "select count(*) from feeds where user = " . $this->getIdUser() . ";"; 69 $num_feeds = 1 ;//count($this->feeds);*/ 70 for($i = 0; $i < $num_feeds; $i++) 57 $feeds = $this->_db->queryAll( 58 'SELECT id, url FROM feeds WHERE user = ?', 59 $this->getIdUser() 60 ); 61 for ($i = 0, $e = sizeof($feeds); $i < $e; ++$i) 71 62 { 72 $this->feeds[$i]['feed'] = new SimplePie(); 73 $this->feeds[$i]['feed']->set_feed_url($result[$i]['url']); 74 $this->feeds[$i]['feed']->set_cache_location(rtrim(DIR_TPL_COMPILE, '/')); 75 $this->feeds[$i]['feed']->init(); 76 $this->feeds[$i]['feed']->handle_content_type(); 77 $this->feeds[$i]['id'] = $result[$i]['id']; 63 $feed = $feeds[$i]; 64 $pie = new SimplePie(); 65 $pie->set_feed_url($feed['url']); 66 $pie->set_cache_location(rtrim(DIR_TPL_COMPILE, '/')); 67 $pie->init(); 68 $pie->handle_content_type(); 69 $this->feeds[] = array( 70 'feed' => $pie, 71 'id' => $feed['id'] 72 ); 78 73 } 79 74 } … … 83 78 $result = $this->client->send($message); 84 79 if($result->errno == 0) 80 { 85 81 $this->addMessage($this->_str['info_ch_dir']); 82 } 86 83 else 84 { 87 85 $this->addMessage($this->_str['err_ch_dir']); 86 } 88 87 } 89 88 private function Download($uri) … … 101 100 public function isView() 102 101 { 103 if($this->view_feed === false) 104 return false; 105 else 106 return true; 102 return $this->view_feed; 107 103 } 108 104 public function getFeeds() … … 124 120 private function fetchFeeds() 125 121 { 126 $num_feeds = count($this->feeds); 127 for($i = 0; $i < $num_feeds;$i++) 128 { 129 $this->info[$i]['title'] = $this->feeds[$i]['feed']->get_title(); 130 $this->info[$i]['description'] = $this->feeds[$i]['feed']->get_description(); 131 $this->info[$i]['id'] = $this->feeds[$i]['id']; 132 /*foreach ($this->feeds[$i]->get_items() as $key => $item) 133 { 134 $this->info[$i]['items'][$key]['title'] = $item->get_title(); 135 $this->info[$i]['items'][$key]['description'] = $item->get_description(); 136 $this->info[$i]['items'][$key]['link'] = $item->get_link(); 137 $this->info[$i]['items'][$key]['date'] = $item->get_date("U"); 138 }*/ 139 } 140 } 141 private function AddFeed($feed_url) 142 { 143 $sql = "INSERT INTO feeds(url, user) VALUES('$feed_url' , '". $this->getIdUser() . "');"; 144 $this->_db->query($sql); 145 $this->addMessage($this->_str['info_add_feed']); 146 } 147 private function DeleteFeed($id) 148 { 149 $sql = "DELETE FROM feeds WHERE user = '". $this->getIdUser() . "' AND id = '$id';"; 150 $this->_db->query($sql); 151 $this->addMessage($this->_str['info_erase_feed']); 152 } 122 $num_feeds = count($this->feeds); 123 for($i = 0; $i < $num_feeds;$i++) 124 { 125 $this->info[$i]['title'] = $this->feeds[$i]['feed']->get_title(); 126 $this->info[$i]['description'] = $this->feeds[$i]['feed']->get_description(); 127 $this->info[$i]['id'] = $this->feeds[$i]['id']; 128 } 129 } 130 private function AddFeed($feed_url) 131 { 132 $this->_db->modify( 133 'INSERT INTO feeds (url, user) VALUES (?, ?)', 134 $feed_url, 135 $this->getIdUser() 136 ); 137 $this->addMessage($this->_str['info_add_feed']); 138 } 139 private function DeleteFeed($id) 140 { 141 $this->_db->modify( 142 'DELETE FROM feeds WHERE user = ? AND id = ?', 143 $this->getIdUser(), 144 $id 145 ); 146 $this->addMessage($this->_str['info_erase_feed']); 147 } 153 148 } 154 149 ?> trunk/wtorrent/wt/cls/ListT.cls.php
r92 r93 46 46 'd.get_creation_date', 47 47 'd.get_left_bytes', 48 'd.get_size_bytes'48 'd.get_size_bytes' 49 49 ); 50 50 private static $TORRENT_VALUES = array( 51 51 't.get_scrape_complete', 52 't.get_scrape_incomplete'52 't.get_scrape_incomplete' 53 53 ); 54 54 trunk/wtorrent/wt/css/estil.css
r90 r93 721 721 filter:alpha(opacity=60); 722 722 } 723 /* Install styles */ 724 #install #col1, #col2 { 725 width: 50%; 726 float: left; 727 } 728 #install #wrapper { 729 margin: 20px 0 20px 0; 730 } 731 #install .row { 732 margin: 10px 0 0 0; 733 } 734 #install label { 735 width: 200px; 736 display: inline; 737 float: left; 738 clear: left; 739 text-align: right; 740 padding: 5px 10px 0 0; 741 font-size: 12px; 742 } 743 #install input[type="text"], #install select { 744 width: 230px; 745 display: inline; 746 float: left; 747 } 748 #install select { 749 width: auto; 750 } 751 h1 { 752 color: #5699d6; 753 font-size: 18px; 754 font-weight: bold; 755 border-bottom: 2px solid #5699d6; 756 margin-left: 10px; 757 } 758 h2 { 759 color: #5699d6; 760 font-weight: bold; 761 margin-left: 10px; 762 font-size: 14px; 763 padding-bottom: 10px; 764 } trunk/wtorrent/wt/lang/en.txt
r91 r93 187 187 confirm_erase = Want to remove %S? 188 188 no_torrents_selected = No torrents selected 189 190 language_err = <b>Error:</b> language file is not readable. Please set proper permissions. 191 config_install_err = <b>Error:</b> cannot write user.conf.php please check conf/ folder permissions. 192 rt_install_err = <b>Error:</b> cannot connect to rtorrent, please check host, folder and port values (and user/password if you have auth set up). 193 dir_torrents_err = <b>Error:</b> cannot write to torrents folder, please check permissions. 194 dir_exec_err = <b>Error:</b> execution folder doesn't exists, please set the proper folder. 195 db_file_err = <b>Error:</b> cannot create database file, please check permissions. 196 db_create_err = <b>Error:</b> cannot open database, please check that you have sqlite PDO extension properly installed. 197 missing_user = <b>Error:</b> please set user and password. 198 try_ok = Configuration seems fine, you can save it now. 199 create_config_ok = Configuration file and database created, enjoy wTorrent and don't forget to delete install.php. 200 201 false = False 202 true = True 203 204 wtorrent_settings = wTorrent Settings 205 user_password = Set wTorrent login 206 language_info = Language: 207 db_file_info = Database file: 208 rt_host_info = rTorrent scgi host: 209 rt_port_info = rTorrent scgi port: 210 rt_dir_info = rTorrent scgi folder: 211 rt_auth_info = Enable auth for the scgi folder: 212 rt_user_info = rTorrent scgi user: 213 rt_passwd_info = rTorrent scgi password: 214 no_multicall_info = Don't use multicall: 215 effects_info = User scriptaculous effects: 216 dir_torrents_info = Folder to save uploaded torrents: 217 dir_exec_info = Folder where wTorrent is: 218 dir_download_info = Default folder to save torrent data: 219 user_info = User: 220 passwd_info = Password: 221 try_info = Try configuration 222 save_info = Save configuration 223 install = INSTALL 224 trunk/wtorrent/wt/tpl/ajax.tpl.php
r4 r93 1 {if $web-> registrado()}1 {if $web->isRegistered()} 2 2 {include file=$web->getTpl()} 3 3 {else} trunk/wtorrent/wt/tpl/index.tpl.php
r90 r93 18 18 {include file="loading.tpl.php" assign="loading"} 19 19 {include file="comm_loading.tpl.php" assign="comm_loading"} 20 {if $web-> registrado()}20 {if $web->isRegistered()} 21 21 {literal} 22 22 <script type="text/javascript"> … … 33 33 34 34 <body> 35 {if $web-> registrado()}35 {if $web->isRegistered()} 36 36 <div id="menu"> 37 37 {include file="menu.tpl.php" width_total="600"} … … 39 39 {/if} 40 40 {include file="messages.tpl.php"} 41 {if $web-> registrado()}41 {if $web->isRegistered()} 42 42 {include file="content.tpl.php"} 43 43 {else}
