File: feedback.py

package info (click to toggle)
relational 3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,168 kB
  • sloc: python: 2,984; makefile: 101
file content (50 lines) | stat: -rw-r--r-- 1,757 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# Relational
# Copyright (C) 2023  Salvo "LtWorf" Tomaselli
#
# Relation is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
#
# Used to receive feedback from relational

from os import environ
from syslog import *

HEADERHTTP='HTTP/1.0 200 Ok\r\nContent-Type: text/html; charset=UTF-8\r\nConnection: close\r\n\r\n'
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>'

def main():
    if 'HTTP_X_SURVEY' not in environ:
        syslog(LOG_ERR, "Got invalid survey")
        print(NOTFOUND)
        return
    syslog(LOG_INFO, "Got valid survey")
    import datetime
    with open('/srv/www/survey.txt', 'at') as f:
        print(datetime.datetime.now(), file=f)
        for k, v in environ.items():
            if k.startswith('HTTP_X_SURVEY'):
                print(f'{k} = {v}', file=f)
        print(file=f)
    print(HEADERHTTP)

if __name__ == '__main__':
    openlog('feedback')
    try:
        main()
    except Exception as e:
        syslog(LOG_ERR, repr(e))
        from sys import exit
        exit(1)