. */ function ssl_redirect() { if(headers_sent()) { echo " ssl_redirect: Headers already sent."; return; } if( !(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") && !(isset($_SERVER['HTTP_HTTPS']) && $_SERVER['HTTP_HTTPS'] != "off") ) { if(!isset($_SERVER['REQUEST_URI']) OR !isset($_SERVER['HTTP_HOST'])) { include("./include/header.php"); echo " Your browser doesn't support HTTP 1.1 requests.\n"; echo " Please use https:// instead of http://\n"; include("./include/footer.php"); return; } echo "\n \n"; echo " \n"; echo " \n"; exit; } } function get_remote_address() { if( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) return $_SERVER["HTTP_X_FORWARDED_FOR"]; else return $_SERVER["REMOTE_ADDR"]; } function get_date($date) { // convert from 2002-02-01 to 01.02.2002 if( $date == "0000-00-00 00:00:00" OR $date == "0000-00-00" ) return ""; elseif( strlen($date)==10 ) return date("d.m.Y", strtotime($date)); elseif( strlen($date)==16 ) return date("d.m.Y H:i", strtotime($date)); elseif( strlen($date)==19 ) return date("d.m.Y H:i:s", strtotime($date)); else return $date; } function get_sql_date($date) { // convert from 01.02.2002 to 2002-02-01 $Y = substr($date, 6, 4); $m = substr($date, 3, 2); $d = substr($date, 0, 2); return "$Y-$m-$d"; } function get_var($var) { if( isset($_GET[$var]) ) return stripslashes($_GET[$var]); elseif( isset($_POST[$var]) ) return stripslashes($_POST[$var]); else return null; } function get_int($var) { if( preg_match("/^-?[0-9]+$/", get_var($var)) ) { return get_var($var); }else { return 0; } } function get_signature($content, $applid) { global $setup; $h = substr(md5(date("U")), 0, 4); return $h . substr(md5( $h . "sEcReT" . "statutory" . $content . $applid ), 0, 24); } function check_signature($sig, $content, $applid) { global $setup; $h = substr($sig, 0, 4); return ( ($h . substr(md5( $h . "sEcReT" . "statutory" . $content . $applid ), 0, 24))==$sig ); } function dolog($section, $message, $type="info") { // $section: section where log event is generated // $message: message that should be logged // $type: type of the message // - info // - warning // - error $query="INSERT INTO `log` (`date`, `section`, `message`, `type`, `sess_name`) VALUES ('".date("Y-m-d H:i:s")."', '".addslashes($section)."', '".addslashes($message)."', '".addslashes($type)."', '".(isset($_SESSION['sess_name'])?addslashes($_SESSION['sess_name']):"")."')"; doquery($query, false); } function check_email($Email) { // Check if the supplied e-mail address is a valid e-mail address. If yes, return true, else return false $re="/(^(\w|\.|-)+@(\w|-)+(\.(\w|-)+)*\.[a-zA-Z]{2,4}$)/"; if( preg_match($re,$Email) ) { //Regex matches, now check MX if( getmxrr(substr($Email,strpos($Email,"@")+1), $mxhosts) ) { return true; }else { return false; } }else { return false; } } function encode($header, $quotesifascii=true) { #=?UTF-8?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= for( $i=0; $i127 ) { // Header contains non-ascii characters return "=?UTF-8?B?".base64_encode($header)."=?="; } } if( $quotesifascii ) return "\"".$header."\""; else return $header; } function send_mail($to, $subject, $message, $Header="", $add_user=true, $add_footer=true) { @include_once("./include/mail_smtp.old.php"); @include_once("../include/mail_smtp.old.php"); global $setup; if( strlen(stristr($Header, "From:"))==0 ) { $Header="Reply-To: \"Webmaster Statutory applications\" <".WEBMASTEREMAIL.">\n".$Header; $Header="From: \"Statutory Application Mailer\" <".WEBMASTEREMAIL.">\n".$Header; $Header.="\n"; }else { $Header.="\n"; } $Header.="X-Mailer: AEGEE-Europe statutary event application\n"; if( get_remote_address()!=NULL ) $Header.="X-Posting-Host: ".$_SERVER['REMOTE_HOST']." [".get_remote_address()."]"; if( $add_footer ) { $message.=str_replace("\\n","\n", MAILFOOTER); } if( $add_user ) { if( $_SESSION['sess_uid']==-3 ) { $message="*** This application was updated by ".$_SESSION['sess_BodyName']." ***\n\n\n$message"; }elseif( $_SESSION['sess_uid']>0 ) { $message="*** This application was updated by ".$_SESSION['sess_name']." ***\n\n\n$message"; } } // It seems that the to e-mail address is normally not put into the headers, so we check this, // and add it when missing. Furthermore, we make sure we use only the e-mail address for to, // otherwise smtp will fail if( check_email($to) ) { $toMail=$to; //echo "\n\n
Email address is already valid\n"; }else { if( preg_match_all("/((\w|\.|-)+@(\w|-)+(\.(\w|-)+)*\.[a-zA-Z]{2,4})/", $to, $matches, PREG_SET_ORDER)>0 ) { $toMail=$matches[0][0]; for( $i=1; $imail($toMail, $subject, $message, MAILRETURNPATH, $Header)) ) { // Failed sending mail $query="INSERT INTO `mailout` (`date`, `to`, `subject`, `message`, `from`, `header`) VALUES ('".date("Y-m-d H:i:s")."', '".addslashes($to)."', '".addslashes($subject)."', '".addslashes($message)."', '".addslashes(MAILRETURNPATH)."', '".addslashes($Header)."')"; if( !doquery($query) ) { // Query failed echo " I was not able to send an e-mail, neither was I able to save\n"; echo " the mail for later sending. Mail has been lost.\n"; } } return $r; } function is_anon() { if( $_SESSION['access_user'] ) return false; elseif( $_SESSION['access_view'] ) return false; elseif( $_SESSION['access_edit'] ) return false; elseif( $_SESSION['access_localorg'] ) return false; elseif( $_SESSION['access_chair'] ) return false; elseif( $_SESSION['access_admin'] ) return false; else return true; } function unhtmlentities($string) { $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); return strtr ($string, $trans_tbl); } function urlopen($host, $path) { if( $fp = fsockopen($host, 80) ) { fputs($fp, "GET $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); fputs($fp, "Connection: close\r\n\r\n"); $buf="a"; while( !feof($fp) AND $buf!="\r\n" ) { $buf = fgets($fp, 1024); } return $fp; }else { return null; } } function get_bytesize($size) { // Return the size, converted to B, KB, MB, GB or TB // Input is in bytes $SIZE_LABEL=array(0=>"B", 1=>"KB", 2=>"MB", 3=>"GB", 4=>"TB"); $size_loop=0; while( $size>950 ) { $size_loop++; $size=$size/1024; } if( $size>99.5 ) return number_format($size, 0, ",", ".")." ".$SIZE_LABEL[$size_loop]; else return number_format($size, 1, ",", ".")." ".$SIZE_LABEL[$size_loop]; } function get_bytes($size) { // Return the size in bytes // Input is in B, KB, MB, GB or TB $SIZE_LABEL=array("B"=>1, "KB"=>1024, "K"=>1024, "MB"=>pow(1024,2), "M"=>pow(1024,2), "GB"=>pow(1024,3), "G"=>pow(1024,3), "TB"=>pow(1024,4), "T"=>pow(1024,4)); if( preg_match("/^([0-9]+)\w*([BKMGT]+)$/", $size, $matches) ) { // Number and measure as input if( array_key_exists($matches[2], $SIZE_LABEL) ) { return $matches[1]*$SIZE_LABEL[ $matches[2] ]; }else { // Unknown measure return false; } }elseif( preg_match("/^([0-9]+$/", $size) ) { // Only numbers, return input return $size; }else { // Unknown return false; } } function admin_setaccess($access) { $_SESSION['sess_access'] = $access; switch( $access ) { case "admin": $_SESSION['access_admin'] = true; $_SESSION['access_chair'] = true; $_SESSION['access_localorg'] = true; $_SESSION['access_jc'] = true; $_SESSION['access_edit'] = true; $_SESSION['access_view'] = true; break; case "chair": $_SESSION['access_chair'] = true; $_SESSION['access_edit'] = true; $_SESSION['access_view'] = true; break; case "localorg": $_SESSION['access_localorg'] = true; $_SESSION['access_edit'] = true; $_SESSION['access_view'] = true; break; case "jc": $_SESSION['access_jc'] = true; #$_SESSION['access_edit'] = true; $_SESSION['access_view'] = true; break; case "edit": $_SESSION['access_edit'] = true; $_SESSION['access_view'] = true; break; case "view": $_SESSION['access_view'] = true; break; } } ?>