slitaz-forge view scn/plugins/sdt/sdt.cgi @ rev 669

scn: fix sdt return IP (silly typo) was usinf testing code (thanks paul)
author Christophe Lincoln <pankso@slitaz.org>
date Wed Mar 01 11:09:44 2017 +0100 (2017-03-01)
parents 9a9e98cc78e4
children
line source
1 #!/bin/sh
2 #
3 # TinyCM Plugin - SliTaz Distro Tracker
4 #
5 # sdt.cgi: SliTaz Distros over the world. We don't track users
6 # info, no mail or IP but the localization. The goal of Sdt is to help
7 # show where SliTaz OS's are in the world. DB is in the flat file:
8 # sdt.txt & using | as separator for easy parsing.
9 #
11 sdtdb="$tiny/$content/sdt/sdt.txt"
13 sdt_summary() {
14 cat << EOT
15 <pre>
16 DB file : <a href="content/sdt/sdt.txt">sdt.txt</a>
17 DB size : $(du -sh $sdtdb | cut -d " " -f 1)
18 Distro : $(wc -l $sdtdb | cut -d " " -f 1)
19 </pre>
20 EOT
21 }
23 sdt_table() {
24 cat << EOT
25 <table>
26 <thead>
27 <td>$(gettext "Date")</td>
28 <td>$(gettext "User")</td>
29 <td>$(gettext "Country")</td>
30 <td>$(gettext "Release")</td>
31 <td>$(gettext "Kernel")</td>
32 <td>$(gettext "Mode")</td>
33 </thead>
34 EOT
35 IFS="|"
36 cat ${sdtdb} | while read date user country release kernel mode;
37 do
38 cat << EOT
39 <tr>
40 <td>$date</td>
41 <td>$user</td>
42 <td>$country</td>
43 <td>$release</td>
44 <td>$kernel</td>
45 <td>$mode</td>
46 </tr>
47 EOT
48 done && unset IFS
49 echo "</table>"
50 }
52 sdt_check_ua() {
53 if ! echo "$HTTP_USER_AGENT" | fgrep -q "SliTaz/SDT"; then
54 echo "Only SDT clients are accepted" && exit 1
55 fi
56 }
58 case " $(GET sdt) " in
59 *\ add\ *)
60 sdt_check_ua
61 date="$(date +%Y%m%d)"
62 user=$(GET user)
63 release=$(GET release)
64 kernel=$(GET kernel)
65 mode=$(GET mode)
66 country=$(GET country)
67 message=$(GET message)
68 cat << EOT
69 SliTaz Distro Tracker
70 --------------------------------------------------------------------------------
71 Date : ${date}
72 User : ${user}
73 Country : ${country}
74 Release : ${release}
75 Kernel : ${kernel}
76 Mode : ${mode}
77 --------------------------------------------------------------------------------
78 EOT
79 # Add to DB
80 echo "$date|$user|$country|$release|$kernel|$mode" >> ${sdtdb}
81 echo "Distro added to the database. Thank you :-)"; echo
82 exit 0 ;;
84 *\ geoloc\ *)
85 # Show IP and country
86 header "Content-Type: text/plain"
87 echo "$REMOTE_ADDR"
88 exit 0 ;;
90 *\ country\ *)
91 # Show distros by country
92 ;;
94 *\ sdt\ *)
95 d="SliTaz Distro Tracker"
96 header
97 html_header
98 user_box
99 cat << EOT
100 <h2>$d</h2>
101 <p>
102 $(gettext "Add your SliTaz distro to the database. Open a terminal and execute:")
103 <b>sdt send [username]</b>
104 <p>
105 EOT
106 sdt_summary
107 echo "<h3>Distros table</h3>"
108 echo "<pre>"
109 sdt_table
110 echo "</pre>"
111 html_footer
112 exit 0 ;;
114 *\ raw\ *)
115 # Plain text stats
116 header "Content-Type: text/plain"
117 cat << EOT
118 Server time : $(date)
119 Database size : $(du -sh $sdtdb | cut -d " " -f 1)
120 Distro tracked : $(wc -l $sdtdb | cut -d " " -f 1)
121 EOT
122 exit 0 ;;
123 esac