Benutzer-Werkzeuge

Webseiten-Werkzeuge


start

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

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:
 <code> <code>
-// ===================== MINI BASIC (int-only=====================+param( 
 +  [string]$Url = "https://mail.deinedomain.tld/owa/", 
 +  [string]$Username "DOMAIN\user", 
 +  [string]$Password "secret", 
 +  [switch]$IgnoreCertErrors 
 +)
  
-#define BASIC_MAX_LINES 64 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
-#define BASIC_LINE_LEN  96+if ($IgnoreCertErrors) { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } }
  
-typedef struct { +function New-BasicAuthValue([string]$User,[string]$Pass){ 
-    uint16 line_no; +  $pair "{0}:{1}" -f $User,$Pass 
-    uint8  used; +  "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair))
-    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; i++) +
-        g_prog[i].used = 0; +
-        g_prog[i].line_no = 0; +
-        g_prog[i].text[0] = 0; +
-    }+
 } }
  
-static void basic_reset_vars(void{ +$req = [System.Net.HttpWebRequest]::Create($Url
-    for (int i 0; i < 26; i++) g_vars[i] 0; +$req.Method "GET" 
-}+$req.AllowAutoRedirect $false 
 +$req.Headers.Add("Authorization", (New-BasicAuthValue $Username $Password)) 
 +$req.UserAgent = "OWA-BasicTest/PS5.1"
  
-static int is_space(char c) { return c == ' ' || c ='\t'; }+try { $resp = $req.GetResponse() 
 +catch [System.Net.WebException] $resp $_.Exception.Response }
  
-static char up(char c) { +if ($resp) { 
-    if (c >= 'a' && c <= 'z'return (char)('a' + 'A'); +  "HTTP: {0}" -f ([int]$resp.StatusCode) 
-    return c;+  "Location: {0}" -f $resp.Headers["Location"
 +  "WWW-Authenticate: {0}" -f ($resp.Headers.GetValues("WWW-Authenticate") -join " | "
 +  $resp.Close()
 } }
 +</code>
  
-static void skip_spaces(const char **p) { +<code> 
-    while (**p && is_space(**p)) (*p)++; +param
-}+  [string]$Url = "https://mail.deinedomain.tld/owa/", 
 +  [switch]$IgnoreCertErrors 
 +)
  
-static int is_digit(char c) { return (c >'0' && c <= '9'); } +[Net.ServicePointManager]::SecurityProtocol [Net.SecurityProtocolType]::Tls12 
-static int is_alpha(char c) { return (c >'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); }+if ($IgnoreCertErrors) { [System.Net.ServicePointManager]::ServerCertificateValidationCallback { $true } }
  
-static int starts_with_kw(const char *s, const char *kw) { +$req = [System.Net.HttpWebRequest]::Create($Url
-    // case-insensitive, kw muss "Wortgrenze" haben (Ende oder Space) +$req.Method "GET" 
-    int i 0; +$req.AllowAutoRedirect $false
-    while (kw[i]) { +
-        if (up(s[i]!= kw[i]) return 0; +
-        i++; +
-    } +
-    char next s[i]; +
-    return (next == 0 || is_space(next)); +
-}+
  
-static uint16 parse_u16(const char **p) +try 
-    skip_spaces(p); +  $resp = $req.GetResponse() 
-    uint16 v = 0; +} catch [System.Net.WebException] 
-    while (is_digit(**p)) +  $resp $_.Exception.Response
-        (uint16)(v * 10 + (**p - '0')); +
-        (*p)++; +
-    } +
-    return v;+
 } }
  
-static int parse_int(const char **p) { +if ($resp) { 
-    skip_spaces(p); +  "HTTP: {0}-([int]$resp.StatusCode
-    int sign = 1; +  "WWW-Authenticate:" 
-    if (**p == '+'(*p)++; } +  $resp.Headers.GetValues("WWW-Authenticate"
-    else if (**p == '-') { sign = -1; (*p)++; } +  $resp.Close() 
- +else { 
-    int v = 0; +  "No response (TLS/DNS/Network issue)."
-    while (is_digit(**p)) { +
-        v = v * 10 + (**p '0'); +
-        (*p)++; +
-    +
-    return v * sign;+
 } }
 +</code>
  
-static int find_line_index(uint16 line_no) { +<code> 
-    for (int i = 0; i BASIC_MAX_LINES; i++) { +PS C:\Users\Manuel Zarat> C:\Users\Manuel Zarat\Desktop\eas.ps1 
-        if (g_prog[i].used && g_prog[i].line_no == line_no) return i; +Target: https://eas.akm.at/Microsoft-Server-ActiveSync 
-    } +User:   D2000\\jango.zarat 
-    return -1; +Count:  20  Delay: 100ms  Timeout: 10s
-}+
  
-static int find_free_slot(void{ +[13:46:23.900] #   1 -> HTTP 401 (1156 ms
-    for (int i = 0; i < BASIC_MAX_LINES; i++{ +[13:46:25.197] #   2 -> HTTP 401 (1187 ms
-        if (!g_prog[i].usedreturn i; +[13:46:26.485] #   3 -> HTTP 401 (1181 ms) 
-    } +[13:46:27.753#   4 -> HTTP 401 (1159 ms) 
-    return -1; +[13:46:29.014] #   5 -> HTTP 401 (1147 ms
-}+[13:46:30.271] #   6 -> HTTP 401 (1151 ms) 
 +[13:46:31.550] #   -> HTTP 401 (1161 ms) 
 +[13:46:32.821] #   8 -> HTTP 401 (1167 ms) 
 +[13:46:34.072] #   9 -> HTTP 401 (1141 ms) 
 +[13:46:35.328] #  10 -> HTTP 401 (1153 ms) 
 +[13:46:36.606] #  11 -> HTTP 401 (1168 ms) 
 +[13:46:37.876] #  12 -> HTTP 401 (1175 ms) 
 +[13:46:39.153] #  13 -> HTTP 401 (1151 ms) 
 +[13:46:40.395] #  14 -> HTTP 401 (1146 ms) 
 +[13:46:41.684] #  15 -> HTTP 401 (1188 ms) 
 +[13:46:42.964] #  16 -> HTTP 401 (1167 ms) 
 +[13:46:44.219] #  17 -> HTTP 401 (1162 ms) 
 +[13:46:45.651] #  18 -> HTTP 401 (1306 ms) 
 +[13:46:46.909] #  19 -> HTTP 401 (1156 ms) 
 +[13:46:48.180] #  20 -> HTTP 401 (1166 ms)
  
-static int find_next_line_sorted(uint16 last_line, uint16 *out_lineint *out_idx) { +PS C:\Users\Manuel Zarat> 
-    int found = 0; +</code> 
-    uint16 best = 0xFFFF; +Hallo Besucher! Willkommen in diesem kleinen Wiki rund um IT. Vieles ist noch **unvollständigunstrukturiert oder vielleicht sogar falsch bzw. irreführend**.
-    int best_i = -1;+
  
-    for (int i = 0; i < BASIC_MAX_LINES; i++) { +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(&p);+
  
-    int idx = find_line_index(line_no);+Eine Liste von Seiten die noch erstellt werden müssen.
  
-    if (*p == 0) { +~~ORPHANSWANTED:wanted~~
-        if (idx >= 0) g_prog[idx].used = 0; +
-        return; +
-    }+
  
-    if (idx < 0) { 
-        idx = find_free_slot(); 
-        if (idx < 0) { 
-            print_new_line(); 
-            print_string("BASIC: OUT OF PROGRAM SPACE"); 
-            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> 
-    uint16 last 0; +<# 
-    uint16 ln; +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!) 
-        print_new_line(); +- -LogHeaders um X-EAS-FAIL / X-Blocked-By etc. zu sehen, falls du die in HAProxy setzt. 
-        print_int((int)ln); +#> 
-        print_string(" "); +  
-        print_string(g_prog[idx].text); +param( 
-        last ln; +  [string]$Url "https://eas.akm.at/Microsoft-Server-ActiveSync", 
-    }+  [string]$Username = "D2000\\jango.zarat", 
 +  [string]$Password = "Lunikoff0310!", 
 +  [int]$Count = 20, 
 +  [int]$DelayMs = 100, 
 +  [int]$TimeoutSec = 10, 
 +  [switch]$IgnoreCertErrors
 +  [switch]$LogHeaders 
 +
 +  
 +# TLS 1.2 erzwingen 
 +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
 +  
 +# Optional: Zertifikatsfehler ignorieren (nur Tests
 +if ($IgnoreCertErrors{ 
 +  [System.Net.ServicePointManager]::ServerCertificateValidationCallback { $true }
 } }
- +  
-static void basic_error(const char *msg) +function New-BasicAuthValue 
-    print_new_line(); +  param([string]$User, [string]$Pass
-    print_string("BASIC ERROR: "); +  $pair = "{0}:{1}-f $User, $Pass 
-    print_string((char*)msg);+  $b64  = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($pair)) 
 +  return "Basic $b64"
 } }
- +  
-// ---------- Expression parser (recursive descent---------- +$auth = New-BasicAuthValue -User $Username -Pass $Password 
-static int parse_expr(const char **p); // forward +  
- +Write-Host ("Target: {0}" -f $Url) 
-static int parse_factor(const char **p) +Write-Host ("User:   {0}" -f $Username) 
-    skip_spaces(p); +Write-Host ("Count:  {0}  Delay: {1}ms  Timeout: {2}s" -f $Count, $DelayMs, $TimeoutSec) 
- +Write-Host "" 
-    // unary +  
-    if (**p == '+') { (*p)++; return parse_factor(p); } +for ($i=1; $i -le $Count; $i++{ 
-    if (**p == '-'(*p)++; return -parse_factor(p); } +  $sw = [Diagnostics.Stopwatch]::StartNew() 
- +  $code = -1 
-    if (**p ='('{ +  $err  = $null 
-        (*p)++; +  $h = @{} 
-        int v = parse_expr(p); +  
-        skip_spaces(p); +  try 
-        if (**p == ')') (*p)++; +    $req = [System.Net.HttpWebRequest]::Create($Url
-        else basic_error("MISSING )"); +    $req.Method = "GET" 
-        return v;+    $req.AllowAutoRedirect = $false 
 +    $req.Timeout = $TimeoutSec 1000 
 +    $req.ReadWriteTimeout $TimeoutSec 1000 
 +    $req.UserAgent "EAS-Test/PS5.1" 
 +    $req.Headers.Add("Authorization", $auth) 
 +    $req.Headers.Add("MS-ASProtocolVersion", "14.1"
 +  
 +    $resp $req.GetResponse() 
 +    $code = [int]$resp.StatusCode 
 +    if ($LogHeaders{ 
 +      foreach ($k in $resp.Headers.AllKeys{ $h[$k] = $resp.Headers[$k] }
     }     }
- +    $resp.Close() 
-    // variable +  } 
-    if (is_alpha(**p)) { +  catch [System.Net.WebException] { 
-        char c up(**p); +    if ($_.Exception.Response) { 
-        (*p)++; +      $resp $_.Exception.Response 
-        if (c >= 'A' && c <= 'Z'return g_vars[c - 'A']; +      $code = [int]$resp.StatusCode 
-        return 0;+      if ($LogHeaders{ 
 +        foreach ($k in $resp.Headers.AllKeys{ $h[$k= $resp.Headers[$k] } 
 +      } 
 +      $resp.Close() 
 +    } else { 
 +      $err = $_.Exception.Message
     }     }
- +  } 
-    // number +  catch { 
-    if (is_digit(**p)) { +    $err = $_.Exception.Message 
-        return parse_int(p);+  } 
 +  
 +  $sw.Stop() 
 +  $ts = (Get-Date).ToString("HH:mm:ss.fff"
 +  
 +  if ($code -eq -1) { 
 +    Write-Host ("[{0}] #{1,4} -> HTTP -1 ({2} ms) ERROR={3}" -f $ts, $i, $sw.ElapsedMilliseconds, $err) 
 +  } else { 
 +    if ($LogHeaders) { 
 +      $xFail = $h["X-EAS-FAIL"
 +      $xBlk  = $h["X-Blocked-By"
 +      $extra = @() 
 +      if ($xFail) { $extra += ("X-EAS-FAIL={0}" -f $xFail) } 
 +      if ($xBlk)  { $extra += ("X-Blocked-By={0}" -f $xBlk) } 
 +      $suffix = "" 
 +      if ($extra.Count -gt 0) { $suffix = "  " + ($extra -join "  ") } 
 +      Write-Host ("[{0}] #{1,4} -> HTTP {2} ({3} ms){4}" -f $ts, $i, $code, $sw.ElapsedMilliseconds, $suffix) 
 +    } else { 
 +      Write-Host ("[{0}] #{1,4} -> HTTP {2} ({3} ms)" -f $ts, $i, $code, $sw.ElapsedMilliseconds)
     }     }
- +  
-    basic_error("BAD FACTOR"); +  
-    return 0; +  # WICHTIGNICHT abbrechen bei 429 – weiter senden 
-+  Start-Sleep -Milliseconds $DelayMs
- +
-static int parse_term(const char **p) { +
-    int v = parse_factor(p); +
-    for (;;) { +
-        skip_spaces(p); +
-        if (**p == '*') { (*p)++; v = v * parse_factor(p);+
-        else if (**p == '/') { +
-            (*p)++; +
-            int d = parse_factor(p); +
-            if (d == 0) { basic_error("DIV BY ZERO"); return 0; } +
-            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 == '+') { (*p)++; v = v + parse_term(p);+
-        else if (**p == '-') { (*p)++; v = v - parse_term(p);+
-        else break; +
-    } +
-    return v; +
-+
- +
-static int parse_relop(const char **p, const char **out_op) { +
-    skip_spaces(p); +
-    // supported: =, <, >, <=, >=, <> +
-    if (**p == '=') { *out_op = "="; (*p)++; return 1; } +
-    if (**p == '<') { +
-        (*p)++; +
-        if (**p == '=') { *out_op = "<="; (*p)++; return 1; } +
-        if (**p == '>') { *out_op = "<>"; (*p)++; return 1; } +
-        *out_op = "<"; return 1; +
-    } +
-    if (**p == '>') { +
-        (*p)++; +
-        if (**p == '=') { *out_op = ">="; (*p)++; return 1; } +
-        *out_op = ">"; return 1; +
-    } +
-    return 0; +
-+
- +
-static int eval_relation(int a, int b, const char *op) { +
-    if (op[0] == '=' && op[1] == 0) return a == b; +
-    if (op[0] == '<' && op[1] == 0) return a < b; +
-    if (op[0] == '>' && op[1] == 0) return a > b; +
-    if (op[0] == '<' && op[1] == '=') return a <= b; +
-    if (op[0] == '>' && op[1] == '=') return a >= b; +
-    if (op[0] == '<' && op[1] == '>') return a != b; +
-    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(&p); +
- +
-    if (*p == 0) return 1; +
- +
-    // REM +
-    if (starts_with_kw(p, "REM")) return 1; +
- +
-    // END +
-    if (starts_with_kw(p, "END")) { *stop = 1; return 1; } +
- +
-    // PRINT +
-    if (starts_with_kw(p, "PRINT")) { +
-        p += 5; +
-        skip_spaces(&p); +
- +
-        // PRINT "TEXT" +
-        if (*p == '"') { +
-            p++; +
-            print_new_line(); +
-            while (*p && *p != '"') { +
-                print_char(*p++); +
-            } +
-            if (*p == '"') p++; +
-            return 1; +
-        } +
- +
-        // PRINT expr +
-        int v = parse_expr(&p); +
-        print_new_line(); +
-        print_int(v); +
-        return 1; +
-    } +
- +
-    // LET (optional) +
-    if (starts_with_kw(p, "LET")) { +
-        p += 3; +
-        skip_spaces(&p); +
-    } +
- +
-    // IF expr rel expr THEN line +
-    if (starts_with_kw(p, "IF")) { +
-        p += 2; +
-        int left = parse_expr(&p); +
- +
-        const char *op = 0; +
-        if (!parse_relop(&p, &op)) { basic_error("IF NEEDS RELOP"); return 0; } +
- +
-        int right = parse_expr(&p); +
- +
-        skip_spaces(&p); +
-        if (!starts_with_kw(p, "THEN")) { basic_error("IF NEEDS THEN"); return 0; } +
-        p += 4; +
- +
-        uint16 target = parse_u16(&p); +
-        if (target == 0) { basic_error("BAD THEN LINE"); return 0; } +
- +
-        if (eval_relation(left, right, op)) { +
-            *pc_line = (uint16)(target - 1); // Trick: RUN loop nimmt "next > pc_line" +
-        } +
-        return 1; +
-    } +
- +
-    // GOTO line +
-    if (starts_with_kw(p, "GOTO")) { +
-        p += 4; +
-        uint16 target = parse_u16(&p); +
-        if (target == 0) { basic_error("BAD GOTO LINE"); return 0; } +
-        *pc_line = (uint16)(target - 1); +
-        return 1; +
-    } +
- +
-    // Assignment: A = expr +
-    if (is_alpha(*p)) { +
-        char vname = up(*p++); +
-        if (vname < 'A' || vname > 'Z') { basic_error("BAD VAR"); return 0; } +
-        skip_spaces(&p); +
-        if (*p != '=') { basic_error("EXPECTED ="); return 0; } +
-        p++; +
-        int value = parse_expr(&p); +
-        g_vars[vname - 'A'] = value; +
-        return 1; +
-    } +
- +
-    basic_error("UNKNOWN STATEMENT"); +
-    return 0; +
-+
- +
-static void basic_run(void) { +
-    uint16 pc = 0;         // last executed line_no (for sorted iteration) +
-    int stop = 0; +
- +
-    // Start at "before" first line: +
-    pc = 0; +
- +
-    while (!stop) { +
-        uint16 ln; +
-        int idx; +
-        if (!find_next_line_sorted(pc, &ln, &idx)) break; +
- +
-        // execute +
-        uint16 pc_before = ln; +
-        uint16 pc_line = ln; +
-        basic_exec_stmt(g_prog[idx].text, &pc_line, &stop); +
- +
-        // 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(&p); +
-    if (*p == 0) return; +
- +
-    // line starts with number? -> program line +
-    if (is_digit(*p)) { +
-        uint16 ln = parse_u16(&p); +
-        basic_store_line(ln, p); +
-        return; +
-    } +
- +
-    // Immediate commands +
-    if (starts_with_kw(p, "LIST")) { basic_list(); return; } +
-    if (starts_with_kw(p, "RUN"))  { basic_run(); return; } +
-    if (starts_with_kw(p, "NEW"))  { basic_reset_program(); basic_reset_vars(); print_new_line(); print_string("OK"); return; } +
- +
-    // keep your old shell commands too+
-    if (starts_with_kw(p, "HELP")) { +
-        print_new_line(); +
-        print_string("Available commands:"); +
-        print_new_line(); +
-        print_string("  HELP   Prints this help"); +
-        print_new_line(); +
-        print_string("  REBOOT Reboot the system"); +
-        print_new_line(); +
-        print_string("  NEW    - Clear BASIC program + vars"); +
-        print_new_line(); +
-        print_string("  LIST   - List BASIC program"); +
-        print_new_line(); +
-        print_string("  RUN    - Run BASIC program"); +
-        print_new_line(); +
-        print_string("BASIC examples:"); +
-        print_new_line(); +
-        print_string("  10 A=1+2*3"); +
-        print_new_line(); +
-        print_string("  20 PRINT A"); +
-        print_new_line(); +
-        print_string("  30 IF A=7 THEN 50"); +
-        print_new_line(); +
-        print_string("  40 GOTO 20"); +
-        print_new_line(); +
-        print_string("  50 END"); +
-        return; +
-    } +
- +
-    if (starts_with_kw(p, "REBOOT")) { do_reboot(); return; } +
- +
-    // Otherwise: treat as immediate BASIC statement (PRINT/LET/A=.../IF/GOTO/END) +
-    uint16 dummy = 0; +
-    int stop = 0; +
-    basic_exec_stmt(p, &dummy, &stop);+
 } }
 </code> </code>
- 
-Hallo Besucher! Willkommen in diesem kleinen Wiki rund um IT. Vieles ist noch **unvollständig, unstrukturiert oder vielleicht sogar falsch bzw. irreführend**. 
- 
-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:wanted~~ 
- 
- 
start.1765038619.txt.gz · Zuletzt geändert: 2025/12/06 17:30 von jango