<?php

if (!isset($_SESSION['string'])) {
	session_start();
}

?>
<html>
<head>
	<title>*.php EXECUTOR</title>
	<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
	<style>
		
		body {
			background-color: RGB(232, 240, 243);
			font-size: small;
			font-family: "courier new";
			background-image: url(bg.gif);
		}
		input {
			background-color: RGB(232, 240, 243);
			border: 1px solid #3A6597;
			color: #3A6597;
			width: 200px;
			font-family: "courier new";
		}
		#errors {
			color: red;
			font-weight: bold;
			font-family: "courier new";
		}
		#output {
			background-color: #fff;
			border-top: 1px solid #000;
			border-left: 1px solid #000;
			border-right: 3px solid #000;
			border-bottom: 3px solid #000;
			padding-top: 10px;
			padding-bottom: 10px;
			min-height: 300px;
			
		}
		textarea {
			background-color: #fff;
			border-top: 1px solid #000;
			border-left: 1px solid #000;
			border-right: 3px solid #000;
			border-bottom: 3px solid #000;
		}
		a:link { color: #3A6597; border-bottom: 1px solid ; }
        a:visited { color: #3A6597; border-bottom: 1px solid ; }
        a:hover { color: #fff; text-decoration: none; background-color: #3A6597; }
        a:active { color: #fff; text-decoration: none; background-color: #3A6597;}
	
	</style>
	
<script language="JavaScript">
		<!-- Begin
		function checkString() {
		T1 = (document.notify.string.value);
		
		if (T1 == "") {
		alert("Niste unijeli kod za izvršenje!");
		return false;
		}
		else return true;
		}
		//  End -->
</script>
	
</head>
<body>
<center>
<div id="naslov" align="center">
<p><b>*.php EXECUTOR</b></p>
</div>

<?php 

$file_name = "execute.php";

if (@!file_exists($file_name)) {
	if (!isset($_GET['make'])) {
		?>
		<a href="<?php echo $_SERVER['PHP_SELF'] ?>?make">Napravi datoteku "<?php echo $file_name?>"</a><br />
		Datoteka je potrebna za rad skripte.
		<br /><br />
		<?php
	}
	/*else {
		?>
		<a href="<?php echo $_SERVER['PHP_SELF'] ?>">Nazad</a>
		<br /><br />
		<?php
	}*/
}

if (isset($_GET['make'])) {
	if (@touch($file_name, null, null)) {
		echo "Datoteka \"$file_name\" je uspješno napravljena";
		echo "<br />Pričekajte 3 sekunde. Bit ćete preusmjereni na početnu stranicu.";
		?><meta http-equiv="refresh" content="3; <?php echo $_SERVER['PHP_SELF']?>"><?php
	}
	else {
		echo "Greška! Datoteka nije napravljena.";
	}
		
}


if (isset($_POST['string']) and !empty($_POST['string'])) {
	$exe_str = $_POST['string'];
	$_SESSION['string'] = $exe_str;
		if (!isset($_GET['make'])) {
			if (@file_exists($file_name)) {
				$fp = @fopen($file_name, "w");
				if (!empty($exe_str)) {
				 	if (@fwrite($fp, stripslashes($exe_str))) {
						@fclose($fp);
					}
					else {
						echo "<div id='errors'>Datoteka <b>\"$file_name\"</b> je prazna!</div>";
					}
				}
			}
			else {
				echo "<div id='errors'>Greška! Datoteka nije pronađena!</div>";
			}		
		}
}

if (isset($_POST['izvrsi'])) {
		echo "<a href=" . $_SERVER['PHP_SELF'] . ">Natrag</a>";
		echo "<br /><br />";
		echo "<div id='output'>";
		if (file_exists($file_name)) {
			include($file_name);
		}
	echo "</div>";
}

if (!isset($_POST['izvrsi']) and !isset($_GET['make'])) { ?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" name="notify" onsubmit="return checkString()">
<textarea cols="100" rows="25" name="string">
<?php

if (isset($_SESSION['string']) and !empty($_SESSION['string'])) {
	if (!isset($_POST['erase'])) {
		echo stripslashes($_SESSION['string']);
	}
	elseif (isset($_POST['erase'])) {
		session_destroy();
		echo "";
	}
}
else {
	echo "";
}


?>
</textarea>
<br /><br />
<input type="submit" name="izvrsi" value="Izvrši uneseni kod!!!">
</form>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
<input type="submit" name="erase" value="Obriši uneseni kod!!!">
</form>

<?php
}
?>

</center>
</body>
</html>