Beispiel #1
0
 /**
  * 连接数据库
  */
 private function connect()
 {
     $config = Cellular::config('memcached');
     $mc = new Memcached();
     $mc->addServer($config['host'], $config['port']);
     return $mc;
 }
Beispiel #2
0
 static function authentificationPourRtorrent($keyconnexion)
 {
     if (!is_null($keyconnexion)) {
         $u = \core\Memcached::value($keyconnexion, "user");
         if (is_null($u)) {
             $u = \model\mysql\Utilisateur::authentifierUtilisateurParKeyConnexion($keyconnexion);
             if ($u) {
                 \core\Memcached::value($u->keyconnexion, "user", $u, 60 * 2);
             }
         } else {
             $u = $u->keyconnexion === $keyconnexion ? $u : false;
             if (is_bool($u)) {
                 $u = \model\mysql\Utilisateur::authentifierUtilisateurParKeyConnexion($keyconnexion);
                 if ($u) {
                     \core\Memcached::value($u->keyconnexion, "user", $u, 60 * 2);
                 }
             } else {
                 \core\Memcached::value($u->keyconnexion, "user", $u, 60 * 2);
             }
         }
         \config\Conf::$user["user"] = $u;
         if ($u && !is_null($u)) {
             setcookie("keyconnexion", $u->keyconnexion, strtotime('+1 days'), "/");
             $userscgi = \model\mysql\Rtorrent::getUserscgiDeUtilisateur($u->login);
             if (!$userscgi) {
                 throw new \Exception("Aucun ports scgi sur " . HOST);
             }
             \config\Conf::$userscgi = $userscgi[0]->userscgi;
         }
     }
 }
Beispiel #3
0
 /**
  * 根据全局或者模块配置实例化MemcachedResource对象
  *
  * @access public
  * @param null $persistent_id
  * @param array $config
  * @return \Memcached
  * @throws \MemcachedException
  */
 public static function memcached($persistent_id = NULL, $config = array())
 {
     if (self::$memcached && self::$memcached instanceof MemcachedResource) {
         return self::$memcached;
     } else {
         if (!empty($config)) {
         } else {
             if (Registry::get("config") && Registry::get("config")->memcached_config instanceof Simple && ($config = Registry::get("config")->memcached_config->toArray())) {
             } else {
                 if (isset(Application::app()->getConfig()->application->memcached)) {
                     $config = Application::app()->getConfig()->application->memcached->toArray();
                 }
             }
         }
         if ($persistent_id) {
             self::$memcached = new MemcachedResource((string) $persistent_id);
         } else {
             self::$memcached = new MemcachedResource();
         }
         $look_host = false;
         if (array_key_exists(0, $config)) {
             self::$memcached->addServers($config);
             $look_host = true;
         } else {
             if ($config['host']) {
                 self::$memcached->addServer($config['host'], isset($config['port']) ? (int) $config['port'] : 11211, isset($config['weight']) ? (int) $config['weight'] : 0);
                 $look_host = true;
             }
         }
         if ($look_host) {
             if (self::$memcached->getResultCode() == MemcachedResource::RES_HOST_LOOKUP_FAILURE) {
                 throw new MemcachedException("Add Server To Memcached Failed", MemcachedResource::RES_HOST_LOOKUP_FAILURE);
             }
         }
         return self::$memcached;
     }
 }
 public static function get($user, $create = false)
 {
     if (is_null(self::$theSettings)) {
         self::$theSettings = new rTorrentSettings($user);
         if ($create) {
             self::$theSettings->obtain();
         } else {
             $res = Memcached::value("rtorrent" . $user, "rtorrentsetting");
             if (!$res) {
                 self::$theSettings->obtain();
             } else {
                 self::$theSettings = $res;
             }
         }
     }
     return self::$theSettings;
 }
