Stuff that was not staged

This commit is contained in:
Geoffrey Frogeye 2019-04-22 20:09:01 +02:00
parent baf3cfd510
commit 77b77a3c70
2 changed files with 77 additions and 5 deletions

View file

@ -4,10 +4,18 @@ require __DIR__ . '/vendor/autoload.php';
require_once('config.inc.php');
if (!array_key_exists('REDIRECT_URL', $_SERVER) || rtrim($_SERVER['REDIRECT_URL'], '/') == '') {
include('default.php');
exit;
}
$route = explode('/', trim(substr(explode('?', $_SERVER['REDIRECT_URL'])[0], strrpos($_SERVER['SCRIPT_NAME'], '/')), '/'));
$meth = $_SERVER['REQUEST_METHOD'];
header('Content-Type: text/plain');
$DOMAIN_NAME_REGEX = '[a-zA-Z0-9\p{L}][a-zA-Z0-9\p{L}-\.]{1,61}[a-zA-Z0-9\p{L}]\.[a-zA-Z0-9\p{L}][a-zA-Z\p{L}-]*[a-zA-Z0-9\p{L}]+'; // From http://stackoverflow.com/a/38477788/2766106
// $FQDN_REGEX = '[a-zA-Z0-9\p{L}][a-zA-Z0-9\p{L}-\.]{1,61}[a-zA-Z0-9\p{L}]\.[a-zA-Z0-9\p{L}][a-zA-Z\p{L}-]*[a-zA-Z0-9\p{L}]+'; // From http://stackoverflow.com/a/38477788/2766106
$FQDN_REGEX = '.+'; // From http://stackoverflow.com/a/38477788/2766106
$IP4_REGEX = '/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}/'; // From http://stackoverflow.com/a/5284410
$SSH_KEY_REGEX = '/^(ssh-(rsa|ed25519|dss)|ecdsa-sha2-nistp256) [a-zA-Z0-9+=\/]+/';
$machineArgs = array(
@ -17,9 +25,15 @@ $machineArgs = array(
'repeatable' => false,
'optional' => false
),
'host' => array(
'host' => array( # DEPRECATED
'type' => 'string',
'pattern' => '/^'.$DOMAIN_NAME_REGEX.'(:\d+)?$/',
'pattern' => '/^'.$FQDN_REGEX.'(:\d+)?$/',
'repeatable' => true,
'optional' => true
),
'extIp4' => array(
'type' => 'string',
'pattern' => '/^'.$FQDN_REGEX.'(:\d+)?$/',
'repeatable' => true,
'optional' => true
),
@ -185,6 +199,8 @@ function load($elname) {
return unserialize(file_get_contents($elname.'.ser.db'));
}
// Get keys that can be used to connect
// to the network
function getKeys($network) {
global $SSH_KEY_REGEX;
global $DOMAIN;
@ -368,6 +384,7 @@ function updateGitKeys($api, $keys) {
}
foreach ($toDelete as $id => $ekey) {
echo "387 deleting $id $ekey\n";
apiRequest($api, 'user/keys/'.$id, 'DELETE');
}
}
@ -506,8 +523,9 @@ case 'network':
} elseif (count($route) == 2 && $meth == 'DELETE') {
requireSigned();
$elements = load($elname);
if (isset($elements[$route[1]])) {
unset($elements[$route[1]]);
$name = $route[1];
if (isset($elements[$name])) {
unset($elements[$name]);
save($elname, $elements);
http_response_code(204);
logActivity("Removed $elname \"$name\"");
@ -590,6 +608,40 @@ case 'akey':
}
break;
// Authorized keys for networks
case 'config':
// GET /config/{machine}
if (count($route) == 2 && $meth == 'GET') {
$machineName = $route[1];
$machines = load('machine');
$networks = load('network');
if (isset($machines[$machineName])) {
$machine = $machines[$machineName];
if (!isset($machine['network']) || !isset($networks[$machine['network']])) {
break;
}
$network = $network[$machine['network']];
foreach ($machines as $dMachineName => $dMachine) {
if ($network['secure'] == 'true') {
}
}
var_dump($machine);
} else {
http_response_code(404);
die("Unknown machine\n");
}
} else {
http_response_code(501);
die("Unkown route\n");
}
break;
// Activity log
case 'log':
if (count($route) == 1 && $meth == 'GET') {