Debian Codegraph @

feedback/feedback.py

raw
1 #!/usr/bin/env python3
2 # Relational
3 # Copyright (C) 2023 Salvo "LtWorf" Tomaselli
4 #
5 # Relation is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # author Salvo "LtWorf" Tomaselli <[email protected]>
19 #
20 # Used to receive feedback from relational
21
22 from os import environ
23 from syslog import *
24
25 HEADERHTTP='HTTP/1.0 200 Ok\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\n\r\n'
26 NOTFOUND='HTTP/1.0 404 Not found\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\n\r\n<html><body><p>Not found</p></body></html>'
27
28 def main():
29 if 'HTTP_X_SURVEY' not in environ:
30 syslog(LOG_ERR, "Got invalid survey")
31 print(NOTFOUND)
32 return
33 syslog(LOG_INFO, "Got valid survey")
34 import datetime
35 with open('/srv/www/survey.txt', 'at') as f:
36 print(datetime.datetime.now(), file=f)
37 for k, v in environ.items():
38 if k.startswith('HTTP_X_SURVEY'):
39 print(f'{k} = {v}', file=f)
40 print(file=f)
41 print(HEADERHTTP)
42
43 if __name__ == '__main__':
44 openlog('feedback')
45 try:
46 main()
47 except Exception as e:
48 syslog(LOG_ERR, repr(e))
49 from sys import exit
50 exit(1)