slitaz-forge view ns/web/index.cgi @ rev 700

Add slitaz.exe
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon May 13 09:34:40 2019 +0200 (5 months ago)
parents 77e1cdfb9c9d
children
line source
1 #!/bin/sh
3 # Get parameters with GET, POST and FILE functions
4 . /usr/bin/httpd_helper.sh
6 OWNERFILE=name.users
7 ip="$(GET ip)"
8 [ "$ip" ] || ip=$HTTP_X_FORWARDED_FOR
9 [ "$ip" ] || ip=$REMOTE_ADDR
10 name="$(GET name)"
11 name="${name%.by.slitaz.org}"
12 if [ "$name" -a "$REMOTE_USER" ]; then
13 header
14 addip=yes
15 case " $(GET) " in
16 *\ remove\ *|*\ delete\ *|*\ wipe\ *)
17 addip=
18 esac
19 case "$name" in
20 @*) echo "$name not allowed. Abort."
21 exit 1 ;;
22 *\**) base="${name//\*/}"
23 if grep -qs "^[^ ]*${base//./\\.} " $OWNERFILE ; then
24 owner="$(sed "/^[^ ]*${base//./\\.} /!d;s/.* //" $OWNERFILE | uniq | xargs echo)"
25 if [ "$addip" -o "$owner" != "$REMOTE_USER" ]; then
26 echo "$base is already used by $owner. Abort."
27 exit 1
28 fi
29 fi
30 esac
31 if grep -qs "^$name " $OWNERFILE || grep -qs "^\$name " $OWNERFILE ; then
32 owner="$(sed "/^$name /!d;s/.* //" $OWNERFILE)"
33 [ "$owner" ] || owner="$(sed "/^\$name /!d;s/.* //" $OWNERFILE)"
34 if [ "$owner" != "$REMOTE_USER" ]; then
35 echo "$name is already used by $owner. Abort."
36 exit 1
37 fi
38 else
39 echo "$name $(date -u) $REMOTE_USER" >> $OWNERFILE
40 fi
41 [ "$addip" ] || sed -i "/^$name /d;/^\$name /d" $OWNERFILE
42 ttl=900
43 [ "$(GET ttl)" ] && ttl="$(GET ttl)"
44 req="server 127.0.0.1"
45 if [ "$(GET mx)" ]; then
46 mx="$(GET mx)"
47 [ "$mx" ] || mx=$ip
48 req="$req
49 update delete $name.by.slitaz.org MX"
50 [ "$addip" ] && req="$req
51 update add $name.by.slitaz.org $ttl MX 10 $mx"
52 fi
53 type="A"
54 echo "$ip" | grep -q : && type="AAAA"
55 [ "$(GET ns)" ] && type="NS"
56 [ "$(GET txt)" ] && type="TXT" && ip="$(GET txt)"
57 [ "$(GET cname)" ] && type="CNAME" && ip="$(GET cname)"
58 req="$req
59 update delete $name.by.slitaz.org $type"
60 [ "$addip" ] && req="$req
61 update add $name.by.slitaz.org $ttl $type $ip"
62 echo "$req
63 send" | nsupdate 2>&1
64 else
65 #header "text/html; charset=utf-8"
66 cat <<EOT
67 <!DOCTYPE html>
68 <html xmlns="http://www.w3.org/1999/xhtml">
69 <head>
70 <title>SliTaz Name Server</title>
71 <meta charset="utf-8" />
72 <link rel="shortcut icon" href="favicon.ico" />
73 <link rel="stylesheet" type="text/css" href="style.css" />
74 <style type="text/css">
75 #header h1 {
76 margin: 0;
77 padding: 8px 0 0 42px;
78 width: 250px;
79 }
80 #logo {
81 background: url(/images/logo.png) no-repeat left;
82 position: absolute;
83 float: left;
84 left: 0px;
85 top: 0px;
86 width: 40px;
87 height: 40px;
88 }
89 pre { font-size: 100%; }
90 </style>
91 </head>
92 <body>
94 <div id="header">
95 <div id="logo"></div>
96 <div id="network">
97 <a href="http://www.slitaz.org/">Home</a>
98 <a href="http://bugs.slitaz.org/">Bugs</a>
99 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
100 <a href="http://forum.slitaz.org/">Forum</a>
101 <a href="http://roadmap.slitaz.org/">Roadmap</a>
102 <a href="http://pizza.slitaz.me/">Pizza</a>
103 <a href="http://tank.slitaz.org/">Tank</a>
104 </div>
105 <h1><a href="./">SliTaz Name Server</a></h1>
106 </div>
108 <!-- Content -->
109 <div id="content">
110 <h3>Status</h3>
111 <p>
112 There are $(wc -l < $OWNERFILE) record(s) and
113 $(sed 's/.* //' $OWNERFILE | sort | uniq | wc -l) user(s)
114 in the by.slitaz.org domain.</p>
115 EOT
116 if grep -qs " $REMOTE_USER$" $OWNERFILE; then
117 cat <<EOT
118 $REMOTE_USER has $(grep " $REMOTE_USER$" $OWNERFILE | wc -l) names:
119 <pre>
120 EOT
121 for i in $(grep " $REMOTE_USER$" $OWNERFILE | sed 's/ .*//'); do
122 dig @127.0.0.1 $i.by.slitaz.org ANY | grep ^$i
123 done
124 cat <<EOT
125 </pre>
127 Your current IP address is $REMOTE_ADDR
128 EOT
129 fi
130 cat <<EOT
131 <h3>Usage</h3>
132 <pre>
133 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;[&ip=&lt;ip1&gt;][&mx[=&lt;ip2&gt;]]"
134 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;&remove[&mx]"
135 </pre>
136 <pre>
137 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;&ns=&lt;ip&gt;"
138 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;&ns&remove"
139 </pre>
140 <pre>
141 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;&{txt|cname}=&lt;text&gt;"
142 $ wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;&{txt|cname}&remove"
143 </pre>
144 <h3>Examples</h3>
145 <ul>
146 <li>
147 Update myblog.by.slitaz.org with my current IP address.
148 <pre>
149 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myblog"
150 </pre>
151 </li>
152 <li>
153 Update myblog.by.slitaz.org with the IP address 1.2.3.4.
154 <pre>
155 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myblog&ip=1.2.3.4"
156 </pre>
157 </li>
158 <li>
159 Update myblog.by.slitaz.org with the IPv6 address 1:2:3::4:5
160 <pre>
161 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myblog&ip=1:2:3::4:5"
162 </pre>
163 </li>
164 <li>
165 Remove myblog.by.slitaz.org from the name server.
166 <pre>
167 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myblog&remove"
168 </pre>
169 </li>
170 <li>
171 Update myserver.by.slitaz.org with my current IP address and declare a mail server.
172 <pre>
173 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myserver&mx"
174 </pre>
175 </li>
176 <li>
177 Update myserver.by.slitaz.org with my current IP address and use a mail server at 1.2.3.4.
178 <pre>
179 $ wget -O - "http://user:pass@ns.slitaz.org/?name=myserver&mx=1.2.3.4"
180 </pre>
181 </pre>
182 </li>
183 <li>
184 The Addams family use a name server at 1.2.3.4.
185 <pre>
186 $ wget -O - "http://user:pass@ns.slitaz.org/?name=*.addams&ns=1.2.3.4"
187 $ nslookup blog.gomez.addams.by.slitaz.org
188 Name: blog.gomez.addams.by.slitaz.org
189 Address 1: 5.6.7.8
190 </pre>
191 </li>
192 </ul>
193 </div>
195 <div id="footer">
196 <a href="http://www.slitaz.org/">SliTaz Website</a>
197 <a href="index.cgi">Name Server</a>
198 </div>
200 </body>
201 </html>
202 EOT
203 fi