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

ns.slitaz.org: add ipv6 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Dec 06 21:55:31 2014 +0100 (2014-12-06)
parents 62c8bc6c4e36
children 8c2372deec88
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=$REMOTE_ADDR
9 name="$(GET name)"
10 name="${name%.by.slitaz.org}"
11 if [ "$name" -a "$REMOTE_USER" ]; then
12 header
13 if grep -qs "^$name " $OWNERFILE ; then
14 owner="$(sed "/^$name /!d;s/.* //" $OWNERFILE)"
15 if [ "$owner" != "$REMOTE_USER" ]; then
16 echo "$name is already used by $owner. Abort."
17 exit 1
18 fi
19 else
20 echo "$name $(date -u) $REMOTE_USER" >> $OWNERFILE
21 fi
22 addip=yes
23 case " $(GET) " in
24 *\ remove\ *|*\ delete\ *|*\ wipe\ *)
25 addip=
26 sed -i "/^$name /d" $OWNERFILE
27 esac
28 type="A"
29 echo "$ip" | grep -q : && type="AAAA"
30 req="server 127.0.0.1
31 update delete $name.by.slitaz.org $type"
32 [ "$addip" ] && req="$req
33 update add $name.by.slitaz.org 900 $type $ip"
34 case " $(GET) " in
35 *\ mx\ *)
36 mx="$(GET mx)"
37 [ "$mx" ] || mx=$ip
38 req="$req
39 update delete $name.by.slitaz.org MX"
40 [ "$addip" ] && req="$req
41 update add $name.by.slitaz.org 900 MX 10 $mx"
42 esac
43 echo "$req
44 send" | nsupdate 2>&1
45 else
46 #header "text/html; charset=utf-8"
47 cat <<EOT
48 <!DOCTYPE html>
49 <html xmlns="http://www.w3.org/1999/xhtml">
50 <head>
51 <title>SliTaz Name Server</title>
52 <meta charset="utf-8" />
53 <link rel="shortcut icon" href="favicon.ico" />
54 <link rel="stylesheet" type="text/css" href="style.css" />
55 <style type="text/css">
56 #header h1 {
57 margin: 0;
58 padding: 8px 0 0 42px;
59 width: 250px;
60 }
61 #logo {
62 background: url(/images/logo.png) no-repeat left;
63 position: absolute;
64 float: left;
65 left: 0px;
66 top: 0px;
67 width: 40px;
68 height: 40px;
69 }
70 pre { font-size: 100%; }
71 </style>
72 </head>
73 <body>
75 <div id="header">
76 <div id="logo"></div>
77 <div id="network">
78 <a href="http://www.slitaz.org/">Home</a>
79 <a href="http://bugs.slitaz.org/">Bugs</a>
80 <a href="http://hg.slitaz.org/?sort=lastchange">Hg</a>
81 <a href="http://forum.slitaz.org/">Forum</a>
82 <a href="http://roadmap.slitaz.org/">Roadmap</a>
83 <a href="http://pizza.slitaz.me/">Pizza</a>
84 <a href="http://tank.slitaz.org/">Tank</a>
85 </div>
86 <h1><a href="./">SliTaz Name Server</a></h1>
87 </div>
89 <!-- Content -->
90 <div id="content">
91 EOT
92 if grep -qs " $REMOTE_USER$" $OWNERFILE; then
93 cat <<EOT
94 <h3>Status</h3>
95 $REMOTE_USER has $(grep " $REMOTE_USER$" $OWNERFILE | wc -l) names
96 in the by.slitaz.org domain.
97 <pre>
98 EOT
99 for i in $(grep " $REMOTE_USER$" $OWNERFILE | sed 's/ .*//'); do
100 dig @127.0.0.1 $i.by.slitaz.org ANY | grep ^$i
101 done
102 cat <<EOT
103 </pre>
105 Your current IP address is $REMOTE_ADDR
106 EOT
107 fi
108 cat <<EOT
109 <h3>Usage</h3>
110 <pre>
111 wget -O - "http://user:pass@ns.slitaz.org/?name=&lt;name&gt;[&remove][&ip=&lt;ip1&gt;][&mx[=&lt;ip2&gt;]]"
112 </pre>
113 <h3>Examples</h3>
114 <ul>
115 <li>
116 Update myblog.by.slitaz.org with my current IP address.
117 <pre>
118 wget -O - "http://user:pass@ns.slitaz.org/?name=myblog"
119 </pre>
120 </li>
121 <li>
122 Update myblog.by.slitaz.org with the IP address 1.2.3.4.
123 <pre>
124 wget -O - "http://user:pass@ns.slitaz.org/?name=myblog&ip=1.2.3.4"
125 </pre>
126 </li>
127 <li>
128 Remove myblog.by.slitaz.org from the name server.
129 <pre>
130 wget -O - "http://user:pass@ns.slitaz.org/?name=myblog&remove"
131 </pre>
132 </li>
133 <li>
134 Update myserver.by.slitaz.org with my current IP address and declare the mail server btw.
135 <pre>
136 wget -O - "http://user:pass@ns.slitaz.org/?name=myserver&mx"
137 </pre>
138 </li>
139 <li>
140 Update myserver.by.slitaz.org with my current IP address and use the mail server at 1.2.3.4.
141 <pre>
142 wget -O - "http://user:pass@ns.slitaz.org/?name=myserver&mx=1.2.3.4"
143 </pre>
144 </li>
145 </ul>
146 </div>
148 <div id="footer">
149 <a href="http://www.slitaz.org/">SliTaz Website</a>
150 <a href="index.cgi">Name Server</a>
151 </div>
153 </body>
154 </html>
155 EOT
156 fi