<?php
$message = 'Welcome! Please provide your credentials!';

if(isset($_REQUEST['login']) && isset($_REQUEST['password']))
{	
	/* Login attempt */
	if($_SERVER['SERVER_NAME'] == 'cloudservice' && $_SERVER['REMOTE_ADDR'] == '127.0.0.1')
	{
		/* Request from internal network */
		require("../internal_secrets.php");
		if($_REQUEST['login'] == $secret_login && $_REQUEST['password'] == $secret_password)
			exit('OK!');
		else
			exit('FAIL!');
		
	}
	else
	{
		/* Request from the Internet. Redirect to cloud service.*/
		$result = file_get_contents("http://cloudservice/?login={$_REQUEST['login']}&password={$_REQUEST['password']}");
		if($result === 'FAIL!')
		{
			$message = 'You have failed miserably.';
		}
		else
		{
			$message = require('flag.php');
		}
	}
}
?><!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title>Cloud Service</title>

  <!-- Bootstrap core CSS -->
  <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom fonts for this template -->
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Merriweather:300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
  <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

  <!-- Custom styles for this template -->
  <link href="css/coming-soon.min.css" rel="stylesheet">

</head>

<body>

  <div class="overlay"></div>
  <video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
    <source src="mp4/bg.mp4" type="video/mp4">
  </video>

  <div class="masthead">
    <div class="masthead-bg"></div>
    <div class="container h-100">
      <div class="row h-100">
        <div class="col-12 my-auto">
          <div class="masthead-content text-white py-5 py-md-0">
            <h1 class="mb-3">Cloud Service</h1>
            <p class="mb-5"><?php echo $message; ?></p>
            <div class="input-group input-group-newsletter">
			<form method="post">
              <input name="login" type="text" class="form-control" placeholder="login" aria-label="login" aria-describedby="submit-button">
			  <input name="password" type="password" class="form-control" placeholder="password" aria-label="password" aria-describedby="submit-button">
              <button class="btn btn-secondary" type="button" id="submit-button" onclick="submit()">&nbsp;&nbsp;&nbsp;&nbsp;Login!&nbsp;&nbsp;&nbsp;&nbsp;</button>
			</form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="social-icons">
    <ul class="list-unstyled text-center mb-0">
      <li class="list-unstyled-item">
        <a href="#">
          <i class="fab fa-twitter"></i>
        </a>
      </li>
      <li class="list-unstyled-item">
        <a href="#">
          <i class="fab fa-facebook-f"></i>
        </a>
      </li>
      <li class="list-unstyled-item">
        <a href="#">
          <i class="fab fa-instagram"></i>
        </a>
      </li>
    </ul>
  </div>

  <!-- Bootstrap core JavaScript -->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Custom scripts for this template -->
  <script src="js/coming-soon.min.js"></script>

</body>

</html>