Beispiel #5
0
 function getKeyconnexion()
 {
     $u = null;
     if (isset($_COOKIE["keyconnexion"])) {
         $u = \core\Memcached::value($_COOKIE["keyconnexion"], "user");
         if (is_null($u)) {
             $u = \model\mysql\Utilisateur::authentifierUtilisateurParKeyConnexion($_COOKIE["keyconnexion"]);
             if ($u) {
                 \core\Memcached::value($_COOKIE["keyconnexion"], "user", $u, 60 * 5);
             }
         } else {
             $u = $u->keyconnexion === $_COOKIE["keyconnexion"] ? $u : false;
         }
         $this->set("seedbox", Rtorrent::getUserscgiDeUtilisateur(\config\Conf::$user["user"]->login));
     }
     if ($u && !is_null($u)) {
         \core\Memcached::value($_COOKIE["keyconnexion"], "user", $u, 60 * 5);
         \config\Conf::$user["user"] = $u;
         $this->set("key", $u->keyconnexion);
     } else {
         $u = \model\mysql\Utilisateur::authentifierUtilisateurParMotDePasse($_REQUEST["login"], $_REQUEST["motdepasse"]);
         if (is_object($u)) {
             $this->set("key", $u->keyconnexion);
             if (!\core\Memcached::value($u->keyconnexion, "user", $u, 60 * 5)) {
                 trigger_error("Impossible de mettre des données dans memcached");
             }
             //setcookie("login", $u->login, strtotime('+1 days'), "/");
             setcookie("keyconnexion", $u->keyconnexion, strtotime('+1 days'), "/");
             \config\Conf::$user["user"] = $u;
         }
     }
     if (is_null(\config\Conf::$user["user"])) {
         $this->set("erreur", 1);
     } else {
         $this->set("seedbox", \model\mysql\Rtorrent::getRtorrentsDeUtilisateur(\config\Conf::$user["user"]->login));
     }
 }
