--- /dev/null
+<?php
+error_reporting(E_ALL);
+$root = $_SERVER['DOCUMENT_ROOT'];
+$kind = array_key_exists('kind', $_POST) ? $_POST['kind'] : 'youtube';
+$template = array_key_exists('template', $_POST) ? htmlentities($_POST['template']) : loadFile("$kind.html");
+$csv = array_key_exists('csv', $_POST) ? htmlentities($_POST['csv']) : loadFile("$kind.csv");
+$result = array_key_exists('result', $_POST) ? htmlentities($_POST['result']) : '';
+
+$mode = array_key_exists('mode', $_POST) ? htmlentities($_POST['mode']) : '';
+if (array_key_exists('mode', $_GET)){
+ $mode = $_GET['mode'];
+}
+if ($mode === ''){
+ $mode = 'main';
+}
+$yt_select = '';
+switch($kind){
+case 'youtube':
+ $yt_select = ' select="select"';
+ break;
+default:
+ break;
+}
+$body = "<html><body><pre>Mode: '$mode'</pre></body></html>";
+$result = '';
+if ($mode === 'main'){
+ if (array_key_exists('convert', $_POST)) {
+ $result = convert($template, $csv);
+ } elseif (array_key_exists('save_template', $_POST)) {
+ saveFile("$kind.html", $_POST['template']);
+ } elseif (array_key_exists('save_csv', $_POST)) {
+ saveFile("$kind.csv", $_POST['csv']);
+ } elseif (array_key_exists('upload', $_POST)){
+ $mode = 'upload';
+ }
+ $body = "
+<html>
+<body>
+<form action=\"emastool.php\" method=\"post\">
+<select name=\"kind\">
+<option value=\"youtube\"$yt_select>Youtube</option>
+</select>
+<input type=\"hidden\" name=\"mode\" value=\"$mode\" />
+<p>Vorlage: <button name=\"save_template\">Speichern</button></p>
+<textarea name=\"template\" rows=\"5\" cols=\"80\">$template
+</textArea>
+<p>CSV-Daten: <button name=\"save_csv\">Speichern</button></p>
+<textarea name=\"csv\" rows=\"5\" cols=\"80\">$csv
+</textArea>
+<p><button name=\"convert\">Konvertieren</button>
+</p>
+<p>Ergebnis:</p>
+<textarea name=\"result\" rows=\"15\" cols=\"80\">$result
+</textArea>
+</form>
+</body>
+</html>
+";
+} elseif ($mode === 'upload') {
+ $info = '';
+ if (array_key_exists('toShell', $_POST)) {
+ $mode = "main";
+ } elseif (array_key_exists('select', $_FILES)) {
+ $tempName = $_FILES['select']['tmp_name'];
+ $nodeName = $_FILES['select']['name'];
+ $error = $_FILES['select']['error'];
+ $size = $_FILES['select']['size'];
+ rename($tempName, $tempDir . '/' . $nodeName);
+ if (! file_exists($tempDir)){
+ mkdir($tempDir);
+ }
+ $list = scandir($tempDir);
+ $files = implode("\n", $list);
+ $info = "<h1>Hochladeinfo</h1>
+<p>TempName: $tempName<br/>
+Name: $nodeName<br/>
+Größe: $size<br/>
+Fehler: $error<br/>
+</p>
+<h1>Temp-Verzeichnis $tempDir</h1>
+<pre>$files</pre>
+";
+ }
+ $body = "
+<html>
+<body>
+<form enctype=\"multipart/form-data\" action=\"emastool.php\" method=\"post\">
+<p><a href=\"emastool.php?mode=shell\">Gehe zur Shell</a>
+</p>
+<input type=\"hidden\" name=\"mode\" value=\"$mode\" />
+<p>Eingabe:</p>
+<input type=\"file\" name=\"select\" />
+<p><button name=\"doit\">Hochladen</button>
+</p>
+$info
+</form>
+</body>
+</html>
+";
+}
+print $body;
+
+function saveFile(string $name, string $content){
+ global $root;
+ $fn = "$root/data/$name";
+ file_put_contents($fn, $content);
+}
+function loadFile(string $name): string{
+ global $root;
+ $fn = "$root/data/$name";
+ $rc = file_get_contents($fn);
+ return $rc;
+}
+function convert(string $template, string $csv): string {
+ $rc = '';
+ $data = explode("\n", $csv);
+ if (count($data) > 1){
+ $headers = explode(';', trim($data[0]));
+ unset($data[0]);
+ foreach ($data as $line){
+ if ( ($line = trim($line)) === ''){
+ continue;
+ }
+ $cols = explode(';', $line);
+ $item = $template;
+ for ($ix = 0; $ix < count($cols); $ix++){
+ if ($ix >= count($headers)){
+ continue;
+ }
+ $name = $headers[$ix];
+ $item = str_replace("#$name#", $cols[$ix], $item);
+ }
+ $rc .= $item . "\n";
+ }
+ }
+ return $rc;
+}
\ No newline at end of file
--- /dev/null
+<?php
+error_reporting(E_ALL);
+$content = array_key_exists('input', $_POST) ? htmlentities($_POST['input']) : '';
+$content2 = array_key_exists('output', $_POST) ? htmlentities($_POST['output']) : '';
+;
+$root = $_SERVER['DOCUMENT_ROOT'];
+$tempDir = $root . '/temp';
+$notes = array_key_exists('notes', $_POST) ? htmlentities($_POST['notes']) : '';
+$mode = array_key_exists('mode', $_POST) ? htmlentities($_POST['mode']) : '';
+if (array_key_exists('mode', $_GET)){
+ $mode = $_GET['mode'];
+}
+if ($mode === ''){
+ $mode = 'shell';
+}
+$body = "<html><body><pre>Mode: '$mode'</pre></body></html>";
+if ($mode === 'shell'){
+ if (array_key_exists('doit', $_POST)) {
+ $content2 = html_entity_decode($content);
+ $fn = '/tmp/nanoshell.task';
+ $fn2 = '/tmp/nanoshell.out';
+ file_put_contents($fn, trim($content2));
+ $out = '';
+ $cmd = "/bin/bash $fn >$fn2 2>&1";
+ file_put_contents("/tmp/cmd.txt", $cmd);
+ exec($cmd, $out);
+ $content2 = file_get_contents($fn2);
+ // $content2 = ''.join($out).trim();
+ } elseif (array_key_exists('info', $_POST)) {
+ $content2 = '';
+ foreach ($_SERVER as $entry) {
+ $content2 .= $entry . ': ' . $_SERVER[$entry] . "\n";
+ }
+ } elseif (array_key_exists('upload', $_POST)){
+ $mode = 'upload';
+ }
+ $body = "
+<html>
+<body>
+<form action=\"nanoshell.php\" method=\"post\">
+<p><a href=\"nanoshell.php?mode=upload\">Gehe zu Hochladen</a>
+</p>
+<input type=\"hidden\" name=\"mode\" value=\"$mode\" />
+<p>Eingabe:</p>
+<textarea name=\"input\" rows=\"5\" cols=\"80\">$content
+</textArea>
+<p><button name=\"doit\">Run</button>
+<button name=\"info\">Info</button>
+</p>
+<p>Ergebnis:</p>
+<textarea name=\"output\" rows=\"15\" cols=\"80\">$content2
+</textArea>
+<p>Merkzettel:</p>
+<textarea name=\"notes\" rows=\"5\" cols=\"80\">$notes
+</textArea>
+</form>
+</body>
+</html>
+";
+} elseif ($mode === 'upload') {
+ $info = '';
+ if (array_key_exists('toShell', $_POST)) {
+ $mode = "shell";
+ } elseif (array_key_exists('select', $_FILES)) {
+ $tempName = $_FILES['select']['tmp_name'];
+ $nodeName = $_FILES['select']['name'];
+ $error = $_FILES['select']['error'];
+ $size = $_FILES['select']['size'];
+ rename($tempName, $tempDir . '/' . $nodeName);
+ if (! file_exists($tempDir)){
+ mkdir($tempDir);
+ }
+ $list = scandir($tempDir);
+ $files = implode("\n", $list);
+ $info = "<h1>Hochladeinfo</h1>
+<p>TempName: $tempName<br/>
+Name: $nodeName<br/>
+Größe: $size<br/>
+Fehler: $error<br/>
+</p>
+<h1>Temp-Verzeichnis $tempDir</h1>
+<pre>$files</pre>
+";
+ }
+ $body = "
+
+<html>
+<body>
+<form enctype=\"multipart/form-data\" action=\"nanoshell.php\" method=\"post\">
+<p><a href=\"nanoshell.php?mode=shell\">Gehe zur Shell</a>
+</p>
+<input type=\"hidden\" name=\"mode\" value=\"$mode\" />
+<p>Eingabe:</p>
+<input type=\"file\" name=\"select\" />
+<p><button name=\"doit\">Hochladen</button>
+</p>
+$info
+
+</form>
+</body>
+</html>
+";
+}
+print $body;