Monitor your downloads with a PHP webpage

Monitor your downloads with a PHP webpage

If you need it, check this topic: how to install Apache with PHP

This is a pretty simple PHP page to check the latest downloads and some basic information about your computer. You can change it to your taste and have a pretty cool monitor web interface. For a really nice and advance php sytem monitor, check this topic: Install phpsysinfo for your HTPC


For this webpage, you need the custom extractor script for deluge, since it produce a log. If you just want this script, here is shorten version to produce only the log.
nano /home/user/.config/deluge/scripts/log.sh

#!/bin/bash # ------------ SET THIS VARIABLES ---------- # SET THE GLOBAL LOG FILE syslog=/home/user/data/extracted/unrarzip_sys.log # ---------------------- #LOGING THE DELUGE PARAMATERS # $1 is the Torrent ID # $2 is the folder where the torrent was saved # $3 is the torrent name and the folder name where the torrent is saved echo Params are: >> "$syslog" echo -1: "$1" >> "$syslog" echo -2: "$2" >> "$syslog" echo -3: "$3" >> "$syslog" #SET THE DATE : WHEN THE DOWNLOAD WAS COMPLETED echo "INFO: |date: `date '+%Y-%m-%d'`|Download:$2" >> "$syslog"

Add this script into Deluge Execute Plugin -> Complete tasks:
executeextractor


This php script will read the log and show you the latest downloads in a color code. The page will looks like this, where the green is the most recent, yellow is 24 hours old, and red is more then 48 hours old:php

Thsi is script is also lauching 3 simples command to get the available disks space, running programs and sensors speed.


The PHP page: Change the log path accordingly ( line 3: $logPath = '/home/user/data/extracted/unrarzip_sys.log'; ):

Welcome to your MEDIA SERVER:

[Tasks] - [Sensors] - [Drive Space] - [Downloads] - [Backups]

 array("pipe", "r"),  // stdin
   1 => array("pipe", "w"),  // stdout
   2 => array("pipe", "w"),  // stderr
);

if($cpage == 'df'){
	$retstr = exec('df -h', $retarr);
	
}  else if ($cpage == 'downloads'){
	$fh = fopen($logPath,'r');	

	while ($line = fgets($fh)) {
	  // <... Do your work with the line ...>
	  if(substr($line, 0, 12) == 'INFO: |date:'){	
	    #echo substr($line, 3, strlen($line)-3);
	  	$info = explode("|",$line);
		$date = substr($info[1],6,strlen($info[1])-6);
		$title =  substr($info[2],9,strlen($info[2])-10);
		
		$today = time(); 
		$datetime = strtotime($date);
		$diff = abs($today - $datetime);
		
		$hours_diff = (round($diff / 60 / 60,0));
		
		if($hours_diff < 24){
			$color = '#00FF00';
		}else if($hours_diff < 48){ 
			$color = '#FFFF00';	 
		}else{
			
			$color = '#FF0000';
		}
		
		
		array_push($retarr, ''.$title.' ('.$date.')');
	  }
	} 
	fclose($fh); 	
	$retarr = array_reverse($retarr);	
	
}  else if ($cpage == 'sensors'){
	$retstr = exec('sensors', $retarr);
}  else if ($cpage == 'tasks'){
	$retstr = exec('/usr/bin/top -b -n 1', $retarr);
}
	 

foreach ($retarr as $ret) {
	print $ret . '
'; } ?>


The log (/home/user/data/extracted/unrarzip_sys.log) should looks something like this:

---------------------- Params are: -1: bc5e8a2bd5f804385356fa5b09e3f9eae1881b76 -2: MyMovie.1080p.HDTV -3: /home/user/data/torrents INFO: |date: 2014-10-07|Download:MyMovie.1080p.HDTV is DIR: /home/user/data/torrents/MyMovie.1080p.HDTV cd ~/data/torrents/MyMovie.1080p.HDTV mkdir -p /home/user/data/extracted/MyMovie.1080p.HDTV destination path: /home/user/data/extracted/MyMovie.1080p.HDTV unrar >> /home/user/data/torrents/MyMovie.1080p.HDTV/./Subs/MyMovie.1080p.HDTV.subs.rar mkdir -p /home/user/data/extracted/MyMovie.1080p.HDTV destination path: /home/user/data/extracted/MyMovie.1080p.HDTV unrar >> /home/user/data/torrents/MyMovie.1080p.HDTV/./MyMovie.1080p.HDTV.rar RENAMING FROM /home/user/data/extracted/MyMovie.1080p.HDTV/./MyMovie.1080p.HDTV.mkv TO /home/user/data/extracted/MyMovie.1080p.HDTV/MyMovie.1080p.HDTV.mkv ----------------------