tazcraft diff 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 diff
     1.1 --- a/web/tazcraft.cgi	Sun Mar 19 17:44:13 2017 +0100
     1.2 +++ b/web/tazcraft.cgi	Sun Mar 19 22:29:36 2017 +0100
     1.3 @@ -11,9 +11,10 @@
     1.4  home="/home/minecraft"
     1.5  server="$home/server"
     1.6  config="$server/server.properties"
     1.7 +whitelist="${server}/whitelist.json"
     1.8  
     1.9 -# Get a value in
    1.10 -get_value() {
    1.11 +# Get a key value from server config file
    1.12 +get_key() {
    1.13  	val=$(grep ^${1}= ${config} | cut -d "=" -f 2)
    1.14  	cat << EOT
    1.15  <tr>
    1.16 @@ -23,50 +24,116 @@
    1.17  EOT
    1.18  }
    1.19  
    1.20 +# HTML footer
    1.21 +html_footer() {
    1.22 +	cat << EOT
    1.23 +</div>
    1.24 +<footer style="text-align: center; margin: 10px; color: #888;">
    1.25 +	&copy; $(date '+%Y') <a href="http://www.slitaz.org">SliTaz GNU/Linux</a>
    1.26 +</footer>
    1.27 +</body>
    1.28 +</htnl>
    1.29 +EOT
    1.30 +}
    1.31 +
    1.32  # HTML header
    1.33 -cat << EOT
    1.34 +html_header() {
    1.35 +	cat << EOT
    1.36  <!DOCTYPE html>
    1.37  <html>
    1.38  <head>
    1.39  	<meta charset="utf-8" />
    1.40 -	<title>Tazcraft</title>
    1.41 +	<title>Tazcraft - $1</title>
    1.42  	<link rel="stylesheet" href="http://play.slitaz.me/style.css" />
    1.43  </head>
    1.44  <body>
    1.45  <header>
    1.46  	<div id="logo"></div>
    1.47  	<div id="network">
    1.48 +		<a href="tazcraft.cgi">Tazcraft</a>
    1.49 +		<a href="tazcraft.cgi?README">README</a>
    1.50 +		<span style="color: #682368;">&hearts;</span> 
    1.51  		<a href="http://play.slitaz.me">play.SliTaz.me</a>
    1.52 -		<a href="http://www.slitaz.org">SliTaz.org</a>
    1.53  	</div>
    1.54  	<h1>Tazcraft Server</h1>
    1.55  </header>
    1.56  <div id="content">
    1.57 +EOT
    1.58 +}
    1.59  
    1.60 +#
    1.61 +# Handle GET commands
    1.62 +#
    1.63 +
    1.64 +case " $(GET) " in
    1.65 +	
    1.66 +	*\ README\ *)
    1.67 +		
    1.68 +		if [ -f "../README" ]; then
    1.69 +			README="../README"
    1.70 +		else
    1.71 +			README="/usr/share/doc/slitaz/tazcraft.txt"
    1.72 +		fi
    1.73 +		
    1.74 +		html_header "README"
    1.75 +		echo "<h2>README</h2>"
    1.76 +		echo "<pre>"
    1.77 +		# Let have a few color in README
    1.78 +		cat ${README} | sed \
    1.79 +			-e "/^====.*/"d -e "/^----.*/"d \
    1.80 +			-e s"#==\([^']*\)==#<h3 style='margin: 0;'>\1</h3>#"g \
    1.81 +			-e s"#^	[\#|\$|\/]\([^']*\)#<span style='color: green;'>\0</span>#"g \
    1.82 +			-e s"#http://\([^']*\).*#<a href='\0'>\0</a>#"g
    1.83 +		echo "</pre>"
    1.84 +		html_footer 
    1.85 +		exit 0 ;;
    1.86 +	
    1.87 +esac
    1.88 +
    1.89 +#
    1.90 +# Home page with server information and configuration
    1.91 +#
    1.92 +html_header "Welcome"
    1.93 +
    1.94 +uptime=$(ps | grep minecraft_server | grep -v grep | awk '{print $3}')
    1.95 +if [ ! "$uptime" ]; then
    1.96 +	uptime="Not running"
    1.97 +fi
    1.98 +
    1.99 +cat << EOT
   1.100  <h2>Welcome to Tazcraft</h2>
   1.101 -<p>A SliTaz GNU/Linux Minecraft server</p>
   1.102 +<p>
   1.103 +	A SliTaz GNU/Linux Minecraft server
   1.104 +	- Uptime: <span style="color: green;">$uptime</span>
   1.105 +</p>
   1.106 +
   1.107  <pre>
   1.108 -<img src="minecraft.png" alt="*" />Server address: <b>play.slitaz.me</b>
   1.109 +<img src="minecraft.png" alt="*" />Server address: \
   1.110 +<span style="color: green; font-size: 20px;">play.slitaz.me</span>
   1.111  </pre>
   1.112  
   1.113  <h3>Configuration</h3>
   1.114  <table>
   1.115  	<thead>
   1.116 -		<td>$(gettext "Variable")</td>
   1.117 +		<td>$(gettext "Key")</td>
   1.118  		<td>$(gettext "Value")</td>
   1.119  	</thead>
   1.120  EOT
   1.121  
   1.122 -for var in gamemode server-port level-name difficulty max-players; do
   1.123 -	get_value ${var}
   1.124 +for var in gamemode server-port level-name difficulty max-players \
   1.125 +	allow-flight white-list
   1.126 +do
   1.127 +	get_key ${var}
   1.128  done
   1.129 +echo "</table>"
   1.130  
   1.131 -# HTML footer
   1.132 -cat << EOT
   1.133 -</table>
   1.134 -</div>
   1.135 -<footer></footer>
   1.136 -</body>
   1.137 -</htnl>
   1.138 -EOT
   1.139 +# White listed users names
   1.140 +if grep -q "white-list=true" ${config}; then
   1.141 +	echo "<h3>White list</h3>"
   1.142 +	echo "<pre>"
   1.143 +	fgrep name ${whitelist} | cut -d '"' -f 4
   1.144 +	echo "</pre>"
   1.145 +fi
   1.146 +
   1.147 +html_footer
   1.148  exit 0