Files
WHIT/install/html/set1.php
2025-06-03 22:42:44 +00:00

319 lines
10 KiB
PHP

<script type="text/javascript">
window.onload=function(){
setInterval(function() {
var currentTime = new Date ( );
var currentHours = currentTime.getHours ( );
var currentMinutes = currentTime.getMinutes ( );
var currentSeconds = currentTime.getSeconds ( );
currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
currentHours = ( currentHours == 0 ) ? 12 : currentHours;
var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
document.getElementById("timer").innerHTML = currentTimeString;
}, 1000);
}
</script>
<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
//Var Setup
$ftp_result=Pending;
$overscan_result=Pending;
$rotation_result=Pending;
$net_result=Pending;
$cron_result=Pending;
//File setup
$userfolder="local.admin"
$startup="/home/$userfolder/config/autostart.sh";
$hostname = gethostname();
$hosts="/etc/hosts";
$config="/boot/config.txt";
$admin_password="/var/www/html/index.php";
$cron="/etc/cron.d/020_whit";
$configtest="/home/$userfolder/config/config.txt";
$wifitest="/home/$userfolder/config/wifitest.sh";
/* Reboot call Requires
add the following lines to:
sudo nano /etc/sudoers.d/020_webdata
www-data ALL=(root) NOPASSWD: /sbin/reboot
www-data ALL=(root) NOPASSWD: /bin/cp
www-data ALL=(root) NOPASSWD: /var/www/html/config/move.sh
sudo chmod 666 /etc/hosts
sudo chmod 666 /etc/hostname
sudo chmod 666 /var/www/html/config.txt
sudo chmod 666 /etc/wpa_supplicant/wpa_supplicant.conf
*/
// ifconfig info for mac settings.
exec("ifconfig eth0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}'",$getipinfo);
exec('ifconfig eth0 | grep ether ',$getipinfo);
exec("ifconfig wlan0 | grep 'inet ' | cut -d: -f2 | awk '{ print $2}'",$getipinfo);
exec('ifconfig wlan0 | grep ether ',$getipinfo);
$getipinfo[1]=strtoupper(substr($getipinfo[1],14,-29));
$getipinfo[3]=strtoupper(substr($getipinfo[3],14,-29));
//get var for Overscan and Rotation
$handle_cfg = file("$config");
if (substr($handle_cfg[9],17,-1)==1){
$getoverscan_d='checked';
}
else{
$getoverscan_e='checked';
}
if (substr($handle_cfg[10],15,-1)==0){
$getrotate[0] = checked;
}
if (substr($handle_cfg[10],15,-1)==90){
$getrotate[1] = checked;
}
if (substr($handle_cfg[10],15,-1)==180){
$getrotate[2] = checked;
}
if (substr($handle_cfg[10],15,-1)==270){
$getrotate[3] = checked;
}
$admin_pass_cfg = file("$admin_password");
$autostart_cfg = file("$startup");
//foreach($autostart_cfg as $fo) {
//echo nl2br ($fo);
//}
$getftp = (substr($autostart_cfg[13],7,-1));
//echo nl2br ("\n");
$getusername = (substr($autostart_cfg[14],5,-1));
//echo nl2br ("\n");
$getpassword = (substr($autostart_cfg[15],5,-1));
//echo nl2br ("\n");
$gettimeout = (substr($autostart_cfg[17],5,-1));
//echo nl2br ("\n");
$getapptype = (substr($autostart_cfg[20],8,-1));
//echo nl2br ("\n");
$getupdatewifi[0] = (substr($autostart_cfg[23],18,-1));
//echo nl2br ("\n");
$getssid = (substr($autostart_cfg[24],13,-1));
//echo nl2br ("\n");
$getpsk = (substr($autostart_cfg[25],20,-1));
//echo nl2br ("\n");
if ($getupdatewifi[0]=='true'){
$getupdatewifi[1]='checked';
}
else{
$getupdatewifi[1]='not checked';
}
//setup vars for Cronjob
$handle_cronjob = file($cron);
$hselect = substr($handle_cronjob[0],3,-25);
$mselect = substr($handle_cronjob[0],0,-28);
//Main Program
session_start();
//Write files to config file.
if(isset($_POST["update"])) {
if (strcmp($_POST['webadmin1'], $_POST['webadmin']) <>0){
echo "Admin password didn't match";
header("refresh: 5;");
die;
}
$handle_cfg[9]="overscan=". $_POST['overscan'] . ("\n");
$handle_cfg[10]="rotate=". $_POST['rotate'] . ("\n");
if (empty($_POST['SSID'])){
$_POST['SSID'] = "whit";
$_POST['PSK'] = "whitwhit";
}
if (!empty($_POST['webadmin'])){
$admin_pass_cfg[70]='$validUser[2] = $_POST["username"] == "admin" && $_POST["password"] == "' . $_POST['webadmin'] . '";';
}
$autostart_cfg[14] = "USER=" . $_POST['username'] . ("\n");
$autostart_cfg[15] = "PASS=" . $_POST['password'] . ("\n");
$autostart_cfg[13] = "Server=" . $_POST['ftp'] . ("\n");
$autostart_cfg[17] = "time=" . $_POST['timeout'] . ("\n");
$autostart_cfg[24] = "export essid=" . $_POST['SSID'] . ("\n");
$autostart_cfg[25] = "export wifipassword=" . $_POST['PSK'] . ("\n");
$autostart_cfg[23] = ("export wifiupdate=true\n");
$autostart_cfg[26] = "export updatehost=" . $_POST['netname'] . ("\n");
$autostart_cfg[36] = "export reboottime=" . $_POST['crontime'] . ("\n");
file_put_contents($startup, $autostart_cfg);
file_put_contents($configtest, $handle_cfg);
file_put_contents($admin_password, $admin_pass_cfg);
echo "Rebooting reload page in about 1 min.";
header("refresh: 10;");
exec('sudo /sbin/reboot');
}
if(isset($_POST["reboot"])) {
echo "Server is rebooting please wait.";
exec('sudo /sbin/reboot');
}
?>
<html>
<body style="margin:0;">
<head>
<style>
.label1 {
border: 1px solid blue;
border-radius: 5px;
}
.a {
display: inline-block;
width: 150px;
}
.grid-container2 {
display: grid;
grid-template-columns: 250px auto;
grid-gap: 1px;
padding: 1px;
}
.grid-container {
display: grid;
grid-template-columns: 250px auto;
grid-gap: 1px;
background-color: #2196F3;
padding: 1px;
}
.grid-container > div {
background-color: rgba(255, 255, 255, 0.8);
text-align: left;
padding: 2px;
font-size: 18px;
}
.item3 {
grid-row-start: 2;
grid-row-end: 4;
}
.button {
display: inline-block;
padding: 10px 15px;
font-size: 12px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.button:hover {background-color: #3e8e41}
.button:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
</head>
<form name="restart" action="" method="POST">
<div class="grid-container centered">
<div class="item1">Site Settings</div>
<div class="item2">
<span class="a">Username</span> <span class="c"><input name="username" type="text" value="<?php echo htmlspecialchars($getusername); ?>" class="label"></span><br>
<span class="a">Password</span> <span class="c"><input name="password" type="password" value="<?php echo htmlspecialchars($getpassword); ?>" class="label"></span><br>
<span class="a">Site IP or Name</span> <span class="c"><input name="ftp" type="text" value="<?php echo htmlspecialchars($getftp); ?>" class="label"></span><br>
<span class="a">Image Timing</span> <span class="c"><input name="timeout" type="text" value="<?php echo htmlspecialchars($gettimeout); ?>" class="label"></span><br>
</div>
<div class="item3">Network</div>
<div class="item4">
<span class="a">SSID</span> <span class="c"> <input name="SSID" type="text" value="<?php echo htmlspecialchars($getssid); ?>" class="label"></span><br>
<span class="a">PSK</span> <span class="c"> <input name="PSK" type="password" value="<?php echo htmlspecialchars($getpsk); ?>" class="label"></span><br>
<span class="a">Host Name</span> <span class="c"> <input name="netname" type="text" value="<?php echo htmlspecialchars($hostname); ?>" class="label"></span><br>
</div>
<div class="item14">
<span class="a">Lan IP address:</span> <span class="c"> <?php echo $getipinfo[0]; ?> </span><br>
<span class="a">Lan Mac address:</span> <span class="c"> <?php echo $getipinfo[1]; ?> </span><br>
<span class="a">Wifi IP address:</span> <span class="c"> <?php echo $getipinfo[2]; ?> </span><br>
<span class="a">Wifi Mac address:</span> <span class="c"> <?php echo $getipinfo[3]; ?> </span><br>
</div>
<div class="item5">Overscan</div>
<div class="item6">
<input type="radio" name="overscan" value="0" <?php echo htmlspecialchars($getoverscan_e); ?> class="label">Enabled
<input type="radio" name="overscan" value="1" <?php echo htmlspecialchars($getoverscan_d); ?> class="label">Disabled
</div>
<div class="item7">Rotation</div>
<div class="item8">
<input type="radio" name="rotate" value="0" <?php echo htmlspecialchars($getrotate[0]); ?> class="label">Normal 0&#176;
<input type="radio" name="rotate" value="90" <?php echo htmlspecialchars($getrotate[1]); ?> class="label">90&#176;
<input type="radio" name="rotate" value="180" <?php echo htmlspecialchars($getrotate[2]); ?> class="label">180&#176;
<input type="radio" name="rotate" value="270" <?php echo htmlspecialchars($getrotate[3]); ?> class="label">270&#176;
</div>
<div class="item9">Server time</div>
<div class="item10">
<div id="timer"></div>
<script>
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: "pLsgJ"
}], "*")
}
// always overwrite window.name, in case users try to set it manually
window.name = "result"
</script>
</div>
<div class="item11">Set a time for nightly Reboot</div>
<div class="item12"><input type="time" id="crontime" value="<?php echo $hselect; ?>:<?php echo $mselect;?>" name="crontime" Required>
</div>
<div class="item13">Webadmin password</div>
<div class="item14">
<input name="webadmin" type="password" value="" class="label"> =
<input name="webadmin1" type="password" value="" class="label"></div>
<div class="item15">
<input type="submit" class="button" value="Update and Reboot" name="update">
</div>
<div class="item16">
<input type="submit" class="button" value="Reboot" name="reboot"></form>
</div>
</div>
</body>
</html>