\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 ' '; } function currently_downloading ($phpvars) { global $supportpostparam, $TimeZoneCorrection; echo '
'; if (isset($phpvars['activegroup'])) { //Download in progress, display info $cur_queued=$phpvars['activegroup']; if (!$phpvars['status']['ServerPaused']) echo '
Currently downloading

'; else echo '
Currently downloading (pausing)

'; echo ''; #echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; /* if ($supportpostparam) { // PPWeb mod echo ''; }*/ echo ""; echo ''; echo ''; echo ""; echo ""; if ($phpvars['status']['DownloadRate'] > 0) echo ""; else echo ""; echo ''; echo ''; echo ''; echo '
namecategorydownload rateleftremaining time
namecategoryageratelefttime
remove nzbmove nzb to top in queuemove nzb upmove nzb downmove nzb to bottom in queuepause nzbresume nzbedit parameters".namereplace($cur_queued['NZBNicename'])."'; add_category_combo($cur_queued['Category'], $cur_queued['LastID'], false); echo ''.formatAge($cur_queued['MinPostTime'] + $TimeZoneCorrection*60*60).'".round0($phpvars['status']['DownloadRate']/1024)." KB/s".formatSizeMB($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB'])." ".sec2hms(($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB'])/($phpvars['status']['DownloadRate']/1024/1024))."
'; $a=$cur_queued['FileSizeMB']-$cur_queued['PausedSizeMB']; if ($a > 0) $percent_complete=round0(($a-($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB']))*100/$a); else $percent_complete=100; echo ""; echo '  '.$percent_complete.'%
'; } else { echo ''; echo ''; echo '
'; if ($phpvars['status']['ServerPaused']) { echo '
Server is paused

'; echo '
resume
'; } else echo '
Server is sleeping

'; echo '
'; } 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 '
Queued

