PHP Code:
<?php
//CONFIG
$admin_id = "root";
$admin_pw = "123";
//CONFIG
echo "<head>";
//echo "<link rel='stylesheet' href='style.css' type='text/css' />";
echo '<style type="text/css">
<!--
body {
background-color:#AFEEEE;
}
.textbox {
background-color : #f8f8f8;
border : 1px solid #ccc;
}
.button {
background-position: center;
//background-color: #9BCCCA;
}
}
-->
</style>';
echo "<title>Autopatcher AdminCP</title>";
echo "</head>";
//echo "<body>";
$generated_patchlist;
$version_form;
$new_exclusionlist = $_POST['exclusionlist'];
$use_clientversion = $_POST['use_clientversion'];
$increase_clientversion = $_POST['increase_clientversion'];
if (isset($_GET["login"]))
{
//Einlogg-Funktion
$username = $_POST['username'];
$password = $_POST['password'];
if ($password == $admin_pw and $username == $admin_id)
{
loadadmincpgui();
}
else
{
loadlogingui($username);
echo "<script>alert(\"Incorrect password or username!\");</script>";
}
}
elseif (isset($_GET["admincp_ok"]))
{
//if (md5($_POST['password']) != md5($admin_pw))
if ($_POST['admincp_spoiler'])
{
loadadmincpgui();
}
elseif ($_POST['admincp_update'])
{
if (file_exists("client/patchconfig.cfg") == false and file_exists("client/clientversion.txt") == false and $use_clientversion == "true")
{
load_clientversionselect();
}
else
{
update_files();
}
}
else
{
echo "
<TABLE border bgcolor='#F8E0E0' align='center' WIDTH='100%' frame='hsides'>
<TR>
<TD align='center'><small><b><font color='#ff0000'>Please log in first to get access.</font></b></small></TD>
</TR>
</TABLE>";
loadlogingui("");
}
}
elseif (isset($_GET['admincp_select_clientversion']))
{
if ($_POST['version_exclusive'])
{
$version_form = "exclusive";
update_files();
}
elseif ($_POST['version_normal'])
{
$version_form = "normal";
load_statusbar();
get_patchconfig();
}
else
{
echo "
<TABLE border bgcolor='#F8E0E0' align='center' WIDTH='100%' frame='hsides'>
<TR>
<TD align='center'><small><b><font color='#ff0000'>Please log in first to get access.</font></b></small></TD>
</TR>
</TABLE>";
loadlogingui("");
}
}
elseif (isset($_GET['admincp_get_patchconfig']))
{
if (isset($_POST['patchconfig']))
{
if ($_POST['patchconfig'] == "")
{
load_statusbar();
echo "
<TABLE border bgcolor='#F8E0E0' align='center' WIDTH='100%' frame='hsides'>
<TR>
<TD align='center'><small><b><font color='#ff0000'>ERROR: No patchconfig inserted!</font></b></small></TD>
</TR>
</TABLE>";
get_patchconfig();
}
else
{
$handler = fOpen("client/patchconfig.cfg" , "w+");
fWrite($handler , $_POST['patchconfig']);
fClose($handler);
update_files();
}
}
else
{
echo "
<TABLE border bgcolor='#F8E0E0' align='center' WIDTH='100%' frame='hsides'>
<TR>
<TD align='center'><small><b><font color='#ff0000'>Please log in first to get access.</font></b></small></TD>
</TR>
</TABLE>";
loadlogingui("");
}
}
elseif (isset($_GET['admincp_update_complete']))
{
if (isset($_POST['update_ok']))
{
loadadmincpgui();
}
else
{
echo "
<TABLE border bgcolor='#F8E0E0' align='center' WIDTH='100%' frame='hsides'>
<TR>
<TD align='center'><small><b><font color='#ff0000'>Please log in first to get access.</font></b></small></TD>
</TR>
</TABLE>";
loadlogingui("");
}
}
else
{
loadlogingui($username);
}
function loadlogingui($username) {
echo '<BODY onLoad="document.forms.post.username.focus()">';
echo "<BR CLEAR=HEIGHT>";
echo "<div id='login'><form name='post' method='post' action='admincp.php?login'>
<table frame='box' width='100px' align='center' class=''>
<tr>
<td colspan='2'><h2 style='color:#A4A4A4' align='left'><b>Admin CP - Login</b></h1></td>
</tr>
<tr valign='middle'>
<td class='tbl2' align='center'>Userame:</td>
<td class='tbl2' align='center'><input type='text' name='username' value='".$username."' maxlength='50' class='textbox' style='width: 180px;'></td>
</tr>
<tr>
<td class='tbl2' align='center'>Password:</td>
<td class='tbl2' align='center'><input type='password' name='password' maxlength='50' class='textbox' style='width: 180px;'></td>
</tr>
<tr>
<td class='tbl2' align='center'> </td>
<td align='right'><input name='login' value='Login' type='submit' class='button'></td>
</tr>
</table>
</div>
";
load_footer();
echo "</body>";
}
function loadadmincpgui() {
load_statusbar();
if (file_exists("patchlist.php"))
{
$actual_patchlist = file_get_contents('./patchlist.php', true);
}
else
{
$actual_patchlist = "";
}
if (file_exists("exclusionlist.txt"))
{
$actual_exclusionlist = file_get_contents('./exclusionlist.txt', true);
}
else
{
$actual_exclusionlist = "--Ausschlussliste:--\nsyserr.txt\nmetin2.cfg\nindex.php\nindex.html";
}
echo "<BR CLEAR=HEIGHT>";
echo "
<div id='admincp'><form name='post' method='post' action='admincp.php?admincp_ok'>
<table align='center' class='' frame='box'>
<tr>
<tr>
<td><h2 style='color:#A4A4A4' align='left'><b>Autopatcher Administrator Control Panel</b></h1></td>
</tr>
";
if ($_POST['admincp_spoiler'] != "Show") {
echo "<tr valign='left'>
<td class='tbl2' align='left'><b>Actual patchlist: </b><input name='admincp_spoiler' value='Show' type='submit' class='button'></td>
</tr>";
} else {
echo "
<tr valign='left' frame='above'>
<td class='tbl2' align='left'><b>Actual patchlist: </b><input name='admincp_spoiler' value='Hide' type='submit' class='button'></td>
</tr>
<tr frame='below'>
<td class='tbl2' align='center'><textarea type='text' name='patchlist' disabled='true' wrap='off' class='textbox' value='test' style='width: 500px; height: 200px;'>".$actual_patchlist."</textarea></td>
</tr>"; }
echo "
<tr valign='left'>
<td class='tbl2' align='left'><b>Exclusionlist:</b></td>
</tr>
<tr valign='left'>
<td class='tbl2' align='left'><small>(This files will not be included in the patchlist)</small></td>
</tr>
<tr frame='below'>
<td class='tbl2' align='center'><textarea type='text' name='exclusionlist' wrap='off' class='textbox' value='test' style='width: 500px; height: 200px;'>".$actual_exclusionlist."</textarea></td>
</tr>";
admincp_clientversion();
echo "
<tr>
<td align='right'><input name='admincp_update' value='Update files' type='submit' class='button'></td>
</tr>
</tr>
</table>
</div>
";
load_footer();
}
function load_statusbar()
{
global $admin_id;
//$datum = date("d.m.Y");
$time = strftime("%b %d, %G - %R %Z");
//$uhrzeit = date("H:i");
echo "
<TABLE align='center' WIDTH='50%' frame='hsides'>
<TR>
<TD align='left'><small>Autopatcher Administrator Control Panel v1.3</small></TD>
<TD align='left'><small>logged in as <b>".$admin_id."</b></small></TD>
<TD align='left'><small>".$time."</small></TD>
<TD align='left'><small><a href='http://www.musicinstructor.de/donate' target='_blank'>Donate</a></small></TD>
</TR>
</TABLE>
";
}
function load_footer()
{
echo "<br><br><br><br><br>
<TABLE align='center' WIDTH='50%' frame='hsides'>
<TR>
<TD align='left'><small>optimized for <a href='http://www.mozilla-europe.org/de/firefox/' target='_blank'>Mozilla Firefox</a></small></TD>
<TD align='right'><small>© musicinstructor, 2010</small></TD>
</TR>
</TABLE>
";
}
function admincp_clientversion()
{
if (file_exists("clientversion.php"))
{
$actual_clientversion = file_get_contents('./clientversion.php', true);
}
else
{
$actual_clientversion = "x";
}
$new_clientversion = get_new_clientversion($actual_clientversion);
echo "
<tr valign='left'>
<td class='tbl2' align='left'><b>Clientversion:</b></td>
</tr>
<tr valign='left'>
<td class='tbl2' align='left'><small>If you use clientversion, the time for patching decreases enormously.</small></td>
</tr>
<tr valign='left'>
<td class='tbl2' align='left'><input type='checkbox' name='use_clientversion' value='true' checked> Use clientversion<br></td>
</tr>
<tr valign='left'>
<td class='tbl2' align='left'>Actual: ".$actual_clientversion." <input type='checkbox' name='increase_clientversion' value='true' checked> Increase <small>(new clientversion would be ".$new_clientversion.")</small><br></td>
</tr>
";
}
function get_new_clientversion($old_clientversion)
{
if ($old_clientversion == "x")
{
$old_clientversion = "9.9.9";
}
$old_clientversion = preg_replace('/[^0-9.]/','',$old_clientversion);
$old_clientversion = str_replace('..','.',$old_clientversion);
$positions = array(strpos($old_clientversion, "."));
while (strrpos($old_clientversion, ".") != $positions[(count($positions)-1)])
{
array_push($positions, strpos($old_clientversion, ".", $positions[(count($positions))])+$positions[(count($positions))-1]+1);
}
$new_clientversion = preg_replace('/[^0-9]/','',$old_clientversion);
$new_clientversion++;
$new_cv_p = $new_clientversion;
$new_cv_p = strval ($new_cv_p);
foreach ($positions as $pos)
{
$new_cv_p = str_insert($pos, $new_cv_p, ".");
}
if (substr($new_cv_p, -2, 1) != ".")
{
$new_cv_p = str_insert(strlen($new_cv_p)-1, $new_cv_p, ".");
}
return $new_cv_p;
}
function str_insert($pos_zum_einfuegen, $string, $text_zum_einfuegen)
{
$i = 0;
$str = '';
while($i<strlen($string))
{
if($i == $pos_zum_einfuegen)
{
$str .= $text_zum_einfuegen.$string[$i];
}
else
{
$str .= $string[$i];
}
$i += 1;
}
return $str;
}
function ListFiles($path){
global $generated_patchlist;
$handle = opendir($path);
while (($pathFile = readdir ($handle)) != false)
{
if (preg_match("=^\.{1,2}$=", $pathFile))
{
continue;
}
if(is_dir($path."/".$pathFile))
{
ListFiles($path."/".$pathFile);
}
else
{
if (IsInExclusionList(str_replace("client/","", $path."/".$pathFile)) == false)
{
$generated_patchlist = $generated_patchlist.str_replace("client/","", $path."/".$pathFile)." ##md5Hash= ".strtoupper(md5_file($path."/".$pathFile))."\n";
}
}
}
@closedir($handle);
}
function IsInExclusionList($filename)
{
$returnvalue = false;
global $existexclusionlist;
global $exclusionlist;
if($existexclusionlist === true){
$line = 0;
while($line < key($exclusionlist)+1)
{
if ($filename == $exclusionlist[$line]){$returnvalue = true;}
$line++;
}
}
if ($returnvalue == false){return false;} else {return true;}
}
function IniExclusionList()
{
global $existexclusionlist;
global $exclusionlist;
if (file_exists("exclusionlist.txt")){
$existexclusionlist = true;
$exclusionlist = file("exclusionlist.txt");
krsort($exclusionlist);
}
else
{
$existexclusionlist = false;
}
}
function generate_easypatchlist()
{
global $generated_patchlist;
$generated_patchlist = $generated_patchlist."-###Patchlist [EasyPatchlist-Script v1.0]###-"."\n";
$existexclusionlist;
$exclusionlist;
IniExclusionList();
ListFiles("client");
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
$generated_patchlist = $generated_patchlist. "\n";
}
function update_files()
{
set_time_limit(0);
global $use_clientversion;
global $increase_clientversion;
global $version_form;
if (file_exists("client/patchconfig.cfg"))
{
$mode_clientversion = "normal";
}
elseif (file_exists("client/clientversion.txt"))
{
$mode_clientversion = "exclusive";
}
else
{
$mode_clientversion = $version_form;
}
loadupdategui($use_clientversion, $mode_clientversion);
$old_clientversion;
if (file_exists("clientversion.php"))
{
$old_clientversion = file_get_contents('./clientversion.php', true);
if ($old_clientversion == "")
{
$old_clientversion = "x";
}
}
else
{
$old_clientversion = "x";
}
$new_clientversion = get_new_clientversion($old_clientversion);
if ($use_clientversion != "true")
{
$new_clientversion = "x";
}
if ($increase_clientversion == "true" or $use_clientversion != "true")
{
$handler = fOpen("clientversion.php" , "w+");
fWrite($handler , $new_clientversion);
fClose($handler);
if ($mode_clientversion == "exclusive")
{
$handler = fOpen("client/clientversion.txt" , "w+");
fWrite($handler , $new_clientversion);
fClose($handler);
}
else
{
replace_line(20, "client/patchconfig.cfg", "CLIENTVERSION: ".$new_clientversion);
}
}
else
{
$handler = fOpen("clientversion.php" , "w+");
fWrite($handler , $old_clientversion);
fClose($handler);
}
global $new_exclusionlist;
$handler = fOpen("exclusionlist.txt" , "w+");
fWrite($handler , $new_exclusionlist);
fClose($handler);
generate_easypatchlist();
global $generated_patchlist;
$handler = fOpen("patchlist.php" , "w+");
fWrite($handler , $generated_patchlist);
fClose($handler);
echo "<script>alert(\"All changes have been saved!\");</script>";
//loadadmincpgui();
}
function loadupdategui($clientversion_use, $clientversion_mode) {
load_statusbar();
echo "<BR CLEAR=HEIGHT>";
echo "
<div id='admincp_updating'><form name='post' method='post' action='admincp.php?admincp_update_complete'>
<table cellspacing='0' align='center' class='' frame='box'>
<tr>
<tr>
<td><h2 style='color:#A4A4A4' align='left'><b>Autopatcher Administrator Control Panel</b></h1></td>
</tr>
";
if ($clientversion_use == "true")
{
echo "
<tr>
<td>updated::clientversion.php</td>
</tr>
";
}
if ($clientversion_mode == "normal")
{
echo "
<tr>
<td>updated::client/patchconfig.cfg</td>
</tr>
";
}
elseif ($clientversion_mode == "exclusive")
{
echo "
<tr>
<td>updated::client/clientversion.txt</td>
</tr>
";
}
echo "
<tr>
<td>updated::exclusionlist.php</td>
</tr>
<tr>
<td>updated::patchlist.php</td>
</tr>
<tr>
<td><center><input name='update_ok' value='OK' type='submit' class='button'></center></td>
</tr>
</tr>
</table>
</div>
";
load_footer();
}
function load_clientversionselect()
{
load_statusbar();
global $new_exclusionlist;
global $use_clientversion;
global $increase_clientversion;
echo "<BR CLEAR=HEIGHT>";
echo "
<div id='admincp_select_clientversion'><form name='post' method='post' action='admincp.php?admincp_select_clientversion'>
<table align='center' class='' frame='box'>
<tr>
<tr>
<td><h2 style='color:#A4A4A4' align='left'><b>Autopatcher Administrator Control Panel</b></h1></td>
</tr>
<tr>
<td><center>Are you using a normal version or an exclusive version?</center><br></td>
</tr>
<tr>
<td><center><input name='version_normal' value='normal' type='submit' class='button'><input name='version_exclusive' value='exclusive' type='submit' class='button'></center></td>
</tr>
<tr>
<input type='hidden' name='exclusionlist' value='".$new_exclusionlist."'><input type='hidden' name='use_clientversion' value='".$use_clientversion."'><input type='hidden' name='increase_clientversion' value='".$increase_clientversion."'>
</tr>
</tr>
</table>
</div>
";
load_footer();
}
function get_patchconfig()
{
global $new_exclusionlist;
global $use_clientversion;
global $increase_clientversion;
echo "<BR CLEAR=HEIGHT>";
echo "
<div id='admincp_get_patchconfig'><form name='post' method='post' action='admincp.php?admincp_get_patchconfig'>
<table align='center' class='' frame='box'>
<tr>
<tr>
<td><h2 style='color:#A4A4A4' align='left'><b>Autopatcher Administrator Control Panel</b></h1></td>
</tr>
<tr>
<td>Please insert the content of your actual patchconfig.cfg here:</td>
</tr>
<tr>
<td align='center'><textarea type='text' name='patchconfig' wrap='off' class='textbox' value='test' style='width: 500px; height: 200px;'></textarea></td>
</tr>
<tr>
<td align='right'><input name='patchconfig_ok' value='OK' type='submit' class='button'></td>
</tr>
<tr>
<input type='hidden' name='exclusionlist' value='".$new_exclusionlist."'><input type='hidden' name='use_clientversion' value='".$use_clientversion."'><input type='hidden' name='increase_clientversion' value='".$increase_clientversion."'>
</tr>
</tr>
</table>
</div>
";
load_footer();
}
function replace_line($zeile, $datei, $neuer_text)
{
$file=file($datei);
$neuer_text = $neuer_text."\n";
$algemh = fopen($datei,"w+");
for($num=0;$num<count($file);$num++){
if($num==$zeile){
fputs($algemh, $neuer_text);
} else {
fputs($algemh, $file[$num]);
}
}
fclose($algemh);
}
?>