Email: {email} Telephone: {telephone} """ class Handler(server.RequestHandler): def get(self): self.write({'smtpEnabled': network.smtpEnabled()}) async def post(self): issueText = text.format( description=self.get_body_argument("description"), name=self.get_body_argument("name"), email=self.get_body_argument("email"), telephone=self.get_body_argument("telephone"), ) issue = await server.run_in_executor(Issue, issueText) issue['Reply-To'] = self.get_body_argument("email") action = self.get_query_argument('action', 'download') if action.startswith('send'): await server.run_in_executor(network.sendEmail, issue) else: self.set_header('Content-Type', 'message/rfc822') self.set_header('Content-Disposition', 'attachment; filename=issue.eml') self.write(bytes(issue)) server.addAjax(__name__, Handler)
class WlanLanHandler(LanHandler): def initialize(self): self.confFile = '/etc/systemd/network/wlan.network.d/local.conf' class SmtpHandler(server.RequestHandler): def get(self): if network.smtpEnabled(): self.write(Conf(network.smtpConfFile).dict()) else: self.write({}) def post(self): if self.request.body: Conf(network.smtpConfFile, self.readJson()).save() else: try: os.remove(network.smtpConfFile) except OSError: pass server.addAjax(__name__ + '/status', StatusHandler) server.addAjax(__name__ + '/syswlan', SyswlanHandler) server.addAjax(__name__ + '/lan', LanHandler) server.addAjax(__name__ + '/wlan', WlanHandler) server.addAjax(__name__ + '/wlan/lan', WlanLanHandler) server.addAjax(__name__ + '/smtp', SmtpHandler)
# Copyright (c) 2018 Artur Wiebe <*****@*****.**> # # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and # associated documentation files (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import server from shared import system class PoweroffHandler(server.RequestHandler): def post(self): system.poweroff() server.addAjax(__name__+'/poweroff', PoweroffHandler)
import server import pathlib, os, subprocess class Handler(server.RequestHandler): def get(self): try: self.write(pathlib.Path('/version').read_text()) except: pass async def put(self): await server.run_in_executor(lambda: subprocess.run( ['update'], input=self.request.files['update'][0]['body'])) class RevertHandler(server.RequestHandler): def get(self): try: self.write(str(os.path.getmtime('/var/revert'))) except: pass async def post(self): await server.run_in_executor( lambda: subprocess.run(['update', '--revert'])) server.addAjax(__name__, Handler) server.addAjax(__name__ + '/revert', RevertHandler)
def open(self): args = journalArgs.copy() args.extend(shlex.split(self.get_argument('args'))) args.append('--lines=300') args.append('--output=json') args.append('--all') args.append('--follow') args.append('--merge') self.task = asyncio.create_task(self.readJournal(args)) def on_close(self): self.task.cancel() class LogFieldHandler(server.RequestHandler): async def get(self, field): args = journalArgs.copy() args.append('--field={}'.format(field)) journalProc = process.Subprocess(args, stdout=process.Subprocess.STREAM) values = await journalProc.stdout.read_until_close() self.writeJson(values.decode().splitlines()) await journalProc.wait_for_exit(raise_error=False) server.addAjax(__name__, Handler) server.addAjax(__name__ + '/(.*)', LogFieldHandler)