Stuff that was not staged
This commit is contained in:
parent
baf3cfd510
commit
77b77a3c70
20
default.php
Normal file
20
default.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
$title = 'Machines';
|
||||||
|
$longTitle = 'Gestion des machines';
|
||||||
|
include('../header.inc.php');
|
||||||
|
?>
|
||||||
|
<p>Voici le composant serveur de mon projet « Machines », qui me permet d'améliorer la sécurité des ordinateurs et serveurs sur lequel j'ai un accès en définissant des règles d'autorisation de connexion avec une clef SSH par machine, tout en facilitant la connexion aux machines par la génération automatique de fichiers de configuration SSH.</p>
|
||||||
|
<p>Bien que ce domaine ne soit pas d'une grande utilité pour vous, vous pouvez étudier le code si vous le désirez :
|
||||||
|
<ul class="fa-ul" >
|
||||||
|
<li><a href="https://git.frogeye.fr/geoffrey/dotfiles/src/master/scripts/machines.sh"><i class="fa fa-li fa-git"></i> Composante client</a></li>
|
||||||
|
<li>
|
||||||
|
<i class="fa fa-li fa-lock"></i>
|
||||||
|
Composante serveur <br/>
|
||||||
|
<em>(pas encore ouverte pour des raisons de sécurité)</em>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
|
<p>Malheureusement, comme la plupart des projets que je réalise pour moi-même, le code n'est pas très bien commenté, cela est notamment dû au manque d'objectif précis et de cahier des charges lors de la rédaction du code. Cependant, si vous êtes interessés par le système, <a href="mailto:geoffrey@frogeye.fr">dites-le moi</a> et je ferais un effort de clarification.</p>
|
||||||
|
<?php
|
||||||
|
include('../footer.inc.php');
|
||||||
|
?>
|
62
index.php
62
index.php
|
@ -4,10 +4,18 @@ require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
require_once('config.inc.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'], '/')), '/'));
|
$route = explode('/', trim(substr(explode('?', $_SERVER['REDIRECT_URL'])[0], strrpos($_SERVER['SCRIPT_NAME'], '/')), '/'));
|
||||||
$meth = $_SERVER['REQUEST_METHOD'];
|
$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+=\/]+/';
|
$SSH_KEY_REGEX = '/^(ssh-(rsa|ed25519|dss)|ecdsa-sha2-nistp256) [a-zA-Z0-9+=\/]+/';
|
||||||
|
|
||||||
$machineArgs = array(
|
$machineArgs = array(
|
||||||
|
@ -17,9 +25,15 @@ $machineArgs = array(
|
||||||
'repeatable' => false,
|
'repeatable' => false,
|
||||||
'optional' => false
|
'optional' => false
|
||||||
),
|
),
|
||||||
'host' => array(
|
'host' => array( # DEPRECATED
|
||||||
'type' => 'string',
|
'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,
|
'repeatable' => true,
|
||||||
'optional' => true
|
'optional' => true
|
||||||
),
|
),
|
||||||
|
@ -185,6 +199,8 @@ function load($elname) {
|
||||||
return unserialize(file_get_contents($elname.'.ser.db'));
|
return unserialize(file_get_contents($elname.'.ser.db'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get keys that can be used to connect
|
||||||
|
// to the network
|
||||||
function getKeys($network) {
|
function getKeys($network) {
|
||||||
global $SSH_KEY_REGEX;
|
global $SSH_KEY_REGEX;
|
||||||
global $DOMAIN;
|
global $DOMAIN;
|
||||||
|
@ -368,6 +384,7 @@ function updateGitKeys($api, $keys) {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($toDelete as $id => $ekey) {
|
foreach ($toDelete as $id => $ekey) {
|
||||||
|
echo "387 deleting $id $ekey\n";
|
||||||
apiRequest($api, 'user/keys/'.$id, 'DELETE');
|
apiRequest($api, 'user/keys/'.$id, 'DELETE');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -506,8 +523,9 @@ case 'network':
|
||||||
} elseif (count($route) == 2 && $meth == 'DELETE') {
|
} elseif (count($route) == 2 && $meth == 'DELETE') {
|
||||||
requireSigned();
|
requireSigned();
|
||||||
$elements = load($elname);
|
$elements = load($elname);
|
||||||
if (isset($elements[$route[1]])) {
|
$name = $route[1];
|
||||||
unset($elements[$route[1]]);
|
if (isset($elements[$name])) {
|
||||||
|
unset($elements[$name]);
|
||||||
save($elname, $elements);
|
save($elname, $elements);
|
||||||
http_response_code(204);
|
http_response_code(204);
|
||||||
logActivity("Removed $elname \"$name\"");
|
logActivity("Removed $elname \"$name\"");
|
||||||
|
@ -590,6 +608,40 @@ case 'akey':
|
||||||
}
|
}
|
||||||
break;
|
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
|
// Activity log
|
||||||
case 'log':
|
case 'log':
|
||||||
if (count($route) == 1 && $meth == 'GET') {
|
if (count($route) == 1 && $meth == 'GET') {
|
||||||
|
|
Reference in a new issue