83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
function combinedImplode($asPieces, $sKeyValGlue='', $sRowGlue='')
|
|
{
|
|
$asResult = array();
|
|
foreach($asPieces as $sKey=>$sValue)
|
|
{
|
|
$asResult[] = is_array($sValue)?combinedImplode($sValue, $sKeyValGlue, $sRowGlue):$sKey.$sKeyValGlue.$sValue;
|
|
}
|
|
return implode($sRowGlue, $asResult);
|
|
}
|
|
|
|
function getSabContent($sSabServer, $asParams)
|
|
{
|
|
$sQueueUrl = $sSabServer.'?'.combinedImplode($asParams, '=', '&');
|
|
return json_decode(file_get_contents($sQueueUrl), true);
|
|
}
|
|
|
|
$sUploadResult = $sQueueResult = $sHistoryResult = '';
|
|
if(isset($_GET['api']) && $_GET['api']=='123456')
|
|
{
|
|
|
|
$sSabServer = 'http://192.168.0.2:8085/sabnzbd/api';
|
|
$asCommonParams = array('output'=>'json', 'apikey'=>'d93d02d23510871b0252fe282a0f591c');
|
|
$asQueueParams = $asCommonParams + array('mode'=>'queue', 'start'=>0, 'limit'=>1);
|
|
$asHistoryParams = $asCommonParams + array('mode'=>'history', 'start'=>0, 'limit'=>3);
|
|
|
|
//Displaying current download
|
|
$asQueueResult = getSabContent($sSabServer, $asQueueParams);
|
|
if(count($asQueueResult['queue']['slots'])==0) $sQueueResult = 'Empty queue';
|
|
else
|
|
{
|
|
$asFile = $asQueueResult['queue']['slots'][0];
|
|
$sQueueResult = 'Downloading '.$asFile['filename'].' ('.$asFile['size'].') ';
|
|
$sQueueResult.= 'at '.$asQueueResult['queue']['speed'].'. File expected at ';
|
|
$sQueueResult.= $asFile['eta'].' ('.$asFile['sizeleft'].' / '.$asFile['timeleft'].' left)';
|
|
}
|
|
|
|
//Displaying history
|
|
$asHistoryResult = getSabContent($sSabServer, $asHistoryParams);
|
|
if(count($asHistoryResult['history']['slots'])==0) $asHistoryResult = 'Empty history';
|
|
else
|
|
{
|
|
foreach($asHistoryResult['history']['slots'] as $asFile)
|
|
{
|
|
$sHistoryResult .= '<li>'.$asFile['name'].' ('.$asFile['size'].') ';
|
|
if($asFile['status']=='Failed') $sHistoryResult.= 'failed to be downloaded ("'.$asFile['fail_message'].'")';
|
|
else $sHistoryResult.= 'has been downloaded with success';
|
|
$sHistoryResult .= '</li>';
|
|
}
|
|
}
|
|
|
|
//Uploading file
|
|
$sUploadResult = '';
|
|
if(array_key_exists('upload', $_FILES) && strtolower(substr($_FILES['upload']['name'], -4))=='.nzb')
|
|
{
|
|
$sWatchDir = "/tmp/downloads/watchdir/";
|
|
$sPath = $sWatchDir.basename($_FILES['upload']['name']);
|
|
$ok=1;
|
|
if(move_uploaded_file($_FILES['upload']['tmp_name'], $sPath))
|
|
{
|
|
$sUploadResult = "The file ". basename( $_FILES['upload']['name']). " has been uploaded";
|
|
}
|
|
else $sUploadResult = "Sorry, there was a problem copying your file.";
|
|
}
|
|
}
|
|
else $sUploadResult = 'Missing API key';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Add to NZB</title>
|
|
</head>
|
|
<body>
|
|
<form enctype="multipart/form-data" action="upload.php" method="POST">
|
|
Add to NZB: <input name="upload" type="file" /> <input type="submit" value="Upload" />
|
|
</form>
|
|
<p class="result"><?php echo $sUploadResult; ?></p>
|
|
<p class="queue"><?php echo $sQueueResult; ?></p>
|
|
<p class="history"><ul><?php echo $sHistoryResult; ?></ul></p>
|
|
</body>
|
|
</html>
|