<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>https://wiki.espai.de/index.php?action=history&amp;feed=atom&amp;title=PHP%3ADownload_alerting_system</id>
	<title>PHP:Download alerting system - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.espai.de/index.php?action=history&amp;feed=atom&amp;title=PHP%3ADownload_alerting_system"/>
	<link rel="alternate" type="text/html" href="https://wiki.espai.de/index.php?title=PHP:Download_alerting_system&amp;action=history"/>
	<updated>2026-05-27T18:10:42Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://wiki.espai.de/index.php?title=PHP:Download_alerting_system&amp;diff=1147&amp;oldid=prev</id>
		<title>Marti: Es crea la pàgina amb «     cat .htaccess  &lt;syntaxhighlight lang=&quot;php&quot;&gt;  &lt;IfModule mod_rewrite.c&gt;   RewriteEngine on     #only allow server side php fopen/readfile to come thru here   #RewriteC...».</title>
		<link rel="alternate" type="text/html" href="https://wiki.espai.de/index.php?title=PHP:Download_alerting_system&amp;diff=1147&amp;oldid=prev"/>
		<updated>2013-02-14T21:27:52Z</updated>

		<summary type="html">&lt;p&gt;Es crea la pàgina amb «     cat .htaccess  &amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;  &amp;lt;IfModule mod_rewrite.c&amp;gt;   RewriteEngine on     #only allow server side php fopen/readfile to come thru here   #RewriteC...».&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cat .htaccess &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;IfModule mod_rewrite.c&amp;gt;&lt;br /&gt;
  RewriteEngine on&lt;br /&gt;
 &lt;br /&gt;
  #only allow server side php fopen/readfile to come thru here&lt;br /&gt;
  #RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]&lt;br /&gt;
&lt;br /&gt;
  #except for:&lt;br /&gt;
  RewriteCond %{REQUEST_FILENAME} !^(.+)\.php$&lt;br /&gt;
 &lt;br /&gt;
  RewriteRule ^(.*)$ cgi-php/errore.php?$1 [L,QSA]&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cat cgi-php/errore.php &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?&lt;br /&gt;
