Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from ltworf/feedback
Browse files Browse the repository at this point in the history
Fix feedback (for now, at least)
  • Loading branch information
ltworf authored Oct 7, 2023
2 parents d0a0284 + c64f72c commit af19502
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Add support for localization
- Add Italian localization
- Use setuptools because python dropped distutil -_-'
- Fix survey

3.0
- UI shows different colours for different types
Expand Down
9 changes: 0 additions & 9 deletions feedback-ltworf/app.yaml

This file was deleted.

37 changes: 0 additions & 37 deletions feedback-ltworf/feedback.py

This file was deleted.

23 changes: 0 additions & 23 deletions feedback-ltworf/micro_webapp2.py

This file was deleted.

50 changes: 50 additions & 0 deletions feedback/feedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 <[email protected]>
#
# 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)
28 changes: 19 additions & 9 deletions relational/maintenance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Relational
# Copyright (C) 2008-2020 Salvo "LtWorf" Tomaselli
# Copyright (C) 2008-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
Expand Down Expand Up @@ -29,15 +29,18 @@
from relational.rtypes import is_valid_relation_name


def send_survey(data) -> int:
def send_survey(data: dict[str, str]) -> int:
'''Sends the survey. Data must be a dictionary.
returns the http response.
returns 0 in case of error
returns -1 in case of swearwords'''
import urllib.parse
from http.client import HTTPConnection
from http.client import HTTPSConnection
import ssl


# Scan for swearwords
SWEARWORDS = {'fuck', 'shit', 'suck', 'merda', 'mierda', 'merde'}

post = ''
Expand All @@ -50,14 +53,21 @@ def send_survey(data) -> int:
return -1

# sends the string
params = urllib.parse.urlencode({'survey': post})
headers = {"Content-type":
"application/x-www-form-urlencoded", "Accept": "text/plain"}
connection = HTTPConnection('feedback-ltworf.appspot.com')
headers = {
"Accept": "text/plain",
"X-Survey": "relational",
}
for k, v in data.items():
headers[f'X-Survey-{k}'] = v
connection = HTTPSConnection(
'tomaselli.page',
context = ssl._create_unverified_context() # Of course python can't find the root cert
)

try:
connection.request("POST", "/feedback/relational", params, headers)
connection.request("GET", "feedback.py", headers=headers)
return connection.getresponse().status
except:
except Exception:
return 0


Expand Down

0 comments on commit af19502

Please sign in to comment.