Changeset 93

Show
Ignore:
Timestamp:
10/12/08 19:53:45 (1 year ago)
Author:
royger
Message:

* Migrated database from sqlite 2 to sqlite 3.
* From now on, you will need php to be compiled with PDO and sqlite to run wTorrent.
* Applied patch from tn123 to migrate to PDO and use prepared statements (ticket #188).
* Created new install script.
* To apply this update you will need to run sqlite_migration.sh to migrate your old database to sqlite3. This script assumes you have your database in db/database.db, if that's not the case edit the script and change the path.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wtorrent/cls/rtorrent.cls.php

    r91 r93  
    6767        protected function construct( ){} 
    6868 
    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 ); 
    9072        } 
    9173        public function getUser( ) 
    9274        { 
    93                 return $this->_sesion->user; 
     75                return $this->_session->user; 
    9476        } 
    9577        public function getIdUser( ) 
    9678        { 
    97                 return $this->_sesion->id_user; 
     79                return $this->_session->id_user; 
    9880        } 
    9981        public function getMenu() 
    10082        { 
    101                 if($this->_sesion->admin === true) 
     83                if($this->_session->admin === true) 
    10284                        $return = $this->menu_admin; 
    10385                else  
     
    11496                return floor($total/(count($menu_items)+1)) - 1; 
    11597        } 
    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                 else  
    124                         $return = false; 
    125                          
    126                 return $return; 
    127         } 
    12898        public function login( $user, $password ) 
    12999        {        
    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; 
    142113        } 
    143114        public function isAdmin() 
    144115        { 
    145                 return $this->_sesion->admin; 
    146         } 
    147         public function logout(
    148         { 
    149                 if($this->registrado()) 
    150                 { 
    151                         $this->_sesion = null; 
     116                return $this->_session->admin; 
     117        } 
     118        public function logout(
     119        { 
     120                if($this->isRegistered()) 
     121                { 
     122                        $this->_session = null; 
    152123                        $this->addMessage($this->_str['info_logout']); 
    153124                } 
     
    155126        private function getPrivate() 
    156127        { 
    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; 
    165134        } 
    166135        public function setClient() 
     
    248217        protected function erase_db($hash) 
    249218        { 
    250                 $sql = "delete from torrents where hash = '" . $hash . "'"; 
    251                 $this->_db->query($sql); 
     219                $this->_db->modify('DELETE FROM torrents WHERE hash = ?', $hash); 
    252220        } 
    253221        protected function setPerm() 
  • trunk/wtorrent/install.php

    r77 r93  
    11<?php 
    2 require_once( 'conf/user.conf.php' ); 
     2/* 
     3This file is part of wTorrent. 
     4 
     5wTorrent is free software; you can redistribute it and/or modify 
     6it under the terms of the GNU General Public License as published by 
     7the Free Software Foundation; either version 3 of the License, or 
     8(at your option) any later version. 
     9 
     10wTorrent is distributed in the hope that it will be useful, 
     11but WITHOUT ANY WARRANTY; without even the implied warranty of 
     12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     13GNU General Public License for more details. 
     14 
     15You should have received a copy of the GNU General Public License 
     16along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     17 
     18Modified version of class done by David Marco Martinez 
     19*/ 
     20require_once("lib/cls/Web.cls.php"); 
     21require_once("cls/install.cls.php"); 
     22error_reporting(E_ALL); 
     23// Record the start time of execution 
     24$mtime = microtime( true ); 
     25// Start php session BEFORE ANY output 
     26session_start(); 
     27// Load conf 
     28//require_once( 'conf/user.conf.php' ); 
     29install::setDefines(); 
    330require_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 
     41if($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; 
    448?> 
    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         Install 
    18 </div> 
    19 <?php 
    20 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                         else 
    48                                 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                 else 
    70                         echo 'Error performing update, please check wTorrent for correct installation and/or reinstall'; 
    71         } else 
    72                 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/password 
    81     </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  
    3030 
    3131        protected $_str                         = array( ); 
    32         protected $_sesion            = null; 
     32        protected $_session           = null; 
    3333        protected $_request             = null; 
    3434        protected $_post                        = null; 
     
    4444        protected $_ajax                        = false; 
    4545 
    46         public function __construct(
     46        public function __construct($install = false
    4747        { 
    4848                // 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                } 
    5159                // Instance of Smarty templates system 
    5260                $this->_smarty                                                          = new Smarty( ); 
     
    6270                foreach( $this->_getConstants( ) as $k => $v ) $this->smartyAssign( $k, $v ); 
    6371 
    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; 
    7380                 
    7481                // Create json class 
    7582                $this->_json                    = new Services_JSON(); 
    76                  
     83                if($install) 
     84                { 
     85                        $this->_lang = 'en'; 
     86                } 
    7787                $this->loadLanguage( $this->getLang( ) ); 
    7888                if(isset($this->_request['ajax']))      $this->_ajax = true; 
     
    110120 
    111121                // Subclass constructor 
    112                 if($this->registrado()) 
     122                if($this->isRegistered()) 
    113123                { 
    114124                        $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(); 
    119126                } 
    120127 
  • trunk/wtorrent/lib/inc/includes.inc.php

    r91 r93  
    2424require_once( 'cls/torrent.cls.php' ); 
    2525require_once( 'cls/multicall.cls.php' ); 
     26//require_once( 'cls/install.cls.php' ); 
    2627require_once( 'lib/xmlrpc/xmlrpc.inc.php' ); 
    2728require_once( 'lib/inc/utils.inc.php' ); 
  • trunk/wtorrent/lib/inc/string.inc.php

    r4 r93  
    3737} 
    3838 
    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; 
     39function _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
     50function unescape( $var ) 
     51
     52        if (!get_magic_quotes_gpc()) 
     53        { 
     54                return; 
     55        } 
     56        return _unescape_internal($var); 
    5157} 
    5258function html( $str ) 
  • trunk/wtorrent/wt/cls/AddT.cls.php

    r84 r93  
    2121        public function construct() 
    2222        { 
    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']); 
    114106                        @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); 
    115138                } 
    116139                $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        }  
    129155        public function getDir() 
    130156        { 
    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()); 
    135158        } 
    136159        public function getForceDir() 
    137160        { 
    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()); 
    142162        } 
    143163        private function uploadTorrent($fileU, $dir, $start_now, $private) 
    144164        { 
    145                 if($this->getForceDir() == 1) 
     165                if ($this->getForceDir() == 1) 
     166                { 
    146167                        $dir = $this->getDir(); 
     168                } 
    147169                $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)) 
    149171                { 
    150172                        $this->addMessage($this->_str['err_add_dir']); 
     
    164186 
    165187                if($start_now == 'on') 
     188                { 
    166189                        $method = 'load_start'; 
    167                 else 
     190                } 
     191                else 
     192                { 
    168193                        $method = 'load'; 
     194                } 
    169195                if($private == 'on') 
    170196                { 
     
    172198                        $bencode = new BEncodeLib(); 
    173199                        $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                } 
    178202 
    179203                $message = new xmlrpcmsg($method, array(new xmlrpcval($uploadfile , 'string'))); 
    180204                $result2 = $this->client->send($message); 
    181205 
    182                 /*print_r($result1); 
    183                 print_r($result2);*/ 
    184  
    185206                if(($result1->errno == 0) && ($result2->errno == 0) && ($res[0] !== false)) 
    186207                        $this->addMessage($this->_str['info_add_torrent']); 
  • trunk/wtorrent/wt/cls/Admin.cls.php

    r74 r93  
    4444        public function showUsers() 
    4545    { 
    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'); 
    5247    } 
    5348    public function deleteUsers($users) 
    5449    { 
    55                 if(count($users) > 0) 
     50                if (!count($users) > 0) 
    5651                { 
    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 { 
    6252                        $this->addMessage($this->_str['err_users_nosel']); 
     53                        return; 
    6354                } 
     55                $list = array_keys($users); 
     56                $this->_db->modifyMany('DELETE FROM tor_passwd WHERE id = ?', $list); 
     57                $this->addMessage($this->_str['info_users_deleted']); 
    6458    } 
    6559    public function addUser($user, $passwd, $admin, $dir, $force_dir) 
    6660    { 
    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                { 
    7563                        $this->addMessage($this->_str['err_users_add']); 
     64                        return; 
    7665                } 
    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']); 
    7878    } 
    7979    protected function setPerm() 
  • trunk/wtorrent/wt/cls/Cookie.cls.php

    r91 r93  
    3535                } 
    3636 
    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()); 
    3838        } 
    3939        public function getCookies() 
     
    4848                        return; 
    4949                } 
    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 (?, ?, ?)', 
    5253                        $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'] 
    5556                ); 
    56                 $this->_db->queryExec($sql); 
     57 
    5758                $this->addMessage($this->_str['info_add_cookie']); 
    5859        } 
     
    6566                } 
    6667 
    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 = ?'
    6970                        $this->getIdUser(), 
    70                         $this->_post['cookie_id'] 
     71                        intval($this->_post['cookie_id']) 
    7172                ); 
    72                 $this->_db->query($sql); 
    7373                $this->addMessage($this->_str['info_erase_cookie']); 
    7474        } 
  • trunk/wtorrent/wt/cls/Feeds.cls.php

    r51 r93  
    3737                        $this->setFeeds(); 
    3838                        $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']);*/         
    4339                } 
    4440        } 
     
    4642        { 
    4743                $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                ); 
    5249                $this->feeds = new SimplePie(); 
    53                 $this->feeds->set_feed_url($result[0]['url']); 
     50                $this->feeds->set_feed_url($url); 
    5451                $this->feeds->set_cache_location(DIR_TPL_COMPILE); 
    5552                $this->feeds->init(); 
    5653                $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();*/ 
    6154        } 
    6255        private function setFeeds() 
    6356        {        
    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) 
    7162                { 
    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                        ); 
    7873                } 
    7974        } 
     
    8378                $result = $this->client->send($message); 
    8479                if($result->errno == 0) 
     80                { 
    8581                        $this->addMessage($this->_str['info_ch_dir']); 
     82                } 
    8683                else 
     84                { 
    8785                        $this->addMessage($this->_str['err_ch_dir']); 
     86                } 
    8887        } 
    8988        private function Download($uri) 
     
    101100        public function isView() 
    102101        { 
    103                 if($this->view_feed === false) 
    104                         return false; 
    105                 else 
    106                         return true; 
     102                return $this->view_feed; 
    107103        } 
    108104        public function getFeeds() 
     
    124120        private function fetchFeeds() 
    125121        { 
    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        } 
    153148} 
    154149?> 
  • trunk/wtorrent/wt/cls/ListT.cls.php

    r92 r93  
    4646                'd.get_creation_date', 
    4747                'd.get_left_bytes', 
    48                       'd.get_size_bytes' 
     48              'd.get_size_bytes' 
    4949        ); 
    5050        private static $TORRENT_VALUES = array( 
    5151                't.get_scrape_complete', 
    52                       't.get_scrape_incomplete' 
     52              't.get_scrape_incomplete' 
    5353        ); 
    5454 
  • trunk/wtorrent/wt/css/estil.css

    r90 r93  
    721721        filter:alpha(opacity=60); 
    722722} 
     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} 
     751h1 { 
     752        color: #5699d6; 
     753        font-size: 18px; 
     754        font-weight: bold; 
     755        border-bottom: 2px solid #5699d6; 
     756        margin-left: 10px; 
     757} 
     758h2 { 
     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  
    187187confirm_erase = Want to remove %S? 
    188188no_torrents_selected = No torrents selected 
     189 
     190language_err = <b>Error:</b> language file is not readable. Please set proper permissions. 
     191config_install_err = <b>Error:</b> cannot write user.conf.php please check conf/ folder permissions. 
     192rt_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). 
     193dir_torrents_err = <b>Error:</b> cannot write to torrents folder, please check permissions. 
     194dir_exec_err = <b>Error:</b> execution folder doesn't exists, please set the proper folder. 
     195db_file_err = <b>Error:</b> cannot create database file, please check permissions. 
     196db_create_err = <b>Error:</b> cannot open database, please check that you have sqlite PDO extension properly installed. 
     197missing_user = <b>Error:</b> please set user and password. 
     198try_ok = Configuration seems fine, you can save it now. 
     199create_config_ok = Configuration file and database created, enjoy wTorrent and don't forget to delete install.php. 
     200 
     201false = False 
     202true = True 
     203 
     204wtorrent_settings = wTorrent Settings 
     205user_password = Set wTorrent login 
     206language_info = Language: 
     207db_file_info = Database file: 
     208rt_host_info = rTorrent scgi host: 
     209rt_port_info = rTorrent scgi port: 
     210rt_dir_info = rTorrent scgi folder: 
     211rt_auth_info = Enable auth for the scgi folder: 
     212rt_user_info = rTorrent scgi user: 
     213rt_passwd_info = rTorrent scgi password: 
     214no_multicall_info = Don't use multicall: 
     215effects_info = User scriptaculous effects: 
     216dir_torrents_info = Folder to save uploaded torrents: 
     217dir_exec_info = Folder where wTorrent is: 
     218dir_download_info = Default folder to save torrent data: 
     219user_info = User: 
     220passwd_info = Password: 
     221try_info = Try configuration 
     222save_info = Save configuration 
     223install = INSTALL 
     224  
  • trunk/wtorrent/wt/tpl/ajax.tpl.php

    r4 r93  
    1 {if $web->registrado()} 
     1{if $web->isRegistered()} 
    22        {include file=$web->getTpl()} 
    33{else} 
  • trunk/wtorrent/wt/tpl/index.tpl.php

    r90 r93  
    1818  {include file="loading.tpl.php" assign="loading"} 
    1919  {include file="comm_loading.tpl.php" assign="comm_loading"} 
    20         {if $web->registrado()} 
     20        {if $web->isRegistered()} 
    2121                {literal} 
    2222                        <script type="text/javascript"> 
     
    3333 
    3434<body> 
    35 {if $web->registrado()} 
     35{if $web->isRegistered()} 
    3636<div id="menu"> 
    3737        {include file="menu.tpl.php" width_total="600"} 
     
    3939{/if} 
    4040{include file="messages.tpl.php"} 
    41 {if $web->registrado()} 
     41{if $web->isRegistered()} 
    4242        {include file="content.tpl.php"} 
    4343{else}