bebou

Le site web bebou.netlib.re - retour accueil

git clone git://bebou.netlib.re/bebou

Log | Files | Refs |

scrabble.cgi (1933B)


      1 #! /bin/sh
      2 
      3 if echo "$HTTP_ACCEPT" | grep -q "text/plain";then
      4 	contenttype="text/plain"
      5 else
      6 	contenttype="text/html"
      7 fi
      8 
      9 printf "Content-Type: $contenttype\r\n"
     10 printf "\r\n"
     11 
     12 if echo "$QUERY_STRING" | grep -q "mot=" ;then
     13 	mot="$(echo "${QUERY_STRING##'mot='}" |
     14 	          sed 's,%\([0-9A-F][0-9A-F]\),\\\\\x\1,g' |
     15 	          xargs printf "%b\n" |
     16 	          sed 'y/éàùèçîïöëê/eaueciioee/;s/œ/oe/')"
     17 
     18 	if [ -n "$mot" ]; then
     19 		grep -iq "^$mot$" ../scrabble/mots-valides-scrabble \
     20 		&& res="✅ Valide" \
     21 		|| res="❌ Pas valide"
     22 	fi
     23 fi
     24 
     25 if [ "$contenttype" = "text/plain" ];then
     26 	echo "$res"
     27 else
     28 	<<-. cat
     29 	<!DOCTYPE html>
     30 	<html lang="fr">
     31 	<head>
     32 		<meta charset="utf-8">
     33 		<meta name="color-scheme" content="light dark">
     34 		<meta name="viewport" content="width=device-width, initial-scale=1">
     35 		<title>Vérificateur Scrabble</title>
     36 		<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>">
     37 		<style>
     38 			* { box-sizing: border-box }
     39 			html { font: 1rem sans-serif }
     40 			body { height: 100vh; margin: 0; padding: 1rem; display: grid; place-items: center }
     41 			input { font: inherit; padding: .5em }
     42 			form { margin-inline: auto; width: fit-content; min-height: 6rem }
     43 			form > * { display: inline-block; margin-bottom: .5em }
     44 			li { list-style-type: none }
     45 		</style>
     46 	</head>
     47 	<body>
     48 		<form>
     49 			<label for="mot">Mot</label><br>
     50 			<input type="text" name="mot" id="mot" minlength="2" maxlength="15" placeholder="Votre mot…" value="$mot" required>
     51 			<input type="submit" value="Vérifier"><br>
     52 			<output name="resultat" for="mot">$res</output><br>
     53 		</form>
     54 		<ul>
     55 			<li><a href="/scrabble/mots-valides-scrabble.gz">Liste complète des mots valides (1,2Mo)</a></li>
     56 			<li><a href="http://arthur.bebou.netlib.re/scrabble-valide">Article sur le sujet</a></li>
     57 		</ul>
     58 	</body>
     59 	</html>
     60 	.
     61 fi