Tag: PHP

Eir SMS Web Text in PHP

Simple PHP script to send EIR SMS texts via Eir website

The code


Bordgais Energy Charts

Work in progress. script available soon including gas bills.


Synology Filebot Autonaming cron job

Having a synology NAS is great. However when dealing with 32tb, good file management is a must!
I have 2 primary folders, Films and Series. The set of below scripts iterate the files and use the TVDB and MovieDB to clean up the file names.
The second scripts downloads any missing subtitles for the media 🙂

File renaming

&1" ) );

foreach( $loglines as $logline )
{
  $line = trim( $logline );

  if( $line == "" ) continue;
  if( preg_match( "/^Skipped.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/^Auto-detect movie from context.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/.*Rename movies using.*$/", $line, $dontcare ) ) continue;

  $ploglines[] = $line;
}

$frt = implode( "\r\n" , $ploglines );

$body = "Dear user,\n\n $frt \n\nSincerely,\nSynology DiskStation\n\n";
mail($email, 'DSM - Filebot Rename Report - Films', "$body");


$log = "/volume1/homes/admin/cleanup/report-rename.txt";
unlink( $log );
touch( $log );

if ($handle = opendir('/volume1/Entertainment/Series/'))
{
  while (false !== ($entry = readdir($handle)))
  {
    if ($entry != "." && $entry != "..")
    { 
      $cmd = "filebot -r -rename \"/volume1/Entertainment/Series/$entry/\" --db TheTVDB 2>&1";
      $frt = shell_exec( $cmd );
      file_put_contents( $log, $frt . "\n\n", FILE_APPEND | LOCK_EX );
    }
  }
  closedir($handle);
}

$ploglines = array();
$loglines = file( $log );

foreach( $loglines as $logline )
{
  $line = trim( $logline );

  if( $line == "" ) continue;
  if( preg_match( "/'^Skipped.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/^Fetching episode data.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/^Processed.$*/", $line, $dontcare ) ) continue;
  if( preg_match( "/^Done.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/^Failure.*$/", $line, $dontcare ) ) continue;
  if( preg_match( "/^No media files.*$/", $line, $dontcare ) ) continue;

  $ploglines[] = $line;
}

$frt = implode( "\r\n" , $ploglines );

$body = "Dear user,\n\n $frt \n\nSincerely,\nSynology DiskStation\n\n";
mail($email, "DSM - Filebot Rename Report - Series $entry", "$body");

Subtitles scripts

&1" );
$body = "Dear user,\n\n $fst \n\nSincerely,\nSynology DiskStation\n\n";
mail($email, 'DSM - Filebot Subtitles Report - Films', "$body");

if ($handle = opendir('/volume1/Entertainment/Series/'))
{
  while (false !== ($entry = readdir($handle)))
  {
    if ($entry != "." && $entry != "..")
    { 
      $cmd = "filebot -r -script fn:suball \"/volume1/Entertainment/Series/$entry/\" --lang en -non-strict --db TheTVDB 2>&1";
      $frt = shell_exec( $cmd );
      file_put_contents( $log, $frt . "\n\n", FILE_APPEND | LOCK_EX );
    }
  }
  closedir($handle);
}

$frt = file_get_contents( $log );
$body = "Dear user,\n\n $frt \n\nSincerely,\nSynology DiskStation\n\n";
mail('dave@fio.ie', "DSM - Filebot Subtitles Report - Series $entry", "$body");

Cron Job

ash-4.3# cat /etc/crontab 
MAILTO=""
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin
#minute hour    mday    month   wday    who     command
0       0       1       *       *       root    /usr/syno/bin/syno_disk_health_record
0       0       *       *       3       root    /usr/bin/php /var/services/homes/admin/cleanup/filebot-rename.php
0       0       *       *       5       root    /usr/bin/php /var/services/homes/admin/cleanup/filebot-subtitles.php
5       3       *       *       6       root    /usr/syno/bin/synomyds --report_info
0       3       *       *       1       root    /tmp/synoschedtask --run id=1
0       3       13      *       *       root    /tmp/synoschedtask --run id=2
11      2       *       *       4       root    /tmp/synoschedtask --run id=3

