Jump to content

Recommended Posts

The file works by including it to any page like header, footer etc and when activated it redirects to a offline template so I can do maintenance etc. I want to integrate it into my CMS but the file has its own login section and I want to remove the login section of the code and also remove the success part of the code. Basically I just want to have the section where I can activate and deactivate the site. I have tired with no success all i get is a blank page no errors. I would appreciate any help.

<?php 
if (!isset($_SESSION)){session_start();}
$page_offline 			= TRUE;
$page_offline_title 	= "Coming Soon | Under Construction";
$page_offline_message 	= "There are some problems with our server. Nothing too serious, but it causes some downtime.";
$admin_ip				= "IP address";
$page_offline_message 	= "There are some problems with our server. Nothing too serious, but it causes some downtime.";
$page_offline_template 	= "templates/example1/index.html";
$page_offline_foradmin	= TRUE;

$admin_password		= "431301000c51954230c969f2e04c3add";
$page_offline_template 	= "templates/example1/index.html";

$page_offline_foradmin	= TRUE;

error_reporting(E_ALL);
$page = strstr($_SERVER['PHP_SELF'], "offline.php") ? "admin" : "website";

get_template_list();

// Try login
$login_error = FALSE;
if(isset($_POST['txtpassword'])){
if(md5($_POST['txtpassword']) == $admin_password){
	$_SESSION['offline_admin'] = TRUE;
}else{
	$login_error = TRUE;
}
}

// Save config settings
$offline 		= $page_offline ? 'checked="checked"' : "";
$title 			= $page_offline_title;
$message 		= $page_offline_message;
$saved 			= FALSE;
$template		= $page_offline_template;
$adminoffline 	= $page_offline_foradmin ? 'checked="checked"' : "";

if(isset($_POST['btnsave']) && $_SESSION['offline_admin']){
$val_offline 	= isset($_POST['chkoffline']) && ($_POST['chkoffline'] == "true") ? TRUE : FALSE;
$val_title 		= htmlspecialchars($_POST['txttitle']);
$val_message 	= htmlspecialchars($_POST['txtmessage']);
$val_template 	= htmlspecialchars($_POST['txttemplate']);
$val_password 	= htmlspecialchars($_POST['txtpassword']);
$val_adminoffline 	= isset($_POST['chkconstruct']) && ($_POST['chkconstruct'] == "true") ? TRUE : FALSE;

$offline 		= $val_offline ? 'checked="checked"' : "";
$title 			= $val_title;
$message 		= $val_message;
$template		= $val_template;
$adminoffline 	= $val_adminoffline ? 'checked="checked"' : "";

if(empty($val_password)){
	page_offline_save($val_offline, $val_title, $val_message, $val_template, $adminoffline);
}else{
	page_offline_save($val_offline, $val_title, $val_message, $val_template, $adminoffline, $val_password);
}

$saved = TRUE;
}

// Templates
$admin_style_tpl = <<<ADMINSTYLETPL
body{
font-family:Arial, Helvetica, sans-serif;
font-size:11px; 
text-align: center;
background-color:#F9F9F9;
color:#555555;
}
#wrapper{
width:400px;
padding:20px;
margin: 0 auto;
border:1px solid #DADADA;
background-color: #FFF;
text-align: left;
}
h2{
margin: 0px 0px 10px 0px;
padding: 0px;
font-size: 24px;
color:#464646;
font-family:Georgia,"Times New Roman",Times,serif;
font-style: italic;
font-weight: normal;
}
label{
display: block;
width: 150px;
font-weight: bold;
padding: 14px 0px 3px 0px;
}
input{
-moz-border-radius-bottomleft:3px;
-moz-border-radius-bottomright:3px;
-moz-border-radius-topleft:3px;
-moz-border-radius-topright:3px;
width: 300px;
background:#F5F5F5 none repeat scroll 0 0;
border:1px solid #CCCCCC;
color:#666666;
padding: 4px 8px;
}	
#chkoffline, #chkconstruct{
width: 20px;
}
.error{
border: solid 1px #CC0000;
}

ADMINSTYLETPL;

$admin_login_tpl = <<<ADMINLOGINTEMPLATE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebConstruct Login</title>
<style>
%s
</style>
</head>

<body>
<div id="wrapper">
<h2>WebConstruct Login</h2>
<form id="form1" name="form1" method="post" action="">
	<label for="txtpassword">Password</label>
  		<input type="password" name="txtpassword" %s id="txtpassword" /><br /><br />
  		<input name="btnlogin" type="submit" value="Login" />
   </form>
</div>
</body>
</html>

ADMINLOGINTEMPLATE;

$admin_config_tpl = <<<ADMINCONFIGTEMPLATE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebConstruct Admin</title>
<style>
%s
</style>
</head>

