Make a Raspberry Pi into a precise NTP server using a GPS unit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.1 KiB

import subprocess
import sys
import os
import cgi
import cgitb; cgitb.enable() # for troubleshooting
# constants
SUPERVISOR_CONF = "/etc/supervisor/conf.d/daemons.conf"
AUTH_FILE = "/opt/gps-timekeep/auth"
<h3>Can't change password via web interface: permissions problem</h3>
<h4>Change password "manually"</h4>
<li>SSH into the machine.</li>
<li>Change name:pass by editing two files:
<li>Passwords need to match!!</li>
<li>Restart the machine (otherwise unexpected stuff can occur).</li>
<h4>Alternatively, fix the permissions</h4>
The two files above need to be write-accessible by the lighttpd process, so you can for instance (after SSHing into the machine):
sudo chgrp www-data /opt/gps-timekeep/auth
sudo chmod g+w /opt/gps-timekeep/auth
and the same with the other file.
print "Content-Type: text/html" # HTML is following
print # blank line, end of headers
# print html header
print """
<title>ntpi: change password</title>
<h1>ntpi: change password</h1>
# get the submitted form contents
form = cgi.FieldStorage()
# if rebooting requested, just print a message and exit
if "reboot-button" in form:
print "<h1>Rebooting now!</h1></body></html>"
# check if the appropriate files are writable
if (not os.access(SUPERVISOR_CONF, os.W_OK | os.R_OK)) or (not os.access(AUTH_FILE, os.W_OK | os.R_OK)):
# change of password requested
if "submit-button" in form:
username = form.getvalue("username")
password = form.getvalue("password")
with open(AUTH_FILE, "w") as f:
with open(SUPERVISOR_CONF) as f:
lines = f.readlines()
with open(SUPERVISOR_CONF, "w") as f:
for line in lines:
if line.startswith("username "):
f.write("username = " + username + "\n")
elif line.startswith("password "):
f.write("password = " + password + "\n")
print """
<form method="post" action="">
</p><strong>Message:</strong> Username and password changed. You should
<input type="submit" value="Reboot!" name="reboot-button"> now.
# read username and password
username = "some error"
password = "has occured"
with open(AUTH_FILE) as f:
username, password = f.readline().strip().split(':')
# print the form
print """
<form method="post" action="">
Username: <input type="text" name="username" value="%s"/><br />
Password: <input type="text" name="password" value="%s"/><br />
<input type="submit" value="Submit" name="submit-button"></p>
Note: No sanity checking is done, so be careful!
<a href="/cgi-bin/">Go back.</a>
""" % (username, password)