Skip to content

Instantly share code, notes, and snippets.

@Suzhou65
Last active February 9, 2021 18:00
Show Gist options
  • Save Suzhou65/eed12200e516aac88b83f8ee6ec3dc7a to your computer and use it in GitHub Desktop.
Save Suzhou65/eed12200e516aac88b83f8ee6ec3dc7a to your computer and use it in GitHub Desktop.
Port Forwarding Status Monitor, PHP based webpage
<html>
<head>
<!-- META -->
<meta http-equiv="Cache-Control" content="No-Cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Style -->
<style>
html{font-size:100%; font-family:sans-serif; color:#666666;}
body{margin-top:10%;}
a{font-size:0.917rem; color:#8DB6CD; text-decoration:none;}
.fail{margin:0px auto; text-align:center; font-size:1rem; color:#FF5733; font-weight:bold; padding:1rem;}
.footer{margin:0px auto; text-align:center; font-size:0.8rem; padding:1rem;}
/* Authorization */
.access_holder{margin:0px auto; text-align:center; font-size:1rem;}
form.login{margin:0px auto;}
input[type="username"]{ border:1px #666666 solid; border-radius:5px; margin:3px; text-align:center; min-width:15rem;}
input[type="password"]{ border:1px #666666 solid; border-radius:5px; margin:3px; text-align:center; min-width:15rem;}
input[type='submit']{border:1px #8DB6CD solid; background:#8DB6CD; border-radius:5px; margin:5px; min-width:10rem;}
/*Table*/
table.csv_output{margin:0px auto; border:1px solid #FFFFFF; width:80%; border-collapse:collapse;}
tr{background:#FFFFFF; height:25px; border-left:none; padding:3px 2px;}
/*Header*/
tr:nth-child(1){background:#0B6FA4; color:#FFFFFF; border-left:none; padding:3px 2px;}
/*Column*/
td{padding:0.3rem;}
td:nth-child(1){text-align:center; min-width:12rem;}
td:nth-child(2){text-align:center; font-weight:bold; min-width:12rem;}
td:nth-child(3){text-align:center; min-width:12rem;}
</style>
<!-- Title -->
<title>Forwarding Status</title>
</head>
<!-- Body -->
<body>
<table class="csv_output">
<!-- php block -->
<?php
// Authorization configuration
$username = "github";
$password = "Nyanyanyanyanyanyanya";
//Authorization
//python_script_location
if(isset($_POST['submit'])){
if($_POST['username'] == $username && $_POST['password'] == $password){
// File path as you python script location
if ($file = fopen("/python_script_location/wakeup_record.csv","r")){
// Load CSV file
while (($line = fgetcsv($file)) !== false){
echo "<tr>";
foreach ($line as $cell){echo "<td>" . htmlspecialchars($cell) . "</td>";}
echo "</tr>\n";}
fclose($file);
}else{
// If unable open file
echo '<div class="fail">';
echo "Unable to open monitoring file.";
echo "</div>";}
// Authorization fail
}else{
echo '<div class="fail">';
echo "Password Incorrect.";
echo "</div>";}
}else{
// Authorization
?>
<div class="access_holder">
<form method="post" name="login">
<input type="username" name="username"/><br>
<input type="password" name="password"/><br>
<input type='submit' name='submit' value="Access"/>
</form>
</div>
<?php
}
?>
<!-- php block -->
</table>
<div class="footer"><a href="https://github.com/Suzhou65/Python-Wake-on-LAN">Python-Wake-on-LAN</a></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment