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

scn: tiny edit
author Paul Issott <paul@slitaz.org>
date Mon Feb 27 17:42:09 2017 +0000 (2017-02-27)
parents af57a0cc4aa6
children 3dd8a58a91ba
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 to help us to know who uses
104 SliTaz :-) Open a terminal and execute:")
105 <b>sdt send [username]</b>
106 <p>
107 EOT
108 sdt_summary
109 echo "<h3>Distros table</h3>"
110 echo "<pre>"
111 sdt_table
112 echo "</pre>"
113 html_footer
114 exit 0 ;;
116 *\ raw\ *)
117 # Plain text stats
118 header "Content-Type: text/plain"
119 cat << EOT
120 Server time : $(date)
121 Database size : $(du -sh $sdtdb | cut -d " " -f 1)
122 Distro tracked : $(wc -l $sdtdb | cut -d " " -f 1)
123 EOT
124 exit 0 ;;
125 esac