"Fossies" - the Fresh Open Source Software Archive

Member "eventh/functions.php" (12 Jul 2010, 9704 Bytes) of package /linux/privat/old/eventh-1.1.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "functions.php" see the Fossies "Dox" file reference documentation.

    1 <?
    2 /*
    3     This file is part of Event Horizon (EVH).
    4 
    5     EVH is free software; you can redistribute it and/or modify
    6     it under the terms of the GNU General Public License as published by
    7     the Free Software Foundation; either version 3 of the License, or
    8     (at your option) any later version.
    9 
   10     EVH is distributed in the hope that it will be useful,
   11     but WITHOUT ANY WARRANTY; without even the implied warranty of
   12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13     GNU General Public License for more details.
   14 
   15     You should have received a copy of the GNU General Public License
   16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
   17 */
   18 
   19 // Version (please do not edit this);
   20 $appversion = '1.1.11';
   21 
   22 include 'lang/en.inc';
   23 // set php timeout to 7 days (604800 seconds) in the php.ini file;
   24 // set php max post size and max file size to 10GB (10000MB) in the php.ini file;
   25 
   26 // Get a mysql-formatted date string for today;
   27 $mydate = date('Y-m-d');
   28 $date1d = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
   29 $date3d = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+3, date("Y")));
   30 $date1w = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+7, date("Y")));
   31 $date2w = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+14, date("Y")));
   32 $date3w = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+21, date("Y")));
   33 
   34 // Make Database connection;        
   35 $dbh = mysql_pconnect($dbhost,$dbuser,$dbpass);
   36 mysql_select_db($dbname);
   37 
   38 // Determine protocol to use;
   39 if ($enablessl) $proto='https';
   40 else $proto='http';
   41 
   42 // set default mail headers to get  UTF-8 to work;
   43 // this MUST end in "\r\n" or it will cause problems later;
   44 $utf8mailhdr = "MIME-Version: 1.0\r\n";
   45 $utf8mailhdr = "Content-type: text/html; charset=UTF-8\r\n";
   46 
   47 // default mail from address;
   48 //$ehmailaddr = "$appname <eh@localhost>";
   49 if (isset($YourEmail)) $ehmailaddr = "$YourEmail";
   50 
   51 // File Upload Errors (HTTP);
   52 $UPLOADERRORS = array(
   53         0=>"There is no error, the file uploaded with success",
   54         1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
   55         2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
   56         3=>"The uploaded file was only partially uploaded",
   57         4=>"No file was uploaded",
   58         6=>"Missing a temporary folder");
   59     
   60 // Default title and menu header for all pages;
   61 $titleandmenu = '<table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0">';
   62 $titleandmenu .= '<tr>';
   63 $titleandmenu .= '<th class="p_title" scope="row">' . $appname . '</th>';
   64 $titleandmenu .= '</tr>';
   65 $titleandmenu .= '<tr>';
   66 $titleandmenu .= '<th class="content-text" scope="row">' . $appdesc . '</th>';
   67 $titleandmenu .= '</tr>';
   68 $titleandmenu .= '<tr>';
   69 $titleandmenu .= '<th scope="row"><hr align="center" width="65%" size="1" noshade></th>';
   70 $titleandmenu .= '</tr> ';
   71 $titleandmenu .= '<tr>';
   72 $titleandmenu .= '<th scope="row"><span class="menu">.:. <a href="' . $proto . '://' . $servername . '/index.php">' . $homelinktext . '</a>' . $sep;
   73 if ($enableFTP == 1) $titleandmenu .= $uploadlinktext . ' [<a href="' . $proto . '://' . $servername . '/upload.php">HTTP</a> | <a href="' . $proto . '://' . $servername . '/ftp-up.php">FTP</a>]' . $sep;
   74 else $titleandmenu .=  '<a href="' . $proto . '://' . $servername . '/upload.php">' . $uploadlinktext . '</a>' . $sep;
   75 $titleandmenu .= '<a href="' . $proto . '://' . $servername . '/download.php">' . $downloadlinktext . '</a>' . $sep;
   76 $titleandmenu .= '<a href="' . $proto . '://' . $servername . '/download.php?mod=1">' . $moddellinktext . '</a>' . $sep;
   77 $titleandmenu .= '</tr>';
   78 $titleandmenu .= '</table>';
   79 $titleandmenu .= '<p>&nbsp;</p>';
   80 $titleandmenu .= '<p><br></p>';
   81 
   82 // footer;
   83 if (!$showdisclaimer) $footertext = '';
   84 
   85 $footer = '<p>&nbsp;</p><p><table width="90%"  border="0" align="center" cellpadding="0" cellspacing="0">';
   86 $footer .= '<!-- <tr>';
   87 $footer .= '<th scope="row" class="content-text">Languages: English Japanese<br><hr align="center" width="65%" size="1" noshade></th>';
   88 $footer .= '</tr> -->';
   89 $footer .= '<tr>';
   90 $footer .= '<th scope="row" class="content-text">Version ' . $appversion . '<br>' . $footertext;
   91 if ($discloselogging) $footer .= '<br>' . $historyfootertext;
   92 if ($banner != '') $footer .= '<br><img src="' . $banner . '">';
   93 $footer .= '</tr>';
   94 $footer .= '</table></p>';
   95 
   96 // function for verifying email addresses;
   97 // This is from: http://iamcal.com/publish/articles/php/parsing_email
   98 // return of 0 is an invalid address, and a return value of 1 means a good address
   99 function is_valid_email_address($email){
  100        $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  101        $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  102        $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c' . '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  103        $quoted_pair = '\\x5c\\x00-\\x7f';
  104        $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d";
  105        $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22";
  106        $domain_ref = $atom;
  107        $sub_domain = "($domain_ref|$domain_literal)";
  108        $word = "($atom|$quoted_string)";
  109        $domain = "$sub_domain(\\x2e$sub_domain)*";
  110        $local_part = "$word(\\x2e$word)*";
  111        $addr_spec = "$local_part\\x40$domain";
  112        return preg_match("!^$addr_spec$!", $email) ? 1 : 0;
  113 }
  114 
  115 // Clean potentially nasty stuff from a string
  116 function clean_email_string($string) {
  117     $string = ereg_replace('( |  +|, +|;|; +)', ',', $string);
  118     return $string;
  119 }
  120 
  121 // regex searching within an array;
  122 function preg_array($pattern, $array) {
  123   $match = 0;
  124    foreach ($array as $key => $value){
  125          if (preg_match($pattern, $value)){
  126                $match = 1;
  127                break;
  128         }
  129    }
  130  return ($match == 1) ? true : false;
  131 }
  132 
  133 // remove a directory and all files in it;
  134 function remove_files($code) {
  135    error_log($code . ': Beginning file deletion');
  136    $jnk = system('rm -rf ' . $GLOBALS['fpath'] . '/' . $code . '/');
  137    $jnk = system('rm -rf ' . $GLOBALS['ftppath'] . '/' . $code . '/');  
  138    $jnk = system('rm -f ' .  $GLOBALS['serverpath'] . '/' . $code);
  139 }
  140 
  141 // create ftp upload directory
  142 function create_upload_dir() {
  143     $dirname = substr(md5(uniqid(rand(),1)),0,8);
  144     $path = $GLOBALS['ftppath'] . $dirname;
  145     mkdir($path) or die("Could not create temp ftp dir: $path.");
  146     chmod($path,0777);
  147     error_log($dirname . ": Created new FTP upload dir.");
  148     return $dirname;
  149 }
  150 
  151 // find the name and size of the file uploaded via FTP;
  152 function find_ftp_file($dirloc) {
  153     // Find file in the ftp upload location;
  154     if ($handle = opendir($dirloc)) {
  155         while (false !== ($file = readdir($handle))) {
  156             $fullfile = $dirloc . "/" . $file;
  157             if ($file != "." && $file != "..") {
  158                 $command = "ls -l \"$fullfile\" | awk '{print $5}'";
  159                 $fsize = exec($command); 
  160                 $finfo = array($file,$fsize,$fullfile);
  161             }
  162             else error_log("$file is not a valid file");
  163         }
  164         closedir($handle);
  165     }
  166     return $finfo;
  167 }
  168 
  169 // Save file action to History table;
  170 function insert_history_entry($type, $fid, $sessid) {
  171     $srcip = $_SERVER['REMOTE_ADDR'];
  172     $browser = $_SERVER['HTTP_USER_AGENT'];
  173     
  174     $query = 'select srcemail, destemail from Sessions where id=' . $sessid;
  175     $res = mysql_query($query,$GLOBALS['dbh']);
  176     $row = mysql_fetch_row($res);
  177     $srcemail = $row[0];
  178     $dstemail = $row[1];
  179     
  180     $query = 'select name from Files where id=' . $fid;
  181     $res = mysql_query($query,$GLOBALS['dbh']);
  182     $row = mysql_fetch_row($res);
  183     $filename = $row[0];
  184     
  185     $query = 'insert into History (moddate, srcip, type, filename, srcemail, dstemail, browser) values("' . $GLOBALS['mydate'] . '","' . $srcip . '","' . $type . '","' . $filename . '","' . $srcemail . '","' . $dstemail . '","' . $browser . '");';
  186     $res = mysql_query($query,$GLOBALS['dbh']);
  187     
  188     error_log('History saved: ' . $query);
  189 }
  190 ?>
  191 <!-- necessary java scripts -->
  192 <script language="JavaScript" type="text/JavaScript">
  193 <!--
  194 function MM_findObj(n, d) { //v4.01
  195   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  196     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  197   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  198   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  199   if(!x && d.getElementById) x=d.getElementById(n); return x;
  200 }
  201 
  202 function MM_validateForm() { //v4.0
  203   var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  204   for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
  205     if (val) { nm=val.name; if ((val=val.value)!="") {
  206       if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  207         if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  208       } else if (test!='R') { num = parseFloat(val);
  209         if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  210         if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  211           min=test.substring(8,p); max=test.substring(p+1);
  212           if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  213     } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  214   } if (errors) alert('The following error(s) occurred:\n\n'+errors);
  215   document.MM_returnValue = (errors == '');
  216 }
  217 
  218 function MM_goToURL() { //v3.0
  219   var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  220   for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
  221 }
  222 //-->
  223 </script>