From 8f401eb72179700f241599609265e0e601c4566e Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Wed, 15 Mar 2017 10:31:26 +0000 Subject: [PATCH] - Modified how paths to scripts are handled. Paths are now relative to the directory of the question yaml file (instead of questions_dir). --- BUGS.md | 5 +++-- README.md | 47 +++++++++++++++++++++++++++++++++++++---------- questions.py | 21 +++++++++++++++------ serve.py | 15 ++++++++++++--- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/BUGS.md b/BUGS.md index 12e030a..56a1a4a 100644 --- a/BUGS.md +++ b/BUGS.md @@ -2,13 +2,12 @@ # BUGS - Review de um teste que foi apagado rebenta. -- Gerar pdf's com todos os testes no final (pdfkit). - permitir eliminar teste a decorrer de modo a que o aluno possa recomeçar (e.g. noutro browser) - servidor nao esta a lidar com eventos scroll/resize. ignorar? # TODO -- configurar pf em freebsd, port forward 80 -> 8080. documentacao +- Gerar pdf's com todos os testes no final (pdfkit). - testar SSL - manter registo dos unfocus durante o teste e de qual a pergunta visivel nesse momento @@ -28,6 +27,8 @@ # FIXED +- configuração do teste não joga bem com o do aprendizations. Em particular os scripts não ficam com o mesmo path!!! +- configurar pf em freebsd, port forward 80 -> 8080. documentacao - barras com notas em grade estão desalinhadas. - erros nos generators devem ser ERROR e não WARNING. - se directorio "logs" não existir no directorio actual aborta com mensagem de erro. diff --git a/README.md b/README.md index 53eaddb..4addf32 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ### Requirements -The webserver is a python application and requires `python3.5` and `pip` to be installed, plus the following additional packages: +The webserver is a python application and requires `python3.6` and `pip` to be installed, plus the following additional packages: - CherryPy - Mako @@ -29,7 +29,7 @@ pip install --user cherrypy mako markdown pyyaml pygments sqlalchemy bcrypt #### Installing packages in a virtual environment (alternative) ```.bash -pyvenv-3.5 venv/perguntations # or other virtualenv directory +pyvenv-3.6 venv/perguntations # or other virtualenv directory source venv/perguntations/bin/activate # activate virtualenv pip install cherrypy mako markdown pyyaml pygments sqlalchemy bcrypt @@ -80,7 +80,7 @@ We are now ready to run the server: ./serve.py demo/test.yaml # run demo test ``` -By default the server listens on all IPs of all network interfaces. +By default the server listens on port 8080 and on all IPs of all network interfaces. Open the browser at `http://127.0.0.1:8080/` and login as user number `0` (administrator) and choose any password. Then 1. Authorize students by clicking the checkboxes. @@ -90,7 +90,7 @@ The server can be stoped from the terminal with `^C`. ## Running on port 80 -Port 80 is reserved for the root user and and this software _should NOT be run as root_. Instead, the firewall should be configured to forward tcp traffic from port 80 to 8080 where the server is listening. The details depend on the operating system. +Ports 80 and 443 are reserved for the root user and and this software _should NOT be run as root_. Instead, the firewall should be configured to forward tcp traffic from port 80 to 8080 where the server is listening. The details depend on the operating system. ### debian: @@ -109,9 +109,28 @@ Explanation: - `-j REDIRECT` what to do when packet matches the rule. - `--to-ports 8080` where to redirect the packets. -### freebsd +### FreeBSD and pf -Todo... +Edit `/etc/pf.conf`: + + ext_if="em0" + rdr on $ext_if proto tcp from any to any port 80 -> 127.0.0.1 port 8080 + rdr on $ext_if proto tcp from any to any port 443 -> 127.0.0.1 port 8443 + +or `ext_if="vtnet0"` for guest additions under virtual box. + +Edit `rc.conf` + + pf_enable="YES" + pf_flags="" + pf_rules="/etc/pf.conf" + + # optional logging: + pflog_enable="YES" + pflog_flags="" + pflog_logfile="/var/log/pflog" + +Reboot. ## Enabling SSL @@ -119,12 +138,20 @@ Todo... ## Troubleshooting -* The server tries to run `python3`. If only a `python3.5` command is available, you need to set the default python using the OS package manager or manually create a symbolic link: - - macOS/macports: `sudo port select --set python3 python35` - - FreeBSD 11: `cd /usr/local/bin; ln -s python3.5 python3` +* The server tries to run `python3`. If only a `python3.6` command is available, you need to set the default python using the OS package manager or manually create a symbolic link: + - macOS/macports: `sudo port select --set python3 python36` + - FreeBSD 11: `cd /usr/local/bin; ln -s python3.6 python3` -* If you are getting any `UnicodeEncodeError` type of errors that's because the terminal is not supporting UTF-8. Try running `locale` on the terminal and see if there is any error messages. Solutions: +* If you are getting any `UnicodeEncodeError` type of errors that's because the terminal is not supporting UTF-8. This error may occur when a unicode character is printed to the screen by the server or, when running question generator or correction scripts, a message is piped between the server and the scripts that includes unicode characters. +Try running `locale` on the terminal and see if there are any error messages. Solutions: - debian: fix it with `sudo dpkg-reconfigure locales`, select your UTF-8 locales and try again. + - FreeBSD: edit `~/.login_conf` to use UTF-8, for example: + + ``` + me:\ + :charset=UTF-8:\ + :lang=en_US.UTF-8: + ``` ## Contribute ### diff --git a/questions.py b/questions.py index 02e80d4..58bf28e 100644 --- a/questions.py +++ b/questions.py @@ -83,24 +83,33 @@ class QuestionFactory(dict): # ----------------------------------------------------------------------- # load single YAML questions file # ----------------------------------------------------------------------- - def load_file(self, filename, questions_dir=''): - f = path.normpath(path.join(questions_dir, filename)) - questions = load_yaml(f, default=[]) + def load_file(self, pathfile, questions_dir=''): + # questions_dir is a base directory + # pathfile is a path of a file under the questions_dir + # For example, if + # pathfile = 'math/questions.yaml' + # questions_dir = '/home/john/questions' + # then the complete path is + # fullpath = '/home/john/questions/math/questions.yaml' + fullpath = path.normpath(path.join(questions_dir, pathfile)) + (dirname, filename) = path.split(fullpath) + + questions = load_yaml(fullpath, default=[]) n = 0 for i, q in enumerate(questions): if isinstance(q, dict): q.update({ 'filename': filename, - 'path': questions_dir, + 'path': dirname, 'index': i # position in the file, 0 based }) self.add(q) # add question n += 1 # counter else: - logger.error('Question index {0} from file {1} is not a dictionary. Skipped!'.format(i, filename)) + logger.error('Question index {0} from file {1} is not a dictionary. Skipped!'.format(i, pathfile)) - logger.info('Loaded {0} questions from "{1}".'.format(n, filename)) + logger.info('Loaded {0} questions from "{1}".'.format(n, pathfile)) # ----------------------------------------------------------------------- # load multiple YAML question files diff --git a/serve.py b/serve.py index 7d2a3fc..fecf886 100755 --- a/serve.py +++ b/serve.py @@ -1,6 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- - from os import path import sys @@ -9,10 +7,21 @@ import logging.config import json try: + # required here import cherrypy from mako.lookup import TemplateLookup + # required elsewhere + from json import __version__ as json_version + from bcrypt import __version__ as bcrypt_version + from sqlalchemy import __version__ as alchemy_version + from yaml import __version__ as yaml_version + from markdown import version as markdown_version except ImportError: - print('Some python packages are missing. See README.md for instructions.') + print(''' + Some python packages are missing. + Try running "pip3 install --user cherrypy mako markdown pyyaml pygments sqlalchemy bcrypt" + See README.md for instructions. + ''') sys.exit(1) from tools import load_yaml -- libgit2 0.21.2