1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
<?php
class SpotPage_nzbhandlerapi extends SpotPage_Abs {
private $_nzbHandler;
function __construct(SpotDb $db, SpotSettings $settings, $currentSession) {
parent::__construct($db, $settings, $currentSession);
} # ctor
function render() {
# Controleer de users' rechten
$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_use_sabapi, '');
parse_str($_SERVER['QUERY_STRING'], $request);
$apikey = $this->_currentSession['user']['apikey'];
if ($this->_tplHelper->apiToHash($apikey) != $request['nzbhandlerapikey']) {
error_log('API Key Incorrect');
echo 'API Key Incorrect';
return ;
} # if
$nzbHandlerFactory = new NzbHandler_Factory();
$this->_nzbHandler = $nzbHandlerFactory->build($this->_settings,
$this->_currentSession['user']['prefs']['nzbhandling']['action'],
$this->_currentSession['user']['prefs']['nzbhandling']);
if ($this->_nzbHandler->hasApiSupport() !== false)
{
$action = strtolower($request['action']);
switch($action)
{
# actions on the entire queue
case 'getstatus':
$result = $this->_nzbHandler->getStatus();
break;
case 'pausequeue':
$result = $this->_nzbHandler->pauseQueue();
break;
case 'resumequeue':
$result = $this->_nzbHandler->resumeQueue();
break;
case 'setspeedlimit':
$result = $this->_nzbHandler->setSpeedLimit($request['limit']);
break;
# actions on a specific download
case 'movedown':
$result = $this->_nzbHandler->moveDown($request['id']);
break;
case 'moveup':
$result = $this->_nzbHandler->moveUp($request['id']);
break;
case 'movetop':
$result = $this->_nzbHandler->moveTop($request['id']);
break;
case 'movebottom':
$result = $this->_nzbHandler->moveBottom($request['id']);
break;
case 'setcategory':
$result = $this->_nzbHandler->setCategory($request['id'], $request['category']);
break;
case 'setpriority':
$result = $this->_nzbHandler->setPriority($request['id'], $request['priority']);
break;
case 'setpassword':
$result = $this->_nzbHandler->setPassword($request['id'], $request['password']);
break;
case 'delete':
$result = $this->_nzbHandler->delete($request['id']);
break;
case 'rename':
$result = $this->_nzbHandler->rename($request['id'], $request['name']);
break;
case 'pause':
$result = $this->_nzbHandler->pause($request['id']);
break;
case 'resume':
$result = $this->_nzbHandler->resume($request['id']);
break;
# non download related actions
case 'getcategories':
$result = $this->_nzbHandler->getCategories();
break;
case 'getversion':
$tmp = $this->_nzbHandler->getVersion();
if ($tmp === false)
{
$result = false;
}
else
{
$result['version'] = $tmp;
}
break;
default:
# default action
$result = false;
}
}
else
{
error_log('The configured NZB handler has no api support');
echo 'The configured NZB handler has no api support';
return ;
}
# de nzbhandlerapi output moet niet gecached worden
$this->sendExpireHeaders(true);
$this->sendContentTypeHeader('json');
if (($result === true) || ($result === false))
{
$tmp['result'] = $result;
$result = $tmp;
}
$result = json_encode($result);
echo $result;
} # render
} # class SpotPage_nzbhandlerapi
|