Des cgis cools - retour accueil
Anonyme, en lecture seule : git clone git://bebou.netlib.re/cgis
Authentifié·e, en écriture : git clone ssh://git@bebou.netlib.re:1459/srv/git/cgis
Log | Files | Refs | README | zip | tar.gz |
webring.cgi (1268B)
1 #! /bin/awk -f
2
3 # Un script implémentant un webring
4 # Typiquement à installer dans le /cgi-bin/ d'un serveur web
5 # Par du principe qu'il existe un fichier webring.txt avec
6 # des # en début de ligne comme commentaires et un lien par ligne sinon
7 #
8 # Si votre fichier webring est ailleurs il faut modifier la ligne avec getline
9 #
10 # Dépendances :
11 #
12 # * un awk posix
13 # * un shell posix
14 # * un grep avec -v
15 #
16 # Testé avec gawk et mawk en 2025
17
18 BEGIN {
19 srand();
20 RS=""
21 "< ../webring.txt grep -v ^#" | getline webring
22 len=split(webring,links);
23 res=-1;
24 if(ENVIRON["QUERY_STRING"]=="random") {
25 res=int((len+2)*rand())-1
26 } else {
27 if(ENVIRON["QUERY_STRING"] ~ "^prev(&from=https://.+)?$") { offset=-1 }
28 else if(ENVIRON["QUERY_STRING"] ~ "^next(&from=https://.+)?$") { offset=+1 }
29 if(ENVIRON["HTTP_REFERER"]) {
30 from=ENVIRON["HTTP_REFERER"]
31 } else {
32 sub(".*&from=","",ENVIRON["QUERY_STRING"])
33 from=ENVIRON["QUERY_STRING"]
34 }
35 for(i=1;i<=len;i++) {
36 if(links[i]~from"/?") {
37 res=i+offset
38 if(res<=0) { res=len }
39 else if(res>len) { res=1 }
40 break;
41 }
42 }
43 }
44
45 if(res!=-1) { to=links[res]; }
46 else { to="http://bebou.netlib.re/webring.txt"; }
47
48 printf "Status: 302 Redirect\r\n"
49 printf "Location: %s\r\n",to
50 printf "\r\n"
51 }
52