<body>
<div id="wrapper">
<h2>WebConstruct Admin</h2>
<form id="frmadmin" name="frmadmin" method="post" action="">
   		<label for="chkoffline">Offline</label>
   		<input name="chkoffline" id="chkoffline" %s type="checkbox" value="true" />
	<label for="chkconstruct">Show offline to admin</label>
   		<input name="chkconstruct" id="chkconstruct" %s type="checkbox" value="true" />
	<label for="txttitle">Title</label>
  		<input type="text" name="txttitle" value="%s" id="txttitle" />
        <label for="txtmessage">Message</label>
  		<input type="text" name="txtmessage" value="%s" id="txtmessage" />
	<label for="txttemplate">Template</label>
  		%s
        <label for="txtpassword">Admin password</label>
  		<input type="password" name="txtpassword" id="txtpassword" />
  		<br /> Leave this field empty if you don't want to change the admin password.
	<br /><br />
  		<input name="btnsave" type="submit" value="Save" />
   </form>
</div>
</body>
</html>

ADMINCONFIGTEMPLATE;

$admin_saved_tpl = <<<ADMINSAVEDTEMPLATE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Offline Admin</title>
<style>
%s
</style>
</head>

<body>
<div id="wrapper">
<h2>Configuration saved</h2>
The configuration is saved succesfully. You can continue to <a href="offline.php">config</a> or go to your <a href="index.php">website</a>.
</div>
</body>
</html>

ADMINSAVEDTEMPLATE;

if($page == "admin"){

// If user not is loggedin then show login screen
if(!isset($_SESSION['offline_admin']) || !$_SESSION['offline_admin']){
	echo sprintf($admin_login_tpl, $admin_style_tpl, ($login_error) ? 'class="error"' : '');
}else{
	if(!$saved){
		echo sprintf($admin_config_tpl, $admin_style_tpl, $offline, $adminoffline, $title, $message, html_select('txttemplate', 'txttemplate', $template, get_template_list()));
	}else{
		echo sprintf($admin_saved_tpl, $admin_style_tpl);
	}
}
exit();

}else{

if($page_offline && (($_SERVER['REMOTE_ADDR'] != $admin_ip) || $page_offline_foradmin)){

	ob_start();
	include($page_offline_template);
	$template = ob_get_contents();
	ob_end_clean();

	// Replace variables
	$template = str_replace(array("{TITLE}", "{MESSAGE}"), array($page_offline_title, $page_offline_message), $template);

	// Show template
	echo $template;
	exit();
}

}

// Write settings to file
function page_offline_save($offline, $title, $message, $template, $adminoffline, $password=""){
$lines = explode("\n", file_get_contents("offline.php"));

// Set configuration
$offline_state = ($offline) ? "TRUE" : "FALSE";
$lines[2] = '$page_offline 			= ' . $offline_state . ';';
$lines[3] = '$page_offline_title 	= "' . $title . '";';
$lines[4] = '$page_offline_message 	= "' . $message . '";';
$lines[5] = '$admin_ip				= "' . $_SERVER['REMOTE_ADDR'] . '";';
$lines[7] = '$page_offline_template 	= "' . $template . '";';
$adminoffline_state = ($adminoffline) ? "TRUE" : "FALSE";
$lines[8] = '$page_offline_foradmin	= ' . $adminoffline_state . ';';
if(!empty($password)){
	$lines[6] = '$admin_password		= "' . md5($password) . '";';
}

// Save to file
file_put_contents("offline.php", implode("\n", $lines));
}

// Make list of templates
function get_template_list(){
$templates = array();
if ($handle = opendir(dirname(__FILE__) . '/templates/')) {
	while (false !== ($file = readdir($handle))) {
		if($file != '.' && $file != '..' && !strstr($file, '.')){
			$templates['templates/' . $file . '/index.html'] = ucfirst($file);
		}
	}
}
return $templates;
}

/**
* Generate select element
* 
* @param string $id
* @param string $name
* @param string $selected
* @param array $values
* @param array $extra
* @return string
*/
function html_select($id, $name, $selected, $values){
$options = '';
foreach($values as $key => $value){
	$selected_string = ($selected == $value) || ($selected == $key) ? 'selected="selected"' : '';
	$options .= sprintf('<option value="%s" %s>%s</option>', $key, $selected_string, $value);
}		
return sprintf('<select id="%s" name="%s">%s</select>', $id, $name, $options);
}


Link to comment
https://forums.phpfreaks.com/topic/235045-please-help-with-code/
Share on other sites

Have you got display_errors on?  http://www.digitalamit.com/kb/kb/5.html

 

Yes I have that on. Its when i try to remove the portion of code that contains the login and success section thats when i get a blank page. I know i am doing something wrong but can not figure it out. I made some changes before to it and received errors and corrected my mistakes but removing large portions of the code is whats getting me. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.