diff --git a/lib/copy_this/www/lib/nzbget.php b/lib/copy_this/www/lib/nzbget.php new file mode 100644 index 000000000..31f8adfed --- /dev/null +++ b/lib/copy_this/www/lib/nzbget.php @@ -0,0 +1,245 @@ +serverurl = $page->serverurl; + $this->uid = $page->userdata['id']; + $this->rsstoken = $page->userdata['rsstoken']; + + switch($page->site->sabintegrationtype) + { + case SABnzbd::INTEGRATION_TYPE_USER: + if (!empty($_COOKIE['nzbget_'.$this->uid.'__host'])) + { + $this->url = $_COOKIE['nzbget_'.$this->uid.'__host']; + $this->username = $_COOKIE['nzbget_'.$this->uid.'__username']; + $this->password = $_COOKIE['nzbget_'.$this->uid.'__password']; + } + elseif (!empty($page->userdata['nzbgeturl'])) + { + $this->url = $page->userdata['nzbgeturl']; + $this->username = $page->userdata['nzbgetusername']; + $this->password = $page->userdata['nzbgetpassword']; + } + $this->integrated = SABnzbd::INTEGRATION_TYPE_USER; + break; + case SABnzbd::INTEGRATION_TYPE_SITEWIDE: + if (!empty($page->site->nzbgeturl)) + { + $this->url = $page->site->nzbgeturl; + $this->username = $page->site->nzbgetusername; + $this->password = $page->site->nzbgetpassword; + } + $this->integrated = SABnzbd::INTEGRATION_TYPE_SITEWIDE; + break; + } + } + + public function fullurl() + { + $url = $this->url; + if (preg_match('/(?Phttps?):\/\/(?P.+?)(:(?P\d+\/)|\/)$/i', + $url, + $matches)) { + return + $matches['protocol'] . + '://' . + $this->username . + ':' . + $this->password . + '@' . + $matches['url'] . + (isset($matches['port']) ? ':' . $matches['port'] : (substr($matches['url'], -1) === '/' ? '' : '/')) . + 'xmlrpc/'; + } else { + return false; + } + } + + public function sendToNZBGet($guid) + { + $releases = new Releases(); + $reldata = $releases->getByGuid($guid); + $url = "{$this->serverurl}getnzb/{$guid}&i={$this->uid}&r={$this->rsstoken}"; + $header = << + + appendurl + + + {$reldata['searchname']}.nzb + + + {$reldata['category_name']} + + + 0 + + + >False + + + + $url + + + + +NZBGet_URL; + + Utility::getUrl(['url' => $this->fullurl()."appendurl",'method' => "POST", 'postdata' => $header, 'verifycert' => false]); + } + + public function pauseAll() + { + $header = << + + pausedownload2 + + + 1 + + + +NZBGet_PAUSE_ALL; + + Utility::getUrl(['url' => $this->fullurl().'pausedownload2', 'method' => "POST", 'postdata' =>$header, 'verifycert' => false]); + } + + public function resumeAll() + { + $header = << + + resumedownload2 + + + 1 + + +' +NZBGet_RESUME_ALL; + + Utility::getUrl(['url' => $this->fullurl().'resumedownload2', 'method' => "POST", 'postdata' => $header, 'verifycert' => false]); + } + + public function delFromQueue($id) + { + $header = << + + editqueue + + + GroupDelete + + + 0 + + + "" + + + + + $id + + + + + +NZBGet_DELETE_FROM_QUEUE; + + Utility::getUrl(['url' => $this->fullurl().'editqueue', 'method' => "POST", 'postdata' => $header, 'verifycert' => false]); + } + + public function getQueue() + { + $data = Utility::getUrl(['url' => $this->fullurl().'listgroups', 'verifycert' => false]); + $retVal = false; + if ($data) { + $xml = simplexml_load_string($data); + if ($xml) { + $retVal = array(); + $i = 0; + foreach ($xml->params->param->value->array->data->value as $value) { + foreach ($value->struct->member as $member) { + $value = (array)$member->value; + $value = array_shift($value); + if (!is_object($value)) { + $retVal[$i][(string)$member->name] = $value; + } + } + $i++; + } + } + } + + return $retVal; + } + + public function status() + { + $data = Utility::getUrl(['url' => $this->fullurl()."status", 'verifycert' => false]); + $retVal = false; + if ($data) { + $xml = simplexml_load_string($data); + if ($xml) { + foreach ($xml->params->param->value->struct->member as $member) { + $value = (array)$member->value; + $value = array_shift($value); + if (!is_object($value)) { + $retVal[(string)$member->name] = $value; + } + } + } + } + + return $retVal; + } + + public function checkCookie() + { + $res = false; + if (isset($_COOKIE['nzbget_'.$this->uid.'__host'])) + $res = true; + if (isset($_COOKIE['nzbget_'.$this->uid.'__username'])) + $res = true; + if (isset($_COOKIE['nzbget_'.$this->uid.'__password'])) + $res = true; + + return $res; + } + + public function setCookie($host, $username, $password) + { + setcookie('nzbget_'.$this->uid.'__host', $host, (time()+2592000)); + setcookie('nzbget_'.$this->uid.'__username', $username, (time()+2592000)); + setcookie('nzbget_'.$this->uid.'__password', $password, (time()+2592000)); + } + + public function unsetCookie() + { + setcookie('nzbget_'.$this->uid.'__host', '', (time()-2592000)); + setcookie('nzbget_'.$this->uid.'__username', '', (time()-2592000)); + setcookie('nzbget_'.$this->uid.'__password', '', (time()-2592000)); + } +} \ No newline at end of file