Memo to display Server name Info and OS info in IoTtalk Home Page:
by tsaiwn@cs.nctu.edu.tw
*** You need to modify the following two files:
lib/csm.py (port 9999)
lib/template/web_da_index.html
*** 效果請參考 http://iottalk.vip 和 http://iottalk.me
*** in your lib/csm.py
(related to lib/template/web_da_index.html)
''' Find the app.route for '/'
'''
@app.route('/')
def show_web_da_list():
...
...
### add/modify the following:
# return render_template('web_da_index.html', vp_da_list=vp_da_list, js_da_list=js_da_list)
import subprocess
yyIP = subprocess.check_output("hostname -I", shell=True).decode("utf-8")
# if using AliYun 阿里云, use the following line
#yyIP = subprocess.check_output("curl http://members.3322.org/dyndns/getip", shell=True).decode("utf-8")
### if in AWS EC2, use the following two lines:
# bash_com = 'curl -s http://169.254.169.254/latest/meta-data/public-ipv4'
# yyIP = subprocess.check_output(bash_com, shell=True).decode("utf-8")
try:
dname = subprocess.check_output(["hostname", "--fqdn"]).decode("utf-8")
except:
dname = subprocess.check_output("domainname").decode("utf-8")
dname = dname + " " + yyIP
osinfo = subprocess.check_output("cat /etc/*release", shell=True).decode("utf-8")
return render_template('web_da_index.html',
vp_da_list=vp_da_list, js_da_list=js_da_list, ggName=dname, osinfo=osinfo) #################
#return render_template('web_da_index.html', vp_da_list=vp_da_list, js_da_list=js_da_list)
###############################################
##############################
# 如果是 AWS EC2, 則 hostname -I 得到的是內部 Private IP,
# 這時 yyIP = subprocess... 那列改用以下兩列:
bash_com = 'curl -s http://169.254.169.254/latest/meta-data/public-ipv4'
yyIP = subprocess.check_output(bash_com, shell=True).decode("utf-8")
###############################################
///
*** in your lib/template/web_da_index.html
*** add at the very beginning but after <body>:
<h4 style="margin-bottom:0;">IoTtalk: (<font color="55dd88"> {{ ggName }}
</font>)</h4>
*** add at the very end of this file but before the last </div>:
<table bgcolor=lightCyan><tr><td>
<pre><b><font color=black size=5>
{{ osinfo }}
</pre>
</table>
/// 把以上 5 列放在 </div></body> 之前
///以上這項修改要重開機(sudo reboot)後才有效 !
點這看 lib/template/web_da_index.html 內容
點這下載 lib/template/web_da_index.html
點這偷看 lib/csm.py 內容
點這下載 lib/csm.py 檔案
點這偷看 da/web.py 內容
點這下載 da/web.py 檔案