add com.daplie.walnut.init
This commit is contained in:
		
							parent
							
								
									58590737e2
								
							
						
					
					
						commit
						fbd5e48596
					
				
							
								
								
									
										6961
									
								
								lib/com.daplie.walnut.init/css/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6961
									
								
								lib/com.daplie.walnut.init/css/bootstrap.css
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										33
									
								
								lib/com.daplie.walnut.init/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								lib/com.daplie.walnut.init/index.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
  <title>WALNUT</title>
 | 
			
		||||
  <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />
 | 
			
		||||
</head>
 | 
			
		||||
<body class="container">
 | 
			
		||||
  <h1 class="header">Welcome to WALNUT</h1>
 | 
			
		||||
  <p class="lead">Your server has no security certificates.
 | 
			
		||||
  In order to continue we need to know what email address and domain the certificates should be issued to:
 | 
			
		||||
  </p>
 | 
			
		||||
  <form class="js-form-le">
 | 
			
		||||
    <div>
 | 
			
		||||
      <label>Device: <span class="js-devicename"></span></label>
 | 
			
		||||
      <pre><code class="js-inets"> </code></pre>
 | 
			
		||||
    </div>
 | 
			
		||||
    <label>Primary Domain:</label>
 | 
			
		||||
    <input class="js-domain form-control" type="text" placeholder="ex: example.com" required />
 | 
			
		||||
    <br>
 | 
			
		||||
    <label>Primary Email:</label>
 | 
			
		||||
    <input class="js-email form-control" type="email" placeholder="ex: john.doe@example.com" required />
 | 
			
		||||
    <br>
 | 
			
		||||
    <label>
 | 
			
		||||
      <input class="js-agree-tos" type="checkbox" required /> Agree to the
 | 
			
		||||
        <a href="https://letsencrypt.org/repository/">Let's Encrypt Subscriber Agreement</a>
 | 
			
		||||
    </label>
 | 
			
		||||
    <br>
 | 
			
		||||
    <button class="btn btn-primary" type="submit">Submit</button>
 | 
			
		||||
  </form>
 | 
			
		||||
  <script src="/js/jquery-2.2.2.js"></script>
 | 
			
		||||
  <script src="/js/index.js"></script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										110
									
								
								lib/com.daplie.walnut.init/js/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								lib/com.daplie.walnut.init/js/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,110 @@
 | 
			
		||||
