PHP Classes
Icontem

File: changeconfig.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Colin Sandy Pittendrigh  >  Site Bot  >  changeconfig.php  
File: changeconfig.php
Role: Auxiliary script
Content type: text/plain
Description: aux config file editor
Class: Site Bot
Recursive-automic site buider: static OR dynamic
 

Contents

Class file image Download
<?php

include "page_config.inc";

page_opener();
function 
setVal($key$default)
{
   global 
$_GET;
   global 
$_POST;
   
   if(isset(
$_POST[$key]))
   
$ret $_POST[$key];
   elseif(isset(
$_GET[$key]))
   
$ret $_GET[$key];
   else
   
$ret $default;
   return(
trim($ret));
}

function 
page_opener()
{
   global 
$sys_stylesheet;

        echo 
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">";
   echo 
"\n<html>";
   echo 
"\n<head>";
   echo 
"\n<title>Config File Editor</title>";
   echo 
"\n<link rel=\"stylesheet\" href=\"/ssite_bot/site_bot.css\" type=\"text/css\">";
   echo 
"\n</head>";
   echo 
"\n<body class=\"dispBkg\">";
        echo 
"\n<b>mkdir</b> /src/www/htdocs/site_bot &nbsp; &nbsp; (for instance)<br/>";
        echo 
"\n<b>cp</b> &nbsp; &nbsp; site_bot.tgz &nbsp; &nbsp; /src/www/htdocs/site_bot<br/>";
        echo 
"\n<b>cd</b> &nbsp; &nbsp; /src/www/htdocs/site_bot<br/>";
        echo 
"\n<b>tar -xvzf</b> &nbsp; &nbsp; site_bot.tgz <br/>";
        echo 
"\n<b>chmod 777</b> &nbsp; &nbsp; *inc<br/>";
        echo 
"\n<br/>";
        echo 
"\n<b>mkdir</b> /srv/www/htdocs/src/Pages &nbsp; &nbsp; (file src directory, for instance)<br/>";
        echo 
"\n<b>mkdir</b> /srv/www/htdocs/Pages &nbsp; &nbsp; (file output directory, for instance)<br/>";
        echo 
"\n<b>chmod -R 777</b> &nbsp; &nbsp; /srv/www/htdocs/src<br/>";
        echo 
"\n<b>chmod -R 777</b> &nbsp; &nbsp; /srv/www/htdocs/Pages<br/>";
        echo 
"\n<b>chmod 777</b> &nbsp; &nbsp; database_config.inc &nbsp; page_config.inc <br/>";
        echo 
"\n<b>cp</b> &nbsp; &nbsp; /tmp/*jpg /src/www/htdocs/src/Pages (copy some img's to src/Pages)<br/>";
        echo 
"\nedit these two config files: database_config.inc page_config.inc<br/>";
        echo 
"\nclick the admin link at page bottom<br/>";
        
}

function 
page_closer()
{
   echo 
"</body></html>\n";
}

function 
file_opener ($fp)
{
   
print_msg($fp'<?php');
}

function 
file_closer ($fp)
{
   
print_msg ($fp'?>');
   
fclose($fp);
}

function 
print_msg($fp$msg)
{
   
$msg trim($msg);
   
$msg $msg."\n";
   
fwrite ($fp$msg);
}

function 
print_pair($fp$label$value)
{
   
$label trim($label);
   
$value trim($value);
   
$line sprintf("\$%s='%s';\n"$label$value);
   
fwrite ($fp$line);
}

function 
cleanit ($msg)
{
   
$value trim ($msg);
   
$value ereg_replace (";"""$value);
   
$value ereg_replace ("'"""$value);
   
$value ereg_replace ('\$'""$value);
   return (
$value);
}

function 
getFirstConfig()
{
   
$ret "config.inc";
   
$dp opendir(".");
   while (
$FILE readdir($dp))
   {
      if(
strstr($FILE"_config"))
      {
         
$ret=basename($FILE);
         
//break;
      
}
   }
   return(
$ret);
}

