Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

VariableDescriptionDetails
passadmin passwordbase64encoded password
EMAIL_TO/EMAIL_FROM

SHOWRSS_FEED

TEMP_FOLDER

DEST_FOLDER
baseURL
base URL
http://xxx.xxx.xxx.xxx:8080

Two factor authentication will work with these scripts if:

baseURL=http://localhost:8080



Scripts

In order to make it easier to run your php scripts, we can wrap them in a shell script like the following:

Code Block
#!/bin/sh

PHP=/mnt/ext/opt/apache/bin/php
SCRIPT_PATH=/share/homes/xxx/scripts/
cd $SCRIPT_PATH
$PHP $SCRIPT_PATH/xxxshowRss.php <ACTION>


showRss.php

...

Usage:

> php showRss.php <download/removeCompleted/listDownloads/removeAll>


Code Block
languagephp
titleshowrss.php
linenumberstrue
collapsetrue
<<?php

//custom variables
$pass=urlencode("xxx_BASE64ENCODED_PASSWORDBASE64ENCODEDPASSWORD_xxx");
$baseURL="http://localhost:8080$EMAIL_TO="xxxx@xxx.com";
$EMAIL_FROM="xxxx@xxx.com";
$SHOWRSS_FEED="http://showrss.info/user/xxxxxxx.rss?magnets=true&namespaces=true&name=clean&quality=hd&re=null";

$EMAIL$TEMP_TOFOLDER="j****@yahoo.comtv/tmp";
$EMAIL$DEST_FROMFOLDER="j****@yahoo.comtv/incoming";
$EMAIL_SUBJECT="TORRENT STARTED [NAS]

//default variables
$baseURL="http://localhost:8080";
$DB_FILE_NAME="db_showrss.json";
$EMAIL_SUBJECT_DOWNLOADED="DOWNLOADED - ";
$EMAIL_SUBJECT_STARTED="DOWNLOAD STARTED - ";
$EMAIL_SUBJECT_FAILED="FAILED TO DOWNLOAD [NAS0] - ";



$DB_FILE_NAME="db_showrss.json";
$TEMP_FOLDER="tv/tmp";
$DEST_FOLDER="tv/incoming";


//login to NAS0
$sid = $EMAIL_SUBJECT_REMOVED="CANCELLED DOWNLOAD - ";

//login
$sid=loginToQnap();

//get Process showRSSCommand FeedLine
$xml = file_get_contents($SHOWRSS_FEED);
//echo $xml;

//process xml
$xml = simplexml_load_file($SHOWRSS_FEED);

$showArray = array();

$showdb = json_decode(file_get_contents($DB_FILE_NAME), true);
if($showdb==null){
  $showdb = array();
}


// loop through 
foreach ($xml->channel->item as $item) {
    $title =  $item->title;
	$link = $item->link;

    //echo "title=" . $title ."\n";

	//$pattern = "/S(\d{1,2})E(\d{1,2})/";
	$pattern = "/(\d{1,2})x(\d{1,2})/";
	preg_match($pattern, $title, $matches);
    if(sizeof($matches)>=3){
	  $season=intval($matches[1]$cmd="download";
if ($argc > 1) {
  $cmd=$argv[1];
};

switch ($cmd) {
  case "download":
    echo "DOWNLOAD:\n";
    download();
    break;
  case "removeCompleted":
    echo "REMOVE COMPLETED:\n";
    removeCompleted();
    break;
  case "listDownloads":
    echo "LIST DOWNLOADS:\n";
    listDownloads();
    break;
  case "removeAll":
    echo "REMOVE ALL:\n";
    removeAll();
    break;
  $episode=intval($matches[2]);	
 	default:
  $show = trim(substr($title,0,strrpos($title,$matches[0])));	
 	  $showAndEpisode=sprintf("%s %02dx%02d", $show,$season,$episode);
	}else{
	  $show=(string)$title;
	  $showAndEpisode=(string)$title;
	  $season=0;
	  $episode=0;
    }

	//echo "SHOW: " . $show . "\n";
	//echo "SEASON: " . $season . "\n";
	//echo "EPISODE: " . $episode . "\n";
        
    $showInfo=array($showAndEpisode, $show, $season, $episode, $link);
	array_push($showArray, $showInfo);	
}

//echo "\n\n";

sort($showArray);
//print_r($showArray);

foreach ($showArray as $show) {

  //echo "show: " .  $show[0] . "\n";
  //add torrent

  $found =false;
  foreach($showdb as &$showEntryshowUsage();
    exit(1);
}

//done
exit(0);

//***************************************
// download
//***************************************
function download(){
  global $SHOWRSS_FEED, $DB_FILE_NAME, $baseURL, $sid, $EMAIL_TO, $EMAIL_FROM, $EMAIL_SUBJECT_DOWNLOADED;

  //get showRSS Feed
  $xml = file_get_contents($SHOWRSS_FEED);
  //echo $xml;
 
  //process xml
  $xml = simplexml_load_file($SHOWRSS_FEED);
 
  $showArray = array();
 
  $showdb = json_decode(file_get_contents($DB_FILE_NAME), true);
  if($showdb==null){
    $showName$showdb = $showEntry[0];

    if($showName==$show[1]){
      $found=true;
  array();
  }
 
  // loop through
  foreach ($xml->channel->item as $item) {
    $title =  $item->title;
    $link = $item->link;
    //echo "Found title=" . $show[1]$title . " in showdb \n";
 
    $pattern $newSeason=$show[2];
      $newEpisode=$show[3];= "/(\d{1,2})x(\d{1,2})/";
    preg_match($pattern, $title, $matches);
    if(sizeof($matches)>=3){
      $lastSeason$season=$showEntryintval($matches[1]);   
      $lastEpisode$episode=$showEntryintval($matches[2]); 
      //echo "--- " . $lastSeason . "x" . $lastEpisode . " -> " .  $newSeason . "x" . $newEpisode ."\n";

$show = trim(substr($title,0,strrpos($title,$matches[0])));  
      $showAndEpisode=sprintf("%s %02dx%02d", $show,$season,$episode);
    }else{
      if($lastSeason == $newSeason && $newEpisode > $lastEpisode){$show=(string)$title;
      $showAndEpisode=(string)$title;
      $season=0;
  if(downloadShow($show)){
  	  $showEntry[2]= $newEpisode$episode=0;
    }
 
     //echo "USHOW: " . $showEntry[0]$show . "\n";
 " . $showEntry[1] . //echo "xSEASON: " . $season $showEntry[2] . "\n";
        }else{
          //echo "FEPISODE: " . $showEntry[0]$episode . "\n";
 " . $showEntry[1] . "x" . $showEntry[2] . "\n";
    $showInfo=array($showAndEpisode, $show, $season, $episode, }$link);
      }elseif ($newSeason > $lastSeason ){array_push($showArray, $showInfo); 
  } //for
 
    if(downloadShow($show)){
	  $showEntry[1]= $newSeason;
	  $showEntry[2]= $newEpisode;
          echo "U+sort($showArray);
  //print_r($showArray);
 
  foreach ($showArray as $show) {
 
    //echo "show: " . $showEntry $show[0] . "\n";
   " . $showEntry[1] . "x" . $showEntry[2] . "\n";
	}else{
	  echo "F+ " .//add torrent
 
    $found =false;
    foreach($showdb as &$showEntry){
      $showName = $showEntry[0];
 
 .  " " . $showEntry if($showName==$show[1]){
 . "x" . $showEntry[2] . "\n";
	}
      }else{  $found=true;
        // echo "WTFFound " . $lastSeason$show[1] . "x" .in $lastEpisodeshowdb . \n";
 -> " .  $newSeason . "x" . $newEpisode ."\n" $newSeason=$show[2];
      }
   $newEpisode=$show[3];
     break; 
  $lastSeason=$showEntry[1];  }
  }
 
  //set latest season/episode
  if ($found==false) {
 $lastEpisode=$showEntry[2];
    if(downloadShow($show)){
      //echo "A--- " . $show[1]$lastSeason .  " x" . $show[2]$lastEpisode . " -> " .  $newSeason . "x" . $show[3]$newEpisode . "\n" ;
 
     $showDetails=array($show[1], $show[2], $show[3]);
      array_push($showdb, $showDetails);
    }else if($lastSeason == $newSeason && $newEpisode > $lastEpisode){
      echo "F " . $show[1] .  if(downloadShow($show)){
            $showEntry[2]= $newEpisode;
            echo "U " . $showEntry[0] . " " . $show$showEntry[21] . "x" . $show$showEntry[32] . "\n" ;

      }
  }
  
}

//save showdb to file
//print_r($showdb);

file_put_contents($DB_FILE_NAME,json_encode($showdb));

exit;

//***************************************
// downloadShow
//***************************************
function downloadShow($show){
    global $baseURL;

    $showAndEpisode =  $show[1] .  " " . $show[2] . "x" . $show[3];
    //echo "D: " . $showAndEpisode . "\n";
    //echo "L: " . $show[4] . "\n\n";

    $temp=$GLOBALS['TEMP_FOLDER'];
    $dest=$GLOBALS['DEST_FOLDER'] . "/" . $show[1]; 
    
    $realDest = "/share/" . $dest;
    if (!file_exists($realDest)) else{
            echo "F " . $showEntry[0] . " " . $showEntry[1] . "x" . $showEntry[2] . "\n";
          }
        }elseif ($newSeason > $lastSeason ){
      mkdir($realDest, 0777, true);    if(downloadShow($show)){
    }

        if($show$showEntry[21]>0){= $newSeason;
       $dest=$dest . "/Season " . $show$showEntry[2]= $newEpisode;
  
      }
    //echo "Dest:U+ " . $dest$showEntry[0] . "\n";

    $realDest = "/share/" . $dest;
    if (!file_exists($realDest)) {
      mkdir($realDest, 0777, true)$showEntry[1] . "x" . $showEntry[2] . "\n";
    }

    $url = $baseURL . '/downloadstation/V4/Task/AddUrl?sid=' . $GLOBALS['sid']  . '&temp=' . urlencode($temp) . '&move=' . urlencode($dest) . '&url=' . urlencode($show[4]); 
    //echo "URL: " . $url}else{
            echo "F+ " . $showEntry[0] . " " . $showEntry[1] . "x" . $showEntry[2] . "\n";
          }
        $resp=file_get_contents($url);}else{
          //echo $resp;
    if($resp=='{"error":0}'){
      //sendNotification($showAndEpisode,true);
      return true echo "WTF " . $lastSeason . "x" . $lastEpisode . " -> " .  $newSeason . "x" . $newEpisode ."\n";
        }else{
       sendNotification($showAndEpisode,fail) break;
      return false;}
    }
}

//***************************************
// sendNotification
//***************************************
function sendNotification($showAndEpisode,$success){
  
    //set latest season/episode
    if ($found==false) {
 
      if(success == true){
      $subject= "\"" . $GLOBALS['EMAIL_SUBJECT'] . $showAndEpisode(downloadShow($show)){
        echo "A " . $show[1] .  " " . $show[2] . "x" . $show[3] . "\n"" ;
    }else{
       $showDetails=array($show[1], $show[2], $show[3]);
   $subject= "\"" . $GLOBALS['EMAIL_SUBJECT_FAILED'] . $showAndEpisode . "\"" array_push($showdb, $showDetails);
      }else{
    $cmd= getCwd() . "/sendEmail.sh    echo "F " . $subject$show[1] . . " " . $GLOBALS['EMAIL_FROM'$show[2] . " x" . $GLOBALS['EMAIL_TO'$show[3] . " " . $subject;\n" ;
      }
    }
   
  }
 
  //echo "cmd=" . $cmd . "\n"save showdb to file
  //print_r($showdb);
 
   shell_exec($cmdfile_put_contents($DB_FILE_NAME,json_encode($showdb));

}

//***************************************
// endsWithdownloadShow
//***************************************
function endsWith($haystack, $needle)
{downloadShow($show){
    global $baseURL,$sid, $TEMP_FOLDER, $DEST_FOLDER;
 
    $length$showAndEpisode = strlen($needle);
    if ($length == 0) {  $show[1] .  " " . $show[2] . "x" . $show[3];
    //echo "D: " . $showAndEpisode . "\n";
    //echo "L: " . $show[4] return true. "\n\n";
    }

    return (substr($haystack, -$length) === $needle);
}

//***************************************
// loginToQnap
//***************************************
function loginToQnap(){
  global $baseURL, $pass;

  //login
  $vars = 'user=admin&pass=' . $pass;
  $ch = curl_init( $baseURL . '/downloadstation/V4/Misc/Login' );
  curl_setopt( $ch, CURLOPT_POST, 1);
  curl_setopt( $ch, CURLOPT_POSTFIELDS, $vars);
  curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt( $ch, CURLOPT_HEADER, 0);
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
  $resp = curl_exec( $ch );
  //echo $resp;

  $sid = json_decode($resp)->{'sid'};
  //echo "sid='" . $sid . "'\n";

  return $sid;
}
?>

removeTorrents.php

Code Block
languagephp
titleremoveTorrents.sh
<?php

$pass=urlencode("xxx_BASE64ENCODED_PASSWORD_xxx");
$baseURL="http://localhost:8080";

$EMAIL_TO="jxxx@yahoo.com";
$EMAIL_FROM="jxxx@yahoo.com";
$EMAIL_SUBJECT="TORRENT DOWNLOADED - ";

//login
$temp=$TEMP_FOLDER;
    $dest=$DEST_FOLDER . "/" . $show[1];
     
    $realDest = "/share/" . $dest;
    if (!file_exists($realDest)) {
      mkdir($realDest, 0777, true);
    }
 
    if($show[2]>0){
      $dest=$dest . "/Season " . $show[2];
    }
    //echo "Dest: " . $dest . "\n";
 
    $realDest = "/share/" . $dest;
    if (!file_exists($realDest)) {
      mkdir($realDest, 0777, true);
    }
 
    $url = $baseURL . '/downloadstation/V4/Task/AddUrl?sid=' . $sid  . '&temp=' . urlencode($temp) . '&move=' . urlencode($dest) . '&url=' . urlencode($show[4]);
    //echo "URL: " . $url . "\n";
    $resp=file_get_contents($baseURL . '/cgi-bin/authLogin.cgi?user=admin&pwd=' . $pass);
//echo $resp;

$sid=getSid($resp);
//echo "sid='" . $sid . "'\n";

$resp=file_get_contents($baseURL . '/downloadstation/V4/Misc/Login?sid=' . $sid);
//echo $resp . "\n";


$resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Query?start=0&limit=25&status=completed&from=0&to=25&sid=' . $sid);
//echo $resp . "\n";


$json = json_decode($resp);
$data = $json->{'data'};
//var_dump($data);
file_put_contents("/var/log/download.log",$json,FILE_APPEND | LOCK_EX);
//echo "CWD: " . getCwd() . "\n";

foreach($data as $torrent){
  $name= $torrent->{'source_name'};
  $hash=$torrent->{'hash'};
  //echo "torrent: " . $name . "\n";
  //echo "hash: " . $hash . "\n";

  if(endsWith($name,".torrent")){
  //  echo "torrent file - just delete\n";
  }else{
    //echo "file - notify completion\n";
    $url);
    //echo $resp;
    if($resp=='{"error":0}'){
      //sendNotification($showAndEpisode,"started"); 
      return true;
    }else{
      sendNotification($showAndEpisode,"failed"); 
      return false;
    }
}

//***************************************
// sendNotification
//***************************************
function sendNotification($showAndEpisode,$status){
    global $EMAIL_SUBJECT_DOWNLOADED, $EMAIL_SUBJECT_STARTED,$EMAIL_SUBJECT_REMOVED, $EMAIL_SUBJECT_FAILED, $EMAIL_FROM, $EMAIL_TO;

    if($status == "started"){
      $subject= "\"" . $EMAIL_SUBJECT_STARTED . $showAndEpisode . "\"";
    }else if($status == "downloaded"){
      $subject= "\"" . $EMAIL_SUBJECT_DOWNLOADED . $showAndEpisode . "\"";
    }else if($status == "failed"){
      $subject= "\"" . $EMAIL_SUBJECT_FAILED . $name$showAndEpisode . "\""; 
    $cmd=}else getCwdif()$status .== "/sendEmail.sh " . $subject  . " "removed"){
      $subject= "\"" . $EMAIL_TO_SUBJECT_REMOVED . $showAndEpisode . "\"";
 " . $EMAIL_FROM . " " . $subject;
    //echo "cmd= }else{
      $subject= "\"" . "ERROR " . $cmd$showAndEpisode . "\n"";

    shell_exec($cmd); }

  }

  //remove torrent 
  $resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Remove?clean=0&hash=' . $hash . '&sid=' . $sid);

  //echo $resp ."\n";
  //break;
$cmd= getCwd() . "/sendEmail.sh " . $subject  . " " . $EMAIL_FROM . " " . $EMAIL_TO . " " . $subject;
    shell_exec($cmd);
 
}

//***************************************
// endsWithremoveCompleted
//***************************************
function endsWith($haystack, $needle)
removeCompleted(){
  global $baseURL,  $length = strlen($needle)$sid, $EMAIL_TO, $EMAIL_FROM, $EMAIL_SUBJECT_DOWNLOADED;
  
  if ($length == 0) {
        return true;
    }

    return (substr($haystack, -$length) === $needle);
}

//***************************************
// getSid
//***************************************
function getSid($xml){

    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, $xml, $values, $tags);
    xml_parser_free($parser);
    //print_r($values);
 
    // loop through the structures
    foreach ($values as $val) {
      $tag=$val['tag'];
      $value=$val['value'];$resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Query?start=0&limit=25&status=completed&from=0&to=25&sid=' . $sid);
  //echo $resp . "\n";
 
  $json = json_decode($resp);
  $data = $json->{'data'};
  //var_dump($data);
  file_put_contents("/var/log/download.log",$json,FILE_APPEND | LOCK_EX);
  //echo "CWD: " . getCwd() . "\n";

  if(count($data)==0){
    echo "- no completed downloads\n";
  }else{
 
    foreach($data as $torrent){
      $name= $torrent->{'source_name'};
      $hash=$torrent->{'hash'};
      echo "removing torrent: " . $name . "\n";
      //echo "hash: " . $hash . "\n";
 
      if($tag=="authSid"endsWith($name,".torrent")){
      //  return $value;
      } echo "torrent file - just delete\n";
      //echo "tag=" . $tag . ", value=" . $value . "\n";
}else{
        sendNotification($name,"downloaded"); 
      }
}
?>

showTorrents.php

Code Block
languagephp
titleshowTorrents.php
<?php

$baseURL="http://localhost:8080";
$pass=urlencode("xxx_BASE64ENCODED_PASSWORD_xxx");

//login
$vars = 'user=admin&pass=' . $pass;
$ch = curl_init(  
      //remove torrent
      $resp=file_get_contents($baseURL . '/downloadstation/V4/Misc/Login' );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec( $ch );
//echo $resp;

$sid = json_decode($resp)->{'sid'};
//echo "sid='" . $sid . "'\n";

$resp=file_get_contents($baseURL . '/downloadstation/V4/Misc/Login?sid=' . $sid);
//echo $resp . "\n";

Task/Remove?clean=0&hash=' . $hash . '&sid=' . $sid);
    }
  }
}
//***************************************
// removeAll
//***************************************
function removeAll(){
  global $baseURL, $sid, $EMAIL_TO, $EMAIL_FROM, $EMAIL_SUBJECT_DOWNLOADED;

  $resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Query?start=0&limit=100&status=all&from=0&to=100&sid=' . $sid);
echo $resp
 . "\n";

$json = json_decode($resp);
$data = $json->{'data'};
//var_dump($data);

//echo "CWD: " . getCwd() . "\n";

foreach($data as $torrent){
  $name= $torrent$json->{'source_namedata'};

  echo "torrent: " . $name . "\n";

}

?>

removeAllTorrents.php

Code Block
languagephp
titleremoveAllTorrents.php
<?php

$EMAIL_TO="j****@yahoo.com";
$EMAIL_FROM="j****@yahoo.com";
$EMAIL_SUBJECT="TORRENT DOWNLOADED [NAS] - ";

$pass=urlencode("xxx_BASE64ENCODED_PASSWORD_xxx");
$baseURL="http://localhost:8080";

//login
$resp = file_get_contents($baseURL . "/cgi-bin/authLogin.cgi?user=admin&pwd=" . $pass );
$sid=getSid($resp);
 
$resp=file_get_contents($baseURL . '/downloadstation/V4/Misc/Login?sid=' . $sid);

$resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Query?start=0&limit=100&status=all&from=0&to=100&sid=' . $sid);


$json = json_decode($resp);
$data = $json->{'data'};

foreach($data as $torrent){
  $name= $torrent->{'source_name'};
  $hash=$torrent->{'hash'};

  if(endsWith($name,".torrent")){
  //  echo "torrent file - just delete\n";
  }else{
    //echo "file - notify completion\n";
    $subject= "\"" . $EMAIL_SUBJECT . $name . "\""; 
    $cmd= getCwd() . "/sendEmail.sh " . $subject  . " " . $EMAIL_FROM . " " . $EMAIL_TO . " " . $subject;
    //echo "cmd=" . $cmd . "\n";

    //shell_exec($cmd); 
  }

  //remove torrent 
  $resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Remove?clean=0&hash=' . $hash . '&sid=' . $sid);

  //echo $resp ."\n";
  //break;

}

// if(count($data)==0){
    echo "- no downloads\n";
  }else{ 
    foreach($data as $torrent){
      $name= $torrent->{'source_name'};
      $hash=$torrent->{'hash'};
 
      if(endsWith($name,".torrent")){
      //  echo "torrent file - just delete\n";
      }else{
        echo "- " . $name . "\n";
        //echo "file - notify completion\n";
        //sendNotification($name,"removed"); 
      }
 
      //remove torrent
      $resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Remove?clean=0&hash=' . $hash . '&sid=' . $sid);
    }
  }
}

//***************************************
// listDownloads
//***************************************
function listDownloads(){
  global $baseURL, $sid;

  $resp=file_get_contents($baseURL . '/downloadstation/V4/Task/Query?start=0&limit=100&status=all&from=0&to=100&sid=' . $sid);
  //echo $resp . "\n";
 
  $json = json_decode($resp);
  $data = $json->{'data'};

  if(count($data)==0){
    echo "- no downloads\n";
  }else{  
    foreach($data as $torrent){
      $name= $torrent->{'source_name'};
      echo "torrent: " . $name . "\n";
    }
  }
}

//***************************************
// loginToQnap
//********************************************
// endsWith
//***************************************
function endsWith($haystack, $needle)
{
    $length = strlen($needle);
    if ($length == 0) {
        return true;
    }

    return (substr($haystack, -$length) === $needle)
function loginToQnap(){
  global $baseURL, $pass;
 
  //login
  $vars = 'user=admin&pass=' . $pass;
  $ch = curl_init( $baseURL . '/downloadstation/V4/Misc/Login' );
  curl_setopt( $ch, CURLOPT_POST, 1);
  curl_setopt( $ch, CURLOPT_POSTFIELDS, $vars);
  curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt( $ch, CURLOPT_HEADER, 0);
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
  $resp = curl_exec( $ch );
  //echo $resp;
 
  $sid = json_decode($resp)->{'sid'};
  //echo "sid='" . $sid . "'\n";
 
  return $sid;
}

//***************************************
// getSidendsWith
//***************************************
function getSid($xml)endsWith($haystack, $needle)
{

    $parser$length = xml_parser_createstrlen($needle);
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING,if ($length == 0); {
      xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1)  return true;
    xml_parse_into_struct($parser, $xml, $values, $tags);
    xml_parser_free($parser);
    //print_r($values);
 
    // loop through the structures
    foreach ($values as $val) {
      $tag=$val['tag'];
      $value=$val['value'];
      if($tag=="authSid"){
        return $value;
      } 
      //echo "tag=" . $tag . ", value=" . $value . "\n";
    }

}
?>
}
    return (substr($haystack, -$length) === $needle);
}

//******************************************
// showUsage
//******************************************
function showUsage(){
  global $argv;
  echo "Usage: php " . $argv[0] . " download/removeCompleted/listDownloads/removeAll\n";
}

?>


sendEmail.sh

Code Block
languagebash
titlesendEmail.sh
collapsetrue
#!/bin/sh

SUBJECT=$1
TO=$2
FROM=$3
CONTENT=$4

echo "Subject: $SUBJECT"
echo "From: $FROM"
echo "To: $TO"
echo "CONTENT $CONTENT"

echo "Subject: $SUBJECT" > mail.txt
echo "From: $FROM" >> mail.txt
echo "To: $TO" >> mail.txt
echo "" >> mail.txt
echo $CONTENT >> mail.txt

cat mail.txt |sendmail -t
#rm mail.txt