diff --git a/selfsign.crt b/UHRH.crt similarity index 100% rename from selfsign.crt rename to UHRH.crt diff --git a/selfsign.key b/UHRH.key similarity index 100% rename from selfsign.key rename to UHRH.key diff --git a/UHRR b/UHRR index 4ce8c48..4d10cb0 100755 --- a/UHRR +++ b/UHRR @@ -26,6 +26,14 @@ config = configparser.ConfigParser() config.read('UHRR.conf') e="No" +############ Global functions ################################## +def writte_log(logmsg): + logfile = open(config['SERVER']['log_file'],"w") + msg = str(datetime.datetime.now())+":"+str(logmsg) + logfile.write(msg) + print(msg) + logfile.close() + ############ Generate and send FFT from RTLSDR ############## is_rtlsdr_present = True @@ -491,16 +499,19 @@ class threadtimeoutTRXshutdown(threading.Thread): time.sleep(60) timeoutTRXshutdown() -############ Main ############## -class MainHandler(tornado.web.RequestHandler): +############ BaseHandler tornado ############## +class BaseHandler(tornado.web.RequestHandler): + def get_current_user(self): + return self.get_secure_cookie("user") +############ Config ############## +class ConfigHandler(BaseHandler): def get(self): - self.application.settings.get("compiled_template_cache", False) - self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') - self.render("www/index.html") - -class ConfigHandler(tornado.web.RequestHandler): - def get(self): + + if bool(config['SERVER']['auth']) and not self.current_user: + self.redirect("/login") + return + self.application.settings.get("compiled_template_cache", False) self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') try: @@ -513,7 +524,11 @@ class ConfigHandler(tornado.web.RequestHandler): rig_models=[s[10:] for s in dir(Hamlib) if "RIG_MODEL_" in s] self.write("""
""") self.write("""[SERVER]

""") - self.write("""SERVER TCP/IP port:

""") + self.write("""SERVER TCP/IP port:Defautl:8888.The server port

""") + self.write("""SERVER Authentification type: Defautl:leave blank. Else you can use "FILE" or/and "PAM".

""") + self.write("""SERVER database users file: Defautl:UHRR_users.db Only if you use Authentification type "FILE".

""") + self.write("""You can change database users file in UHRR.conf.
To add a user in FILE type, add it in UHRR_users.db (default file name).
Add one account per line as login password.
""") + self.write("""If you plan to use PAM you can add account in command line: adduser --no-create-home --system thecallsign.

""") self.write("""If you whant to change certfile and keyfile, replace "UHRH.crt" and "UHRH.key" in the boot folder, and when the pi boot, it will use those files to start http ssl.

""") self.write("""[AUDIO]

""") @@ -522,29 +537,30 @@ class ConfigHandler(tornado.web.RequestHandler): self.write("""""") for c in audiodevicesoutput: self.write("""""") - self.write("""

""") + self.write(""" Output from audio soundcard to the mic input of TRX.

""") self.write("""AUDIO inputdevice:

""") + self.write(""" Input from audio soundcard from the speaker output of TRX.

""") self.write("""[HAMLIB]

""") - self.write("""HAMLIB serial port:

""") - + self.write("""HAMLIB radio model:

""") + self.write(""" Hamlib trx model.

""") + + self.write("""HAMLIB serial port: Serial port of the CAT interface.

""") self.write("""HAMLIB radio rate:

""") + self.write(""" Serial port baud rate.

""") self.write("""HAMLIB auto tx poweroff:

""") + self.write("""""") + self.write("""""") + self.write(""" Set to auto power off the trx when it's not in use

""") self.write("""[PANADAPTER]

""") self.write("""PANADAPTER FI frequency (hz):

""") @@ -594,6 +610,11 @@ class ConfigHandler(tornado.web.RequestHandler): self.write("""