function 
mkFileSelecter($name$file_widget)
{
   
$dp opendir(".");
   
   while (
$FILE readdir($dp))
   {
      if(
strstr($FILE"_config") && strstr($FILE"inc"))
      
$configs[]=$FILE;
   }
   
$str "<select name=\"$name\" onchange=\"document.forms[0].submit();\">";

   if(isset(
$file_widget))
   
$str .= " <option> $file_widget ";
   if(
$configs)
   while(list(
$dc,$file)=each($configs))
   {
      if(
$file && $file != $file_widget)
      
$str .= " <option> $file ";
   }
   
$str .= "</select>";
   return(
$str);
}

/*
** note: setVal returns the label's value from $_POST (if exists)
** else from $_GET (if exists) else the second param sent,
** which may or may not be null
*/
$file_widget trim(setVal('file_widget''') ? setVal('file_widget''') : getFirstConfig());
//echo $file_widget,"<br/>";

$mode setVal('mode''');


if(!isset(
$mode))
   
$mode="";

if (
$mode == 'write')
{
   global 
$file_widget;
   
$fp fopen ($file_widget"w");
   
file_opener($fp);
   while (list (
$label$value) = each ($_POST))
   {
      
print_pair($fp,$label,$value);
   }
   
file_closer($fp);
   
$getstr sprintf("%s?file_widget=%s"$_SERVER['PHP_SELF'], $file_widget);
}

echo 
"<center><b style=\"font-size: large;\">Edit Config(s)</b></center>";

echo 
'<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo 
"<table width=\"100%\" border=0>";
echo 
"<tr>
        <td>
          <table width=\"100%\">
            <tr>
              <td width=300 align=right> 
                  <b>Edit this file</b>
              </td>
              <td>"
;
echo               
mkFileSelecter("file_widget"$file_widget);
echo 
"             <input type=submit value='Edit'>
              </td>
           </tr>
          </table>
        </td>
      </tr>"
;
echo  
"</table></form>";

echo 
"<br>\n<center><b style=\"font-size: large;\"> $file_widget </b>&nbsp; Note: site_bot requires all filepaths to end in / </enter>";

////read the file
$lines = @file (trim($file_widget));
$dir getcwd ();
$line sprintf ("\$sys_this_dir_path='%s'"$dir);
$lines[] = $line;

////transfer file lines to a hashed array, to remove any duplicates
$sysvalues = array ();
while (list (
$num$line) = each ($lines))
{
   
$tokens = array ();
   
$line cleanit ($line);
   
$tokens explode ("="$line);
   
$label $tokens[0];

        
$value "";
        if(isset(
$tokens[1]))
    
$value $tokens[1];
   
   if (
strstr ($line'<?php') || strstr ($line'?>') || !$label)
   continue;
   
   if (
strstr ($label"path") || strstr ($label"document_root"))
   {
      
$lastchar strlen ($value) - 1;
      if (
$value[$lastchar] != "/")
      
$value .= "/";
   }
   
$sysvalues[$label] = $value;
}

////offer the write to file choice
echo "<form action=\"".$_SERVER['PHP_SELF']."?mode=write&file_widget=$file_widget\"  method=\"post\">\n";
if(isset(
$posted_file))
echo 
"<input type=hidden name=inc value=$posted_file>";
echo 
"<table cellpadding=\"2\ cellspacing=\"2\" border=\"0\">\n";

while (list (
$label$value) = each ($sysvalues))
{
   echo 
"<tr><td valign=\"middle\" align=\"right\"> $label &nbsp; </td>\n";
   echo 
"<td colspan=4><input type=text size=64 name=\"$label\" value=\"$value\"></td></tr>\n";
}
echo 
"<tr><td colspan=1> <a href=\"index.html\" ><b>Admin</b></a></td>";
echo 
"<td colspan=3> <input type=submit style=\"color:black; background-color:#ccab99; border-width: 5px; border-color:#bbbbdd\" value=save_config> </td> </tr>\n";
echo 
"</table></form>\n";

?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products