'; echo ''; #echo ''; echo ''; foreach (array_slice($phpvars['queuedgroups'], ($page - 1) * $GroupsPerPage, $GroupsPerPage) as $cur_queued) { $grouppaused=($cur_queued['PausedSizeLo'] != 0) && ($cur_queued['RemainingSizeLo']==$cur_queued['PausedSizeLo']); if ($grouppaused) echo ''; else echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; /* if ($supportpostparam) { // PPweb mod echo ''; }*/ echo ''; echo ''; echo ''; echo ''; echo ''; if ($phpvars['status']['DownloadRate'] > 0) echo ''; else echo ''; echo ''; } #echo ''; echo '
namecategorytotalleftestimated time
namecategoryagetotallefttime
remove nzbmove nzb to top in queuemove nzb upmove nzb downmove nzb to bottom in queuepause nzbresume nzbedit parameters'.namereplace($cur_queued['NZBNicename']).''; add_category_combo($cur_queued['Category'], $cur_queued['LastID'], $grouppaused); echo ''.formatAge($cur_queued['MinPostTime'] + $TimeZoneCorrection*60*60).''.formatSizeMB($cur_queued['FileSizeMB']).''.formatSizeMB($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB']).''.sec2hms(($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB'])/($phpvars['status']['DownloadRate']/1024/1024)).'
Total:how to get total time?
'; if ($cnt > $GroupsPerPage) { pagelist($cnt, $page, $GroupsPerPage, 'page'); } 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 ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
namestage%'.($remtime ? "remaining time" : "elapsed time").'
terminate job'.namereplace($cur_proc[has_other_postfiles_from_same_nzb($phpvars, $cur_proc) ? 'InfoName' : 'NZBNicename']).''.$stage.''.$completed.''.$disptime.'
'; if (($cur_proc['Stage'] == 'LOADING_PARS') || ($cur_proc['Stage'] == 'VERIFYING_SOURCES') || ($cur_proc['Stage'] == 'VERIFYING_REPAIRED')) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'.($cur_proc['ProgressLabel']).' ('.(round1($cur_proc['FileProgress'] / 10)).'%)
'; } // 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 ""; } echo '
".$info['Kind']."".FormatLogText($info['Text'])."
'; 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 '
Queued

'; echo ''; echo ''; foreach ($queue as $cur_proc) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
name
delete jobmove job to top in queuemove job upmove job downmove job to bottom in queue'.namereplace($cur_proc[has_other_postfiles_from_same_nzb($phpvars, $cur_proc) ? 'InfoName' : 'NZBNicename']).'
'; } 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 ""; } echo '
".$info['Kind']. "".date($LogTimeFormat, $info['Time'] + $TimeZoneCorrection*60*60)." ".FormatLogText($info['Text'])."
'; 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 'timenamecategorysizefilesPar StatusScript Status'; foreach ($history as $hist) { echo ''; echo 'remove from history'; echo ''.($hist['RemainingFileCount'] > 0 ? '' : '').'return to download queue'.($hist['RemainingFileCount'] > 0 ? '' : '').''; echo 'post-process again'; 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 ""; } echo '
".$info['Kind']. "".date($LogTimeFormat, $info['Time'] + $TimeZoneCorrection*60*60)." ".FormatLogText($info['Text'])."
'; 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 '
Files for downloading

'; echo ''; echo ''; foreach (array_slice($phpvars['files'], ($page - 1) * $FilesPerPage, $FilesPerPage) as $cur_queued) { $paused=$cur_queued['Paused']; if ($paused) echo ''; else echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ""; echo ''; echo ""; echo ''; } echo '
nameagetotal
remove filemove file to top in queuemove file upmove file downmove file to bottom in queuepause fileresume file".namereplace($cur_queued['NZBNicename'])."/".namereplace($cur_queued['Filename'])."'.formatAge($cur_queued['PostTime'] + $TimeZoneCorrection*60*60).'".(round1($cur_queued['FileSizeLo'] / 1024 / 1024))." MB
'; if ($cnt > $FilesPerPage) { pagelist($cnt, $page, $FilesPerPage, 'page'); } 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 ''; } function servercommandbox($phpvars) { global $connected, $WebUsername, $ServerStartCommand, $ServerConfigTemplate, $ServerConfigFile, $groupmode, $historymode; 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 ''; echo ''; if (isset($_COOKIE['upload_status'])) { echo ''; } if (isset($_COOKIE['newzbin_status'])) { echo ''; } } function BuildErrorPage() { global $wantstart, $phpvars, $hasusermenu; if ($wantstart) { start_server(); } else { connect_error($phpvars); } servercommandbox($phpvars); if ($hasusermenu) { usermenu($phpvars); } echo ''; echo ''; echo ''; } //***************************************************************************** // 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 '
    '; echo ''; echo ''; echo ''; $hasparams = false; $cur_queued = null; if (isset($phpvars['activegroup']) && $phpvars['activegroup']['LastID'] == $editpostparamid) { $cur_queued = $phpvars['activegroup']; } else { foreach ($phpvars['queuedgroups'] as $cur) { if ($cur['LastID'] == $editpostparamid) { $cur_queued = $cur; break; } } } if ($cur_queued != null) { echo '
    Postprocessing parameters

    '; echo ''; echo ''; $grouppaused=($cur_queued['PausedSizeLo'] != 0) && ($cur_queued['RemainingSizeLo']==$cur_queued['PausedSizeLo']); if ($grouppaused) echo ''; else echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ($phpvars['status']['DownloadRate'] > 0) echo ''; else echo ''; echo ''; echo ''; echo ''; echo '
    namecategorytotalleftestimated time
    remove nzb'.namereplace($cur_queued['NZBNicename']).''; add_category_combo($cur_queued['Category'], $cur_queued['LastID'], false); echo ''.formatSizeMB($cur_queued['FileSizeMB']).''.formatSizeMB($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB']).''.sec2hms(($cur_queued['RemainingSizeMB']-$cur_queued['PausedSizeMB'])/($phpvars['status']['DownloadRate']/1024/1024)).'
     
    '; MergePostValues($config, $cur_queued['Parameters']); $hasparams = count($config) > 0; BuildOptionsContent($config, null, false); echo '
    '; echo '
    '; } if (!$hasparams) { echo '
    '; echo 'INFO Current postprocessing-script does not have any postprocessing parameters.'; echo '
    '; } echo '
    '; if ($hasparams) { echo '  '; } echo ''; // TIP: uncomment for debug purposes //echo '  '; echo '
    '; echo '

    '; } function BuildPostParamPage() { global $hasusermenu; $phpvars = GetInfo(true); post_params($phpvars); serverinfobox($phpvars); servercommandbox($phpvars); if ($hasusermenu) { usermenu($phpvars); } echo ''; echo ''; if (isset($_COOKIE['upload_status'])) { echo ''; } if (isset($_COOKIE['newzbin_status'])) { echo ''; } } 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(); } ?>