Beispiel #6
0
 function liste($keyconnexion = null, $cid = null, $hashtorrentselectionne = "")
 {
     \model\simple\Utilisateur::authentificationPourRtorrent($keyconnexion);
     $tor = null;
     if (!\config\Conf::$user["user"]) {
         throw new \Exception("Non User");
     }
     $cmds = array("d.hash=", "d.is_open=", "d.is_hash_checking=", "d.is_hash_checked=", "d.state=", "d.name=", "d.size_bytes=", "d.completed_chunks=", "d.size_chunks=", "d.bytes_done=", "d.up.total=", "d.ratio=", "d.up.rate=", "d.down.rate=", "d.chunk_size=", "d.custom1=", "d.peers_accounted=", "d.peers_not_connected=", "d.peers_connected=", "d.peers_complete=", "d.left_bytes=", "d.priority=", "d.state_changed=", "d.skip.total=", "d.hashing=", "d.chunks_hashed=", "d.base_path=", "d.creation_date=", "d.tracker_focus=", "d.is_active=", "d.message=", "d.custom2=", "d.free_diskspace=", "d.is_private=", "d.is_multi_file=", "d.throttle_name=", "d.custom=chk-state", "d.custom=chk-time", "d.custom=sch_ignore", 'cat="$t.multicall=d.hash=,t.scrape_complete=,cat={#}"', 'cat="$t.multicall=d.hash=,t.scrape_incomplete=,cat={#}"', 'cat=$d.views=', "d.timestamp.finished=", "d.timestamp.started=", "d.custom=clefunique", "d.custom=typemedias");
     $cmd = new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, "d.multicall2", array("", "main"));
     $res = array();
     foreach ($cmds as $v) {
         $res[] = \model\xmlrpc\rTorrentSettings::getCmd(\config\Conf::$userscgi, $v);
     }
     $cmd->addParameters($res);
     $cnt = count($cmd->params) - 1;
     $req = new \model\xmlrpc\rXMLRPCRequest(\config\Conf::$userscgi, $cmd);
     $t = null;
     Debug::startTimer("rtorrent");
     /*$req->success();
       Debug::endTimer("rtorrent");
       $this->set(array(
           //"torrent"=>$req->val,
           "tt"=> $req->vals
       ));
       return true;//*/
     if ($req->success(false)) {
         Debug::endTimer("rtorrent");
         $i = 0;
         $tmp = array();
         $status = array('started' => 1, 'paused' => 2, 'checking' => 4, 'hashing' => 8, 'error' => 16);
         $i = preg_match_all("/<array><data>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<value>(<string>|<i.>)(.*)((\n)?<\\/string>|<\\/i.>)<\\/value>.*<\\/data><\\/array>/Us", $req->val, $tmp1);
         for ($ii = 0; $ii < $i; $ii++) {
             $torrent = null;
             $state = 0;
             $is_open = $tmp1[2 + 4 * 1][$ii];
             $is_hash_checking = $tmp1[2 + 4 * 2][$ii];
             $is_hash_checked = $tmp1[2 + 4 * 3][$ii];
             $get_state = $tmp1[2 + 4 * 4][$ii];
             $get_hashing = $tmp1[2 + 4 * 24][$ii];
             $is_active = $tmp1[2 + 4 * 29][$ii];
             $msg = $tmp1[2 + 4 * 30][$ii];
             if ($is_open != 0) {
                 $state |= $status["started"];
                 if ($get_state == 0 || $is_active == 0) {
                     $state |= $status["paused"];
                 }
             }
             if ($get_hashing != 0) {
                 $state |= $status["hashing"];
             }
             if ($is_hash_checking != 0) {
                 $state |= $status["checking"];
             }
             if ($msg != "" && $msg != "Tracker: [Tried all trackers.]") {
                 $state |= $status["error"];
             }
             $torrent[] = $state;
             //state 0
             $torrent[] = $tmp1[2 + 4 * 5][$ii];
             //nom 1
             $torrent[] = intval($tmp1[2 + 4 * 6][$ii]);
             //taille 2
             $get_completed_chunks = $tmp1[2 + 4 * 7][$ii];
             $get_hashed_chunks = $tmp1[2 + 4 * 25][$ii];
             $get_size_chunks = $tmp1[2 + 4 * 8][$ii];
             $chunks_processing = $is_hash_checking == 0 ? $get_completed_chunks : $get_hashed_chunks;
             $done = floor($chunks_processing / $get_size_chunks * 1000);
             $torrent[] = $done;
             // 3
             $torrent[] = intval($tmp1[2 + 4 * 9][$ii]);
             //downloaded 4
             $torrent[] = intval($tmp1[2 + 4 * 10][$ii]);
             //Uploaded 5
             $torrent[] = intval($tmp1[2 + 4 * 11][$ii]);
             //ratio 6
             $torrent[] = intval($tmp1[2 + 4 * 12][$ii]);
             //UL 7
             $torrent[] = intval($tmp1[2 + 4 * 13][$ii]);
             //DL 8
             $get_chunk_size = $tmp1[2 + 4 * 14][$ii];
             $torrent[] = $tmp1[2 + 4 * 13][$ii] > 0 ? floor(($get_size_chunks - $get_completed_chunks) * $get_chunk_size / $tmp1[2 + 4 * 13][$ii]) : -1;
             //Eta 9 (Temps restant en seconde)
             /*$get_peers_not_connected = $tmp1[2+4*17][$ii];
               $get_peers_connected = $tmp1[2+4*18][$ii];
               $get_peers_all = $get_peers_not_connected+$get_peers_connected;*/
             $torrent[] = intval($tmp1[2 + 4 * 16][$ii]);
             //Peer Actual 10
             $torrent[] = intval($tmp1[2 + 4 * 19][$ii]);
             //Seed Actual 11
             $seeds = 0;
             foreach (explode("#", $tmp1[2 + 4 * 39][$ii]) as $k => $v) {
                 $seeds += $v;
             }
             $peers = 0;
             foreach (explode("#", $tmp1[2 + 4 * 40][$ii]) as $k => $v) {
                 $peers += $v;
             }
             $torrent[] = $peers;
             //Peer total 12
             $torrent[] = $seeds;
             //Seed tota 13
             $torrent[] = intval($tmp1[2 + 4 * 20][$ii]);
             //Taille restant 14
             $torrent[] = intval($tmp1[2 + 4 * 21][$ii]);
             //Priority 15 (0 ne pas télécharger, 1 basse, 2 moyenne, 3 haute)
             $torrent[] = intval($tmp1[2 + 4 * 22][$ii]);
             //State change 16 (dernière date de change d'état)
             $torrent[] = intval($tmp1[2 + 4 * 23][$ii]);
             //Skip total Contiens les rejets en mo 17
             $torrent[] = $tmp1[2 + 4 * 26][$ii];
             //Base Path 18
             $torrent[] = intval($tmp1[2 + 4 * 27][$ii]);
             //Date create 19
             $torrent[] = intval($tmp1[2 + 4 * 28][$ii]);
             //Focus tracker 20
             /*try {
                   torrent.comment = this.getValue(values,31);
                   if(torrent.comment.search("VRS24mrker")==0)
                       torrent.comment = decodeURIComponent(torrent.comment.substr(10));
               } catch(e) { torrent.comment = ''; }*/
             $torrent[] = intval($tmp1[2 + 4 * 32][$ii]);
             //Torrent free diskspace 21
             $torrent[] = intval($tmp1[2 + 4 * 33][$ii]);
             //Torrent is private 22
             $torrent[] = intval($tmp1[2 + 4 * 34][$ii]);
             //Torrent is multifile 23
             $torrent[] = intval($tmp1[2 + 4 * 42][$ii]);
             //Torrent seed time 24
             $torrent[] = intval($tmp1[2 + 4 * 43][$ii]);
             //Torrent add time 25
             $torrent[] = $msg;
             //Message tracker 26
             $torrent[] = $tmp1[2 + 4 * 0][$ii];
             //Hash 27
             $torrent[] = $tmp1[2 + 4 * 44][$ii];
             //Clefunique
             $torrent[] = $tmp1[2 + 4 * 45][$ii];
             //Type medias
             if ($hashtorrentselectionne == $tmp1[2 + 4 * 0][$ii]) {
                 $tor = $torrent;
             }
             $tmp[$tmp1[2 + 4 * 0][$ii]] = $torrent;
         }
         $data = $tmp;
         if (!is_null($cid)) {
             if ($anc = \core\Memcached::value("torrentlist" . \config\Conf::$userscgi, $cid)) {
                 foreach ($anc as $k => $v) {
                     if (!isset($tmp[$k])) {
                         $tmp[$k] = false;
                     }
                     foreach ($v as $kk => $vv) {
                         if (isset($tmp[$k][$kk]) && $tmp[$k][$kk] == $vv) {
                             unset($tmp[$k][$kk]);
                         }
                     }
                     if (count($tmp[$k]) == 0) {
                         unset($tmp[$k]);
                     }
                 }
             }
         }
         $ncid = \model\simple\String::random(5);
         \core\Memcached::del("torrentlist" . \config\Conf::$userscgi, $cid);
         if (!\core\Memcached::value("torrentlist" . \config\Conf::$userscgi, $ncid, $data, 60 * 5)) {
             trigger_error("Impossible de mettre des données dans le cache");
         }
         $t[] = $tmp;
         $t[] = $ncid;
         $path = DS . "home" . DS . \config\Conf::$user["user"]->login . DS . "rtorrent" . DS . "data";
         $t[] = disk_total_space($path) - disk_free_space($path);
         $t[] = disk_total_space($path);
         $cmds = array("throttle.global_up.rate", "throttle.global_up.max_rate", "throttle.global_up.total", "throttle.global_down.rate", "throttle.global_down.max_rate", "throttle.global_down.total");
         $req = new \model\xmlrpc\rXMLRPCRequest(\config\Conf::$userscgi);
         foreach ($cmds as $cmd) {
             $req->addCommand(new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, $cmd));
         }
         if ($req->success()) {
             $t[] = $req->val;
         }
     }
     if (is_null($t)) {
         trigger_error("Impossible de se connecter à rtorrent :(");
     }
     $torrent = null;
     if ($hashtorrentselectionne !== "") {
         /*
          * =================================================
          * Détails du torrent hashtorrent
          * =================================================
          */
         $tmp = $tor;
         $data = $tmp;
         if (!is_null($cid)) {
             if ($anc = \core\Memcached::value("detaillist" . \config\Conf::$userscgi, sha1($cid . $hashtorrentselectionne))) {
                 foreach ($anc as $k => $v) {
                     if (isset($tmp[$k]) && $tmp[$k] == $v) {
                         unset($tmp[$k]);
                     }
                 }
             }
         }
         \core\Memcached::del("detaillist" . \config\Conf::$userscgi, sha1($cid . $hashtorrentselectionne));
         if (!\core\Memcached::value("detaillist" . \config\Conf::$userscgi, sha1($ncid . $hashtorrentselectionne), $data, 60 * 5)) {
             trigger_error("Impossible de mettre des données dans le cache");
         }
         $torrent["detail"] = $tmp;
         /*
          * =================================================
          * Détails du torrent hashtorrent (file liste)
          * =================================================
          */
         $cmds = array("f.path=", "f.completed_chunks=", "f.size_chunks=", "f.size_bytes=", "f.priority=", "f.prioritize_first=", "f.prioritize_last=");
         $cmd = new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, "f.multicall", array($hashtorrentselectionne, ""));
         foreach ($cmds as $prm) {
             $cmd->addParameter(\model\xmlrpc\rTorrentSettings::getCmd(\config\Conf::$userscgi, $prm));
         }
         $req = new \model\xmlrpc\rXMLRPCRequest(\config\Conf::$userscgi, $cmd);
         $files = null;
         $to = null;
         if (!$req->success()) {
             trigger_error("Impossible de récupéré la liste des fichiers de " . $hashtorrentselectionne);
             $files = $req->val;
         } else {
             $taille = count($req->val);
             $j = 0;
             for ($i = 0; $i < $taille; $i += 7) {
                 $files[] = array($j, $req->val[$i], $req->val[$i + 1], $req->val[$i + 2], $req->val[$i + 3], $req->val[$i + 4], $req->val[$i + 5], $req->val[$i + 6]);
                 $j++;
             }
             $tmp = $files;
             $data = $tmp;
             if (!is_null($cid)) {
                 if ($anc = \core\Memcached::value("fileslist" . \config\Conf::$userscgi, sha1($cid . $hashtorrentselectionne))) {
                     foreach ($anc as $k => $v) {
                         if (!isset($tmp[$k])) {
                             $tmp[$k] = false;
                         }
                         foreach ($v as $kk => $vv) {
                             if (isset($tmp[$k][$kk]) && $tmp[$k][$kk] == $vv) {
                                 unset($tmp[$k][$kk]);
                             }
                         }
                         if (count($tmp[$k]) == 0) {
                             unset($tmp[$k]);
                         }
                     }
                 }
             }
             \core\Memcached::del("fileslist" . \config\Conf::$userscgi, sha1($cid . $hashtorrentselectionne));
             if (!\core\Memcached::value("fileslist" . \config\Conf::$userscgi, sha1($ncid . $hashtorrentselectionne), $data, 60 * 5)) {
                 trigger_error("Impossible de mettre des données dans le cache");
             }
             $torrent["files"] = $tmp;
         }
         /*
          * =================================================
          * Détails du torrent hashtorrent (traker liste)
          * =================================================
          */
         $cmds = array("t.url=", "t.type=", "t.is_enabled=", "t.group=", "t.scrape_complete=", "t.scrape_incomplete=", "t.scrape_downloaded=", "t.normal_interval=", "t.scrape_time_last=");
         $cmd = new \model\xmlrpc\rXMLRPCCommand(\config\Conf::$userscgi, "t.multicall", array($hashtorrentselectionne, ""));
         foreach ($cmds as $prm) {
             $cmd->addParameter(\model\xmlrpc\rTorrentSettings::getCmd(\config\Conf::$userscgi, $prm));
         }
         $req = new \model\xmlrpc\rXMLRPCRequest(\config\Conf::$userscgi, $cmd);
         $trackers = null;
         if (!$req->success()) {
             trigger_error("Impossible de récupéré la liste des trakers de " . $hashtorrentselectionne);
             $traker = $req->val;
         } else {
             $taille = count($req->val);
             $j = 0;
             for ($i = 0; $i < $taille; $i += 9) {
                 $trackers[] = array($j, $req->val[$i], $req->val[$i + 1], $req->val[$i + 2], $req->val[$i + 3], $req->val[$i + 4], $req->val[$i + 5], $req->val[$i + 6], $req->val[$i + 7], $req->val[$i + 8]);
                 $j++;
             }
             /*for ($i = 0; $i < 30; $i++)
                                 $trackers[] = $trackers[0];
                                 /*$tmp = $files;
                                 $data = $tmp;
                                 if (!is_null($cid)) {
                                     if ($anc = \core\Memcached::value("fileslist" . \config\Conf::$userscgi, sha1($cid . $hashtorrentselectionne))) {
                                         foreach ($anc as $k => $v) {
                                             if (!isset($tmp[$k]))
                                                 $tmp[$k] = false;
                                             foreach ($v as $kk => $vv) {
                                                 if (isset($tmp[$k][$kk]) && $tmp[$k][$kk] == $vv) {
                                                     unset($tmp[$k][$kk]);
                                                 }
                                             }
                                             if (count($tmp[$k]) == 0)
                                                 unset($tmp[$k]);
                                         }
                                     }
                                 }
             
                                 if (!(\core\Memcached::value("fileslist" . \config\Conf::$userscgi, sha1($ncid . $hashtorrentselectionne), $data, 60 * 5)))
                                     trigger_error("Impossible de mettre des données dans le cache");
                                 */
             $torrent["trackers"] = $trackers;
         }
     }
     $this->set(array("torrent" => $t, "torrentselectionnee" => $torrent, "hashtorrent" => $hashtorrentselectionne, "host" => HOST));
 }
