[index.php]

[code]<?php
/*------------------------------*/
/*----------FileEditor----------*/
/*-Copyright By Wessel Bruinsma-*/
/*------------------------------*/
session_start();
?>
<html>
	<head>
		<title>
			FileEditor
		</title>
		<link rel="stylesheet" href="style.css" type="text/css">
	</head>
	<body>
		<?php
		if (isset($_GET['editor']))
			echo '<form action="index.php?path='.$_GET['path'].'&save&editor" method="POST">';
		?>
		<div id="Kop">
		FileEditor
		</div>
		<div id="Dat">
		<?php
		/*----------------*/
		/*-----CONFIG-----*/
		/*----------------*/
				
		//System
		$StartDirectory = ''; //Niks is de relative map.
		$DoNotGoOutOfAboveDir = false;
		$WritePermission = true;
		$SupervisorInIP = '';  //Scheiden door een puntkomma: ';'.
		
		//Style
		$AutoUpdate = true;
		$StyleWidth = '50%';
		$StyleTopColor = '32CD32'; //Hex.
		$StyleMiddleColor = 'FFA500'; //Hex.
		$StyleBottomColor = '87CEEB'; //Hex.
		
		/*HANDLEIDING
		Zet deze 'index.php' in de map waar hij moet komen.
		Vul vervolgens de CONFIG in naar wens en het is klaar voor gebruik.
		Voor de bovenstaande gevens in voor de style, en die zal dan worden aangemaakt.
		-----------*/
		
		/*HIERONDER NIKS MEER BEWERKEN*/
		$StartDirectory = str_replace('\\','/',$StartDirectory);
		$buff = explode(';',$SupervisorInIP);
		$IpTrue = false;
		for ($nr = 0;$nr < count($buff);$nr++)
		{
			if ($buff[$nr] == $_SERVER['REMOTE_ADDR'])
				$IpTrue = true;
		}
		if (!file_exists('BlokkedIps'))
		{
			fclose(fopen('BlokkedIps','w'));
			chmod('BlokkedIps',0777);
		}
		if (!file_exists('style.css') || $AutoUpdate == tru)
		{
			$handle = fopen('style.css','w');
			fwrite($handle,'BODY
{
	background-color: #C0C0C0;
	color: #000000;
	font-size: 12pt;
	margin: 0;
	padding: 5;
}

#Kop, #Dat, #Foot
{
	border: #000000 solid 1px;
	font-family: Arial;
	margin: 1px;
	padding: 1px;
	width: '.$StyleWidth.';
	text-align: left;
	color: #000000;
}

#Kop
{
	background-color: #'.$StyleTopColor.';
	font-weight: bold;
	padding: 2pt;
	margin-bottom: 0px;
}

#Dat
{
	background-color: #'.$StyleMiddleColor.';
	padding: 2pt;
	margin-top: -1px;
	margin-bottom: -1px;
}

#Foot
{
	background-color: #'.$StyleBottomColor.';
	padding: 2pt;
	margin-top: 0px;
}

A
{
	text-decoration: none;
	color: #00008B;
}

A:hover
{
	text-decoration: none;
	color: #0000CD;
	position: relative;
	left: 2;
}

#Mod
{
	font-size: 10pt;
	width: 30%;
	margin: -1px;
	padding: 1px;
	float: right;
	border: #000000 solid 1px;
	background-color: #00BFFF;
}

INPUT
{
	font-size: 9pt;
	border: #000000 solid 1px;
	background-color: #FFFFFF;
	margin: 1pt;
	padding: 1pt;
	font-family: Arial;
}

INPUT:hover
{
	font-size: 9pt;
	border: #000000 solid 1px;
	background-color: #C0C0C0;
	margin: 1pt;
	padding: 1pt;
}

#TxtArea
{
	font-size: 9pt;
	border: #000000 solid 1px;
	background-color: #FFFFFF;
	font-family: Arial;
	margin: 1pt;
	padding: 1pt;
}

#Line
{
	height: 1pt;
	margin-bottom: 3pt;
	margin-top: 3pt;
}');
		fclose($handle);
	}
		function ipcheck()
		{
			$ret = true;
			$file = file('BlokkedIps');
			for ($nr = 0;$nr < count($file);$nr++)
			{
				$buf = explode(':',$file[$nr]);
				if ($buf[1] == $_SERVER['REMOTE_ADDR'])
					$ret = false;
			}
			return $ret;
		}
		if ($StartDirectory != '')
			$StartDirectory = str_replace('\\','/',realpath($StartDirectory));
		function ipban()
		{
			$buf = '';
			$file = file('BlokkedIps');
			for ($nr = 0;$nr < count($file);$nr++)
			{
				if ($nr == 0)
					$buf .= chr(10);
				$file .= $file[$nr];
			}
			if ($buf != '')
				$file .= chr(10);
			$file .= ':'.$_SERVER['REMOTE_ADDR'].':';
			$handle = fopen('BlokkedIps','w');
			fwrite($handle,$file);
			fclose($handle);
		}
		function insLine()
		{
			echo '<br><img src="LinePix.bmp" id="Line" alt="Line" width="100%" height="16pt">';
		}
		function urlcheck($sdir,$path)
		{
			$sdir = str_replace('/','\\/',$sdir);
			if (ereg('^'.$sdir,$path))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		if ($DoNotGoOutOfAboveDir == true && isset($_GET['path']))
			$UC = urlcheck($StartDirectory,$_GET['path']);
		elseif (!isset($_GET['path']))
			$UC = true;
		else
			$UC = true;
		if ((!isset($_GET['editor']) && $UC == true) || $IpTrue)
		{
			if (isset($_GET['path']))
				$path = $_GET['path'];
			else
				$path = $StartDirectory;
			if (isset($_GET['editor']))
				$mod = 'File Edit';
			else
				$mod = 'Search File';
			echo '<div id="Mod">Mod: <u>'.$mod.'</u></div>';
			if ($start_dir == '')
			{
				$buff = substr($_SERVER['PHP_SELF'],1,strlen($_SERVER['PHP_SELF']));
				$buff = explode('/',$buff);
				if (count($buff) < 2)
				{
					$start_dir = '/';
				}
				else
				{
					$start_dir = '../'.$buff[count($buff)-2];
				}
			}
			$somedat = false;
			$canDo = true;
			$once = true;
			$start_dir = str_replace('\\', '/',$start_dir);
			if ($path == '')
			{
				$path_parent = '../';
				$path_with = '';
			}
			else
			{
				if ($path[strlen($path)-2] == '.')
				{
					if (substr($path,strlen($path)-1,strlen($path)-1) != '/')
						$path .= '/';
					$path_parent = $path.'../';
				}
				else
				{
					if (substr($path,strlen($path)-1,strlen($path)-1) != '/')
						$path_parent = $path.'/';
					else
						$path_parent = $path;
					$buf = explode('/',$path_parent);
					$path_parent = '';
					if (count($buf) > 3)
					{
						for ($nr = 0;$nr < count($buf)-3;$nr++)
							$path_parent .= $buf[$nr].'/';
					}
					$path_parent .= $buf[count($buf)-3].'/';
				}
				
				if (substr($path,strlen($path)-1,strlen($path)-1) != '/')
					$path .= '/';
				
				$path_with = $path;
			}
			
			if ($path == '')
				$startdir = $start_dir;
			else
				$startdir = $path;
			if ($handle = opendir($startdir))
			{
				while (false !== ($file = readdir($handle)))
				{
					if ($canDo == true && $file == '..')
					{
						echo '<img src="IcoUp.bmp" alt="Level Up"> <a href="index.php?path='.$path_parent.'">Parent Directory</a>';
						insLine();
						$canDo = false;
					} elseif ($once == true && $file != '..') {
						$noPar = true;
						if ($_handle = opendir($startdir))
						{
							while (false !== ($_file = readdir($_handle)))
							{
								if ($_file == '..')
								{
									$noPar = false;
								}
							}
							if ($noPar)
							{
								echo '<img src="IcoUp.bmp" alt="Level Up"> <i>No Parent Directory</i>';
								insLine();
								$once = false;
							}
						}
						closedir($_handle);
					}
				}
				closedir($handle);
			}
			if ($handle = opendir($startdir))
			{
				while (false !== ($file = readdir($handle)))
				{
					if ($file != '.' && $file != '..')
					{
						if (is_dir($path_with.$file))
							echo '<br><img src="IcoMap.bmp" alt="Map"> <a href="index.php?path='.$path_with.$file.'">'.$file.'</a> - <i>Directory</i>';
						else
						{
							if ($WritePermission == true || $IpTrue)
								echo '<br><img src="IcoFile.bmp" alt="File"> <a href="index.php?editor&path='.$path_with.$file.'">'.$file.'</a> - <i>File</i> - <i>'.filesize($path_with.$file).' Bytes</i>';
							else
								echo '<br><img src="IcoFile.bmp" alt="File"> '.$file.' - <i>File</i> - <i>'.filesize($path_with.$file).' Bytes</i>';
						}
						$somedat = true;
					}
				}
				closedir($handle);
			}
			
			if (!$somedat)
			{
				echo '<br>Er zijn geen bestanden gevonden...';
			}
		}
		elseif ((isset($_GET['path']) && (($IsPos == true || ($WritePermission == true && $UC == true)) || $IpTrue)))
		{
			if (isset($_GET['editor']))
				$mod = 'File Edit';
			else
				$mod = 'Search File';
			echo '<div id="Mod">Mod: <u>'.$mod.'</u></div>';
			echo 'File: ';
			$buff = $_GET['path'];
			$buff = explode('/',$buff);
			echo $buff[count($buff)-1];
			insLine();
			if (isset($_GET['save']) && isset($_SESSION['Save']) && $_SESSION['Save'] == 'Check' && ipcheck() == true && $WritePermission == true && $UC == true)
			{
				$handle = fopen($_GET['path'],'w');
				chmod($_GET['path'],0777);
				$txt = str_replace('$lt;','<',$_POST['txt']);
				fwrite($handle,$txt);
				fclose($handle);
				echo 'Opgeslagen...';
				session_unregister('Save');
				session_destroy();
			} elseif (isset($_GET['save'])) {
				ipban();
				echo 'Wegens niet-gebruik van deze site om bestanden te<br>bewerken bent u geblokt om te bewerken!';
				$blocktwice = true;
			}
			if (ipcheck() == false && !isset($blocktwice))
			{
				ipban();
				echo 'Wegens niet-gebruik van deze site om bestanden te<br>bewerken bent u geblokt om te bewerken!';
			}
			$inBuf = '';
			for ($nr = 0;$nr < count($buff)-1; $nr++)
				$inBuf .= $buff[$nr].'/';
			$cont = '';
			$file = file($_GET['path']);
			for ($nr = 0;$nr < count($file);$nr++)
				$cont .= $file[$nr];
			$cont = str_replace('<','&lt;',$cont);
			?><br>Content:<br>
			<textarea cols="100" rows="20" name="txt" id="TxtArea"><?php echo $cont; ?></textarea><br>
			<input type="submit" value="Opslaan"> |
			<input type="button" value="Terug" onClick="javascript:document.location='index.php?path=<?php echo $inBuf; ?>';">
			<?php
			$_SESSION['Save'] = 'Check';
		} elseif(isset($_GET['save']) && isset($_GET['editor'])) {
			echo 'Door dit illegale gebruik zal u worden geblokt.<br><input type="button" value="Terug" onClick="javascript:history.go(-1);">';
			ipban();
		}
		else
		{
			echo 'Deze functie is beperkt of de toegang is geweigerd door de webmaster.<br><input type="button" value="Terug" onClick="javascript:history.go(-1);">';
		}
		?>
		</div>
		<div id="Foot"><i>
		Copyright &copy; By Wessel Bruinsma
		</i></div>
		<?php
		if (isset($_GET['editor']))
			echo '</form>';
		?>
	</body>
</html>
[/code]