summaryrefslogtreecommitdiff
path: root/readme.md
blob: 0b16214f15516397b6e8390c0deed8a5116921b5 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Installation
============

Install the following packages:

  - apache2
  - nodejs (>= 10.0.22)
  - python3 (>= 3.4)
  - python3-ply
  - python3-psycopg2
  - python3-termcolor
  - swi-prolog-nox (>= 7.2)

SWI prolog
----------

To use the correct SWI prolog package (>= 7.2) on Debian, add a custom
repository by creating the file /etc/apt/sources.list.d/prolog.list
containing the following 2 lines:

deb http://ppa.launchpad.net/swi-prolog/stable/ubuntu trusty main
deb-src http://ppa.launchpad.net/swi-prolog/stable/ubuntu trusty main

After that run the following sequence of shell statements to update
the package cache, register the new repository's key, and again refresh
the package cache using the additional key:

apt-get update
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EF8406856DBFCA18
apt-get update

libseccomp
----------

A new version of libseccomp (≥ 2.2) with Python bindings is needed to sandbox
Python interpreters. This is not available yet in most distributions, so fetch
the latest sources with

    git clone https://github.com/seccomp/libseccomp

then build and install it with

    ./configure --enable-python
    make
    make install

nodejs
------

Run "npm install" inside the "web" directory to install all dependencies (they
will be installed inside the "web" directory)

Settings
========

  - point webroot to codeq-web
  - set up reverse proxy for /ws/ to the node server:
    - using the command a2enmod enable apache modules: proxy, proxy_http, proxy_wstunnel, rewrite
    - add to the apache configuration the following directives:
      RewriteEngine on
      RewriteCond %{REQUEST_URI} ^/ws/ [NC]
      RewriteCond %{QUERY_STRING} transport=websocket [NC]
      RewriteRule /(.*) ws://localhost:8083/$1 [P,L]
      ProxyPass /ws/ http://localhost:8083/ws/
      ProxyPassReverse /ws/ http://localhost:8083/ws/
  - set _path_prefix in server.problems
  - set DB settings in db

Running
=======

  - run the prolog interpreter server: swipl prolog/runner/main.pl
  - run the session daemon: python3 daemon.py
  - run the web server for client communication: node web/main.js

Misc.
=====

Add a new problem to the database by running

    python -m scripts.add_problem

in the toplevel directory. This will ask for language and problem group (groups
can be shared between languages, e.g. Introduction can be used for both Prolog
and Python). The script will print the ID and path for the new problem.

You can test stuff in a python interpreter:

    >>> import server
    >>> session = server.user_session.authenticate_and_create_session(<user>, <pass>)
    >>> session.get_problem_data('python', 'introduction', 'fahrenheit_to_celsius')

    >>> python = session.get_python()
    >>> python.test(231, 180, '''print('-17.7')''')
    >>> python.hint(231, 180, '''print('-17.7')''')

    >>> prolog = session.get_prolog()
    >>> prolog.test(231, 96, 'sister(X,Y):- parent(P,X), parent(P,Y), female(X).')
    >>> prolog.hint(231, 96, 'sister(X,Y):- parent(P,X), parent(P,Y), female(X).')