Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
|
start [2025/12/06 17:30] jango |
start [2026/02/19 22:31] (aktuell) jango |
||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| < | < | ||
| - | // ===================== MINI BASIC (int-only) ===================== | + | param( |
| + | [string]$Url = " | ||
| + | [string]$Username | ||
| + | [string]$Password | ||
| + | [switch]$IgnoreCertErrors | ||
| + | ) | ||
| - | #define BASIC_MAX_LINES 64 | + | [Net.ServicePointManager]:: |
| - | #define BASIC_LINE_LEN | + | if ($IgnoreCertErrors) { [System.Net.ServicePointManager]:: |
| - | typedef struct { | + | function New-BasicAuthValue([string]$User,[string]$Pass){ |
| - | uint16 line_no; | + | |
| - | uint8 used; | + | " |
| - | char text[BASIC_LINE_LEN]; | + | |
| - | } BasicLine; | + | |
| - | + | ||
| - | static BasicLine g_prog[BASIC_MAX_LINES]; | + | |
| - | static int g_vars[26]; // A..Z | + | |
| - | + | ||
| - | static void basic_reset_program(void) { | + | |
| - | for (int i = 0; i < BASIC_MAX_LINES; | + | |
| - | | + | |
| - | g_prog[i].line_no = 0; | + | |
| - | g_prog[i].text[0] = 0; | + | |
| - | } | + | |
| } | } | ||
| - | static void basic_reset_vars(void) { | + | $req = [System.Net.HttpWebRequest]:: |
| - | for (int i = 0; i < 26; i++) g_vars[i] | + | $req.Method |
| - | } | + | $req.AllowAutoRedirect |
| + | $req.Headers.Add(" | ||
| + | $req.UserAgent = " | ||
| - | static int is_space(char c) { return c == ' ' || c == ' | + | try { $resp = $req.GetResponse() } |
| + | catch [System.Net.WebException] | ||
| - | static char up(char c) { | + | if ($resp) { |
| - | | + | " |
| - | | + | " |
| + | " | ||
| + | | ||
| } | } | ||
| + | </ | ||
| - | static void skip_spaces(const char **p) { | + | < |
| - | while (**p && is_space(**p)) (*p)++; | + | param( |
| - | } | + | |
| + | [switch]$IgnoreCertErrors | ||
| + | ) | ||
| - | static int is_digit(char c) { return (c >= ' | + | [Net.ServicePointManager]:: |
| - | static int is_alpha(char c) { return (c >= ' | + | if ($IgnoreCertErrors) { [System.Net.ServicePointManager]:: |
| - | static int starts_with_kw(const char *s, const char *kw) { | + | $req = [System.Net.HttpWebRequest]::Create($Url) |
| - | // case-insensitive, | + | $req.Method |
| - | int i = 0; | + | $req.AllowAutoRedirect |
| - | while (kw[i]) { | + | |
| - | if (up(s[i]) != kw[i]) return 0; | + | |
| - | | + | |
| - | } | + | |
| - | char next = s[i]; | + | |
| - | | + | |
| - | } | + | |
| - | static uint16 parse_u16(const char **p) { | + | try { |
| - | | + | $resp = $req.GetResponse() |
| - | | + | } catch [System.Net.WebException] |
| - | while (is_digit(**p)) | + | |
| - | | + | |
| - | (*p)++; | + | |
| - | } | + | |
| - | return v; | + | |
| } | } | ||
| - | static int parse_int(const char **p) { | + | if ($resp) { |
| - | | + | " |
| - | int sign = 1; | + | " |
| - | if (**p == ' | + | |
| - | else if (**p == '-') { sign = -1; (*p)++; } | + | |
| - | + | } else { | |
| - | int v = 0; | + | " |
| - | while (is_digit(**p)) { | + | |
| - | v = v * 10 + (**p - ' | + | |
| - | (*p)++; | + | |
| - | } | + | |
| - | | + | |
| } | } | ||
| + | </ | ||
| - | static int find_line_index(uint16 line_no) { | + | <code> |
| - | for (int i = 0; i < BASIC_MAX_LINES; | + | PS C: |
| - | if (g_prog[i].used && g_prog[i].line_no == line_no) return i; | + | Target: https:// |
| - | } | + | User: |
| - | return | + | Count: |
| - | } | + | |
| - | static int find_free_slot(void) { | + | [13: |
| - | | + | [13: |
| - | | + | [13: |
| - | } | + | [13: |
| - | | + | [13:46:29.014] # 5 -> HTTP 401 (1147 ms) |
| - | } | + | [13: |
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| + | [13: | ||
| - | static int find_next_line_sorted(uint16 last_line, uint16 | + | PS C: |
| - | int found = 0; | + | </ |
| - | uint16 best = 0xFFFF; | + | Hallo Besucher! Willkommen in diesem kleinen Wiki rund um IT. Vieles ist noch **unvollständig, unstrukturiert oder vielleicht sogar falsch bzw. irreführend**. |
| - | int best_i = -1; | + | |
| - | for (int i = 0; i < BASIC_MAX_LINES; | + | Du kannst Artikel gerne [[todo|ergänzen oder verbessern]]. Gerne mit so vielen Links wie nötig. Bitte keine Werbelinks und nur selbst verfasste oder lizenzfreie Texte! Copyright beachten! |
| - | if (!g_prog[i].used) continue; | + | |
| - | uint16 ln = g_prog[i].line_no; | + | |
| - | if (ln > last_line && ln < best) { | + | |
| - | best = ln; | + | |
| - | best_i = i; | + | |
| - | found = 1; | + | |
| - | } | + | |
| - | } | + | |
| - | if (!found) return 0; | ||
| - | *out_line = best; | ||
| - | *out_idx = best_i; | ||
| - | return 1; | ||
| - | } | ||
| - | static void basic_store_line(uint16 line_no, const char *rest) { | + | =====Fehlende Verlinkungen===== |
| - | // rest: nach der Zeilennummer (inkl. leading spaces) | + | |
| - | // Wenn rest leer -> löschen | + | |
| - | const char *p = rest; | + | |
| - | skip_spaces(& | + | |
| - | int idx = find_line_index(line_no); | + | Eine Liste von Seiten die noch erstellt werden müssen. |
| - | if (*p == 0) { | + | ~~ORPHANSWANTED: |
| - | if (idx >= 0) g_prog[idx].used = 0; | + | |
| - | return; | + | |
| - | } | + | |
| - | if (idx < 0) { | ||
| - | idx = find_free_slot(); | ||
| - | if (idx < 0) { | ||
| - | print_new_line(); | ||
| - | print_string(" | ||
| - | return; | ||
| - | } | ||
| - | g_prog[idx].used = 1; | ||
| - | g_prog[idx].line_no = line_no; | ||
| - | } | ||
| - | // copy text, uppercase keywords funktionieren trotzdem case-insensitive | ||
| - | int j = 0; | ||
| - | while (*p && j < BASIC_LINE_LEN - 1) { | ||
| - | g_prog[idx].text[j++] = *p++; | ||
| - | } | ||
| - | g_prog[idx].text[j] = 0; | ||
| - | } | ||
| - | static void basic_list(void) { | + | <code powershell> |
| - | | + | <# |
| - | | + | PowerShell 5.1 – EAS Basic-Auth Test (sendet IMMER weiter, auch bei 429) |
| - | int idx; | + | |
| - | + | Optional: | |
| - | while (find_next_line_sorted(last, &ln, &idx)) { | + | - -IgnoreCertErrors (nur Test!) |
| - | | + | - -LogHeaders um X-EAS-FAIL / X-Blocked-By etc. zu sehen, falls du die in HAProxy setzt. |
| - | | + | #> |
| - | | + | |
| - | | + | param( |
| - | last = ln; | + | [string]$Url |
| - | | + | |
| + | | ||
| + | [int]$Count = 20, | ||
| + | | ||
| + | | ||
| + | [switch]$IgnoreCertErrors, | ||
| + | | ||
| + | ) | ||
| + | |||
| + | # TLS 1.2 erzwingen | ||
| + | [Net.ServicePointManager]:: | ||
| + | |||
| + | # Optional: Zertifikatsfehler ignorieren | ||
| + | if ($IgnoreCertErrors) { | ||
| + | [System.Net.ServicePointManager]:: | ||
| } | } | ||
| - | + | ||
| - | static void basic_error(const char *msg) { | + | function New-BasicAuthValue |
| - | | + | param([string]$User, |
| - | | + | $pair = "{0}:{1}" |
| - | | + | |
| + | return "Basic $b64" | ||
| } | } | ||
| - | + | ||
| - | // ---------- | + | $auth = New-BasicAuthValue |
| - | static int parse_expr(const char **p); // forward | + | |
| - | + | Write-Host (" | |
| - | static int parse_factor(const char **p) { | + | Write-Host (" |
| - | | + | Write-Host (" |
| - | + | Write-Host "" | |
| - | | + | |
| - | | + | for ($i=1; $i -le $Count; $i++) { |
| - | | + | $sw = [Diagnostics.Stopwatch]:: |
| - | + | $code = -1 | |
| - | | + | |
| - | | + | $h = @{} |
| - | | + | |
| - | | + | try { |
| - | | + | |
| - | else basic_error(" | + | |
| - | return v; | + | |
| + | | ||
| + | $req.ReadWriteTimeout | ||
| + | | ||
| + | $req.Headers.Add(" | ||
| + | $req.Headers.Add("MS-ASProtocolVersion", | ||
| + | |||
| + | | ||
| + | $code = [int]$resp.StatusCode | ||
| + | if ($LogHeaders) { | ||
| + | | ||
| } | } | ||
| - | + | $resp.Close() | |
| - | // variable | + | } |
| - | if (is_alpha(**p)) { | + | catch [System.Net.WebException] { |
| - | char c = up(**p); | + | if ($_.Exception.Response) { |
| - | (*p)++; | + | |
| - | | + | $code = [int]$resp.StatusCode |
| - | | + | if ($LogHeaders) { |
| + | | ||
| + | } | ||
| + | $resp.Close() | ||
| + | } else { | ||
| + | $err = $_.Exception.Message | ||
| } | } | ||
| - | + | } | |
| - | | + | catch { |
| - | if (is_digit(**p)) { | + | |
| - | | + | } |
| + | |||
| + | $sw.Stop() | ||
| + | $ts = (Get-Date).ToString(" | ||
| + | |||
| + | if ($code -eq -1) { | ||
| + | Write-Host (" | ||
| + | } else { | ||
| + | if ($LogHeaders) { | ||
| + | $xFail = $h[" | ||
| + | $xBlk = $h[" | ||
| + | $extra = @() | ||
| + | if ($xFail) { $extra += (" | ||
| + | | ||
| + | $suffix = "" | ||
| + | if ($extra.Count -gt 0) { $suffix = " | ||
| + | Write-Host (" | ||
| + | } else { | ||
| + | Write-Host (" | ||
| } | } | ||
| - | + | | |
| - | basic_error(" | + | |
| - | return 0; | + | |
| - | } | + | |
| - | + | ||
| - | static int parse_term(const char **p) { | + | |
| - | int v = parse_factor(p); | + | |
| - | for (;;) { | + | |
| - | skip_spaces(p); | + | |
| - | if (**p == ' | + | |
| - | else if (**p == '/' | + | |
| - | (*p)++; | + | |
| - | int d = parse_factor(p); | + | |
| - | if (d == 0) { basic_error(" | + | |
| - | v = v / d; | + | |
| - | } else break; | + | |
| - | } | + | |
| - | return v; | + | |
| - | } | + | |
| - | + | ||
| - | static int parse_expr(const char **p) { | + | |
| - | int v = parse_term(p); | + | |
| - | for (;;) { | + | |
| - | skip_spaces(p); | + | |
| - | if (**p == ' | + | |
| - | else if (**p == ' | + | |
| - | else break; | + | |
| - | } | + | |
| - | return v; | + | |
| - | } | + | |
| - | + | ||
| - | static int parse_relop(const char **p, const char **out_op) { | + | |
| - | skip_spaces(p); | + | |
| - | // supported: =, <, >, <=, >=, <> | + | |
| - | if (**p == ' | + | |
| - | if (**p == '<' | + | |
| - | (*p)++; | + | |
| - | if (**p == ' | + | |
| - | if (**p == '>' | + | |
| - | *out_op = "<"; | + | |
| - | } | + | |
| - | if (**p == '>' | + | |
| - | (*p)++; | + | |
| - | if (**p == ' | + | |
| - | *out_op = ">"; | + | |
| - | } | + | |
| - | return 0; | + | |
| - | } | + | |
| - | + | ||
| - | static int eval_relation(int a, int b, const char *op) { | + | |
| - | if (op[0] == ' | + | |
| - | if (op[0] == '<' | + | |
| - | if (op[0] == '>' | + | |
| - | if (op[0] == '<' | + | |
| - | if (op[0] == '>' | + | |
| - | if (op[0] == '<' | + | |
| - | return 0; | + | |
| - | } | + | |
| - | + | ||
| - | // ---------- Statement execution ---------- | + | |
| - | static int basic_exec_stmt(const char *line, uint16 *pc_line /*in/out*/, int *stop /*out*/) { | + | |
| - | const char *p = line; | + | |
| - | skip_spaces(& | + | |
| - | + | ||
| - | if (*p == 0) return 1; | + | |
| - | + | ||
| - | // REM | + | |
| - | if (starts_with_kw(p, | + | |
| - | + | ||
| - | // END | + | |
| - | if (starts_with_kw(p, | + | |
| - | + | ||
| - | + | ||
| - | if (starts_with_kw(p, | + | |
| - | p += 5; | + | |
| - | skip_spaces(& | + | |
| - | + | ||
| - | // PRINT " | + | |
| - | if (*p == '"' | + | |
| - | p++; | + | |
| - | print_new_line(); | + | |
| - | while (*p && *p != '"' | + | |
| - | print_char(*p++); | + | |
| - | } | + | |
| - | if (*p == '"' | + | |
| - | return 1; | + | |
| - | } | + | |
| - | + | ||
| - | // PRINT expr | + | |
| - | int v = parse_expr(& | + | |
| - | print_new_line(); | + | |
| - | print_int(v); | + | |
| - | return 1; | + | |
| - | } | + | |
| - | + | ||
| - | // LET (optional) | + | |
| - | if (starts_with_kw(p, | + | |
| - | p += 3; | + | |
| - | skip_spaces(& | + | |
| - | } | + | |
| - | + | ||
| - | // IF expr rel expr THEN line | + | |
| - | if (starts_with_kw(p, | + | |
| - | p += 2; | + | |
| - | int left = parse_expr(& | + | |
| - | + | ||
| - | const char *op = 0; | + | |
| - | if (!parse_relop(& | + | |
| - | + | ||
| - | int right = parse_expr(& | + | |
| - | + | ||
| - | skip_spaces(& | + | |
| - | if (!starts_with_kw(p, | + | |
| - | p += 4; | + | |
| - | + | ||
| - | uint16 target = parse_u16(& | + | |
| - | if (target == 0) { basic_error(" | + | |
| - | + | ||
| - | if (eval_relation(left, | + | |
| - | *pc_line = (uint16)(target - 1); // Trick: RUN loop nimmt "next > pc_line" | + | |
| - | } | + | |
| - | return 1; | + | |
| - | } | + | |
| - | + | ||
| - | // GOTO line | + | |
| - | if (starts_with_kw(p, | + | |
| - | p += 4; | + | |
| - | uint16 target = parse_u16(& | + | |
| - | if (target == 0) { basic_error(" | + | |
| - | *pc_line = (uint16)(target - 1); | + | |
| - | return 1; | + | |
| - | } | + | |
| - | + | ||
| - | // Assignment: A = expr | + | |
| - | if (is_alpha(*p)) { | + | |
| - | char vname = up(*p++); | + | |
| - | if (vname < ' | + | |
| - | skip_spaces(& | + | |
| - | if (*p != ' | + | |
| - | p++; | + | |
| - | int value = parse_expr(& | + | |
| - | g_vars[vname - ' | + | |
| - | return 1; | + | |
| - | } | + | |
| - | + | ||
| - | basic_error(" | + | |
| - | return 0; | + | |
| - | } | + | |
| - | + | ||
| - | static void basic_run(void) { | + | |
| - | uint16 pc = 0; // last executed line_no (for sorted iteration) | + | |
| - | int stop = 0; | + | |
| - | + | ||
| - | // Start at " | + | |
| - | pc = 0; | + | |
| - | + | ||
| - | while (!stop) { | + | |
| - | uint16 ln; | + | |
| - | int idx; | + | |
| - | if (!find_next_line_sorted(pc, | + | |
| - | + | ||
| - | // execute | + | |
| - | uint16 pc_before = ln; | + | |
| - | uint16 pc_line = ln; | + | |
| - | basic_exec_stmt(g_prog[idx].text, | + | |
| - | + | ||
| - | // pc_line may be changed by GOTO/IF | + | |
| - | pc = pc_line; | + | |
| - | + | ||
| - | // normal case: move to next after current | + | |
| - | if (pc == pc_before) pc = ln; | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | // ---------- REPL line handler ---------- | + | |
| - | static void basic_repl_line(const char *input) { | + | |
| - | const char *p = input; | + | |
| - | skip_spaces(& | + | |
| - | if (*p == 0) return; | + | |
| - | + | ||
| - | // line starts with number? -> program line | + | |
| - | if (is_digit(*p)) { | + | |
| - | uint16 ln = parse_u16(& | + | |
| - | basic_store_line(ln, | + | |
| - | return; | + | |
| - | } | + | |
| - | + | ||
| - | // Immediate commands | + | |
| - | if (starts_with_kw(p, | + | |
| - | if (starts_with_kw(p, | + | |
| - | if (starts_with_kw(p, | + | |
| - | + | ||
| - | // keep your old shell commands too: | + | |
| - | if (starts_with_kw(p, | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | print_new_line(); | + | |
| - | print_string(" | + | |
| - | return; | + | |
| - | } | + | |
| - | + | ||
| - | if (starts_with_kw(p, | + | |
| - | + | ||
| - | // Otherwise: treat as immediate BASIC statement (PRINT/ | + | |
| - | uint16 dummy = 0; | + | |
| - | int stop = 0; | + | |
| - | basic_exec_stmt(p, | + | |
| } | } | ||
| </ | </ | ||
| - | |||
| - | Hallo Besucher! Willkommen in diesem kleinen Wiki rund um IT. Vieles ist noch **unvollständig, | ||
| - | |||
| - | Du kannst Artikel gerne [[todo|ergänzen oder verbessern]]. Gerne mit so vielen Links wie nötig. Bitte keine Werbelinks und nur selbst verfasste oder lizenzfreie Texte! Copyright beachten! | ||
| - | |||
| - | |||
| - | =====Fehlende Verlinkungen===== | ||
| - | |||
| - | Eine Liste von Seiten die noch erstellt werden müssen. | ||
| - | |||
| - | ~~ORPHANSWANTED: | ||
| - | |||
| - | |||