$(function () {
 | 
			
		||||
  'use strict';
 | 
			
		||||
 | 
			
		||||
  var apiHostname = window.location.hostname.replace(/^www\./, '');
 | 
			
		||||
  var hostname = window.location.hostname.replace(/^www\./, '');
 | 
			
		||||
  var baseUrl;
 | 
			
		||||
 | 
			
		||||
  $.http = $.ajax;
 | 
			
		||||
  if (/[a-z]+/.test(apiHostname)) {
 | 
			
		||||
    apiHostname = 'api.' + apiHostname;
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    apiHostname = '';
 | 
			
		||||
  }
 | 
			
		||||
  baseUrl = window.location.protocol.replace(/:$/, '')
 | 
			
		||||
    + '://' + apiHostname
 | 
			
		||||
    + window.location.host.replace(/^www\./, '').replace(/.[^:]+(:(\d+))?/, '$2')
 | 
			
		||||
  ;
 | 
			
		||||
 | 
			
		||||
  function readConfig() {
 | 
			
		||||
    $('input.js-domain').val(hostname);
 | 
			
		||||
 | 
			
		||||
    return $.http({
 | 
			
		||||
      method: 'GET'
 | 
			
		||||
    , url: baseUrl + '/api/com.daplie.walnut.init'
 | 
			
		||||
    , headers: {
 | 
			
		||||
        "Accept" : "application/json; charset=utf-8"
 | 
			
		||||
      }
 | 
			
		||||
    }).then(function (results) {
 | 
			
		||||
      results.le = results.le || {};
 | 
			
		||||
      $('input.js-agree-tos').prop('checked', results.le.agreeTos);
 | 
			
		||||
      $('input.js-email').val(results.le.email || results.email);
 | 
			
		||||
      $('.js-devicename').text(results.hostname);
 | 
			
		||||
      $('.js-inets').text(
 | 
			
		||||
        results.inets.map(function (a) {
 | 
			
		||||
          return 'IPv' + a.family + ' ' + a.address;
 | 
			
		||||
        }).join('\n')
 | 
			
		||||
        + '\n\n'
 | 
			
		||||
        + '# set this device to your account\n'
 | 
			
		||||
        + "daplie devices:set -d '" + results.hostname + "'"
 | 
			
		||||
          + " -a '" + results.inets.map(function (a) { return a.address; }).join() + "'\n"
 | 
			
		||||
        + '\n'
 | 
			
		||||
        + '# attach this device to the necessary subdomains\n'
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n '" + ($('input.js-domain').val() || '<<domainname>>') + "'\n"
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n 'www." + ($('input.js-domain').val() || '<<domainname>>') + "'\n"
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n 'api." + ($('input.js-domain').val() || '<<domainname>>') + "'\n"
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n 'assets." + ($('input.js-domain').val() || '<<domainname>>') + "'\n"
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n 'cloud." + ($('input.js-domain').val() || '<<domainname>>') + "'\n"
 | 
			
		||||
        + "daplie devices:attach -d '" + results.hostname + "'"
 | 
			
		||||
          + " -n 'api.cloud." + ($('input.js-domain').val() || '<<domainname>>') + "'"
 | 
			
		||||
      );
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  readConfig();
 | 
			
		||||
 | 
			
		||||
  $('body').on('submit', 'form.js-form-le', function (ev) {
 | 
			
		||||
    ev.preventDefault();
 | 
			
		||||
 | 
			
		||||
    var data = {
 | 
			
		||||
      domain: $('input.js-domain').val()
 | 
			
		||||
    , email: $('input.js-email').val()
 | 
			
		||||
    , agreeTos: $('input.js-agree-tos').prop('checked')
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if (!data.domain) {
 | 
			
		||||
      window.alert("Please enter the primary domain of this device.");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!data.email) {
 | 
			
		||||
      window.alert("Please enter the email of the owner of this device.");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    if (!data.agreeTos) {
 | 
			
		||||
      window.alert("Please click to agree to the Let's Encrypt Subscriber Agreement. This server cannot function without encryption. Currently you must use Let's Encrypt. In the future we will enable other options.");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    $.http({
 | 
			
		||||
      method: 'POST'
 | 
			
		||||
    , url: baseUrl + '/api/com.daplie.walnut.init'
 | 
			
		||||
    , headers: {
 | 
			
		||||
        "Accept" : "application/json; charset=utf-8"
 | 
			
		||||
      , "Content-Type": "application/json; charset=utf-8"
 | 
			
		||||
      }
 | 
			
		||||
    , data: JSON.stringify(data)
 | 
			
		||||
    }).then(function (data) {
 | 
			
		||||
      var d;
 | 
			
		||||
      if (data.error) {
 | 
			
		||||
        d = $.Deferred();
 | 
			
		||||
        d.reject(new Error(data.error.message));
 | 
			
		||||
        return d.promise();
 | 
			
		||||
      }
 | 
			
		||||
      return data;
 | 
			
		||||
    }).then(function (data) {
 | 
			
		||||
      console.log('Result:');
 | 
			
		||||
      console.log(data);
 | 
			
		||||
      window.alert('Hoo hoo! That tickles! ' + JSON.stringify(data));
 | 
			
		||||
    }, function (err) {
 | 
			
		||||
      console.error('Error POSTing form:');
 | 
			
		||||
      console.error(err);
 | 
			
		||||
      window.alert("Check the console! There's a big, fat error!");
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										9842
									
								
								lib/com.daplie.walnut.init/js/jquery-2.2.2.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										9842
									
								
								lib/com.daplie.walnut.init/js/jquery-2.2.2.js
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user