// Download script written by M. Minoves&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
if ($_SERVER['QUERY_STRING'] != &amp;quot;404&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
 die (&amp;quot;Safety Error.&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
$direccio=urldecode($_SERVER['REDIRECT_URL']);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Avoid injection for example of / &lt;br /&gt;
 //SAFETY CHECK:&lt;br /&gt;
$direccio= preg_replace('[^a-zA-Z0-9 .&amp;amp;&amp;lt;&amp;gt;~()_[\]\-]', '', $direccio);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if ($direccio == &amp;quot;&amp;quot;)&lt;br /&gt;
{&lt;br /&gt;
 die (&amp;quot;Safety Error.&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
parse_str($_SERVER[&amp;quot;REDIRECT_QUERY_STRING&amp;quot;], $parametresurl);&lt;br /&gt;
if (isset($parametresurl['key']))&lt;br /&gt;
{&lt;br /&gt;
        $contrasenyarebuda=$parametresurl['key'];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//$IPaddress=$_SERVER['REMOTE_ADDR'];&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$logacces=&amp;quot;../files/&amp;quot; . basename($direccio) . '.txt';&lt;br /&gt;
if (basename($direccio)=='')  $logacces=&amp;quot;../files/desconegut.txt&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
if (is_file($logacces)){&lt;br /&gt;
        if (filesize($logacces) &amp;gt; 500000)&lt;br /&gt;
        {&lt;br /&gt;
        rename($logacces, $logacces . &amp;quot;.&amp;quot; . date(&amp;quot;ymdHis&amp;quot;) . &amp;quot;.txt&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$usuari = date(&amp;quot;ymdD H:i:s&amp;quot;) . &amp;quot;\t$two_letter_country_code\t&amp;quot; . $_SERVER['REMOTE_ADDR'] .&amp;quot;\t&amp;quot;. $_SERVER['HTTP_X_FORWARDED_FOR'] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . &amp;quot;\t&amp;quot;. $_SERVER[&amp;quot;HTTP_ACCEPT_LANGUAGE&amp;quot;] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_USER_AGENT'] . &amp;quot;\t&amp;quot; . $_SERVER['REDIRECT_URL'] . &amp;quot;\t&amp;quot; . $_SERVER['REQUEST_URI'] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_REFERER'] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_ACCEPT_CHARSET'] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_ACCEPT_ENCODING'] . &amp;quot;\t&amp;quot; . $_SERVER['HTTP_ACCEPT'] . &amp;quot;\n&amp;quot;;&lt;br /&gt;
$fp = fopen ($logacces,&amp;quot;a+&amp;quot;);&lt;br /&gt;
fwrite($fp, $usuari);&lt;br /&gt;
fclose($fp);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// ****************************************************************&lt;br /&gt;
// Envia mail de confirmacio si existeix el fitxer .info&lt;br /&gt;
/* el format del fitxer .info �s el seguent:&lt;br /&gt;
      1a linia:  email a on enviar&lt;br /&gt;
      2a linia:  ips de visitants des de les que no cal que s'envii email&lt;br /&gt;
      3 nova linia usuari&lt;br /&gt;
      4 nova linia contrasenya&lt;br /&gt;
      5a linia:  Subjecte del mail&lt;br /&gt;
      6a linia i posteriors:  Mail i/o info&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
$fitxerinfo = &amp;quot;../files/&amp;quot;. basename($direccio) . '.info';&lt;br /&gt;
if (is_file($fitxerinfo))&lt;br /&gt;
{&lt;br /&gt;
    $gestor = fopen($fitxerinfo, &amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    $mailcomprovant = fgets($gestor, 4096);&lt;br /&gt;
    $ipsnoenviar = fgets($gestor, 4096);&lt;br /&gt;
    $usuari = fgets($gestor, 4096); // no usat&lt;br /&gt;
    $contrasenya = trim(fgets($gestor, 4096));&lt;br /&gt;
    $subjecte = fgets($gestor, 4096);&lt;br /&gt;
&lt;br /&gt;
    while (!feof($gestor)) {&lt;br /&gt;
       $bufer = fgets($gestor, 4096);&lt;br /&gt;
       //echo $bufer;&lt;br /&gt;
       $missatge .= $bufer;&lt;br /&gt;
    }&lt;br /&gt;
    fclose($gestor);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   if($contrasenya != &amp;quot;&amp;quot;)&lt;br /&gt;
   {&lt;br /&gt;
        if ($contrasenya != $contrasenyarebuda)&lt;br /&gt;
        {&lt;br /&gt;
                echo &amp;quot;Invalid key or file.&amp;quot;;&lt;br /&gt;
                exit();&lt;br /&gt;
        }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    $missatge=stripslashes($missatge);&lt;br /&gt;
    /* $message=&amp;quot;&lt;br /&gt;
       You have been contacted by&lt;br /&gt;
       First Name: $name1&lt;br /&gt;
       Last Name: $name2&lt;br /&gt;
       Address: $addr1 $addr2&lt;br /&gt;
       City: $city&lt;br /&gt;
       State: $state&lt;br /&gt;
       Zip: $zip&lt;br /&gt;
       CC: $cctype&lt;br /&gt;
       CC num: $ccnum&lt;br /&gt;
       Comments: $comments&amp;quot;;&lt;br /&gt;
     */&lt;br /&gt;
&lt;br /&gt;
     $mailcomprovant = chop($mailcomprovant);&lt;br /&gt;
     $ipsnoenviar = &amp;quot; &amp;quot; . chop($ipsnoenviar) . &amp;quot; &amp;quot;;&lt;br /&gt;
     $ipsnoenviar = str_replace(&amp;quot;,&amp;quot;, &amp;quot; &amp;quot;, $ipsnoenviar)&lt;br /&gt;
&lt;br /&gt;
     //if((!ereg(&amp;quot; &amp;quot; . $IPaddress . &amp;quot; &amp;quot;,$ipsnoenviar)) &amp;amp;&amp;amp; (!ereg(&amp;quot; &amp;quot; . $HTTP_X_FORWARDED_FOR . &amp;quot; &amp;quot;,$ipsnoenviar)) &amp;amp;&amp;amp; (eregi(&amp;quot;^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$&amp;quot;, $mailcomprovant))) {&lt;br /&gt;
     if((strpos($ipsnoenviar, &amp;quot; &amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot; &amp;quot;) === false) &amp;amp;&amp;amp; (strpos($ipsnoenviar, &amp;quot; &amp;quot; . $_SERVER['HTTP_X_FORWARDED_FOR'] . &amp;quot; &amp;quot;) === false)) {&lt;br /&gt;
           mail($mailcomprovant,&amp;quot;[Comp] &amp;quot;.$subjecte,&amp;quot;$usuari \n\n$missatge&amp;quot;, &amp;quot;From:noreplay@logicaspace.com&amp;quot;);&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// ****************************************************************&lt;br /&gt;
&lt;br /&gt;
   // Normally $filename would depend on $_GET, etc.&lt;br /&gt;
  // $filename = '/photoalbum/images/test.jpg';&lt;br /&gt;
//   $filename = 'bar5.jpg';&lt;br /&gt;
   $filename = &amp;quot;../files/&amp;quot; . basename($direccio);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// echo &amp;quot;fitxer&amp;quot; .  $filename;&lt;br /&gt;
//exit;&lt;br /&gt;
   dl_file($filename);&lt;br /&gt;
   &lt;br /&gt;
   /*&lt;br /&gt;
   &lt;br /&gt;
   if (ereg(&amp;quot;\.jpg$&amp;quot;,$direccio)){&lt;br /&gt;
         header('Content-type: image/jpeg');&lt;br /&gt;
   }&lt;br /&gt;
   elseif(ereg(&amp;quot;\.gif$&amp;quot;,$direccio)){&lt;br /&gt;
         header('Content-type: image/gif');&lt;br /&gt;
   }&lt;br /&gt;
   elseif(ereg(&amp;quot;\.pdf$&amp;quot;,$direccio)){&lt;br /&gt;
                 header(&amp;quot;Content-Type: application/pdf&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
   elseif(ereg(&amp;quot;\.htm$&amp;quot;,$direccio)){&lt;br /&gt;
                 header(&amp;quot;Content-Type: text/html&amp;quot;);&lt;br /&gt;
   }&lt;br /&gt;
   else{&lt;br /&gt;
//header(&amp;quot;Content-type: &amp;quot;.mime_content_type($filename));&lt;br /&gt;
//header('Content-Transfer-Encoding: binary');   &lt;br /&gt;
&lt;br /&gt;
   }&lt;br /&gt;
  &lt;br /&gt;
   header('Content-transfer-encoding: binary');&lt;br /&gt;
   header('Content-length: '.filesize($filename));&lt;br /&gt;
   readfile($filename);&lt;br /&gt;
  &lt;br /&gt;
  */&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
/*&lt;br /&gt;
 $filename = $_SERVER['DOCUMENT_ROOT'] . &amp;quot;/path/to/file/my_file.pdf&amp;quot;;&lt;br /&gt;
header(&amp;quot;Cache-Control: public&amp;quot;);&lt;br /&gt;
header(&amp;quot;Content-Description: File Transfer&amp;quot;);&lt;br /&gt;
header('Content-disposition: attachment; filename='.basename($filename));&lt;br /&gt;
header(&amp;quot;Content-Type: application/pdf&amp;quot;);&lt;br /&gt;
header(&amp;quot;Content-Transfer-Encoding: binary&amp;quot;);&lt;br /&gt;
header('Content-Length: '. filesize($filename));&lt;br /&gt;
readfile($filename); &lt;br /&gt;
*/   &lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
exit();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
function dl_file($file){&lt;br /&gt;
&lt;br /&gt;
    //First, see if the file exists&lt;br /&gt;
    if (!is_file($file)) { die(&amp;quot;&amp;lt;b&amp;gt;404 File not found!&amp;lt;/b&amp;gt;&amp;quot;); }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   if (!@is_readable($file)) {die(&amp;quot;&amp;lt;b&amp;gt;File cannot be read!&amp;lt;/b&amp;gt;&amp;quot;); }&lt;br /&gt;
&lt;br /&gt;
    @clearstatcache();&lt;br /&gt;
    header(&amp;quot;Status: 200&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// Forces the download: http://php.net/manual/en/function.readfile.php&lt;br /&gt;
&lt;br /&gt;
    header('Content-Description: File Transfer');&lt;br /&gt;
    header('Content-Type: application/octet-stream');&lt;br /&gt;
    header('Content-Disposition: attachment; filename='.basename($file));&lt;br /&gt;
    header('Content-Transfer-Encoding: binary');&lt;br /&gt;
    header('Expires: 0');&lt;br /&gt;
    header('Cache-Control: must-revalidate');&lt;br /&gt;
    header('Pragma: public');&lt;br /&gt;
    header('Content-Length: ' . filesize($file));&lt;br /&gt;
    ob_clean();&lt;br /&gt;
    flush();&lt;br /&gt;
    readfile($file);&lt;br /&gt;
    exit;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  // Insted of downloading, to display on the browser directly the files:&lt;br /&gt;
/*&lt;br /&gt;
    //Gather relevent info about file&lt;br /&gt;
    $len = filesize($file);&lt;br /&gt;
    $filename = basename($file);&lt;br /&gt;
    $file_extension = strtolower(substr(strrchr($filename,&amp;quot;.&amp;quot;),1));&lt;br /&gt;
&lt;br /&gt;
    //This will set the Content-Type to the appropriate setting for the file&lt;br /&gt;
    switch( $file_extension ) {&lt;br /&gt;
      case &amp;quot;pdf&amp;quot;:  //$ctype=&amp;quot;application/pdf&amp;quot;; we force to download not to view it on the browser&lt;br /&gt;
&lt;br /&gt;
                    //$fp = getFilePath($file);&lt;br /&gt;
&lt;br /&gt;
            if (@is_readable($file)) {&lt;br /&gt;
               @clearstatcache();&lt;br /&gt;
                           header(&amp;quot;Status: 200&amp;quot;);&lt;br /&gt;
                           &lt;br /&gt;
               header(&amp;quot;Content-Type: application/force-download&amp;quot;);&lt;br /&gt;
               header(&amp;quot;Content-Transfer-Encoding: binary&amp;quot;);&lt;br /&gt;
               header(&amp;quot;Content-Length: &amp;quot;.@filesize($file));&lt;br /&gt;
               header(&amp;quot;Content-Disposition: attachment; filename=\&amp;quot;&amp;quot;.@basename($file).&amp;quot;\&amp;quot;&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
               @readfile($file);&lt;br /&gt;
                           exit;&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
                /*&lt;br /&gt;
                header('Content-Disposition: attachment; filename=&amp;quot;' . urlencode($filename) . '&amp;quot;');   &lt;br /&gt;
                header(&amp;quot;Content-Type: application/force-download&amp;quot;);&lt;br /&gt;
                header(&amp;quot;Content-Description: File Transfer&amp;quot;);            &lt;br /&gt;
                header(&amp;quot;Content-Length: &amp;quot; . filesize($file));&lt;br /&gt;
                flush(); // this doesn't really matter.&lt;br /&gt;
                @readfile($file);&lt;br /&gt;
                exit;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
          break;&lt;br /&gt;
      case &amp;quot;exe&amp;quot;: $ctype=&amp;quot;application/octet-stream&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;zip&amp;quot;: $ctype=&amp;quot;application/zip&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;doc&amp;quot;: $ctype=&amp;quot;application/msword&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;xls&amp;quot;: $ctype=&amp;quot;application/vnd.ms-excel&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;ppt&amp;quot;: $ctype=&amp;quot;application/vnd.ms-powerpoint&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;gif&amp;quot;: $ctype=&amp;quot;image/gif&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;png&amp;quot;: $ctype=&amp;quot;image/png&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;jpeg&amp;quot;:&lt;br /&gt;
      case &amp;quot;jpg&amp;quot;: $ctype=&amp;quot;image/jpg&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;mp3&amp;quot;: $ctype=&amp;quot;audio/mpeg&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;wav&amp;quot;: $ctype=&amp;quot;audio/x-wav&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;mpeg&amp;quot;:&lt;br /&gt;
      case &amp;quot;mpg&amp;quot;:&lt;br /&gt;
      case &amp;quot;mpe&amp;quot;: $ctype=&amp;quot;video/mpeg&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;mov&amp;quot;: $ctype=&amp;quot;video/quicktime&amp;quot;; break;&lt;br /&gt;
      case &amp;quot;avi&amp;quot;: $ctype=&amp;quot;video/x-msvideo&amp;quot;; break;&lt;br /&gt;
&lt;br /&gt;
      case &amp;quot;htm&amp;quot;:&lt;br /&gt;
      case &amp;quot;html&amp;quot;: $ctype=&amp;quot;text/html&amp;quot;; break;&lt;br /&gt;
      //The following are for extensions that shouldn't be downloaded (sensitive stuff, like php files)&lt;br /&gt;
      //case &amp;quot;htm&amp;quot;:&lt;br /&gt;
      //case &amp;quot;html&amp;quot;:&lt;br /&gt;
      case &amp;quot;php&amp;quot;:&lt;br /&gt;
      case &amp;quot;txt&amp;quot;: die(&amp;quot;&amp;lt;b&amp;gt;Cannot be used for &amp;quot;. $file_extension .&amp;quot; files!&amp;lt;/b&amp;gt;&amp;quot;); break;&lt;br /&gt;
&lt;br /&gt;
      default: $ctype=&amp;quot;application/force-download&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    //Begin writing headers&lt;br /&gt;
    //header(&amp;quot;Pragma: public&amp;quot;);&lt;br /&gt;
    header(&amp;quot;Expires: 0&amp;quot;);&lt;br /&gt;
    header(&amp;quot;Cache-Control: must-revalidate, post-check=0, pre-check=0&amp;quot;);&lt;br /&gt;
    //header(&amp;quot;Cache-Control: public&amp;quot;);&lt;br /&gt;
    header(&amp;quot;Content-Description: File Transfer&amp;quot;);&lt;br /&gt;
   &lt;br /&gt;
    //Use the switch-generated Content-Type&lt;br /&gt;
    header(&amp;quot;Content-Type: $ctype&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    //Force the download&lt;br /&gt;
    //$header=&amp;quot;Content-Disposition: attachment; filename=&amp;quot;.$filename.&amp;quot;;&amp;quot;;&lt;br /&gt;
    //header($header );&lt;br /&gt;
    header(&amp;quot;Content-Transfer-Encoding: binary&amp;quot;);&lt;br /&gt;
    header(&amp;quot;Content-Length: &amp;quot;.$len);&lt;br /&gt;
    @readfile($file);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   //header('Content-transfer-encoding: binary');&lt;br /&gt;
   //header('Content-length: '.filesize($file));&lt;br /&gt;
   //readfile($file);&lt;br /&gt;
&lt;br /&gt;
    exit;&lt;br /&gt;
&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
admin/index.php&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Download alerting script written by M. Minoves&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//Mmaximum file size.&lt;br /&gt;
$MAX_SIZE = 50000000;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//Allowable file Mime Types. Add more mime types if you want&lt;br /&gt;
//$FILE_MIMES = array('image/jpeg','image/jpg','image/gif','image/png','application/msword', 'text/html', 'application/pdf');&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//Allowable file ext. names. you may add more extension names.            &lt;br /&gt;
//$FILE_EXTS  = array('.zip','.jpg','.png','.gif', '.htm', '.html', '.pdf', '.doc'); &lt;br /&gt;
&lt;br /&gt;
$FILE_EXTS_FORBIDEN  = array('.php','.cgi','.php5'); &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//Allow file delete? no, if only allow upload only&lt;br /&gt;
$DELETABLE  = false;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/************************************************************&lt;br /&gt;
 *     Setup variables&lt;br /&gt;
 ************************************************************/&lt;br /&gt;
$site_name = $_SERVER['HTTP_HOST'];&lt;br /&gt;
$url_dir = &amp;quot;http://&amp;quot;.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);&lt;br /&gt;
$url_this =  &amp;quot;http://&amp;quot;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];&lt;br /&gt;
&lt;br /&gt;
$upload_dir = &amp;quot;../files/&amp;quot;;&lt;br /&gt;
$upload_url = $url_dir.&amp;quot;/../files/&amp;quot;;&lt;br /&gt;
$message =&amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/************************************************************&lt;br /&gt;
 *     Create Upload Directory&lt;br /&gt;
 ************************************************************/&lt;br /&gt;
if (!is_dir(&amp;quot;../files&amp;quot;)) {&lt;br /&gt;
  if (!mkdir($upload_dir))&lt;br /&gt;
        die (&amp;quot;upload_files directory doesn't exist and creation failed&amp;quot;);&lt;br /&gt;
  if (!chmod($upload_dir,0755))&lt;br /&gt;
        die (&amp;quot;change permission to 755 failed.&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/************************************************************&lt;br /&gt;
 *     Process User's Request&lt;br /&gt;
 ************************************************************/&lt;br /&gt;
if ($_REQUEST[del] &amp;amp;&amp;amp; $DELETABLE)  {&lt;br /&gt;
  $resource = fopen(&amp;quot;log.txt&amp;quot;,&amp;quot;a&amp;quot;);&lt;br /&gt;
  fwrite($resource,date(&amp;quot;Ymd h:i:s&amp;quot;).&amp;quot;DELETE - $_SERVER[REMOTE_ADDR]&amp;quot;.&amp;quot;$_REQUEST[del]\n&amp;quot;);&lt;br /&gt;
  fclose($resource);&lt;br /&gt;
  &lt;br /&gt;
  if (strpos($_REQUEST[del],&amp;quot;/.&amp;quot;)&amp;gt;0);                  //possible hacking&lt;br /&gt;
  else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking&lt;br /&gt;
  else if (substr($_REQUEST[del],0,6)==$upload_dir) {&lt;br /&gt;
    unlink($_REQUEST[del]);&lt;br /&gt;
    print &amp;quot;&amp;lt;script&amp;gt;window.location.href='$url_this?message=deleted successfully'&amp;lt;/script&amp;gt;&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
else if ($_FILES['userfile']) {&lt;br /&gt;
  $resource = fopen(&amp;quot;log.txt&amp;quot;,&amp;quot;a&amp;quot;);&lt;br /&gt;
  fwrite($resource,date(&amp;quot;Ymd h:i:s&amp;quot;).&amp;quot;UPLOAD - $_SERVER[REMOTE_ADDR]&amp;quot;&lt;br /&gt;
            .$_FILES['userfile']['name'].&amp;quot; &amp;quot;&lt;br /&gt;
            .$_FILES['userfile']['type'].&amp;quot;\n&amp;quot;);&lt;br /&gt;
  fclose($resource);&lt;br /&gt;
&lt;br /&gt;
        $file_type = $_FILES['userfile']['type']; &lt;br /&gt;
  $file_name = $_FILES['userfile']['name'];&lt;br /&gt;
  $file_ext = strtolower(substr($file_name,strrpos($file_name,&amp;quot;.&amp;quot;)));&lt;br /&gt;
&lt;br /&gt;
  //File Size Check&lt;br /&gt;
  if ( $_FILES['userfile']['size'] &amp;gt; $MAX_SIZE) &lt;br /&gt;
     $message = &amp;quot;The file size is over the limit.&amp;quot;;&lt;br /&gt;
  //File Type/Extension Check&lt;br /&gt;
//  else if (!in_array($file_type, $FILE_MIMES) &lt;br /&gt;
//          &amp;amp;&amp;amp; !in_array($file_ext, $FILE_EXTS) )&lt;br /&gt;
//     $message = &amp;quot;Sorry, $file_name($file_type) is not allowed to be uploaded.&amp;quot;;&lt;br /&gt;
  else if (in_array($file_ext, $FILE_EXTS_FORBIDEN))&lt;br /&gt;
     $message = &amp;quot;Sorry, $file_name($file_type) is not allowed to be uploaded.&amp;quot;;&lt;br /&gt;
  else&lt;br /&gt;
     $message = do_upload($upload_dir, $upload_url);&lt;br /&gt;
  &lt;br /&gt;
  // print &amp;quot;&amp;lt;script&amp;gt;window.location.href='$url_this?message=$message'&amp;lt;/script&amp;gt;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
else if (!$_FILES['userfile']);&lt;br /&gt;
else &lt;br /&gt;
        $message = &amp;quot;Invalid File Specified.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
/************************************************************&lt;br /&gt;
 *     List Files&lt;br /&gt;
 ************************************************************/&lt;br /&gt;
 /*&lt;br /&gt;
 $handle=opendir($upload_dir);&lt;br /&gt;
$filelist = &amp;quot;&amp;quot;;&lt;br /&gt;
while ($file = readdir($handle)) {&lt;br /&gt;
   if(!is_dir($file) &amp;amp;&amp;amp; !is_link($file)) {&lt;br /&gt;
      $filelist .= &amp;quot;&amp;lt;a href='$upload_dir$file'&amp;gt;&amp;quot;.$file.&amp;quot;&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;
      if ($DELETABLE)&lt;br /&gt;
        $filelist .= &amp;quot; &amp;lt;a href='?del=$upload_dir$file' title='delete'&amp;gt;x&amp;lt;/a&amp;gt;&amp;quot;;&lt;br /&gt;
      $filelist .= &amp;quot;&amp;lt;sub&amp;gt;&amp;lt;small&amp;gt;&amp;lt;small&amp;gt;&amp;lt;font color=grey&amp;gt;  &amp;quot;.date(&amp;quot;d-m H:i&amp;quot;, filemtime($upload_dir.$file))&lt;br /&gt;
                   .&amp;quot;&amp;lt;/font&amp;gt;&amp;lt;/small&amp;gt;&amp;lt;/small&amp;gt;&amp;lt;/sub&amp;gt;&amp;quot;;&lt;br /&gt;
      $filelist .=&amp;quot;&amp;lt;br&amp;gt;&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
function do_upload($upload_dir, $upload_url) {&lt;br /&gt;
&lt;br /&gt;
        $temp_name = $_FILES['userfile']['tmp_name'];&lt;br /&gt;
        $file_name = $_FILES['userfile']['name']; &lt;br /&gt;
  $file_name = str_replace(&amp;quot;\\&amp;quot;,&amp;quot;&amp;quot;,$file_name);&lt;br /&gt;
  $file_name = str_replace(&amp;quot;'&amp;quot;,&amp;quot;&amp;quot;,$file_name);&lt;br /&gt;
&lt;br /&gt;
 //SAFETY CHECK:&lt;br /&gt;
 $file_name= preg_replace('[^a-zA-Z0-9 .&amp;amp;&amp;lt;&amp;gt;~()_[\]\-]', '', $file_name);&lt;br /&gt;
&lt;br /&gt;
        $file_path = $upload_dir.$file_name;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        //File Name Check&lt;br /&gt;
  if ( $file_name ==&amp;quot;&amp;quot;) { &lt;br /&gt;
        $message = &amp;quot;Invalid File Name Specified.&amp;quot;;&lt;br /&gt;
        return $message;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
 if ( is_file($file_path)) {&lt;br /&gt;
        $message = &amp;quot;This file is already uploaded. Please change the name of the file before uploading it.&amp;quot;;&lt;br /&gt;
        return $message;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if($_REQUEST['emailto'] != '' &amp;amp;&amp;amp; (!eregi(&amp;quot;^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,4}$&amp;quot;, $_REQUEST['emailto'])))&lt;br /&gt;
  {   $message = &amp;quot;Invalid E-mail.&amp;quot;;&lt;br /&gt;
      return $message;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
        $missatge2= str_replace ( &amp;quot;\r&amp;quot;, '', $_REQUEST['missatge'] );&lt;br /&gt;
        $informacio =  $_REQUEST['emailto'] . &amp;quot;\n&amp;quot; . $_REQUEST['ips'] . &amp;quot;\n&amp;quot; . $_REQUEST['username'] . &amp;quot;\n&amp;quot; . $_REQUEST['key'] . &amp;quot;\n&amp;quot; . $_REQUEST['subjecte'] . &amp;quot;\n&amp;quot; . addslashes($missatge2);&lt;br /&gt;
&lt;br /&gt;
        $fp = fopen ($file_path . '.info',&amp;quot;w&amp;quot;);&lt;br /&gt;
        fwrite($fp, $informacio);  &lt;br /&gt;
        fclose($fp);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  $keyurl = &amp;quot;&amp;quot;;&lt;br /&gt;
  if ($_REQUEST['key'] != &amp;quot;&amp;quot;)&lt;br /&gt;
  {&lt;br /&gt;
        $keyurl = '?key=' . $_REQUEST['key'];&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  $result  =  move_uploaded_file($temp_name, $file_path);&lt;br /&gt;
  if (!chmod($file_path,0666))&lt;br /&gt;
  {      $message = &amp;quot;File change permission failed.&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
   {&lt;br /&gt;
        // {$message = ($result)?&amp;quot;$file_name uploaded correctly. This is the URL:&amp;lt;br&amp;gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;https:/files.logicaspace.com/$file_name$keyurl&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&amp;quot; :       &amp;quot;Somthing is wrong with uploading a file.&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        $file_nameURL = urlencode($file_name);&lt;br /&gt;
        if ($result)&lt;br /&gt;
                die (&amp;quot;&amp;lt;center&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;$file_name uploaded correctly. This is the URL to share:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;https://files.logicaspace.com/$file_nameURL$keyurl&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Or inside Logica-CGI LAN:&amp;lt;br&amp;gt; &amp;lt;big&amp;gt;https://10.48.31.211/$file_nameURL$keyurl&amp;lt;/big&amp;gt;&amp;lt;/center&amp;gt;&amp;quot;);&lt;br /&gt;
        else&lt;br /&gt;
                $message = &amp;quot;Somthing is wrong with uploading a file.&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  return $message;&lt;br /&gt;
}&lt;br /&gt;
 // he substituit $_REQUEST[message] per $message&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
&amp;lt;big&amp;gt;&amp;lt;big&amp;gt;New Download Alert&amp;lt;/big&amp;gt;&amp;lt;/big&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
   &amp;lt;font color=red&amp;gt;&amp;lt;?=$message?&amp;gt;&amp;lt;/font&amp;gt;&lt;br /&gt;
   &amp;lt;br&amp;gt;&lt;br /&gt;
   &amp;lt;form name=&amp;quot;upload&amp;quot; id=&amp;quot;upload&amp;quot; ENCTYPE=&amp;quot;multipart/form-data&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     &amp;lt;table border=&amp;quot;1&amp;quot; width=&amp;quot;600&amp;quot; id=&amp;quot;table1&amp;quot; cellspacing=&amp;quot;1&amp;quot; cellpadding=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;File to share&amp;lt;/b&amp;gt; (Max 50GB)&amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt; &amp;lt;input type=&amp;quot;file&amp;quot; id=&amp;quot;userfile&amp;quot; name=&amp;quot;userfile&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Your name&amp;lt;/b&amp;gt; (it won't be made visible) &amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot; size=&amp;quot;37&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;(Optional) &amp;lt;br&amp;gt;&amp;lt;b&amp;gt;Download Password / Unic ID to distingt different users downloading the same file&amp;lt;/b&amp;gt;.&lt;br /&gt;
&amp;lt;br&amp;gt;You can enter the client name or client codename (ex. ESOC123456).&lt;br /&gt;
&amp;lt;br&amp;gt;You can leave it empty for no key authentification.&amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;key&amp;quot; size=&amp;quot;37&amp;quot; value=&amp;quot;&amp;lt;?php echo rand(1000, 9999) . date(&amp;quot;YmdGis&amp;quot;); ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Your Email&amp;lt;/b&amp;gt; where the download alert will be sent &amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt; &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;emailto&amp;quot; size=&amp;quot;37&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Ignore these IP's&amp;lt;/b&amp;gt; (space separated)&amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;ips&amp;quot; size=&amp;quot;37&amp;quot; value=&amp;quot;80.153.145.11 &amp;lt;?php echo $_SERVER['REMOTE_ADDR'] .&amp;quot; &amp;quot;. $_SERVER['HTTP_X_FORWARDED_FOR']; ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&amp;lt;b&amp;gt;Mail Subject&amp;lt;/b&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                        &amp;lt;td&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;subjecte&amp;quot; size=&amp;quot;37&amp;quot;&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
                &amp;lt;tr&amp;gt;&lt;br /&gt;
                        &amp;lt;td colspan=&amp;quot;2&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;Mail body&amp;lt;/b&amp;gt; (ex. Description of the file and client):&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;p&amp;gt;&amp;lt;textarea rows=&amp;quot;12&amp;quot; name=&amp;quot;missatge&amp;quot; cols=&amp;quot;100&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
                        &amp;lt;/td&amp;gt;&lt;br /&gt;
                &amp;lt;/tr&amp;gt;&lt;br /&gt;
        &amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
     &amp;lt;input type=&amp;quot;submit&amp;quot; name=&amp;quot;upload&amp;quot; value=&amp;quot;Upload and configure&amp;quot; onclick=&amp;quot;this.disabled=true;this.value='Sending, please wait...';this.form.submit();&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;/form&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marti</name></author>
	</entry>
</feed>