# # phpini,php # # php.ini customization/control script # # This script will let you customize php.ini # in 'Easy setup menu' or 'Detailed setup menu'. # # It will setup daily cronjob to refresh php.ini from # PowWeb's default copy, if you tell so. # # It will setup automatically session.save_path # and session cleanup cronjob, if you choose. # # It will take care of 'Easy method' subdomains, too, if you have any. # # No Editing is required, as usuall. # # # Also, it can download and install powerfull crontab editor/checker/tester, # 'CronAid (cronaid.php)' totally automatically, by clicking the link. # # # WARNING (and rant and background): # # As this script IS very flexible, it can be exploited by bad people # if not protected properly. # # Please at leas password protect the directory or this script. # I recommend using IP (range) protection on top of it. # # Use https secure connection if you feel like. # # Also, keep a copy of php.ini(s) and crontab, just in case. # # Although I've done enough test to feel confortable with it, # this software is still in TESTING stage, and it may contain # bugs, typos, and any other common mistake of mine. # # This is my 2nd PHP program and probably the last. # So, it's not a good coding example for PHP. # If you want to learn programming, learn something other than PHP. # PHP isn't good language. It's not "normal" general language either. # # Actually, I'm not so sure why I wrote it. # As you can clearly see, I'm not a fan of PHP. # I don't like it at all. I don't use it. I wish everyone dump this junk. # # But undeniably, naive newbies are drawn to it with the hype going on, # and suffer because of its poor design .... # And a part of suffering is caused by php.ini customizations, # including crontab setup to go with it. # # So, I decided to write a small automatic script to setup # at least session.save_path related things, # and somehow ended up writing this. # # Well, it's done (other than more testing/debugging/tweaking). # Now, you can enjoy the fruits of my pain, learning retarded language, # and the pain of many naive PHP users. # # I'll be very happy if it helps you to reduce the stress level, # or if you decide to use something better than PHP and it's applications. # # # v0.50 initial alpha # v0.51 Fixed a few typos # v0.52 Added code to turn off safe_mode forcefully. # v0.53 Fixed quotes around session.save_path data # v0.54 session.save_path and upload_tmpdir turned ON by default # v0.55 Modified Messages. # v0.56 Bug fix (wrong mtime argument) # v0.57 Added session deleting crontab removal and some notes/links # v0.58 Bug fix (copying php.ini to easy method subdomains) # $ver = '0.58'; # General setups. # # You don't need to modify these # unless you are trying to use it on non-PowWeb server # or PowWeb has modified some settings ..... # # Crontab related code won't work on other hosts # PowWeb has a special setup dealing with crontab # $user = get_current_user(); $home = "/www/".substr($user,0,1)."/$user"; $myini = "$home/etc/myphpini.txt"; $inipath = '/usr/local/lib/php.ini'; $custompath = $_SERVER['DOCUMENT_ROOT']."/php.ini"; $tmpdir = "$home/tmp"; $sessdir = "$home/sessions"; $etc = "$home/etc"; $ctab = "$etc/crontab"; $baseself = basename($_SERVER['PHP_SELF']); $comeback =0; # This part detect another retarded feature of PHP, safe_mode # and turn it off automatically, before to comeback. # if( ini_get('safe_mode') ){ # safe_mode is on .... # echo system("cp $inipath $custompath;echo -e \"\nsafe_mode=Off\n\" >>$custompath;"); $fh = fopen($custompath, "w"); fwrite($fh, "\nsafe_mode=Off\n"); fclose(); $comeback =1; } ?>
$myinidata\n"; #ob_flush(); if( strstr($myinidata,'stripcomments = off')){ $stripcom = ""; } if(preg_match('/actions = ([1-3])/', $myinidata, $m)){ $act[1] = ""; $act[$m[1]] = " checked"; } if(preg_match('/options = ([1-4])/', $myinidata, $m)){ $opt[1] = ""; $opt[$m[1]] = " checked"; } if(preg_match('/session_life = ([0-9]+[mhd]?)/', $myinidata, $m)){ $session_life = $m[1]; } $mylines = explode("\n",$myinidata); foreach($mylines as $line){ if(preg_match('/^ *([a-zA-Z0-9\._]+)\s*=\s*(.*)/', $line, $m)){ $myarray[$m[1]] = $m[2]; } } if( isset($myarray['session.save_path'])){ #echo 'sess : ',$myarray['session.save_path'] ,"
echo htmlentities($rr); ?>
echo htmlentities($myr); ?>
';
if($dosession){
$sessdir = $myarray['session.save_path'];
if($sessdir == ''){
echo "Error (sd1): Invalid directory name $sessdir
\n";
}elseif(!is_dir($sessdir)){
#echo `id 2>&1`;
if(mkdir($sessdir,0700)){
echo "$sessdir was not there. It was created and permission set to 0700\n";
}else{
echo "Error (sd2): Failed to create $sessdir
\n";
}
}
$minb = rand(6,54); # for session deleting
}
if($douptmp){
$tmpdir = $myarray['upload_tmp_dir'];
if($tmpdir == ''){
echo "Error (td1): Invalid directory name $tmpdir
\n";
}elseif(!is_dir($tmpdir)){
if(mkdir($tmpdir,0700)){
echo "$tmpdir was not there. It was created and permission set to 0700\n";
}else{
echo "Error (td2): Failed to create $tmpdir
\n";
}
}
}
$ct = file_get_contents($ctab);
if($act == 2){
$min = rand(6,54); # somewhere between 1:06 and 1:54
echo "\nYour php.ini will be refreshed at 1:$min AM everyday\n";
}
### remove one or more entries from crontab
if($act == 3 or $prev_act2 or $prevsession){
# Remove php.ini and crontab entry
if(!unlink($custompath )){
echo "Error (ct4): Failed to remove $custompath
\n";
}
if($act == 3 or $prev_act2){
$ctn = preg_replace("#(^|\\n).*?$myini.*#",'',$ct);
if($ct != $ctn){
?>pkp.ini update entry in Crontab removed
$ct = $ctn;
}else{
?>Failed to remove php.ini update entry in Crontab
You may want to check it CronAid
}
}
if($act == 3 or $prevsession){
$ctn = preg_replace("#^.*?find.*? -mtime .*?>>etc/cronlog.txt.*?\n\n#m","",$ct);
if($ct != $ctn){
?>Session deleting entry in Crontab removed
$ct = $ctn;
}else{
?>Failed to remove Session deleting entry in Crontab
You may want to check it CronAid
}
}
$ct = preg_replace("#\\n{3,}#","\n\n",$ct);
$fh = fopen( "$ctab","w") or die("Error (ct1): failed to open $ctab (Action 3)\n");
fputs($fh, $ct);
fclose($fh);
?>
--- remaining crontab entries ---
=$ct?>
}
if($prevsession ){
}
#echo "opt=$opt $custompath = ${_SERVER['DOCUMENT_ROOT']}/php.ini
\n";
if($opt != 3){ # 3: Do nothing
$tbd = "";
$globarray = glob("$home/*");
if($globarray){
foreach ( $globarray as $name) {
if(is_dir($name) and is_dir("$name/htdocs")){
if($opt == 1){
# copy php.ini
#echo "$custompath --> $name/htdocs/php.ini
\n";
#$tbd .="cp htdocs/php.ini $name/htdocs/; ";
copy($custompath, "$name/htdocs/php.ini");
}elseif($opt == 2){
# make symlink
symlink($cumstompath, "$name/htdocs/php.ini");
}else{
# Delete both symlink AND php.ini
unlink("$name/htdocs/php.ini");
}
}
}
if($tbd != ''){ $tbd ="($tbd) 2>>etc/cronerr.txt";}
}
}
if($act == 2 or $dosession){ # Need etc and crontab setup
if(!is_dir($etc)){
mkdir($etc, 0700) or die( "Error (etc1): Failed to create 'etc' directory...
"); # make sure /www/U/USER/etc exists.
echo "$etc directory was not there. It was created and permission set to 0700\n";
}
if($act == 2){
($withcomments ? $cutcom = "" : $cutcom = "-e '^ *;' -e '^ *$'");
ob_flush();
ob_start('nullcall'); # Using html context as HEREDOCUMENT.
?>=$min?> 1 * * * for i in `cut -d ' ' -d '=' -f 1 =$myini?>`; do ii=${i# };x="$x -e '${ii%%[!a-zA-Z0-9_-]}'"; done;(eval "grep -h -v =$cutcom?> $x /usr/local/lib/php.ini" ;echo ';--- added or customized values ---';grep -v -e '^ *;' =$myini?> ;)>htdocs/php.ini 2>>etc/cronerr.txt;=$tbd?>
$ctb .= ob_get_contents();
ob_end_flush();
$ct = preg_replace("#(^|\\n).*?$myini.*#",'',$ct);
}
if($dosession){
$ct = preg_replace("#(^|\\n).*?$sessdir.*#",'',$ct);
$ctb .= "$minb */${session_life} * * * find $sessdir/ -mtime +${session_life}h -delete >>etc/cronlog.txt 2>&1\n\n";
}
$ct = preg_replace("#^\\n+#","",$ct);
$ct = preg_replace("#\\n{3,}#","\n\n",$ct);
$fh = fopen( "$ctab","wb") or die("Error (ct2): failed to open $ctab\n");
fputs($fh, $ct.$ctb);
fclose($fh);
echo "\nFollowing line(s) generated/added to $ctab \n$ctb";
echo "Currently, your crontab contains following entries;\n---- crontab start -----\n";
readfile("$etc/crontab");
?>----- end -----
To edit/add/check crontab, use CronAid tool !
You can install CronAid tool automatically by clicking This Link.
To install other tools install extratools.php (automatic installer).
You can use WebFTP and/or sitemanager to manage files and directories and more !
}
?>