| <?php |
| |
| class sec { |
| |
| var $username; |
| var $password; |
| //var $theme; |
| //var $level; |
| var $site_name="Your site name"; |
| var $admin_email="you@yourdomain.TLD"; |
| |
| function sec() |
| { |
| $this->check_login_cookie(); |
| $this->username=$_SESSION['user']; |
| $this->password=$_SESSION['pass']; |
| //$this->theme=$_SESSION['theme']; |
| //$this->level=$_SESSION['level']; |
| } |
| |
| function level_check($level) |
| { |
| if (!empty($level)) { |
| if ($level > 0) { |
| return true; |
| } else { |
| return false; |
| } |
| } else { |
| return false; |
| } |
| } |
| |
| //Will take some salt and pepper and work it's magic |
| //$pepper [string] - Password |
| //$salt [string] - Password salt |
| function saltnpepper($pepper, $salt=null) |
| { |
| $pepper =strrev(trim($pepper)); |
| $salt = md5(trim($salt)); |
| $pepper1 = md5(str_rot13($pepper) . $salt); |
| $pepper2 = md5("c7fdac2" . $pepper1 . "435df142as3"); |
| $hash = sha1("adf443fa812a" . $pepper2 . "a935ad2efa1" . $salt); |
| return $hash; |
| } |
| |
| //Will return true or false depending on weather a client is running through a proxy |
| function detectProxy(&$ar) |
| { |
| $gotcha = false; |
| |
| if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) || |
| array_key_exists('HTTP_PROXY_CONNECTION', $_SERVER) || |
| array_key_exists('HTTP_VIA', $_SERVER)) { |
| $gotcha = true; |
| } |
| |
| $gotcha = (stristr($_SERVER['REMOTE_HOST'], "proxy") !== false) ? true : $gotcha ; |
| |
| if ($gotcha) { |
| $ar['PORT'] = (array_key_exists('REMOTE_PORT', $_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown"); |
| $ar['HOST'] = (array_key_exists('REMOTE_HOST', $_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown"); |
| $ar['IP'] = (array_key_exists('REMOTE_ADDR', $_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown"); |
| $ar['FORWARDED_FOR'] = (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : "unknown"); |
| $ar['INFO'] = (array_key_exists('HTTP_VIA', $_SERVER) ? $_SERVER['HTTP_VIA'] : "unknown"); |
| } else { |
| $ar['PORT'] = (array_key_exists('REMOTE_PORT', $_SERVER) ? $_SERVER['REMOTE_PORT'] : "unknown"); |
| $ar['HOST'] = (array_key_exists('REMOTE_HOST', $_SERVER) ? $_SERVER['REMOTE_HOST'] : "unknown"); |
| $ar['IP' ] = (array_key_exists('REMOTE_ADDR', $_SERVER) ? $_SERVER['REMOTE_ADDR'] : "unknown"); |
| } |
| |
| return $gotcha; |
| } |
| |
| |
| //Pass one of the 'lengths' in the swith through here, and if you use a salt pass the salt as well |
| function set_login_cookie($length, $salt=null) |
| { |
| switch ($length) { |
| case "minute": |
| $t = 60; |
| break; |
| |
| case "hour": |
| $t = 3600; |
| break; |
| |
| case "day": |
| $t = 86400; |
| break; |
| |
| case "week": |
| $t = 604800; |
| break; |
| |
| case "month": |
| $t = 2419200; |
| break; |
| |
| case "year": |
| $t = 29030400; |
| break; |
| |
| case "forever": |
| $t = 29001369600; |
| break; |
| |
| default: |
| $t = 86400; |
| break; |
| } |
| $user = $this->username; |
| $pass = $this->password; |
| $pass = md5($pass . $salt); |
| $theme = $this->theme; |
| $level = $this->level; |
| setcookie("user", $user, time() + $t, "/"); |
| setcookie("pass", $pass, time() + $t, "/"); |
| //setcookie("theme", $theme, time() + $t, "/"); |
| //setcookie("level", $level, time() + $t, "/"); |
| return true; |
| } |
| |
| |
| //Get the persons age |
| //Pass through the day, month and year of their birthday |
| function getage($day, $month, $year) |
| { |
| $cday = date("d"); |
| $cmon = date("m"); |
| $cyr = date("Y"); |
| $d = $day - $cday; |
| $m = $month - $cmon; |
| if ($m > 0) { // If it's not yet their b-month |
| $age = $cyr - $year; |
| return $age; |
| } else if ($month == $cmon || $month < $cmon) { // If it is their b-month |
| if ($d > 0) { // If it's not yet their b-day |
| $age = $cyr - $year; |
| return $age; |
| } else if ($day == $cday) { // if it's their bday |
| $yr = $cyr - $year; |
| $age = $yr + 1; |
| return $age; |
| } else { // It their b-day has passed |
| $yr = $cyr - $year; |
| $age = $yr; |
| return $age; |
| } |
| } else { // If their b-month has already passed |
| $yr = $cyr - $year; |
| $age = $yr + 1; |
| return $age; |
| } |
| } |
| /* |
| Generates and returns a random password |
| */ |
| function NewPass() |
| { |
| $pass = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789!@$%&()+"; |
| srand((double)microtime() * 1000000); |
| $i = 0; |
| while ($i <= 7) { |
| $num = rand() % 33; |
| $tmp = substr($pass, $num, 1); |
| $pass = $pass . $tmp; |
| $i++; |
| } |
| return $pass; |
| } |
| /* |
| Will determine if they entered a valid email address or not |
| */ |
| function ch_em($email) |
| { |
| if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) { |
| return true; |
| } else { |
| return false; |
| } |
| } |
| |
| // BELOW IS A LANGUAGE FILTER, YOU MAY CUSTOMIZE IT TO FIT YOUR NEEDS |
| //if you decide to use it change $on=0 to $on=1 |
| function langfilter($string, $on=0){ |
| if($on == 1){ |
| $query = "SELECT * FROM `settings`"; |
| $result = mysql_query($query)or die('Query Failed: ' . mysql_error()); |
| $row = mysql_fetch_array($result); |
| $words = $row['lang_words']; |
| if ($row['lang_filter'] == 1) { |
| $words = explode(",", $words); |
| foreach($words as $word) { |
| $string = ereg_replace($word, "[censored]", $string); |
| } |
| } |
| } |
| } |
| |
| /* |
| Prepare a string to return to browser |
| @author Sildaekar Decrura <immortal_suicide_333@hotmail.com> |
| @since 2007-07-26 |
| |
| @return string Returns converted string |
| */ |
| function ret($string) |
| { |
| $string = ereg_replace("<br>", "\n", $string); |
| $string = ereg_replace("<br />", "\n", $string); |
| $string = ereg_replace("<br/>", "\n", $string); |
| |
| $string=langfilter($string); |
| |
| return $string; |
| } |
| /* |
| Prepare a string to be added into the database |
| |
| Options: |
| $string [string] - the string you are passing |
| $h [1 or 0] - strip all html |
| $ht [1 or 0] - replace a line break with <br> |
| $escape [1 or 0] - add slashes to quotations and single quotes |
| */ |
| function prep($string, $h = 0, $ht = 1, $escape = 0) |
| { |
| $tags = array("<b>", "</b>", "<i>", "</i>", "<u>", "<style>", "</style>", "</u>", "<s>", "</s>", "<img"); //Allowed Tags |
| // $string = trim($string); |
| // $string = strip_tags($string, $tag); |
| $string = eregi_replace("<", "<", $string); |
| $string = eregi_replace("<", "<", $string); |
| $string = ereg_replace("<scr", "<sc", $string); |
| $string = ereg_replace("</scr", "</sc", $string); |
| $string = ereg_replace("<iframe", "<iframe", $string); |
| $string = ereg_replace("</iframe", "</iframe", $string); |
| $string = ereg_replace("<meta", "<meta", $string); |
| if ($escape == 1) { |
| $string = addslashes($string); |
| } |
| |
| if ($h == 1) { |
| $string = $this->ht_strip($string); |
| } else { |
| if ($ht == 1) { |
| $string = eregi_replace("\n", "<br>", $string); |
| } |
| } |
| $string=langfilter($string); |
| |
| return $string; |
| } |
| |
| //Strip a string of html characters |
| function ht_strip($string) |
| { |
| $string = htmlspecialchars($string); |
| $string = eregi_replace("\n", "<br>", $string); |
| return $string; |
| } |
| |
| |
| //Check for fake session name |
| //Check the session name against a pre-determined session stored in a database |
| function fake_sess_name($name) |
| { |
| $a = session_name(); |
| if ($a == $name) { |
| return true; |
| } else { |
| echo $a; |
| echo "<script language=\"javascript\"><!-- |
| location.replace(\"index.php\"); |
| --> |
| </script>"; |
| exit; |
| } |
| } |
| |
| /* |
| Create new pin number and store it in the database |
| //Needs to be edited to fit your needs before use! |
| */ |
| function getpin($user) |
| { |
| $query = "SELECT * FROM `users` WHERE `user`='$user'"; |
| $result = mysql_query($query)or die('a Query Failed: ' . mysql_error()); |
| $row = mysql_fetch_array($result); |
| $mail = $row['email']; |
| $pin1 = $user; |
| $pin2 = rand(2712934724, 94728365193); |
| if ($pin2 < 1) { |
| $pin2 = $pin2 * -1; |
| } |
| $pin = $pin1 . "-" . $pin2; |
| $todayis = date("l, F j, Y, g:i a") ; |
| $subject = "Please verify your identity."; |
| $message = " $todayis [EST] \n |
| From: " . SNAME . " \n |
| \n |
| Please verify your identification by entering the following PIN number into our system. |
| You will be unable to login until this pin is entered. |
| |
| $pin |
| \n\n |
| " . SURL . "/pinenter.php\n\n"; |
| // Additional headers |
| $headers .= 'From: ' . $this->site_name . ' <' . $this->admin_email . '>' . "\r\n"; |
| $headers .= 'Reply-To: ' . $this->admin_email . "\r\n"; |
| $headers .= 'X-Mailer: PHP/' . phpversion(); |
| |
| if (mail($mail, $subject, $message, $headers)) { |
| $query = "INSERT INTO `spins`(`user`,`pin`)VALUES('$user','$pin')"; |
| $result = mysql_query($query)or die('Query Failed: ' . mysql_error()); |
| return true; |
| } else { |
| return false; |
| exit(); |
| } |
| } |
| } |
| |
| ?> |