| 1 | <?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 | class rtorrent extends Web |
|---|
| 21 | { |
|---|
| 22 | protected $client; |
|---|
| 23 | private $menu = array('Main' => 'ListT', |
|---|
| 24 | 'Add Torrent' => 'AddT', |
|---|
| 25 | 'Feeds' => 'Feeds', |
|---|
| 26 | 'Cookie' => 'Cookie'); |
|---|
| 27 | private $menu_admin = array('Main' => 'ListT', |
|---|
| 28 | 'Add Torrent' => 'AddT', |
|---|
| 29 | 'Feeds' => 'Feeds', |
|---|
| 30 | 'Admin' => 'Admin', |
|---|
| 31 | 'Cookie' => 'Cookie'); |
|---|
| 32 | private $submenu = array('General' => 'General&tpl=details', |
|---|
| 33 | 'Files' => 'Files&tpl=details', |
|---|
| 34 | 'Tracker' => 'Tracker&tpl=details'); |
|---|
| 35 | protected $admin; |
|---|
| 36 | /////////////////////////////////// C O N S T R U C T O R A S Y D E S T R U C T O R A /////////////////////////////////// |
|---|
| 37 | |
|---|
| 38 | public function __construct( ) |
|---|
| 39 | { |
|---|
| 40 | parent::__construct( ); |
|---|
| 41 | if(isset($this->_request['logout'])) $this->logout(); |
|---|
| 42 | if(isset($this->_request['user_login'])) $this->login($this->_request['userf'], $this->_request['passwdf']); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | protected function construct( ){} |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | public function registrado( ) |
|---|
| 50 | { |
|---|
| 51 | return !is_null( $this->_sesion->id_user ); |
|---|
| 52 | } |
|---|
| 53 | public function compLogin($user, $passwd) |
|---|
| 54 | { |
|---|
| 55 | $passwd = md5($passwd); |
|---|
| 56 | $sql = "select id from tor_passwd where user = '$user' and passwd = '$passwd'"; |
|---|
| 57 | $result = $this->_db->query( $sql ); |
|---|
| 58 | if(is_object($result)) |
|---|
| 59 | { |
|---|
| 60 | $num = $result->numRows(); |
|---|
| 61 | |
|---|
| 62 | if($num > 0) |
|---|
| 63 | $return = $result->current(); |
|---|
| 64 | else |
|---|
| 65 | $return = false; |
|---|
| 66 | |
|---|
| 67 | } else { |
|---|
| 68 | $return = false; |
|---|
| 69 | } |
|---|
| 70 | return $return; |
|---|
| 71 | } |
|---|
| 72 | public function getUser( ) |
|---|
| 73 | { |
|---|
| 74 | return $this->_sesion->user; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public function getIdUser( ) |
|---|
| 78 | { |
|---|
| 79 | return $this->_sesion->id_user; |
|---|
| 80 | } |
|---|
| 81 | public function getMenu() |
|---|
| 82 | { |
|---|
| 83 | if($this->_sesion->admin === true) |
|---|
| 84 | $return = $this->menu_admin; |
|---|
| 85 | else |
|---|
| 86 | $return = $this->menu; |
|---|
| 87 | |
|---|
| 88 | return $return; |
|---|
| 89 | } |
|---|
| 90 | public function getDetailsMenu() |
|---|
| 91 | { |
|---|
| 92 | return $this->submenu; |
|---|
| 93 | } |
|---|
| 94 | public function getWidth($total, $menu_items) |
|---|
| 95 | { |
|---|
| 96 | return floor($total/(count($menu_items)+1)) - 1; |
|---|
| 97 | } |
|---|
| 98 | public function Admin($id) |
|---|
| 99 | { |
|---|
| 100 | $sql = "select admin from tor_passwd where id = '" . $this->_sesion->id_user . "'"; |
|---|
| 101 | $result = $this->_db->query( $sql ); |
|---|
| 102 | $admin = $result->current(); |
|---|
| 103 | if($admin['admin'] == 1) |
|---|
| 104 | $return = true; |
|---|
| 105 | else |
|---|
| 106 | $return = false; |
|---|
| 107 | |
|---|
| 108 | return $return; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | public function login( $user, $password ) |
|---|
| 113 | { |
|---|
| 114 | $id = $this->compLogin($user, $password); |
|---|
| 115 | if($id != false) |
|---|
| 116 | { |
|---|
| 117 | $this->_sesion->id_user = $id['id']; |
|---|
| 118 | $this->_sesion->user = $user; |
|---|
| 119 | $this->_sesion->admin = $this->Admin($id['id']); |
|---|
| 120 | $return = true; |
|---|
| 121 | } else { |
|---|
| 122 | $return = false; |
|---|
| 123 | $this->addMessage($this->_str['err_login']); |
|---|
| 124 | } |
|---|
| 125 | return $return; |
|---|
| 126 | } |
|---|
| 127 | public function isAdmin() |
|---|
| 128 | { |
|---|
| 129 | return $this->_sesion->admin; |
|---|
| 130 | } |
|---|
| 131 | public function logout( ) |
|---|
| 132 | { |
|---|
| 133 | if($this->registrado()) |
|---|
| 134 | { |
|---|
| 135 | $this->_sesion = null; |
|---|
| 136 | $this->addMessage($this->_str['info_logout']); |
|---|
| 137 | } |
|---|
| 138 | } |
|---|
| 139 | public function setClient() |
|---|
| 140 | { |
|---|
| 141 | $this->client = new xmlrpc_client(RT_DIR, RT_HOST, RT_PORT); |
|---|
| 142 | //$this->client->setDebug(2); |
|---|
| 143 | if(RT_AUTH) |
|---|
| 144 | $this->client->setCredentials(RT_USER, RT_PASSWD); |
|---|
| 145 | $this->client->return_type = 'phpvals'; |
|---|
| 146 | $this->client->no_multicall = NO_MULTICALL; |
|---|
| 147 | |
|---|
| 148 | $message = new xmlrpcmsg("system.pid"); |
|---|
| 149 | $result = $this->client->send($message); |
|---|
| 150 | // print_r($result); |
|---|
| 151 | if($result->errno != 0) |
|---|
| 152 | { |
|---|
| 153 | $this->addMessage($this->_str['err_conn']); |
|---|
| 154 | return false; |
|---|
| 155 | } else |
|---|
| 156 | return true; |
|---|
| 157 | } |
|---|
| 158 | protected function setPerm() |
|---|
| 159 | { |
|---|
| 160 | $this->admin = false; |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | ?> |
|---|