Le site web bebou.netlib.re - retour accueil
git clone git://bebou.netlib.re/bebou
Log | Files | Refs |
commit b5aac3a5f5707f6f6476cdaea45d9012ad1f4ba3 parent 9145a811ebd5c01ed07860aa99100cc8c23e3c19 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 28 May 2025 06:50:49 +0200 On déclare le bon content type en retour des CGI Et aussi si c'est text/plain pour qr.cgi on renvoi le base64 Diffstat:
M | contents/cgi-bin/qr.cgi | | | 70 | +++++++++++++++++++++++++++++++++++++++------------------------------- |
M | contents/cgi-bin/scrabble.cgi | | | 10 | ++++++++-- |
2 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/contents/cgi-bin/qr.cgi b/contents/cgi-bin/qr.cgi @@ -1,6 +1,12 @@ #! /bin/sh -printf "Content-Type: text/html\r\n" +if echo "$HTTP_ACCEPT" | grep -q "text/plain";then + contenttype="text/plain" +else + contenttype="text/html" +fi + +printf "Content-Type: $contenttype\r\n" printf "\r\n" if echo "$QUERY_STRING" | grep -q "text=" ;then @@ -8,34 +14,36 @@ if echo "$QUERY_STRING" | grep -q "text=" ;then res="<img src='data:image/png;base64,$base64'>" fi -<<. cat -<!DOCTYPE html> -<html lang="fr"> -<head> - <meta charset="utf-8"> - <meta name="color-scheme" content="light dark"> - <meta name="viewport" content="width=device-width, initial-scale=1"> - <title>Vérificateur Scrabble</title> - <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔤</text></svg>"> - <style> - * { box-sizing: border-box } - html { font: 1rem sans-serif } - body { height: 100vh; margin: 0; padding: 1rem; display: grid; place-items: center } - input { font: inherit; padding: .5em } - form { margin-inline: auto; width: fit-content; min-height: 6rem } - form > * { display: inline-block; margin-bottom: .5em } - </style> -</head> -<body> - <form> - <label for="text">Texte</label><br> - <input type="text" name="text" id="text" placeholder="Votre texte…" value="$text" required> - <input type="submit" value="Encoder"><br> - <output name="resultat" for="text">$res</output> - </form> -</body> -</html> -. - -rm ../a.png +if [ "$contenttype" = "text/plain" ];then + echo "$base64" +else + <<-. cat + <!DOCTYPE html> + <html lang="fr"> + <head> + <meta charset="utf-8"> + <meta name="color-scheme" content="light dark"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Vérificateur Scrabble</title> + <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🔤</text></svg>"> + <style> + * { box-sizing: border-box } + html { font: 1rem sans-serif } + body { height: 100vh; margin: 0; padding: 1rem; display: grid; place-items: center } + input { font: inherit; padding: .5em } + form { margin-inline: auto; width: fit-content; min-height: 6rem } + form > * { display: inline-block; margin-bottom: .5em } + </style> + </head> + <body> + <form> + <label for="text">Texte</label><br> + <input type="text" name="text" id="text" placeholder="Votre texte…" value="$text" required> + <input type="submit" value="Encoder"><br> + <output name="resultat" for="text">$res</output> + </form> + </body> + </html> + . +fi diff --git a/contents/cgi-bin/scrabble.cgi b/contents/cgi-bin/scrabble.cgi @@ -1,6 +1,12 @@ #! /bin/sh -printf "Content-Type: text/html\r\n" +if echo "$HTTP_ACCEPT" | grep -q "text/plain";then + contenttype="text/plain" +else + contenttype="text/html" +fi + +printf "Content-Type: $contenttype\r\n" printf "\r\n" if echo "$QUERY_STRING" | grep -q "mot=" ;then @@ -16,7 +22,7 @@ if echo "$QUERY_STRING" | grep -q "mot=" ;then fi fi -if echo "$HTTP_ACCEPT" | grep -q "text/plain";then +if [ "$contenttype" = "text/plain" ];then echo "$res" else <<-. cat