Upload via GUI (24 Dateien)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Einrichtungshilfe (nur Kommandozeile): php einrichten.php
|
||||
* Legt config.php an, setzt das Admin-Passwort und erzeugt auf Wunsch den Signierschlüssel.
|
||||
*/
|
||||
if (PHP_SAPI !== 'cli') { http_response_code(404); exit; }
|
||||
|
||||
function ask(string $q, string $default = ''): string
|
||||
{
|
||||
echo $q . ($default !== '' ? " [{$default}]" : '') . ': ';
|
||||
$a = trim((string) fgets(STDIN));
|
||||
return $a === '' ? $default : $a;
|
||||
}
|
||||
|
||||
$example = require __DIR__ . '/config.example.php';
|
||||
$file = __DIR__ . '/config.php';
|
||||
$cfg = is_file($file) ? (array) require $file : $example;
|
||||
|
||||
echo "Einrichtung der Plugin- und Theme-Webseite\n\n";
|
||||
$cfg['site_name'] = ask('Name der Webseite', (string) $cfg['site_name']);
|
||||
$cfg['base_url'] = rtrim(ask('Öffentliche Adresse (https://…)', (string) $cfg['base_url']), '/');
|
||||
if (!str_starts_with($cfg['base_url'], 'https://')) echo "HINWEIS: DeskHub lädt nur über https. Mit http:// funktioniert der Katalog nicht.\n";
|
||||
$cfg['admin_user'] = ask('Admin-Benutzername', (string) $cfg['admin_user']);
|
||||
$pw = ask('Neues Admin-Passwort (mindestens 12 Zeichen, leer = unverändert)');
|
||||
if ($pw !== '') {
|
||||
if (strlen($pw) < 12) { fwrite(STDERR, "Das Passwort ist zu kurz.\n"); exit(1); }
|
||||
$cfg['admin_password_hash'] = password_hash($pw, PASSWORD_DEFAULT);
|
||||
}
|
||||
if (empty($cfg['access_key'])) {
|
||||
$cfg['access_key'] = bin2hex(random_bytes(24));
|
||||
echo "Zugangsschlüssel für den Katalog erzeugt (DeskHub schickt ihn bei jedem Abruf mit).\n";
|
||||
}
|
||||
if ($cfg['signing_key_file'] === '' || !is_file($cfg['signing_key_file'])) {
|
||||
if (strtolower(ask('Signierschlüssel jetzt erzeugen? (j/n)', 'j')) === 'j') {
|
||||
$dir = ask('Ordner für den Schlüssel (außerhalb des Webverzeichnisses!)', dirname(__DIR__) . '/plugin-webseite-schluessel');
|
||||
if (!is_dir($dir) && !mkdir($dir, 0700, true)) { fwrite(STDERR, "Ordner konnte nicht angelegt werden.\n"); exit(1); }
|
||||
$cnf = tempnam(sys_get_temp_dir(), 'cnf');
|
||||
file_put_contents($cnf, "[req]\ndistinguished_name=req_dn\n[req_dn]\n");
|
||||
$key = openssl_pkey_new(['config' => $cnf, 'private_key_bits' => 3072, 'private_key_type' => OPENSSL_KEYTYPE_RSA]);
|
||||
if (!$key) { fwrite(STDERR, "Schlüssel konnte nicht erzeugt werden.\n"); exit(1); }
|
||||
openssl_pkey_export($key, $private, null, ['config' => $cnf]);
|
||||
file_put_contents($dir . '/herausgeber-privat.pem', $private);
|
||||
@chmod($dir . '/herausgeber-privat.pem', 0600);
|
||||
file_put_contents($dir . '/herausgeber-oeffentlich.pem', openssl_pkey_get_details($key)['key']);
|
||||
$cfg['signing_key_file'] = realpath($dir) . DIRECTORY_SEPARATOR . 'herausgeber-privat.pem';
|
||||
echo "Schlüssel erzeugt in {$dir}. Den privaten Schlüssel SICHERN und niemals weitergeben.\n";
|
||||
}
|
||||
}
|
||||
file_put_contents($file, "<?php\nreturn " . var_export($cfg, true) . ";\n");
|
||||
@chmod($file, 0640);
|
||||
echo "\nconfig.php geschrieben. Verwaltung: {$cfg['base_url']}/admin.php\n";
|
||||
if ($cfg['signing_key_file'] !== '' && is_file($cfg['signing_key_file'])) {
|
||||
putenv('PLUGIN_SITE_CONFIG=' . $file);
|
||||
require_once __DIR__ . '/inc/lib.php';
|
||||
echo "\n--- Inhalt für DeskHub: includes/catalog_defaults.php (vor dem Release eintragen) ---\n" . site_deskhub_defaults_snippet();
|
||||
}
|
||||
Reference in New Issue
Block a user