Files
ImoBot/web/index.php
Dennis Thiessen 2ace4c3044 Initial commit
2018-09-12 21:33:44 +02:00

56 lines
1.2 KiB
PHP

<?php header('Content-type: text/html; charset=utf-8'); ?>
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$url = $urlErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["url"])) {
$nameErr = "URL is required";
} else {
$url = test_input($_POST["url"]);
if (!preg_match('%^((https?://)|(www\.))([a-z0-9-].?)+(:[0-9]+)?(/.*)?$%i',$url)) {
$urlErr = "Not a valid URL";
} else {
echo "Used URL: ".$url;
echo "<br><br>";
echo "Output: ";
echo "<br>";
$scriptName = "python3 ImoBot.py '$url'";
exec($scriptName,$out);
foreach($out as $key => $value){
echo $key." ".$value."<br>";
}
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
return $data;
}
?>
<h2>ImoBot</h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
URL: <input type="text" size="100" name="url" value="<?php echo $url;?>">
<span class="error">* <?php echo $urlErr;?></span>
<br><br>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>