<?php
require(__DIR__.'/login.php');
require(__DIR__.'/config.php');

function isMobile() {
    //return preg_match("/(android)/i", $_SERVER["HTTP_USER_AGENT"]);
	return true;
}
?>

<?php if(isMobile()){ ?>
<!DOCTYPE html>
<html>

  <?php 
  include 'wol_functions.php'; 
  ?>
  <head>
    <title>blackNET -- /wake on Lan/</title>
    <meta id="viewport" name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="css/style.css?random=<?php echo uniqid(); ?>" />
	<link rel="shortcut icon" href="favicon.ico">
	
	<!-- Piwik -->

	<!-- End Piwik Code -->
	
  </head>
  <body>
	<div class="container">
		<div class="title"><?php echo $sitename; ?></div>
		<div class="undertitle">/wake on Lan/</div>
		<div class="logo"><a href="/wakeonlan/"><img src="img/remote.png" alt="wake on Lan" /></a></div>
		<?php  
		  $result = null;

		 // $wakemachine = $_GET["wake_machine"];
		 $wakemachine = (isset($_GET['wake_machine']) ? $_GET['wake_machine'] : null);  // new and better

		  if($wakemachine != "" && $wakemachine != "-1") 
			$result = WakeOnLan($networkbroadcast, $wakemachine, $port);

		  if($result != null) 
			echo "<div class=\"messageOK\">WOL for ".$wakemachine." was successful!</div>\n<hr />\n"; 
		?>
		<form class="wakeonlanForm" name="WakeOnLan" method="get" action="index.php">
		  <div class="normal">
			<label for="WakeOnLan" class="label">Select a machine to wake-up:<br /></label>
		  </div>
		  <div class="normal">
			<select name="wake_machine" id="WakeOnLan">
			  <option value="-1">------</option><?php PopulateMACList($maclist); ?>
			</select> 
			<input type="submit" value="Wake-up" />
		  </div>
		</form>
		
		<div class="logout"><a href="index.php?logout=1">Logout</a></div>
	</div>
  </body>
</html>
<?php } else { ?>
<meta http-equiv="refresh" content="0; URL=https://www.blackgate.org">
<?php } ?>