Download CSIS Notes quickly!

This handy little script will download all your coursework in a jip

youll need php 5 and mod php_curl!

selectedCourse = $course;
		}
		if( count($modules) > 0 )
		{
			$this->selectedModules = $modules;
		}

		$this->fetchCourses();
	}

	private function fetchCourses()
	{
		echo "Start\n";

		$this->downloader = curl_init();
		curl_setopt( $this->downloader , CURLOPT_URL , "http://www.csis.ul.ie/currentstudents/" );
		curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" );
		curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' );
		curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 );
		curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 );
		$this->store = curl_exec( $this->downloader );
		curl_close( $this->downloader );

		echo "Got courses\n";

		$data = explode( "UNDERGRADUATE COURSES" , $this->store );
		$data = explode( "
" , $data[1] ); $data = preg_match_all( "/(
  • .*<\/li>)/" , $data[0] , $matches); preg_match_all( "/(.*)<\/a>/iU" ,$matches[0][0] , $temp1 ); preg_match_all( "/(.*)<\/a>/iU" , $matches[1][1] , $temp2 ); $courses = array_merge( $temp1 , $temp2 ); $this->courseLinks = array_merge( $courses[1] , $courses[4] ); $this->courseTitles = array_merge( $courses[2] , $courses[5] ); for( $u = 0 ; $u < count( $this->courseLinks ); $u++ ) { if( isset( $this->selectedCourse ) ) { if( !stristr( $this->courseLinks[$u] , $this->selectedCourse ) ) { continue; } } $this->downloader = curl_init(); $url = "http://www.csis.ul.ie" . $this->courseLinks[$u]; curl_setopt( $this->downloader , CURLOPT_URL , $url ); curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" ); curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' ); curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 ); curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 ); $this->store = curl_exec( $this->downloader ); $data = explode( "COURSE STRUCTURE SECTION STARTS" , $this->store ); $data = explode( "COURSE STRUCTURE SECTION ENDS" , $data[1] ); preg_match_all( "/(.*)<\/a>/iUms" , $data[0] , $mods ); for( $y= 0 ; $y < count($mods[2]); $y++ ) { $mods[2][$y] = trim( $mods[2][$y] ); } $this->moduleLinks[$u] = $mods[1]; $this->moduleTitles[$u] = $mods[2]; curl_close( $this->downloader ); echo "Starting the modules\n"; for( $z = 0 ; $z < count( $this->moduleLinks[$u] ); $z++ ) { print $this->courseLinks[$u] . " - " . $this->moduleLinks[$u][$z] . "\n"; $moduletitle = preg_replace( "/\/coursemodule\//" , "" , $this->moduleLinks[$u][$z] ); if( isset( $this->selectedModules ) ) { if( !in_array( $moduletitle , $this->selectedModules ) ) { continue; } } for( $w = 1 ; $w < 17; $w++ ) { $url = "http://www.csis.ul.ie" . $this->moduleLinks[$u][$z] . "/?wkid=" . $w; $this->downloader = curl_init(); curl_setopt( $this->downloader , CURLOPT_URL , $url ); curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" ); curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' ); curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 ); curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 ); $this->store = curl_exec( $this->downloader ); curl_close( $this->downloader ); $data = explode( "MODULE MATERIAL SECTION STARTS" , $this->store ); $data = explode( "MODULE MATERIAL SECTION ENDS" , $data[1] ); $data = explode( "

    " , $data[0] ); foreach( $data as $dt ) { preg_match_all( '/<(a.*) href="(.*?)"(.*)>(.*)(<\/a>)/i' , $dt , $docs ); if( isset($docs[2][0]) != "" ) { $this->documentTitles[] = substr( trim( $docs[4][0]) , 1 , -1 ); $this->documentLinks[] = trim( $docs[2][0] ); $this->documentCourseTitles[] = $this->courseTitles[$u]; $this->documentModulesTitles[] = $this->moduleTitles[$u][$z]; } } print $this->courseLinks[$u] . " - " . $this->moduleLinks[$u][$z] . " - " . $url . "\n"; } for( $t = 0 ; $t < count( $this->documentCourseTitles ); $t++) { $this->downloadFile( $this->documentCourseTitles[$t] ,$this->documentModulesTitles[$t] , $this->documentTitles[$t] , $this->documentLinks[$t] ); } unset($this->documentCourseTitles); unset($this->documentModulesTitles); unset($this->documentTitles); unset($this->documentLinks); } } } private function downloadFile( $course , $module , $docTitle , $docUrl ) { $course = preg_replace( "/\//" , "" , $course); $moduletitle = $module; $doc = $docTitle; $url = $docUrl; if( !file_exists( "coursework" ) ) { mkdir( "coursework" ); } if( !file_exists( "coursework/$course" ) ) { mkdir( "coursework/$course" ); } if( !file_exists( "coursework/$course/$moduletitle" ) ) { mkdir( "coursework/$course/$moduletitle" ); } $dir = "coursework/$course/$moduletitle"; if( !file_exists( $dir . "/" . $doc ) ) { $url = preg_replace( "/&/i" , "&" , $url ); $url = preg_replace( "/amp;/i" , "" , $url ); $url = "http://www.csis.ul.ie" . $url; $this->downloader = curl_init(); curl_setopt( $this->downloader , CURLOPT_URL , $url ); curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" ); curl_setopt( $this->downloader , CURLOPT_TIMEOUT , '10' ); curl_setopt( $this->downloader , CURLOPT_FOLLOWLOCATION , 1 ); curl_setopt( $this->downloader , CURLOPT_RETURNTRANSFER , 1 ); $this->store = curl_exec ( $this->downloader ); curl_close( $this->downloader ); $docurl = preg_match( "/action=\"(.*)\" /" , $this->store , $matches ); $match = explode( "\"", $matches[1] ); $match = preg_replace( "/&/i" , "&" , $match[0] ); $match = preg_replace( "/amp;/i" , "" , $match ); $fp = fopen( $dir . "/" . $doc , 'w' ); $this->downloader = curl_init(); curl_setopt( $this->downloader , CURLOPT_URL , $match ); curl_setopt( $this->downloader , CURLOPT_USERAGENT , "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20090829 Ubuntu/9.04 (jaunty) Shiretoko/3.5.4pre" ); curl_setopt( $this->downloader , CURLOPT_HEADER, 0); curl_setopt( $this->downloader , CURLOPT_FILE , $fp ); curl_exec( $this->downloader ); curl_close( $this->downloader ); fclose( $fp ); } } } $course = "LM051"; $modules = array( "CS4416" ); new csisDownloader( $course , $modules ); ?>


  • AIB Account status

    PHP curl script to fetch your aib accounts (Compilments of Jon (kudos) Cremin)

    updated to work with visa validation by me!

    Linux users can display this infromation neetly on your desktop using such applications as http://conky.sourceforge.net

    Screenshot

    Code

    regnumber = $regnumber;
    		$this->challenge_phone = $challenge_phone;
    		$this->challenge_visa = $challenge_visa;
    		$this->challenge = "";
    		$this->pac = str_split($pac);
    		array_unshift($this->pac, null);
    		$this->ch = curl_init();
    		curl_setopt( $this->ch , CURLOPT_RETURNTRANSFER , 1 );
    		curl_setopt( $this->ch , CURLOPT_SSL_VERIFYPEER , 0 );
    		curl_setopt( $this->ch , CURLOPT_COOKIEFILE , ".cookiefile" );
    		curl_setopt( $this->ch , CURLOPT_COOKIEJAR , ".cookiefile" );
    		curl_setopt( $this->ch , CURLOPT_FOLLOWLOCATION , 1 );
    		curl_setopt( $this->ch , CURLOPT_USERAGENT , "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-gb) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17" );
    	}
    
    	public function balances()
    	{
    		curl_setopt( $this->ch , CURLOPT_URL , "https://aibinternetbanking.aib.ie/inet/roi/login.htm" );
    		$output = curl_exec( $this->ch );
    
    		preg_match( '@id="transactionToken" value="(.*)"@' , $output , $token );
    
    		curl_setopt( $this->ch , CURLOPT_POST , 1 );
    		curl_setopt( $this->ch , CURLOPT_POSTFIELDS , "jsEnabled=TRUE&transactionToken=" . $token[1] . "®Number=".$this->regnumber."&_target1=true" );
    		curl_setopt( $this->ch , CURLOPT_URL , "https://aibinternetbanking.aib.ie/inet/roi/login.htm" );
    		$output = curl_exec( $this->ch );
    
    		preg_match( '@id="transactionToken" value="(.*)"@' , $output, $token);
    		preg_match( '@@' , $output , $pac1 );
    		preg_match( '@@' , $output , $pac2 );
    		preg_match( '@@' , $output , $pac3 );
    
    		$this->challenge = preg_match( "/home phone number/" , $output ) > 0 ? $this->challenge_phone : $this->challenge_visa ;
    
    		$postinfo = "_finish=true&transactionToken=" . $token[1];
    		$postinfo .= "®Number=" . $this->regnumber;
    		$postinfo .= "&pacDetails.pacDigit1=" . $this->pac{$pac1[1]};
    		$postinfo .= "&pacDetails.pacDigit2=".$this->pac{$pac2[1]};
    		$postinfo .= "&pacDetails.pacDigit3=" . $this->pac{$pac3[1]};
    		$postinfo .= "&challengeDetails.challengeEntered=".$this->challenge;
    
    		curl_setopt( $this->ch , CURLOPT_POST , 1 );
    		curl_setopt( $this->ch , CURLOPT_POSTFIELDS , $postinfo );
    		curl_setopt( $this->ch , CURLOPT_URL , "https://aibinternetbanking.aib.ie/inet/roi/login.htm" );
    		$output = curl_exec( $this->ch );
    
    		if( preg_match( "/continue to account overview/" , $output ) > 0 )
    		{
    			preg_match( '@id="transactionToken" value="(.*)"@' , $output , $token );
    			curl_setopt( $this->ch , CURLOPT_POST , 1 );
    			curl_setopt( $this->ch , CURLOPT_POSTFIELDS , "iBankFormSubmission=false&transactionToken=" . $token[1] );
    			curl_setopt( $this->ch , CURLOPT_URL , "https://aibinternetbanking.aib.ie/inet/roi/accountoverview.htm" );
    			$output = curl_exec( $this->ch );
    		}
    
    		$output = str_replace( "\n" , "" , $output );
    		$output = str_replace( "\r" , "" , $output );		
    
    		preg_match_all( '@expand(.*?)(.*?)@s', $output , $names );
    		preg_match_all( '@

    (.*?)

    @s' , $output , $bal ); for( $i = 0; isset( $names[2][$i] ); $i++ ) { $accounts[] = array( "name" => $names[2][$i] , "balance" => str_replace( " " , "" , str_replace( " " , "" , $bal[1][$i] ) ) ); } return $accounts; } public function __destruct() { curl_close( $this->ch ); } } $regnumber = "88888888"; $challenge_phone = "4444"; $challenge_visa = "2222"; $pac = "77777"; $aib = new aib($regnumber, $challenge_phone, $challenge_visa, $pac); $accounts = $aib->balances(); foreach((array)$accounts as $account) { echo trim($account['name']) . "\${goto 150}" . trim($account['balance']) . "\n\n"; } ?>