Public feed
#599411
<?php/** #################################################################### # Kristall Panel Core Class # Handles _most_ of this basics. # Getting browser info and general information etc. # Date Started: 30th April 2007 - 19:14 GMT #################################################################### # @package Default # @copyright Kristall Services, Org. # @author Enumeric # @version 1.0.0 ####################################################################**//** * Unfreeze / initialise sessions ready for use. **/if( !defined( "KP_Core" ) ){ exit; // Exit, give them no reason, should throw them off a bit.}session_start();include("class_config.php");include("class_clean.php");include("class_bbcode.php");$config = new main_config;$config->initialise();/** * This will put the get_opts script into debug mode * instead of returning the sql, it will exit with the result * to enable you to fix a problem, should it arise, with relative ease. * LEAVE THIS ALONE UNLESS YOU KNOW HOW TO DEBUG PHP AND MySQL * * Case insensitive too for future reference. **/define( "EXITSQL", 0, true );class panel_core{ /** * Set core variables **/ // Gets information from the database and sets options function get_opts( $option ) { // Make the $option variable lowercase to stop "BBCode" or "OnOff" (for example) being ignored. $option = strtolower( $option ); // Get needed settings from database (Which just so happens to be.. wait for it... all of them :D) $getsettings = @mysql_fetch_array( mysql_query( "SELECT * FROM `" . TABLEPREFIX . "settings`" ) ) or $this->log( "MySQL Error", mysql_error( ), 1 ); // Put the settings into a big ol' array $settings = array( "bbcode" => $getsettings["bbcode"], // Should return integer "emoticons" => $getsettings["emotes"], // Should return integer "onoff" => $getsettings["onoff"], // Should return integer "filter" => $getsettings["filter"], // Should return integer "sitename" => $getsettings["sitename"], // Should return string "siteurl" => $getsettings["siteurl"], // Should return string "welcome" => $getsettings["welcome"], // Should return string "clean" => $getsettings["clean"], // Should return integer "css" => $getsettings["css_tag"] ); // Gotta make sure what we're after is a valid setting... if( $settings["$option"] != "" ) { if( EXITSQL == 1 ) // Looks like we're debugging { $exit = gettype( $settings["$option"] ); exit( "MySQL Returned type $exit.<br />result: {$settings["$option"]}" ); // Exit with the type returned from sql (Like boolean etc etc) and show them it with the result! } else // Ah, glorious non-debugging-action-which-is-taking-up-this-comment-space. { return $settings["$option"]; // Just return the sql result and let it get on with whatever. } } else // Not a valid setting, that makes me & the script :( { return false; // Return false and let's get out of here. } } /** * Tag cleaning decider function * * Decides what functions to call (What level of cleaning) * for cleaning string passed into it, then cleans it. **/ function clean( $string, $forcelevel = null, $sql = null ) { if( $forcelevel != null ) { $getlevel = $forcelevel; } else { $getlevel = $this->get_opts( "clean" ); } switch( $getlevel ) { default: $string = panel_clean::max_clean( $string ); case 4: // Panicking $string = panel_clean::max_clean( $string ); // Welcome back $string, we missed you! break; // No need to carry on from here, it's instantly protected beyond any "hackers" playing around. case 3: // Nervous $string = panel_clean::med_clean( $string ); $string = panel_clean::base_clean( $string ); $string = panel_clean::core_clean( $string ); $donl2br = 0; break; case 2: // Cool, calm and default $string = panel_clean::base_clean( $string ); $string = panel_clean::core_clean( $string ); break; case 1: // Why panic when you have KOOL-AIDS (lol aids) $string = panel_clean::core_clean( $string ); break; } if( $this->get_opts( "bbcode" ) == 1 ) // Are we parsing bbcode? { // We are, but we need to parse it _last_ to make sure the parsed code isn't cleaned! $string = panel_bbcode::parse_main_bb( $string, $this->get_opts( "emoticons" ) ); } return $string; // Give em it back :( } /** * Ok, lets get on with getting basic user info. **/ function get_info( $requested ) { // Convert to lowercase to stop case insensitive problems. $requested = strtolower( $requested ); $available = array( "username" => $_SESSION["p_username"], "level" => $_SESSION["p_level"], "auth" => $_SESSION["p_randauth"], "passhash" => $_SESSION["p_hash"], "ip" => $_SESSION["p_ip"], // Lol pips "lusername" => $_SESSION["p_lusername"] ); if( $available["$requested"] != "" ) // It's in there, give them the stuff they asked for. { return $available["$requested"]; } else { // Eh, after something that's not there :( return "Not Available."; } } function check_user( $username ) { if( $username == "" ) { return false; } // Simple function to get user information dependant on if the password is supplied or not. // Looks like we're checking info based on just the username (Probably an auth check in the panel) $username = strtolower( $this->clean( $username ) ); // Clean up the username. $sql = @mysql_query( "SELECT * FROM `" . TABLEPREFIX . "users` WHERE `lusername` = '$username'" ) or $this->log( "MySQL Error", mysql_error( ), 1 ); if( @mysql_num_rows( $sql ) == 0 ) { return false; } else { $fetch = @mysql_fetch_array( $sql ) or $this->log( "MySQL Error", mysql_error( ), 1 ); $storedinfo = array( "password" => $this->get_info( "passhash" ), "randauth" => $this->get_info( "auth" ), "getuseip" => $this->get_info( "ip" ), "gtuselvl" => $this->get_info( "level" ) ); if( $storedinfo["password"] != md5( $fetch["password"] ) /*|| $storedinfo["randauth"] != $fetch["randauth"]*/ || $storedinfo["getuseip"] != $_SERVER["REMOTE_ADDR"] || $storedinfo["gtuselvl"] != $fetch["level"] ) { return false; // Ha, not giving the right stuff eh? Better kick em out! } else { return true; } } } function notice( $header, $message, $url ) // Standard notice, don't need to touch this. { @header("Refresh: 9;url=".$url); echo("<html><head><title>" . $this->phrase( $header ) . "</title></head><style type=\"text/css\">body{ text-align: center; width: 100%; margin: 0px; background: #ffffff;}div, a, a:link, a:active{ font-family: verdana; font-size: 10px; color: #000000; text-decoration: none;}a:hover{ font-weight: bold;}.wrapper{ margin-top: 150px; width: 371px; margin-left: auto; margin-right: auto;}.construct{ text-align: left; width: 371px; position: relative; margin-left: auto; margin-right: auto;}.header, .message, .topheader{ background: #f0f5fa; padding: 2px;}.header{ border: 1px solid #c2cfdf;}.topheader{ text-align: center; border: 1px solid #c2cfdf;}.message{ color: #000000; border-left: 2px solid #c2cfdf; border-right: 1px solid #c2cfdf;}.upper{ text-transform: uppercase;}</style><body><div class=\"wrapper\"><div class=\"construct\"><div class=\"topheader\"><strong class=\"upper\">" . $this->phrase( $header ) . "</strong></div><div class=\"message\">" . $this->phrase( $message ) . "</div><div class=\"header\">" . $this->phrase( "redirect" ) . " Click <a href=\"$url\">here</a> to go immediatley.</div></div></div></body></html>"); exit; } function phrase( $phrase ) { $phrase = $this->clean( $phrase ); $sql = @mysql_query( "SELECT * FROM `" . TABLEPREFIX . "phrases` WHERE `phrasename` = '$phrase'" ); // SQL to get the query from the database... if( mysql_num_rows( $sql ) == 0 ) { return "Phrase not available."; } else { $sql = mysql_fetch_array( $sql ); } $replaceable = array( "/{website}/i" , "/{username}/i", "/{date}/i", "/{level}/i", "/{ip}/i"); $replacewith = array( $this->get_opts( "sitename" ), $this->get_info( "username" ), gmdate( "d/m/Y - h:i:s" ), $this->get_info( "level" ), $this->get_info( "ip" ), ); $getit = $sql["phrase"]; $replaceit = preg_replace( $replaceable, $replacewith, $getit ); $replaceit = str_replace( "[apos]", "'", $replaceit ); return $replaceit; } function encrypt( $string ) // Let's begin encryption. { $holda = $string; $holdb = $string; $holdc = $holda . $holdb; $holdc = sha1( md5 ( $holdc ) ); $holdc = strrev( $holdc ); $holdb = strlen( $string ); $holdb = md5( $holdb . $holdc . $holda ); $holdd = strtoupper( $string ); $holdd = sha1( $holdd ); $holda = crc32( $holda ); $holde = md5( $holda . $holdb . $holdc . $holdd ); $holda = crypt( $holde, $holda ); return $holda; } /** * Time to begin action logging. */ function log( $username, $did, $force = null ) { if( main_config::config_setting( "use_http_logs" ) == "1" || $force == 1 ) { // Begin http logging echo("<html><head><title>Error Logging.</title></head><style type=\"text/css\">body{ text-align: center; width: 100%; margin: 0px; background: #ffffff;}div, a, a:link, a:active{ font-family: verdana; font-size: 10px; color: #000000; text-decoration: none;}a:hover{ font-weight: bold;}.wrapper{ margin-top: 150px; width: 371px; margin-left: auto; margin-right: auto;}.construct{ text-align: left; width: 371px; position: relative; margin-left: auto; margin-right: auto;}.header, .message, .topheader{ background: #f0f5fa; padding: 2px;}.header{ border: 1px solid #c2cfdf; text-align: center;}.topheader{ text-align: center; border: 1px solid #c2cfdf;}.message{ color: #000000; border-left: 1px solid #c2cfdf; border-right: 1px solid #c2cfdf;}.upper{ text-transform: uppercase;}</style><body><div class=\"wrapper\"><div class=\"construct\"><div class=\"topheader\"><strong class=\"upper\">Error Logging</strong></div><div class=\"message\">Please wait, we're now doing a few checks to make sure you have the log file ready."); ######### $date = gmdate("d/m/Y - h:i:s") . "GMT"; if( file_exists( "http_error/error.log" ) ) { // Looks like we're gonna be writing to an already active log file. echo("<br />--| File exists, opening now."); $fopen = @fopen( "http_error/error.log", "at" ); if( $fopen ) { echo("<br />---| File opened, writing error."); @fwrite( $fopen, "\n$username ({$_SERVER["REMOTE_ADDR"]}) - [ $date ] => $did" ); echo("<br />----| Error logged, you may now navigate away."); @fclose( $fopen ); } } else { echo("<br />--| File does not exist, attempting to create and open for writing."); $fopen = @fopen( "http_error/error.log", "x+t" ); if( $fopen ) { echo("<br />---| File created and opened, writing error."); @fwrite( $fopen, "Kristall Panel ERROR LOGS\n$username ({$_SERVER["REMOTE_ADDR"]}) - [ $date ] => $did" ); echo("<br />----| Error logged, you may now navigate away."); @fclose( $fopen ); } else { echo("<br />---| Please follow these steps, then refresh this page: <br />----| 1) Create a file named \"error.log\" in the \"http_error\" directory <br />----| 2) CHMOD the file \"error.log\" to \"0666\" (or just 666) <br />----| 3) Refresh this page."); } } #########echo("</div><div class=\"header\">Powered by Kristall Panel</div></div></div></body></html>"); exit; } else { $date = gmdate( "d/m/Y - h:i:s" ); @mysql_query( "INSERT INTO `" . TABLEPREFIX . "log` (`username`, `did`, `date`, `ip`) VALUES ('$username', '$did', '$date', '{$_SERVER["REMOTE_ADDR"]}')" ) or $this->log( "MySQL Error", mysql_error( ), 1 ); } } function nav( $level = null ) { if( $level == "normal" ) { $_SESSION["nav"] = "normal"; } elseif( $level == "admin" && $this->get_info( "level" ) == "Administrator" || $level == "admin" && $this->get_info( "level" ) == "Super Administrator") { $_SESSION["nav"] = "admin"; } else { $_SESSION["nav"] = "normal"; } } function get_nav() { if( $_SESSION["nav"] == "admin" ) { echo("<div class=\"selectmenuleft\"><a href=\"?nav=normal\">Main Links</a></div> <div class=\"selectmenurightg\"><a href=\"?nav=admin\">Admin Links</a></div>"); } else { echo("<div class=\"selectmenuleftg\"><a href=\"?nav=normal\">Main Links</a></div> <div class=\"selectmenuright\"><a href=\"?nav=admin\">Admin Links</a></div>"); } } function get_content( $page = null ) { if( $page == "" ) { include( "pages/welcome.php" ); } else { $page = $this->clean( $page, 2 ); if( file_exists( "pages/$page.php" ) ) { include( "pages/$page.php" ); } else { $this->log( $this->get_info( "username" ), "attempted to access a faulty page, the page was ( $page.php )" ); include( "404.php" ); } } } function meta_redirect( $url, $time ) { $url = $this->clean( $url ); echo( "<meta http-equiv=\"refresh\" content=\"$time;url=main.php$url\">" ); } function gmt_curtime() // Because php time is shit and wont record DST { $checkdst = date( "I" ); $date = gmdate( "H:i:s" ); if( $checkdst == 1 ) { $splittime = split( ":", $date ); $hour = $splittime[0] + 1; if($hour > 23) // Are we at 11pm (E.g, is it reporting 24:00 instead of 23:00) { $hour = "00"; } $newdate = $hour . ":" . $splittime[1] . ":" . $splittime[2]; return( "$newdate" ); } else { return( "$date" ); } } function is_admin( $for = null ) // Specific page admins :P { $for = $this->clean( $for ); // Clean it up (do in mr bean voice, funny). $for = strtolower( $for ); // Case faggotry. if( $for == "timetable" ) { $levels = array( "Super Administrator" => "yes", "Administrator" => "yes", "Head DJ" => "yes", "Senior DJ" => "no", "DJ" => "no", ); if( $levels[$this->get_info( "level" )] == "yes" ) { return true; } else { return false; } } }}?>