tazcraft view web/tazcraft.cgi @ rev 5
Quiet a few improvment to tazcraft and cgi interface
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Mar 19 22:29:36 2017 +0100 (2017-03-19) |
parents | d588912d23cd |
children | 4cfc84382409 |
line source
1 #!/bin/sh
2 #
3 # tazcraft.cgi - A Minecraft server info/admin CGI interface
4 #
5 # Authors: Kayam Lincoln-Vazquez, Christophe Lincoln
6 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
7 #
8 . /usr/lib/slitaz/httphelper.sh
9 header
11 home="/home/minecraft"
12 server="$home/server"
13 config="$server/server.properties"
14 whitelist="${server}/whitelist.json"
16 # Get a key value from server config file
17 get_key() {
18 val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
19 cat << EOT
20 <tr>
21 <td>$1</td>
22 <td>$val</td>
23 </tr>
24 EOT
25 }
27 # HTML footer
28 html_footer() {
29 cat << EOT
30 </div>
31 <footer style="text-align: center; margin: 10px; color: #888;">
32 © $(date '+%Y') <a href="http://www.slitaz.org">SliTaz GNU/Linux</a>
33 </footer>
34 </body>
35 </htnl>
36 EOT
37 }
39 # HTML header
40 html_header() {
41 cat << EOT
42 <!DOCTYPE html>
43 <html>
44 <head>
45 <meta charset="utf-8" />
46 <title>Tazcraft - $1</title>
47 <link rel="stylesheet" href="http://play.slitaz.me/style.css" />
48 </head>
49 <body>
50 <header>
51 <div id="logo"></div>
52 <div id="network">
53 <a href="tazcraft.cgi">Tazcraft</a>
54 <a href="tazcraft.cgi?README">README</a>
55 <span style="color: #682368;">♥</span>
56 <a href="http://play.slitaz.me">play.SliTaz.me</a>
57 </div>
58 <h1>Tazcraft Server</h1>
59 </header>
60 <div id="content">
61 EOT
62 }
64 #
65 # Handle GET commands
66 #
68 case " $(GET) " in
70 *\ README\ *)
72 if [ -f "../README" ]; then
73 README="../README"
74 else
75 README="/usr/share/doc/slitaz/tazcraft.txt"
76 fi
78 html_header "README"
79 echo "<h2>README</h2>"
80 echo "<pre>"
81 # Let have a few color in README
82 cat ${README} | sed \
83 -e "/^====.*/"d -e "/^----.*/"d \
84 -e s"#==\([^']*\)==#<h3 style='margin: 0;'>\1</h3>#"g \
85 -e s"#^ [\#|\$|\/]\([^']*\)#<span style='color: green;'>\0</span>#"g \
86 -e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g
87 echo "</pre>"
88 html_footer
89 exit 0 ;;
91 esac
93 #
94 # Home page with server information and configuration
95 #
96 html_header "Welcome"
98 uptime=$(ps | grep minecraft_server | grep -v grep | awk '{print $3}')
99 if [ ! "$uptime" ]; then
100 uptime="Not running"
101 fi
103 cat << EOT
104 <h2>Welcome to Tazcraft</h2>
105 <p>
106 A SliTaz GNU/Linux Minecraft server
107 - Uptime: <span style="color: green;">$uptime</span>
108 </p>
110 <pre>
111 <img src="minecraft.png" alt="*" />Server address: \
112 <span style="color: green; font-size: 20px;">play.slitaz.me</span>
113 </pre>
115 <h3>Configuration</h3>
116 <table>
117 <thead>
118 <td>$(gettext "Key")</td>
119 <td>$(gettext "Value")</td>
120 </thead>
121 EOT
123 for var in gamemode server-port level-name difficulty max-players \
124 allow-flight white-list
125 do
126 get_key ${var}
127 done
128 echo "</table>"
130 # White listed users names
131 if grep -q "white-list=true" ${config}; then
132 echo "<h3>White list</h3>"
133 echo "<pre>"
134 fgrep name ${whitelist} | cut -d '"' -f 4
135 echo "</pre>"
136 fi
138 html_footer
139 exit 0