updating configuration file in browser
updating configuration file in browser
filename:setup.php
<?php
// USAGE: http://setup.php?strCfgFile=FILE_TO_EDIT
// Example: http://setup.php?strCfgFile=sample.inc.php
*/
$strCfgFile = $_REQUEST['strCfgFile'];
if(!ISSET($strCfgFile)) {
echo 'You did not specify any file to edit.<br>';
echo 'Please call this page like setup.php?strCfgFile=YOUR_FILE';
exit();
}
function ReplaceConfValue($strCfgFile,$strCfgVar,$strCfgVal)
{
$strOldContent = file ($strCfgFile);
$strNewContent = "";
while (list ($intLineNum, $strLine) = each ($strOldContent))
{
if(eregi("^\\$".$strCfgVar."( |\t)*=",$strLine)) // show any line beginning with a $
{
$strLineParts=explode("=",$strLine);
// we should determine type of value here! (BOOL, INT or String)
if("$".$strCfgVar == trim($strLineParts[0]))
{
$strLineParts[1] = "\t\"".$strCfgVal."\"";
$strLine = implode("=",$strLineParts).";\r\n";
}
}
$strNewContent .= $strLine;
$fp = fopen($strCfgFile."_new", "w");
fputs($fp,$strNewContent);
fclose($fp);
}
echo "<center><pre>The value for <b>$$strCfgVar</b> has been replaced with <b>$strCfgVal</b> in File <b>$strCfgFile</b></pre></center>";
if(!rename($strCfgFile,$strCfgFile.".bak")) echo "<pre><b>Error: Could not rename old file!</b></pre>";
if(!rename($strCfgFile."_new",$strCfgFile)) echo "<pre><b>Failed to copy File!</b></pre>";
}
//=================== Begin OUTPUT ===========================?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Setupscript</title></head>
<body>
<script language="JavaScript">
<!--
function GetVarValue(field){
selected=false;
for (Count = 0; Count < document.selectform.strCfgVar.length; Count++){
if(document.selectform.strCfgVar[Count].selected){
selected=true;
var string = document.selectform.strCfgVar[Count].value;
var stringArray = string.split("-/-");
strCfgVarValue = stringArray[1];
strCfgCommentValue = stringArray[2];
}
}
if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)){
document.selectform.currVal.style.backgroundColor="yellow";
}
document.selectform.currVal.value=strCfgVarValue;
document.selectform.strCfgValNew.value=strCfgVarValue;
document.selectform.comment.value=strCfgCommentValue;
document.selectform.strCfgValNew.focus();
return true;
}
//-->
</script>
<table width="100%" heigth="100%" border="0">
<tr>
<td>
<table align="center" cellpadding="3" cellspacing="3" border="0">
<tr>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" size="20" value="<? echo $strCfgFile ?>">
<td>
Variable:
</td>
<td>
<select name="strCfgVar" onChange="GetVarValue(this)">
<option value=""></option>
<?php
include($strCfgFile);
$strContent = file ($strCfgFile);
while (list ($intLineNum, $strLine) = each ($strContent)){
if(eregi("^\\$",$strLine)){ // show any line beginning with a $
$strLineParts=explode("=",$strLine);
$var = ereg_replace("[$\t ]","",($strLineParts[0]));
$val = ereg_replace("//.*","",trim($strLineParts[1]));
$comment = str_replace($val,"",$strLineParts[1]);
$comment = ereg_replace("[$/]","",trim($comment));
if(!eregi("\[",$var)){
echo '<option value="'.$var.'-/-'.$$var.'-/-'.$comment.'">'.$var.'</option>';
}
}
}
?>
</select>
</td>
<td>
Current Value: <input type="text" name="currVal" size="30">
</td>
<td>
New Value: <input type="text" name="strCfgValNew" size="20">
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="Submit Changes" name="DoChange">
</td>
</tr>
<tr>
<td colspan="4" align="right">
Note: <textarea cols="50" rows="5" wrap="hard" name="comment" onBlur="return false;"></textarea>
</td>
</tr>
</table>
</td>
</tr>
<?php if($DoChanges){
$strCfgVars=split("-/-",$strCfgVar);
ReplaceConfValue($strCfgFile,$strCfgVars[0],$strCfgValNew);
?>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" value="<? echo $strCfgFile ?>">
<input type="submit" name="done" value="More changes..">
</form>
<?php } ?>
</table>
</body>
</html>
filename: sample.conf.php
<?php
// sample configuration file for testing setup.php
$cfgDbHost = "localhost"; //Name of DB-Server
$cfgDbUser = "root"; //Name of DB User
$cfgDbPass = ""; //Password for DB Admin
$cfgDatabase = "Database"; //Name of database for this app
$cfgDbCreated = 0; //Time, the database has been created, (0) if not yet
$cfgDatabaseUser = "Database1"; //name of database, which contains usertable, if necessary
$cfgAppTable = "guestbook"; //name of this app
$cfgDomainName = "my-domain.com"; //name of domain, this app is installed
$cfgAdminUser = "admin"; //name of masteradmin
$cfgAdminPassword = "password"; //password for masteradmin
$cfgEnableUpload = 1; // specifies, whether uploads are allowed or not (1=allowed,0=not allowed)
$test = "vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file ";
?>
<?php
// USAGE: http://setup.php?strCfgFile=FILE_TO_EDIT
// Example: http://setup.php?strCfgFile=sample.inc.php
*/
$strCfgFile = $_REQUEST['strCfgFile'];
if(!ISSET($strCfgFile)) {
echo 'You did not specify any file to edit.<br>';
echo 'Please call this page like setup.php?strCfgFile=YOUR_FILE';
exit();
}
function ReplaceConfValue($strCfgFile,$strCfgVar,$strCfgVal)
{
$strOldContent = file ($strCfgFile);
$strNewContent = "";
while (list ($intLineNum, $strLine) = each ($strOldContent))
{
if(eregi("^\\$".$strCfgVar."( |\t)*=",$strLine)) // show any line beginning with a $
{
$strLineParts=explode("=",$strLine);
// we should determine type of value here! (BOOL, INT or String)
if("$".$strCfgVar == trim($strLineParts[0]))
{
$strLineParts[1] = "\t\"".$strCfgVal."\"";
$strLine = implode("=",$strLineParts).";\r\n";
}
}
$strNewContent .= $strLine;
$fp = fopen($strCfgFile."_new", "w");
fputs($fp,$strNewContent);
fclose($fp);
}
echo "<center><pre>The value for <b>$$strCfgVar</b> has been replaced with <b>$strCfgVal</b> in File <b>$strCfgFile</b></pre></center>";
if(!rename($strCfgFile,$strCfgFile.".bak")) echo "<pre><b>Error: Could not rename old file!</b></pre>";
if(!rename($strCfgFile."_new",$strCfgFile)) echo "<pre><b>Failed to copy File!</b></pre>";
}
//=================== Begin OUTPUT ===========================?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Setupscript</title></head>
<body>
<script language="JavaScript">
<!--
function GetVarValue(field){
selected=false;
for (Count = 0; Count < document.selectform.strCfgVar.length; Count++){
if(document.selectform.strCfgVar[Count].selected){
selected=true;
var string = document.selectform.strCfgVar[Count].value;
var stringArray = string.split("-/-");
strCfgVarValue = stringArray[1];
strCfgCommentValue = stringArray[2];
}
}
if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)){
document.selectform.currVal.style.backgroundColor="yellow";
}
document.selectform.currVal.value=strCfgVarValue;
document.selectform.strCfgValNew.value=strCfgVarValue;
document.selectform.comment.value=strCfgCommentValue;
document.selectform.strCfgValNew.focus();
return true;
}
//-->
</script>
<table width="100%" heigth="100%" border="0">
<tr>
<td>
<table align="center" cellpadding="3" cellspacing="3" border="0">
<tr>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" size="20" value="<? echo $strCfgFile ?>">
<td>
Variable:
</td>
<td>
<select name="strCfgVar" onChange="GetVarValue(this)">
<option value=""></option>
<?php
include($strCfgFile);
$strContent = file ($strCfgFile);
while (list ($intLineNum, $strLine) = each ($strContent)){
if(eregi("^\\$",$strLine)){ // show any line beginning with a $
$strLineParts=explode("=",$strLine);
$var = ereg_replace("[$\t ]","",($strLineParts[0]));
$val = ereg_replace("//.*","",trim($strLineParts[1]));
$comment = str_replace($val,"",$strLineParts[1]);
$comment = ereg_replace("[$/]","",trim($comment));
if(!eregi("\[",$var)){
echo '<option value="'.$var.'-/-'.$$var.'-/-'.$comment.'">'.$var.'</option>';
}
}
}
?>
</select>
</td>
<td>
Current Value: <input type="text" name="currVal" size="30">
</td>
<td>
New Value: <input type="text" name="strCfgValNew" size="20">
</td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="Submit Changes" name="DoChange">
</td>
</tr>
<tr>
<td colspan="4" align="right">
Note: <textarea cols="50" rows="5" wrap="hard" name="comment" onBlur="return false;"></textarea>
</td>
</tr>
</table>
</td>
</tr>
<?php if($DoChanges){
$strCfgVars=split("-/-",$strCfgVar);
ReplaceConfValue($strCfgFile,$strCfgVars[0],$strCfgValNew);
?>
<form method="POST" name="selectform" action="<? echo $PHP_SELF ?>">
<input type="hidden" name="strCfgFile" value="<? echo $strCfgFile ?>">
<input type="submit" name="done" value="More changes..">
</form>
<?php } ?>
</table>
</body>
</html>
filename: sample.conf.php
<?php
// sample configuration file for testing setup.php
$cfgDbHost = "localhost"; //Name of DB-Server
$cfgDbUser = "root"; //Name of DB User
$cfgDbPass = ""; //Password for DB Admin
$cfgDatabase = "Database"; //Name of database for this app
$cfgDbCreated = 0; //Time, the database has been created, (0) if not yet
$cfgDatabaseUser = "Database1"; //name of database, which contains usertable, if necessary
$cfgAppTable = "guestbook"; //name of this app
$cfgDomainName = "my-domain.com"; //name of domain, this app is installed
$cfgAdminUser = "admin"; //name of masteradmin
$cfgAdminPassword = "password"; //password for masteradmin
$cfgEnableUpload = 1; // specifies, whether uploads are allowed or not (1=allowed,0=not allowed)
$test = "vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file vinod testing the file ";
?>
Similar topics
» Create simple cross-browser textarea editor
» Php file upload
» Function to validate file extension ( PHP )
» Set file upload limit size
» Check if a file exists on a remote FTP server with PHP
» Php file upload
» Function to validate file extension ( PHP )
» Set file upload limit size
» Check if a file exists on a remote FTP server with PHP
Permissions in this forum:
You cannot reply to topics in this forum
Fri Jul 22, 2011 1:37 pm by shyamsunder
» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12
» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202
» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar
» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar
» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar
» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar
» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar
» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar