| 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 | class Admin extends rtorrent |
|---|
| 19 | { |
|---|
| 20 | public function construct() |
|---|
| 21 | { |
|---|
| 22 | if(isset($this->_request['adduser'])) $this->addUser($this->_request['user'], $this->_request['passwd'], $this->_request['admin'], $this->_request['default_dir'], $this->_request['force_dir']); |
|---|
| 23 | if(isset($this->_request['delete'])) $this->deleteUsers($this->_request['users']); |
|---|
| 24 | |
|---|
| 25 | if(!$this->setClient()) |
|---|
| 26 | return false; |
|---|
| 27 | |
|---|
| 28 | if(isset($this->_request['ch_dw'])) $this->setDownLimit($this->_request['down_rate']); |
|---|
| 29 | if(isset($this->_request['ch_up'])) $this->setUploadLimit($this->_request['up_rate']); |
|---|
| 30 | } |
|---|
| 31 | public function getUpLimit() |
|---|
| 32 | { |
|---|
| 33 | $message = new xmlrpcmsg("get_upload_rate"); |
|---|
| 34 | $result = $this->client->send($message); |
|---|
| 35 | return round($result->val/1024, 1); |
|---|
| 36 | } |
|---|
| 37 | public function getDownLimit() |
|---|
| 38 | { |
|---|
| 39 | $message = new xmlrpcmsg("get_download_rate"); |
|---|
| 40 | $result = $this->client->send($message); |
|---|
| 41 | return round($result->val/1024, 1); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | public function showUsers() |
|---|
| 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; |
|---|
| 52 | } |
|---|
| 53 | public function deleteUsers($users) |
|---|
| 54 | { |
|---|
| 55 | if(count($users) > 0) |
|---|
| 56 | { |
|---|
| 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 | $this->addMessage($this->_str['err_users_nosel']); |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | public function addUser($user, $passwd, $admin, $dir, $force_dir) |
|---|
| 66 | { |
|---|
| 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 { |
|---|
| 75 | $this->addMessage($this->_str['err_users_add']); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | } |
|---|
| 79 | protected function setPerm() |
|---|
| 80 | { |
|---|
| 81 | $this->admin = true; |
|---|
| 82 | } |
|---|
| 83 | private function setDownLimit($limit) |
|---|
| 84 | { |
|---|
| 85 | $message = new xmlrpcmsg("set_download_rate", array(new xmlrpcval($limit*1024, 'int'))); |
|---|
| 86 | $result = $this->client->send($message); |
|---|
| 87 | //print_r($result); |
|---|
| 88 | if($result->errno == 0) |
|---|
| 89 | $this->addMessage($this->_str['info_down_limit']); |
|---|
| 90 | else |
|---|
| 91 | $this->addMessage($this->_str['err_down_limit']); |
|---|
| 92 | } |
|---|
| 93 | private function setUploadLimit($limit) |
|---|
| 94 | { |
|---|
| 95 | $message = new xmlrpcmsg("set_upload_rate", array(new xmlrpcval($limit*1024, 'int'))); |
|---|
| 96 | $result = $this->client->send($message); |
|---|
| 97 | if($result->errno == 0) |
|---|
| 98 | $this->addMessage($this->_str['info_up_limit']); |
|---|
| 99 | else |
|---|
| 100 | $this->addMessage($this->_str['err_up_limit']); |
|---|
| 101 | } |
|---|
| 102 | } |
|---|