Beispiel #7
0
 function roleUser()
 {
     foreach (Conf::$numerorole as $k => $v) {
         if (is_array($v)) {
             foreach ($v as $kk => $vv) {
                 Conf::$rolenumero[$vv] = $k;
             }
         } else {
             Conf::$rolenumero[$v] = $k;
         }
     }
     /*$a["zzz"]="sssd";
       $a["zdz"]= new \model\xmlrpc\rTorrent();
       //Memcached::value("deb","ddd",$a);
       Memcached::value("deb","ddd");
       Memcached::value("deb1","ddd");*/
     $u = null;
     if (isset($_COOKIE["keyconnexion"])) {
         if (extension_loaded("memcached")) {
             $u = Memcached::value($_COOKIE["keyconnexion"], "user");
         }
         if (is_null($u)) {
             $u = \model\mysql\Utilisateur::authentifierUtilisateurParKeyConnexion($_COOKIE["keyconnexion"]);
             if ($u) {
                 \core\Memcached::value($_COOKIE["keyconnexion"], "user", $u, 60 * 5);
             }
         } else {
             $u = $u->keyconnexion === $_COOKIE["keyconnexion"] ? $u : false;
         }
     }
     $role = 1;
     $roletext = "Visiteur";
     if ($u && !is_null($u)) {
         $role = Conf::$rolenumero[$u->role];
         $roletext = $u->role;
         \core\Memcached::value($_COOKIE["keyconnexion"], "user", $u, 60 * 5);
         setcookie("keyconnexion", $u->keyconnexion, strtotime('+1 days'), "/");
     }
     Conf::$user["user"] = $u;
     Conf::$user["role"] = $role;
     Conf::$user["roletxt"] = $roletext;
     if ($u) {
         LoaderJavascript::add("base", "controller.setUtilisateur", array(Conf::$user["user"]->login, Conf::$user["user"]->keyconnexion, Conf::$user["user"]->role));
     }
 }
        }
    }
    if (count($trackers) > 0) {
        $announce_list[] = $trackers;
    }
    $path_edit = trim($request["repertoire"]);
    $piece_size = $request["piece"];
    $callback_log = create_function('$msg', '$fp=fopen("php://stderr","w"); fputs($fp, $msg."\\n"); fclose($fp);');
    $callback_err = create_function('$msg', '$fp=fopen("php://stdout","w"); fputs($fp, $msg."\\n"); fclose($fp);');
    if (count($announce_list) > 0) {
        $torrent = new \model\simple\Torrent($path_edit, $announce_list[0][0], $piece_size, $callback_log, $callback_err);
        if ($trackersCount > 1) {
            $torrent->announce_list($announce_list);
        }
    } else {
        $torrent = new \model\simple\Torrent($path_edit, array(), $piece_size, $callback_log, $callback_err);
    }
    if (isset($request['private'])) {
        $torrent->is_private(true);
    }
    if (isset($request["seed"])) {
        $path_edit = dirname($path_edit);
        //$torrent->save($fname);
        \core\Memcached::value($utilisateur, "torrentfile" . $taskNo, $torrent->__toString(), 60 * 60);
        \model\xmlrpc\rTorrent::sendTorrent($torrent, true, $path_edit);
    } else {
        \core\Memcached::value($utilisateur, "torrentfile" . $taskNo, $torrent->__toString(), 60 * 60);
    }
    exit(0);
}
exit(1);
Beispiel #9
0
 function genereCache()
 {
     for ($i = 0; $i < 100; $i++) {
         $login = \model\simple\String::random(5);
         \core\Memcached::value($login, "user", \model\simple\String::random(105, true), 60 * 60);
     }
 }
<?php

/**
 * Created by PhpStorm.
 * User: salorium
 * Date: 06/07/14
 * Time: 03:03
 */
define('WEBROOT', __DIR__);
define('ROOT', dirname(WEBROOT));
define('DS', DIRECTORY_SEPARATOR);
function __autoload($class_name)
{
    $filename = ROOT . DS . str_replace("\\", DS, $class_name) . ".php";
    if (file_exists($filename)) {
        require_once $filename;
    } else {
    }
}
$path_edit = trim($argv[1]);
$piece_size = "512";
$callback_log = create_function('$msg', '$fp=fopen("php://stderr","w"); fputs($fp, $msg."\\n"); fclose($fp);');
$callback_err = create_function('$msg', '$fp=fopen("php://stdout","w"); fputs($fp, $msg."\\n"); fclose($fp);');
$torrent = new \model\simple\Torrent($path_edit, array(), $piece_size, $callback_log, $callback_err);
$torrent->is_private(true);
\core\Memcached::value("salorium", "torrentfile512", $torrent->__toString(), 60 * 60);