43785de6
Miguel Barão
- added documenta...
|
1
|
# Getting Started
|
a96cd2c7
Miguel Barão
- added logging s...
|
2
|
|
1e8f0810
Miguel Barão
update setup.py a...
|
3
|
Latest review: 2021-07-08
|
5d859a41
Miguel Barão
update documentation
|
4
5
6
|
## Installation
|
93e13002
Miguel Barão
updates README.md.
|
7
|
To complete the installation we will need to perform the following steps:
|
a96cd2c7
Miguel Barão
- added logging s...
|
8
|
|
39126690
Miguel Barão
removes npm and n...
|
9
10
11
12
|
1. install python3, pip and npm
2. download aprendizations from the repository
3. install javascript libraries (with npm)
4. install aprendizations (with pip)
|
f540e673
Miguel Barão
- added README.md
|
13
|
5. generate SSL certificates
|
5d859a41
Miguel Barão
update documentation
|
14
15
|
6. configure the firewall (optional)
|
39126690
Miguel Barão
removes npm and n...
|
16
|
To use the software we need to:
|
443a1eea
Miguel Barão
Update to latest ...
|
17
|
|
39126690
Miguel Barão
removes npm and n...
|
18
|
1. initialize database
|
5d859a41
Miguel Barão
update documentation
|
19
20
|
2. go to the demo directory (or an existing course)
3. run `aprendizations demo.yaml`
|
43785de6
Miguel Barão
- added documenta...
|
21
|
|
39126690
Miguel Barão
removes npm and n...
|
22
|
Each of these steps is explained below.
|
43785de6
Miguel Barão
- added documenta...
|
23
|
|
39126690
Miguel Barão
removes npm and n...
|
24
25
|
### Install python3 with sqlite3 support and npm
|
c54ee176
Miguel Barão
update javascript...
|
26
27
|
Python can be installed either from the system package management or compiled
from sources.
|
39126690
Miguel Barão
removes npm and n...
|
28
29
|
#### Installing from the system package manager
|
1e8f0810
Miguel Barão
update setup.py a...
|
30
|
|
93e13002
Miguel Barão
updates README.md.
|
31
32
|
```sh
sudo pkg install python3 npm # FreeBSD
|
43785de6
Miguel Barão
- added documenta...
|
33
|
sudo apt install python3 npm # Linux (Ubuntu)
|
59213008
Miguel Barão
- fixed user path...
|
34
|
sudo port install python38 npm7 # MacOS
|
443a1eea
Miguel Barão
Update to latest ...
|
35
|
```
|
a96cd2c7
Miguel Barão
- added logging s...
|
36
|
|
43785de6
Miguel Barão
- added documenta...
|
37
|
In FreeBSD also install `py3X-sqlite3` where `X` is the python version.
|
39126690
Miguel Barão
removes npm and n...
|
38
39
|
#### Installing from source (outdated)
|
1e8f0810
Miguel Barão
update setup.py a...
|
40
|
|
43785de6
Miguel Barão
- added documenta...
|
41
|
Make sure that the build tools and libraries are installed:
|
f540e673
Miguel Barão
- added README.md
|
42
|
|
443a1eea
Miguel Barão
Update to latest ...
|
43
44
|
```sh
# Ubuntu:
|
39126690
Miguel Barão
removes npm and n...
|
45
|
sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev \
|
5d859a41
Miguel Barão
update documentation
|
46
|
libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev \
|
1e8f0810
Miguel Barão
update setup.py a...
|
47
48
49
50
51
|
libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev
```
Download [python](http://www.python.org) and
|
5dae401a
Miguel Barão
update README.md
|
52
|
```sh
|
f540e673
Miguel Barão
- added README.md
|
53
|
tar xvfJ Python-3.7.tar.xz
|
43785de6
Miguel Barão
- added documenta...
|
54
55
56
57
|
cd Python-3.7
./configure --prefix=$HOME/.local --enable-optimizations
make && make install
```
|
f540e673
Miguel Barão
- added README.md
|
58
|
|
39126690
Miguel Barão
removes npm and n...
|
59
|
This will install python locally under `~/.local/bin`. Make sure to add it to
|
f540e673
Miguel Barão
- added README.md
|
60
|
your `PATH` in `~/.profile`. If `~/bin` is already in the path, just make a
|
43785de6
Miguel Barão
- added documenta...
|
61
|
symbolic link `ln -s ~/.local/bin ~/bin`.
|
39126690
Miguel Barão
removes npm and n...
|
62
|
|
43785de6
Miguel Barão
- added documenta...
|
63
|
### Install pip
|
f540e673
Miguel Barão
- added README.md
|
64
|
|
c3eba869
Miguel Barão
update README.md
|
65
|
Install `pip` from the system package manager:
|
a96cd2c7
Miguel Barão
- added logging s...
|
66
|
|
443a1eea
Miguel Barão
Update to latest ...
|
67
|
```sh
|
1e8f0810
Miguel Barão
update setup.py a...
|
68
|
sudo apt install python3-pip # Ubuntu
|
a96cd2c7
Miguel Barão
- added logging s...
|
69
|
sudo pkg py38-pip # FreeBSD
|
443a1eea
Miguel Barão
Update to latest ...
|
70
|
sudo port install py39-pip # MacOS
|
39126690
Miguel Barão
removes npm and n...
|
71
|
```
|
f540e673
Miguel Barão
- added README.md
|
72
|
|
39126690
Miguel Barão
removes npm and n...
|
73
74
|
Then run `python3 -m pip install -U pip` to install latest version into your
user account under `~/.local/bin`.
|
5dae401a
Miguel Barão
update README.md
|
75
76
|
In the end you should be able to run `pip --version` and `python3 -c "import
sqlite3"` without errors.
|
93e13002
Miguel Barão
updates README.md.
|
77
|
In some systems, `pip` can be named `pip3`, `pip3.8` or `pip-3.8`.
|
1e8f0810
Miguel Barão
update setup.py a...
|
78
|
|
5dae401a
Miguel Barão
update README.md
|
79
80
|
Edit the configuration file `~/.config/pip/pip.conf` (FreeBSD, Linux) or
`Library/Application Support/pip/pip.conf` (MacOS) and add the lines
|
93e13002
Miguel Barão
updates README.md.
|
81
|
|
b4ceb7fc
Miguel Barão
minor change in l...
|
82
|
```ini
|
93e13002
Miguel Barão
updates README.md.
|
83
84
85
|
[global]
user = yes
```
|
39126690
Miguel Barão
removes npm and n...
|
86
|
|
93e13002
Miguel Barão
updates README.md.
|
87
|
This will set pip to install modules in the user area (recommended).
|
f540e673
Miguel Barão
- added README.md
|
88
|
|
59213008
Miguel Barão
- fixed user path...
|
89
90
|
### Download and install aprendizations
|
443a1eea
Miguel Barão
Update to latest ...
|
91
92
|
```sh
git clone https://git.xdi.uevora.pt/mjsb/aprendizations.git
|
c288f8c6
Miguel Barao
- updated documen...
|
93
|
cd aprendizations
|
443a1eea
Miguel Barão
Update to latest ...
|
94
95
96
|
npm install # install javascript libraries
pip install . # install aprendizations and dependencies
```
|
c288f8c6
Miguel Barao
- updated documen...
|
97
|
|
93e13002
Miguel Barão
updates README.md.
|
98
|
Javascript libraries are installed in `aprendizations/node_modules` and are
|
f540e673
Miguel Barão
- added README.md
|
99
|
linked from `aprendizations/aprendizations/static`.
|
b4ceb7fc
Miguel Barão
minor change in l...
|
100
|
|
59213008
Miguel Barão
- fixed user path...
|
101
|
Python packages are usually installed in:
|
43785de6
Miguel Barão
- added documenta...
|
102
103
104
|
* `~/.local/lib/python3.8/site-packages/` in Linux/FreeBSD.
* `~/Library/python/3.9/lib/python/site-packages/` in MacOS.
|
59213008
Miguel Barão
- fixed user path...
|
105
|
|
93e13002
Miguel Barão
updates README.md.
|
106
107
108
|
When aprendizations is installed with pip, all the dependencies are also
installed. The javascript libraries previously installed with npm are copied to
the above directory and the cloned repository is no longer needed.
|
bbc1c506
Miguel Barão
- documentation u...
|
109
|
|
43785de6
Miguel Barão
- added documenta...
|
110
|
At this point `aprendizations` is installed in
|
443a1eea
Miguel Barão
Update to latest ...
|
111
|
|
5d859a41
Miguel Barão
update documentation
|
112
|
```sh
|
43785de6
Miguel Barão
- added documenta...
|
113
|
~/.local/bin # Linux/FreeBSD
|
bbc1c506
Miguel Barão
- documentation u...
|
114
|
~/Library/Python/3.9/bin # MacOS
|
443a1eea
Miguel Barão
Update to latest ...
|
115
116
|
```
|
bbc1c506
Miguel Barão
- documentation u...
|
117
|
and can be run from the terminal:
|
43785de6
Miguel Barão
- added documenta...
|
118
|
|
93e13002
Miguel Barão
updates README.md.
|
119
120
|
```sh
aprendizations --version
|
43785de6
Miguel Barão
- added documenta...
|
121
|
aprendizations --help
|
bbc1c506
Miguel Barão
- documentation u...
|
122
|
```
|
443a1eea
Miguel Barão
Update to latest ...
|
123
124
125
|
### SSL Certificates
|
bbc1c506
Miguel Barão
- documentation u...
|
126
|
We need certificates for https. Certificates can be self-signed or validated by
|
43785de6
Miguel Barão
- added documenta...
|
127
|
a trusted authority.
|
443a1eea
Miguel Barão
Update to latest ...
|
128
|
|
43785de6
Miguel Barão
- added documenta...
|
129
130
131
132
|
Self-signed can be used locally for development and testing, but browsers will
complain. LetsEncrypt issues trusted and free certificates, but the server must
have a registered publicly accessible domain name.
|
bbc1c506
Miguel Barão
- documentation u...
|
133
|
#### Generating selfsigned certificates
|
5d859a41
Miguel Barão
update documentation
|
134
135
136
137
|
Generate a selfsigned certificate and place it in `~/.local/share/certs`.
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
138
139
|
openssl req -x509 -newkey rsa:4096 -keyout privkey.pem -out cert.pem -days 365 -nodes
```
|
39126690
Miguel Barão
removes npm and n...
|
140
|
|
5d859a41
Miguel Barão
update documentation
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#### LetsEncrypt certificates
Install the certbot from LetsEncrypt:
```sh
sudo pkg install py38-certbot # FreeBSD
sudo apt install certbot # Ubuntu
```
To generate or renew the certificates, ports 80 and 443 must be accessible.
**Any firewall and webserver have to be stopped**.
```sh
sudo certbot certonly --standalone -d www.example.com # first time
sudo certbot renew # renew
|
93e13002
Miguel Barão
updates README.md.
|
156
|
```
|
c55940af
Miguel Barão
- minor change in...
|
157
|
|
39126690
Miguel Barão
removes npm and n...
|
158
|
Certificates are saved under
|
443a1eea
Miguel Barão
Update to latest ...
|
159
|
`/usr/local/etc/letsencrypt/live/www.example.com/`. Copy them to
|
f540e673
Miguel Barão
- added README.md
|
160
|
`~/.local/share/certs` and change permissions to be readable:
|
43785de6
Miguel Barão
- added documenta...
|
161
|
|
3ec49458
Miguel Barão
fix README.md and...
|
162
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
163
|
cd ~/.local/share/certs
|
43785de6
Miguel Barão
- added documenta...
|
164
|
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/cert.pem .
|
59213008
Miguel Barão
- fixed user path...
|
165
|
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/privkey.pem .
|
443a1eea
Miguel Barão
Update to latest ...
|
166
167
|
chmod 400 cert.pem privkey.pem
```
|
93e13002
Miguel Barão
updates README.md.
|
168
|
|
443a1eea
Miguel Barão
Update to latest ...
|
169
170
|
## Configuration
|
c288f8c6
Miguel Barao
- updated documen...
|
171
|
### Database
|
59213008
Miguel Barão
- fixed user path...
|
172
173
|
User data is maintained in a sqlite3 database which has to be created manually
|
443a1eea
Miguel Barão
Update to latest ...
|
174
175
176
|
using the `initdb-aprendizations` command. The database file should be located
in the same directory as the main YAML configuration file.
|
59213008
Miguel Barão
- fixed user path...
|
177
178
179
180
181
|
For example, to run the included demo do:
```sh
cd demo # contains a small example
initdb-aprendizations # show or initialize database
|
43785de6
Miguel Barão
- added documenta...
|
182
|
initdb-aprendizations --admin # add admin user
|
93e13002
Miguel Barão
updates README.md.
|
183
|
initdb-aprendizations inscricoes.csv # add students from CSV
|
43785de6
Miguel Barão
- added documenta...
|
184
185
186
|
initdb-aprendizations --add 1184 "Aladino da Silva" # add new user
initdb-aprendizations --update 1184 --pw alibaba # update password
initdb-aprendizations --help # for available options
|
59213008
Miguel Barão
- fixed user path...
|
187
|
```
|
5d859a41
Miguel Barão
update documentation
|
188
|
|
59213008
Miguel Barão
- fixed user path...
|
189
|
The default password is equal to the user name, if left undefined.
|
43785de6
Miguel Barão
- added documenta...
|
190
|
|
59213008
Miguel Barão
- fixed user path...
|
191
|
### Running the demo
|
43785de6
Miguel Barão
- added documenta...
|
192
193
194
195
|
The application includes a small example in `demo/demo.yaml` that can be used
for initial testing. Run it with
|
59213008
Miguel Barão
- fixed user path...
|
196
|
```sh
|
43785de6
Miguel Barão
- added documenta...
|
197
198
199
200
201
|
cd demo
aprendizations demo.yaml
```
Open the browser at [https://127.0.0.1:8443](https://127.0.0.1:8443).
|
59213008
Miguel Barão
- fixed user path...
|
202
|
If everything looks good, check at the correct address
|
ea4ff4d2
Miguel Barão
- radio: added su...
|
203
|
`https://www.example.com:8443`.
|
59213008
Miguel Barão
- fixed user path...
|
204
|
The option `--debug` provides more verbose logging and might be useful during
|
39126690
Miguel Barão
removes npm and n...
|
205
206
|
testing.
|
93e13002
Miguel Barão
updates README.md.
|
207
208
209
210
|
### Firewall configuration
Ports 80 and 443 are only usable by root. For security reasons the server runs
as an unprivileged user on port 8443 for https. To access the server in the
|
39126690
Miguel Barão
removes npm and n...
|
211
212
|
default https port (443), port forwarding must be configured in the firewall.
|
443a1eea
Miguel Barão
Update to latest ...
|
213
214
215
|
#### FreeBSD and pf
Edit `/etc/pf.conf`:
|
39126690
Miguel Barão
removes npm and n...
|
216
|
|
a203d3cc
Miguel Barão
- new http server...
|
217
|
```sh
|
5d859a41
Miguel Barão
update documentation
|
218
219
220
221
222
|
ext_if="em0" # change em0 to the correct network interface
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
```
|
39126690
Miguel Barão
removes npm and n...
|
223
|
Virtualbox with guest additions uses `ext_if="vtnet0"`.
|
5d859a41
Miguel Barão
update documentation
|
224
225
|
Edit `/etc/rc.conf`
|
59213008
Miguel Barão
- fixed user path...
|
226
227
|
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
228
229
|
pf_enable="YES"
pf_flags=""
|
5dae401a
Miguel Barão
update README.md
|
230
|
pf_rules="/etc/pf.conf"
|
43785de6
Miguel Barão
- added documenta...
|
231
|
|
443a1eea
Miguel Barão
Update to latest ...
|
232
|
# optional logging:
|
5dae401a
Miguel Barão
update README.md
|
233
|
pflog_enable="YES"
|
43785de6
Miguel Barão
- added documenta...
|
234
|
pflog_flags=""
|
443a1eea
Miguel Barão
Update to latest ...
|
235
236
|
pflog_logfile="/var/log/pflog"
```
|
43785de6
Miguel Barão
- added documenta...
|
237
|
|
443a1eea
Miguel Barão
Update to latest ...
|
238
|
Reboot or `sudo service pf start`.
|
59213008
Miguel Barão
- fixed user path...
|
239
|
|
443a1eea
Miguel Barão
Update to latest ...
|
240
241
242
|
### Testing the system
Make sure the following steps have been done:
|
5dae401a
Miguel Barão
update README.md
|
243
|
|
59213008
Miguel Barão
- fixed user path...
|
244
|
* installed python3, pip and npm
|
443a1eea
Miguel Barão
Update to latest ...
|
245
|
* git-cloned the aprendizations from the main repository
|
59213008
Miguel Barão
- fixed user path...
|
246
|
* installed javascript libraries with npm
|
43785de6
Miguel Barão
- added documenta...
|
247
248
249
250
251
|
* installed aprendizations with pip
* initialized database with at least 1 user
* generate and copy certificates to the appropriate place
* (optional) configure the firewall to do port forwarding
* run `aprendizations demo.yaml --check`
|
f75a344f
Miguel Barão
- README.md updat...
|
252
|
|
443a1eea
Miguel Barão
Update to latest ...
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
## Keeping aprendizations updated
To update aprendizations to the latest version do:
```sh
cd aprendizations
git pull # get latest version
npm update # update javascript libraries
pip install -U . # updates installed version
```
## Troubleshooting
To help with troubleshooting, use the option `--debug` when running the server.
This will increase logs in the terminal and will present the python exception
|
db04e658
Miguel Barão
- added option to...
|
268
|
errors in the browser.
|
43785de6
Miguel Barão
- added documenta...
|
269
|
|
f75a344f
Miguel Barão
- README.md updat...
|
270
|
Logging levels can be adjusted in `~/.config/aprendizations/logger.yaml` and
|
93e13002
Miguel Barão
updates README.md.
|
271
|
`~/.config/aprendizations/logger-debug.yaml`.
|
f75a344f
Miguel Barão
- README.md updat...
|
272
|
|
43785de6
Miguel Barão
- added documenta...
|
273
|
If these files do not yet exist, there are examples in `aprendizations/config`
|
d187aad4
Miguel Barão
- adds courses
|
274
275
|
that can be copied to `~/.config/aprendizations`.
|
43785de6
Miguel Barão
- added documenta...
|
276
|
### UnicodeEncodeError
|
f75a344f
Miguel Barão
- README.md updat...
|
277
|
|
d187aad4
Miguel Barão
- adds courses
|
278
|
The server should not generate this error, but when using external scripts to
|
f75a344f
Miguel Barão
- README.md updat...
|
279
|
generate questions or to correct, these scripts can print unicode strings to
|
43785de6
Miguel Barão
- added documenta...
|
280
|
stdout. If the terminal does not support unicode, python will generate an
|
93e13002
Miguel Barão
updates README.md.
|
281
282
|
exception.
|
f75a344f
Miguel Barão
- README.md updat...
|
283
|
* FreeBSD fix: edit `~/.login_conf` to use UTF-8, for example:
|
93e13002
Miguel Barão
updates README.md.
|
284
|
|
443a1eea
Miguel Barão
Update to latest ...
|
285
286
|
```sh
me:\
|
f75a344f
Miguel Barão
- README.md updat...
|
287
|
:charset=UTF-8:\
|
93e13002
Miguel Barão
updates README.md.
|
288
|
:lang=en_US.UTF-8:
|
443a1eea
Miguel Barão
Update to latest ...
|
289
290
|
```
|
93e13002
Miguel Barão
updates README.md.
|
291
|
* Debian fix: check `locale`...
|