slitaz-forge view scn/plugins/sdt/sdt.cgi @ rev 662
tank: include sup-demo package on up-scn
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri Feb 24 08:53:29 2017 +0100 (2017-02-24) |
parents | aa3ea43faa0c |
children | af57a0cc4aa6 |
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 echo "178.196.15.131"
89 exit 0 ;;
91 *\ country\ *)
92 # Show distros by country
93 ;;
95 *\ sdt\ *)
96 d="SliTaz Distro Tracker"
97 header
98 html_header
99 user_box
100 cat << EOT
101 <h2>$d</h2>
102 <p>
103 $(gettext "Add your SliTaz distro to the database. Open a terminal and execute:")
104 <b>sdt send [username]</b>
105 <p>
106 EOT
107 sdt_summary
108 echo "<h3>Distros table</h3>"
109 echo "<pre>"
110 sdt_table
111 echo "</pre>"
112 html_footer
113 exit 0 ;;
115 *\ raw\ *)
116 # Plain text stats
117 header "Content-Type: text/plain"
118 cat << EOT
119 Server time : $(date)
120 Database size : $(du -sh $sdtdb | cut -d " " -f 1)
121 Distro tracked : $(wc -l $sdtdb | cut -d " " -f 1)
122 EOT
123 exit 0 ;;
124 esac