\n";
if (!isset($rpc_api)) {
echo 'NZBGetWeb: Could not find required extension or library. Consult README-file for installation instructions.';
Exit(-1);
}
$editpostparamid = 0;
if (isset($_REQUEST['editpostparam'])) {
$editpostparamid = $_REQUEST['id'];
}
$wantstart = false;
$connected = false;
$supportpostparam = ($PostProcessConfigTemplate != '') && ($PostProcessConfigFile != '');
$phpvars = null;
if (isset($_REQUEST['start']) && $ServerStartCommand != '') {
$wantstart = true;
}
if (!$wantstart) {
$phpvars = GetInfo($groupmode);
$connected = !IsConnectError($phpvars);
}
function add_category_combo($category, $id, $paused) {
global $Categories;
if ($category == '' && count($Categories) == 0) {
return;
}
$catfound = false;
echo '';
foreach ($Categories as $cat) {
if ($cat==$category) {
echo "$cat ";
$catfound = true;
} else {
echo "$cat ";
}
}
if (!$catfound) {
echo "$category ";
}
echo ' ';
}
function currently_downloading ($phpvars) {
global $supportpostparam, $TimeZoneCorrection;
echo '
';
}
function queued_downloading($phpvars, $page) {
if (count($phpvars['queuedgroups']) == 0)
return;
global $GroupsPerPage, $supportpostparam, $TimeZoneCorrection;
$cnt = count($phpvars['queuedgroups']);
$pagecount = pagecount($cnt, $GroupsPerPage);
if ($page > $pagecount)
$page = $pagecount;
if ($page < 1)
$page = 1;
echo '';
}
function postprocess_disabled($cur_queued) {
foreach ($cur_queued['Parameters'] as $param) {
if ($param['Name'] == 'PostProcess') {
if ($param['Value'] == 'no') {
return true;
}
break;
}
}
return false;
}
function has_other_postfiles_from_same_nzb($phpvars, $proc){
foreach ($phpvars['postqueue'] as $cur_proc) {
if (($cur_proc['InfoName'] != $proc['InfoName']) &&
($cur_proc['NZBFilename'] == $proc['NZBFilename']))
return true;
}
return false;
}
function currently_processing($phpvars, $page){
if (count($phpvars['postqueue']) == 0)
return;
$cur_proc=$phpvars['postqueue'][0];
$disptime="";
$completed = "";
$remtime=true;
if ($cur_proc['Stage'] == 'LOADING_PARS') {
$stage="loading par-files";
$stagewidth=110;
}
else if ($cur_proc['Stage'] == 'VERIFYING_SOURCES') {
$stage="verifying files";
$stagewidth=90;
}
else if ($cur_proc['Stage'] == 'REPAIRING') {
$stage="repairing files";
$stagewidth=90;
}
else if ($cur_proc['Stage'] == 'VERIFYING_REPAIRED') {
$stage="verifying repaired files";
$stagewidth=145;
}
else if ($cur_proc['Stage'] == 'EXECUTING_SCRIPT') {
$stage="executing script";
$stagewidth=100;
$remtime=false;
}
else {
$stage="";
$stagewidth=50;
}
if ($remtime)
{
if ($cur_proc['StageTimeSec'] > 0 && $cur_proc['StageProgress'] > 0) {
$requiredtime = $cur_proc['StageTimeSec'] * 1000 / $cur_proc['StageProgress'] - $cur_proc['StageTimeSec'];
$disptime = sec2hms($requiredtime);
}
}
else
{
$disptime=sec2hms($cur_proc['StageTimeSec']);
}
if (($cur_proc['Stage'] == 'REPAIRING') ||
($cur_proc['Stage'] == 'VERIFYING_SOURCES') ||
($cur_proc['Stage'] == 'VERIFYING_REPAIRED'))
$completed = round1($cur_proc['StageProgress'] / 10)."%";
echo 'Currently processing ';
echo '
';
echo '';
echo 'name stage ';
echo '% '.($remtime ? "remaining time" : "elapsed time").' ';
echo ' ';
echo '';
echo ' ';
echo ''.namereplace($cur_proc[has_other_postfiles_from_same_nzb($phpvars, $cur_proc) ? 'InfoName' : 'NZBNicename']).' ';
echo ''.$stage.' ';
echo ''.$completed.' ';
echo ''.$disptime.' ';
echo ' ';
echo '
';
if (($cur_proc['Stage'] == 'LOADING_PARS') ||
($cur_proc['Stage'] == 'VERIFYING_SOURCES') ||
($cur_proc['Stage'] == 'VERIFYING_REPAIRED')) {
echo '
';
echo ' ';
echo '';
echo ''.($cur_proc['ProgressLabel']).' ('.(round1($cur_proc['FileProgress'] / 10)).'%) ';
echo ' ';
echo ' ';
echo '
';
}
// Messages
global $NewMessagesFirst, $PostMessagesPerPage;
$a=$cur_proc['Log'];
if ($PostMessagesPerPage > 0 && isset($a) && count($a) > 0) {
if ($NewMessagesFirst)
$a=array_reverse($a);
$cnt = count($a);
$pagecount = pagecount($cnt, $PostMessagesPerPage);
if ($page > $pagecount)
$page = $pagecount;
if ($page < 1)
$page = 1;
$per_page = $PostMessagesPerPage;
if ($NewMessagesFirst) {
$start = ($page - 1) * $PostMessagesPerPage;
} else {
$start = $cnt - $page * $PostMessagesPerPage;
if ($start < 0) {
$per_page = $PostMessagesPerPage + $start;
$start = 0;
}
}
echo '
Script-output ';
echo '
';
foreach (array_slice($a, $start, $per_page) as $info) {
echo "".$info['Kind']." ".FormatLogText($info['Text'])." ";
}
echo '
';
if ($cnt > $PostMessagesPerPage) {
pagelist($cnt, $page, $PostMessagesPerPage, 'postlogpage');
}
echo '
';
}
echo '
';
}
function queued_processing($phpvars){
$queue=array_slice($phpvars['postqueue'], 1);
if (count($queue) == 0)
return;
echo '';
}
function logging ($phpvars, $page) {
global $NewMessagesFirst, $MessagesPerPage, $LogTimeFormat, $TimeZoneCorrection;
$a=$phpvars['log'];
if ($NewMessagesFirst)
$a=array_reverse($a);
$cnt = count($a);
$pagecount = pagecount($cnt, $MessagesPerPage);
if ($page > $pagecount)
$page = $pagecount;
if ($page < 1)
$page = 1;
$per_page = $MessagesPerPage;
if ($NewMessagesFirst) {
$start = ($page - 1) * $MessagesPerPage;
} else {
$start = $cnt - $page * $MessagesPerPage;
if ($start < 0) {
$per_page = $MessagesPerPage + $start;
$start = 0;
}
}
// PPWeb mod
if (file_exists('/var/www/html/nzbgetweb/ppweb/logs/status.txt')){
echo 'Post Process ';
include '/var/www/html/nzbgetweb/ppweb/logs/status.txt';
echo ' ';
}
echo 'Messages ';
echo '
';
foreach (array_slice($a, $start, $per_page) as $info) {
echo "".$info['Kind'].
" ".date($LogTimeFormat, $info['Time'] + $TimeZoneCorrection*60*60)." ".FormatLogText($info['Text'])." ";
}
echo '
';
if ($cnt > $MessagesPerPage) {
pagelist($cnt, $page, $MessagesPerPage, 'logpage');
}
echo '
';
}
function historymain($phpvars) {
global $HistoryPerMainPage;
$history=$phpvars['history'];
if (count($history) == 0 || $HistoryPerMainPage == 0)
return;
if (count($history) <= $HistoryPerMainPage)
$Caption = 'History';
else
$Caption = 'History (recent '.$HistoryPerMainPage.' items from total '.count($history).')';
echo ''.$Caption.' ';
echo '
';
historydisplay(array_slice($history, 0, $HistoryPerMainPage), false);
echo '
';
if (count($history) > $HistoryPerMainPage) {
echo '
Further items exist. Click here to display the whole history with extra info.';
} else {
echo '
Click here to display the whole history with extra info.';
}
echo '
';
}
function history($phpvars, $page) {
global $HistoryPerPage, $NewHistoryFirst;
$cnt = count($phpvars['history']);
$pagecount = pagecount($cnt, $HistoryPerPage);
if ($page > $pagecount)
$page = $pagecount;
if ($page < 1)
$page = 1;
$h=$phpvars['history'];
if (!$NewHistoryFirst)
$h=array_reverse($h);
echo 'History ';
echo '
';
historydisplay(array_slice($h, ($page - 1) * $HistoryPerPage, $HistoryPerPage), true);
echo '
';
if ($cnt > $HistoryPerPage) {
pagelist($cnt, $page, $HistoryPerPage, 'page');
} else {
echo '
';
}
echo '
';
echo 'Return to groups ';
echo ' or files .';
echo ' ';
echo '
';
}
function historydisplay($history, $showlog) {
global $HistoryTimeFormat, $TimeZoneCorrection, $LogTimeFormat;
echo 'time name category size files Par Status Script Status ';
foreach ($history as $hist) {
echo '';
echo ' ';
echo ''.($hist['RemainingFileCount'] > 0 ? '' : '').' '.($hist['RemainingFileCount'] > 0 ? ' ' : '').' ';
echo ' ';
echo ''.date($HistoryTimeFormat, $hist['HistoryTime'] + $TimeZoneCorrection*60*60).' ';
echo ''.namereplace($hist['NZBNicename']).' ';
echo ''.$hist['Category'].' ';
echo ''.formatSizeMB($hist['FileSizeMB']).' ';
echo ''.$hist['FileCount'].' ';
echo ' ';
echo ''.$hist['ParStatus'].' ';
echo ''.$hist['ScriptStatus'].' ';
echo ' ';
if ($showlog) {
$log = $hist['Log'];
if (count($log) > 0) {
echo '';
echo ' ';
echo '';
foreach ($log as $info) {
echo "".$info['Kind'].
" ".date($LogTimeFormat, $info['Time'] + $TimeZoneCorrection*60*60)." ".FormatLogText($info['Text'])." ";
}
echo '
';
echo ' ';
}
}
}
}
function filelist($phpvars, $page) {
global $FilesPerPage, $TimeZoneCorrection;
$cnt = count($phpvars['files']);
$pagecount = pagecount($cnt, $FilesPerPage);
if ($page > $pagecount)
$page = $pagecount;
if ($page < 1)
$page = 1;
echo '';
}
function pagecount($cnt, $per_page) {
$pagecount = (int)($cnt / $per_page);
if ($cnt % $per_page > 0)
$pagecount++;
return $pagecount;
}
function pagelist($cnt, $page, $per_page, $varname) {
$pagecount = pagecount($cnt, $per_page);
echo ' ';
for ($i = 1; $i <= $pagecount; $i++) {
if ($i == $page)
echo "$i ";
else
echo ''.$i.' ';
}
echo '
';
}
function serverinfobox($phpvars) {
echo '';
echo '
NZBGet version '.$phpvars['version'].' ';
echo '
';
echo 'uptime: '.sec2hms($phpvars['status']['UpTimeSec']).' ';
echo 'download time: '.sec2hms($phpvars['status']['DownloadTimeSec']).' ';
echo 'average download rate: '.round0($phpvars['status']['AverageDownloadRate']/1024).' KB/s ';
echo 'total downloaded: '.formatSizeMB($phpvars['status']['DownloadedSizeMB']).' ';
echo 'free disk space: '.formatSizeMB(freediskspace()).' ';
echo '
';
echo '
';
}
function servercommandbox($phpvars) {
global $connected, $WebUsername, $ServerStartCommand, $ServerConfigTemplate,
$ServerConfigFile, $groupmode, $historymode;
echo '';
echo '
Server control ';
echo '';
echo 'refresh ';
if ($connected) {
if ($phpvars['status']['ServerPaused']) {
echo ' resume ';
} else {
echo ' pause ';
}
echo ' scan ';
if ($ServerStartCommand != '') {
echo ' shutdown ';
}
if ($groupmode) {
echo ' files ';
echo ' history ';
} elseif ($historymode) {
echo ' groups ';
echo ' files ';
} else {
echo ' groups ';
echo ' history ';
}
} else {
if ($ServerStartCommand != '') {
echo ' start ';
}
}
echo ' config ';
if (isset($WebUsername) && $WebUsername != '') {
echo ' logout ';
}
echo ' ';
echo ' ';
echo '
';
}
function connect_error($errormsg) {
global $ServerStartCommand, $ServerConfigTemplate, $ServerConfigFile;
$connectfailed = !strncmp($errormsg, "ERROR: Connect error:", 21);
$connectclosed = $errormsg == "ERROR: Server closed connection";
$connectdecode = !strncmp($errormsg, "ERROR: Could not decode", 23);
echo '';
if ($connectfailed) {
echo '
ERROR: NZBGetWeb could not connect to NZBGet-Server. ';
echo 'Possible reasons include:
';
echo '
';
echo 'NZBGet-Server is not running';
if ($ServerStartCommand != '') {
echo ' (start )';
}
echo ';';
echo 'IP/Port-settings are incorrect. Check config ;';
echo 'Firewall is not properly configured (if nzbget-server and web-interface run on different computer).';
echo '
';
echo "
Error-message reported by OS: ".substr($errormsg, 22)."
";
} else if ($connectclosed) {
echo '
ERROR: NZBGetWeb could not receive response from NZBGet-Server (although successfully connected). ';
echo 'Possible reasons include:
';
echo '
';
echo 'Password incorrect. Check option "ServerPassword" in config ;';
echo 'Server too busy, connect timeout too short. Check option "ConnectTimeout" in config ;';
echo 'Not compatible server version. ';
echo '
';
} else if ($connectdecode) {
echo '
ERROR: NZBGetWeb could not process response received from NZBGet-Server (although successfully connected). ';
echo 'Possible reasons include:
';
echo '
';
echo 'Wrong port-settings, NZBGetWeb tries to communicate with a different kind of server (a web-server for example, but not nzbget-server). ';
echo 'Check option "ServerPort" in config ;';
echo 'Not compatible server version. ';
echo '
';
} else {
echo '
'.$errormsg.' ';
}
echo '
';
}
function start_server() {
echo '';
$output = array();
$retval = StartServer($output);
if ($retval != 0) {
echo "ERROR: Could not start server. Errorcode: $retval. ";
if (count($output) > 0) {
echo 'Output: ';
foreach ($output as $line) {
echo $line.' ';
}
}
} else {
echo 'INFO: Server started successfully. ';
echo 'Please give the server few seconds for initialization, then refresh the page. ';
}
echo '
';
}
function BuildContentPage() {
global $groupmode, $phpvars, $page, $logpage, $postlogpage,
$GroupModeRefreshInterval, $FileModeRefreshInterval, $FileModeLog,
$historymode, $hasusermenu;
if ($groupmode) {
currently_downloading($phpvars);
queued_downloading($phpvars, $page);
currently_processing($phpvars, $postlogpage);
queued_processing($phpvars);
historymain($phpvars);
logging ($phpvars, $logpage);
} elseif ($historymode) {
history($phpvars, $page);
} else {
filelist($phpvars, $page);
if ($FileModeLog) {
echo ' ';
logging ($phpvars, $logpage);
}
}
serverinfobox($phpvars);
servercommandbox($phpvars);
if ($hasusermenu) {
usermenu($phpvars);
}
echo ''.($groupmode ? $GroupModeRefreshInterval : $FileModeRefreshInterval).'
';
echo ''.($phpvars['status']['DownloadLimit'] / 1024).'
';
if (isset($_COOKIE['upload_status'])) {
echo ''.($_COOKIE['upload_status']).'
';
}
if (isset($_COOKIE['newzbin_status'])) {
echo ''.($_COOKIE['newzbin_status']).'
';
}
}
function BuildErrorPage() {
global $wantstart, $phpvars, $hasusermenu;
if ($wantstart) {
start_server();
} else {
connect_error($phpvars);
}
servercommandbox($phpvars);
if ($hasusermenu) {
usermenu($phpvars);
}
echo '
Server information ';
echo '0
';
echo '0
';
}
//*****************************************************************************
// Postprocessing parameters functions
//
function MergePostValues(&$config, &$params) {
foreach ($config as $key => $section) {
if ($section->category == CATEGORY_PPPARAMETERS) {
foreach ($section->options as $option) {
foreach ($params as $param) {
if ($option->name == $param['Name']) {
$option->value = $param['Value'];
}
}
}
} else {
// removing unneeded sections from $config
unset($config[$key]);
}
}
}
function post_params($phpvars) {
global $config, $editpostparamid, $FormMethod;
$postprocessconfig = LoadPostProcessConfig($config);
if (!isset($postprocessconfig)) {
return;
}
echo ' ';
}
function BuildPostParamPage() {
global $hasusermenu;
$phpvars = GetInfo(true);
post_params($phpvars);
serverinfobox($phpvars);
servercommandbox($phpvars);
if ($hasusermenu) {
usermenu($phpvars);
}
echo '0
';
echo ''.($phpvars['status']['DownloadLimit'] / 1024).'
';
if (isset($_COOKIE['upload_status'])) {
echo ''.($_COOKIE['upload_status']).'
';
}
if (isset($_COOKIE['newzbin_status'])) {
echo ''.($_COOKIE['newzbin_status']).'
';
}
}
function SavePostParam() {
global $_REQUEST, $editpostparamid;
$postprocessconfig = LoadPostProcessConfig($config);
if (!isset($postprocessconfig)) {
$upload_status = 'Could not load configuration of post-processing script ';
SetCookie("upload_status", $upload_status, time()+30); // expire in 30 seconds
Redirect('index.php');
return;
}
MergeSettings($config, $_REQUEST);
foreach ($config as $section) {
if ($section->category == CATEGORY_PPPARAMETERS) {
foreach ($section->options as $option) {
$res = GetRequest('editqueue', array('GroupSetParameter', (int)0, $option->name.'='.$option->value, (int)$editpostparamid));
if (!$res) {
$upload_status = 'Could not change post-processing parameters ';
SetCookie("upload_status", $upload_status, time()+30); // expire in 30 seconds
Redirect('index.php');
return;
}
}
}
}
Redirect('index.php');
}
//
// Postprocessing parameters functions - END
//*****************************************************************************
?>
0) {
if (isset($_REQUEST['save'])) {
SavePostParam();
} else {
BuildPostParamPage();
}
} else if ($connected) {
BuildContentPage();
} else {
BuildErrorPage();
}
?>