Possible problem:"""+e+"""""") def post(self): + + if bool(config['SERVER']['auth']) and not self.current_user: + self.redirect("/login") + return + for x in self.request.arguments: (s,o)=x.split(".") v=self.get_argument(x) @@ -607,6 +628,64 @@ class ConfigHandler(tornado.web.RequestHandler): time.sleep(2) os.system("sleep 2;./UHRR &") os._exit(1) + +############ Login ############## +class AuthLoginHandler(BaseHandler): + + def get(self): + if not bool(config['SERVER']['auth']): + self.redirect("/") + return + self.write('
' + 'CallSign:
' + 'Password:
' + '' + '
') + + def post(self): + if self.get_argument("name") != "" and self.get_argument("passwd") != "": + if self.bind(self.get_argument("name"),self.get_argument("passwd")): + self.set_secure_cookie("user", self.get_argument("name")) + self.set_cookie("callsign", self.get_argument("name")) + self.set_cookie("autha", "1") + else: + writte_log("Auth error for CallSign:"+str(self.get_argument("name"))) + self.redirect("/") + + def bind(self,user="",password=""): + retval = False + if (user!="" and password!=""): + if config['SERVER']['auth'].find("FILE") != -1: #test with users db file + f = open(config['SERVER']['db_users_file'], "r") + for x in f: + if x[0]!="#": + db=x.split(" ") + if db[0] == user and db[1]== password: + retval = True + break + if not retval and config['SERVER']['auth'].find("PAM") != -1:#test with pam module + if config['SERVER']['pam_account'].find(user) != -1: + import pam + retval = pam.authenticate(user, password) + return retval + +class AuthLogoutHandler(BaseHandler): + def get(self): + self.clear_cookie("user") + self.clear_cookie("autha") + self.redirect(self.get_argument("next", "/")) + +############ Main ############## +class MainHandler(BaseHandler): + + def get(self): + print("Tornado current user:"+str(self.current_user)) + if bool(config['SERVER']['auth']) and not self.current_user: + self.redirect("/login") + return + self.application.settings.get("compiled_template_cache", False) + self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') + self.render("www/index.html") if __name__ == "__main__": @@ -629,6 +708,8 @@ if __name__ == "__main__": app = tornado.web.Application([ + (r"/login", AuthLoginHandler), + (r"/logout", AuthLogoutHandler), (r'/audioRX', AudioRXHandler), (r'/audioTX', AudioTXHandler), (r'/CTRX', ControlTRX), @@ -636,7 +717,7 @@ if __name__ == "__main__": (r'/CONFIG', ConfigHandler), (r'/', MainHandler), (r'/(.*)', tornado.web.StaticFileHandler, { 'path' : './www' }) - ],debug=bool(config['SERVER']['debug']), websocket_ping_interval=10) + ],debug=bool(config['SERVER']['debug']), websocket_ping_interval=10, cookie_secret=config['SERVER']['cookie_secret']) except: e = str(sys.exc_info()) print(e) @@ -653,3 +734,4 @@ if __name__ == "__main__": http_server.listen(int(config['SERVER']['port'])) print('HTTP server started.') tornado.ioloop.IOLoop.instance().start() + diff --git a/UHRR.conf b/UHRR.conf index 67d5639..1dab8b0 100644 --- a/UHRR.conf +++ b/UHRR.conf @@ -1,7 +1,12 @@ [SERVER] port = 8888 -certfile = /boot/UHRH.crt -keyfile = /boot/UHRH.key +certfile = UHRH.crt +keyfile = UHRH.key +auth = +cookie_secret = L8LwECiNRxq2N0N2eGxx9MZlrpmuMEimlydNX/vt1LM= +db_users_file = UHRR_users.db +pam_account = pi +log_file = UHRR.log debug = True [CTRL] diff --git a/UHRR.log b/UHRR.log new file mode 100644 index 0000000..5623dda --- /dev/null +++ b/UHRR.log @@ -0,0 +1 @@ +2020-11-15 00:53:01.857765:Auth error for CallSign:pi \ No newline at end of file diff --git a/UHRR_users.db b/UHRR_users.db new file mode 100644 index 0000000..a4a2300 --- /dev/null +++ b/UHRR_users.db @@ -0,0 +1,3 @@ +#one line per account like : +#1AAW Paul! +F4HTB test diff --git a/opus/__pycache__/__init__.cpython-37.pyc b/opus/__pycache__/__init__.cpython-37.pyc index 03faa2f..ae0c7fd 100644 Binary files a/opus/__pycache__/__init__.cpython-37.pyc and b/opus/__pycache__/__init__.cpython-37.pyc differ diff --git a/opus/__pycache__/decoder.cpython-37.pyc b/opus/__pycache__/decoder.cpython-37.pyc index 965a5f4..c199fac 100644 Binary files a/opus/__pycache__/decoder.cpython-37.pyc and b/opus/__pycache__/decoder.cpython-37.pyc differ diff --git a/opus/__pycache__/exceptions.cpython-37.pyc b/opus/__pycache__/exceptions.cpython-37.pyc index f60a28a..5971b77 100644 Binary files a/opus/__pycache__/exceptions.cpython-37.pyc and b/opus/__pycache__/exceptions.cpython-37.pyc differ diff --git a/opus/api/__pycache__/__init__.cpython-37.pyc b/opus/api/__pycache__/__init__.cpython-37.pyc index 3a80441..a2177b9 100644 Binary files a/opus/api/__pycache__/__init__.cpython-37.pyc and b/opus/api/__pycache__/__init__.cpython-37.pyc differ diff --git a/opus/api/__pycache__/constants.cpython-37.pyc b/opus/api/__pycache__/constants.cpython-37.pyc index 59f5b8f..764fc13 100644 Binary files a/opus/api/__pycache__/constants.cpython-37.pyc and b/opus/api/__pycache__/constants.cpython-37.pyc differ diff --git a/opus/api/__pycache__/ctl.cpython-37.pyc b/opus/api/__pycache__/ctl.cpython-37.pyc index a7ac8c6..b94d952 100644 Binary files a/opus/api/__pycache__/ctl.cpython-37.pyc and b/opus/api/__pycache__/ctl.cpython-37.pyc differ diff --git a/opus/api/__pycache__/decoder.cpython-37.pyc b/opus/api/__pycache__/decoder.cpython-37.pyc index a92a38c..1b97a46 100644 Binary files a/opus/api/__pycache__/decoder.cpython-37.pyc and b/opus/api/__pycache__/decoder.cpython-37.pyc differ diff --git a/opus/api/__pycache__/info.cpython-37.pyc b/opus/api/__pycache__/info.cpython-37.pyc index 882990f..801a129 100644 Binary files a/opus/api/__pycache__/info.cpython-37.pyc and b/opus/api/__pycache__/info.cpython-37.pyc differ diff --git a/www/controls.js b/www/controls.js index 69dd7a7..591e263 100644 --- a/www/controls.js +++ b/www/controls.js @@ -599,8 +599,10 @@ function getCookie(cname) { function checkCookie() { var callsign=getCookie("callsign"); if (callsign != "") { - alert("Welcome again " + callsign); - document.getElementById("callsign").innerHTML=callsign; + alert("Welcome " + callsign); + labelcalls = document.getElementById("callsign"); + labelcalls.innerHTML=callsign; + if(getCookie("autha"))labelcalls.innerHTML+=' '; } else { callsign = prompt("Please enter your Call Sign:",""); if (callsign != "" && callsign != null) { diff --git a/www/img/logout.png b/www/img/logout.png new file mode 100644 index 0000000..2e96817 Binary files /dev/null and b/www/img/logout.png differ diff --git a/www/style.css b/www/style.css index fcd86f3..d6d6e41 100644 --- a/www/style.css +++ b/www/style.css @@ -89,6 +89,11 @@ overflow: hidden; text-align:center; } +#callsign > a > img{ + height:25px; + width:25px; +} + #personalfrequency { position:absolute;