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: 2022-04-04
|
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 and pip
2. install aprendizations
3. generate SSL certificates
4. configure the firewall (optional)
|
f540e673
Miguel Barão
- added README.md
|
13
|
|
5d859a41
Miguel Barão
update documentation
|
14
15
|
To use the software we need to:
|
39126690
Miguel Barão
removes npm and n...
|
16
|
1. initialize a database
|
443a1eea
Miguel Barão
Update to latest ...
|
17
|
2. go to the demo directory (or an existing course)
|
39126690
Miguel Barão
removes npm and n...
|
18
|
3. run `aprendizations courses.yaml`
|
5d859a41
Miguel Barão
update documentation
|
19
20
|
Each of these steps is explained below.
|
43785de6
Miguel Barão
- added documenta...
|
21
|
|
39126690
Miguel Barão
removes npm and n...
|
22
|
### Install python3 with sqlite3 support
|
43785de6
Miguel Barão
- added documenta...
|
23
|
|
39126690
Miguel Barão
removes npm and n...
|
24
25
|
Minimum supported version is python3.8. The installed versions depend on the
operating system default.
|
c54ee176
Miguel Barão
update javascript...
|
26
27
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
28
29
|
sudo pkg install python3 py38-sqlite3 # FreeBSD
sudo apt install python3 # Linux (Ubuntu)
|
1e8f0810
Miguel Barão
update setup.py a...
|
30
|
sudo port install python310 # MacOS
|
93e13002
Miguel Barão
updates README.md.
|
31
32
|
```
|
43785de6
Miguel Barão
- added documenta...
|
33
|
### Install pip
|
59213008
Miguel Barão
- fixed user path...
|
34
|
|
443a1eea
Miguel Barão
Update to latest ...
|
35
|
Install `pip` from the system package manager:
|
a96cd2c7
Miguel Barão
- added logging s...
|
36
|
|
43785de6
Miguel Barão
- added documenta...
|
37
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
38
39
|
sudo pkg install py38-pip # FreeBSD
sudo apt install python3-pip # Linux (Ubuntu)
|
1e8f0810
Miguel Barão
update setup.py a...
|
40
|
sudo port install py310-pip # MacOS
|
43785de6
Miguel Barão
- added documenta...
|
41
|
```
|
f540e673
Miguel Barão
- added README.md
|
42
|
|
443a1eea
Miguel Barão
Update to latest ...
|
43
44
|
In the end you should be able to run `pip --version` and `python3 -c "import
sqlite3"` without errors.
|
39126690
Miguel Barão
removes npm and n...
|
45
|
In some systems, `pip` can be named `pip3`, `pip3.8` or `pip-3.8`, etc.
|
5d859a41
Miguel Barão
update documentation
|
46
|
|
1e8f0810
Miguel Barão
update setup.py a...
|
47
48
49
50
51
|
Packages should **not** be installed system-wide. Either install them to a
python virtual environment or in the user area.
To install in the user area use `pip install --user some_package` or edit the
configuration file `~/.config/pip/pip.conf` (FreeBSD, Linux) or
|
5dae401a
Miguel Barão
update README.md
|
52
|
`Library/Application Support/pip/pip.conf` (MacOS) and add the lines
|
f540e673
Miguel Barão
- added README.md
|
53
|
|
43785de6
Miguel Barão
- added documenta...
|
54
55
56
57
|
```ini
[global]
user = yes
```
|
f540e673
Miguel Barão
- added README.md
|
58
|
|
39126690
Miguel Barão
removes npm and n...
|
59
|
### Install aprendizations
|
f540e673
Miguel Barão
- added README.md
|
60
|
|
43785de6
Miguel Barão
- added documenta...
|
61
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
62
|
pip install git+https://git.xdi.uevora.pt/mjsb/aprendizations.git
|
43785de6
Miguel Barão
- added documenta...
|
63
|
```
|
f540e673
Miguel Barão
- added README.md
|
64
|
|
c3eba869
Miguel Barão
update README.md
|
65
|
Python packages are usually installed in:
|
a96cd2c7
Miguel Barão
- added logging s...
|
66
|
|
443a1eea
Miguel Barão
Update to latest ...
|
67
|
* `~/.local/lib/python3.8/site-packages/` in Linux/FreeBSD.
|
1e8f0810
Miguel Barão
update setup.py a...
|
68
|
* `~/Library/python/3.10/lib/python/site-packages/` in MacOS.
|
a96cd2c7
Miguel Barão
- added logging s...
|
69
|
|
443a1eea
Miguel Barão
Update to latest ...
|
70
|
When aprendizations is installed with pip, all the dependencies are also
|
39126690
Miguel Barão
removes npm and n...
|
71
|
installed.
|
f540e673
Miguel Barão
- added README.md
|
72
|
|
39126690
Miguel Barão
removes npm and n...
|
73
74
|
At this point, the commands `aprendizations` and `initdb-aprendizations` are
installed in
|
5dae401a
Miguel Barão
update README.md
|
75
76
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
77
|
~/.local/bin # Linux/FreeBSD
|
1e8f0810
Miguel Barão
update setup.py a...
|
78
|
~/Library/Python/3.10/bin # MacOS
|
5dae401a
Miguel Barão
update README.md
|
79
80
|
```
|
93e13002
Miguel Barão
updates README.md.
|
81
|
and can be run from the terminal:
|
b4ceb7fc
Miguel Barão
minor change in l...
|
82
|
|
93e13002
Miguel Barão
updates README.md.
|
83
84
85
|
```sh
aprendizations --version
aprendizations --help
|
39126690
Miguel Barão
removes npm and n...
|
86
|
initdb-aprendizations --help
|
93e13002
Miguel Barão
updates README.md.
|
87
|
```
|
f540e673
Miguel Barão
- added README.md
|
88
|
|
59213008
Miguel Barão
- fixed user path...
|
89
90
|
### SSL Certificates
|
443a1eea
Miguel Barão
Update to latest ...
|
91
92
|
We need certificates for https. Certificates can be self-signed or validated by
a trusted authority.
|
c288f8c6
Miguel Barao
- updated documen...
|
93
|
|
443a1eea
Miguel Barão
Update to latest ...
|
94
95
96
|
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.
|
c288f8c6
Miguel Barao
- updated documen...
|
97
|
|
93e13002
Miguel Barão
updates README.md.
|
98
|
#### Generating selfsigned certificates
|
f540e673
Miguel Barão
- added README.md
|
99
|
|
b4ceb7fc
Miguel Barão
minor change in l...
|
100
|
Generate a selfsigned certificate and place it in `~/.local/share/certs`.
|
59213008
Miguel Barão
- fixed user path...
|
101
|
|
43785de6
Miguel Barão
- added documenta...
|
102
103
104
|
```sh
openssl req -x509 -newkey rsa:4096 -keyout privkey.pem -out cert.pem -days 365 -nodes
```
|
59213008
Miguel Barão
- fixed user path...
|
105
|
|
93e13002
Miguel Barão
updates README.md.
|
106
107
108
|
#### LetsEncrypt certificates
Install the certbot from LetsEncrypt:
|
bbc1c506
Miguel Barão
- documentation u...
|
109
|
|
43785de6
Miguel Barão
- added documenta...
|
110
|
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
111
|
sudo pkg install py38-certbot # FreeBSD
|
5d859a41
Miguel Barão
update documentation
|
112
|
sudo apt install certbot # Ubuntu
|
43785de6
Miguel Barão
- added documenta...
|
113
|
```
|
bbc1c506
Miguel Barão
- documentation u...
|
114
|
|
443a1eea
Miguel Barão
Update to latest ...
|
115
116
|
To generate or renew the certificates, ports 80 and 443 must be accessible.
**Any firewall and webserver have to be stopped**.
|
bbc1c506
Miguel Barão
- documentation u...
|
117
|
|
43785de6
Miguel Barão
- added documenta...
|
118
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
119
120
|
sudo certbot certonly --standalone -d www.example.com # first time
sudo certbot renew # renew
|
43785de6
Miguel Barão
- added documenta...
|
121
|
```
|
bbc1c506
Miguel Barão
- documentation u...
|
122
|
|
443a1eea
Miguel Barão
Update to latest ...
|
123
124
125
|
Certificates are saved under
`/usr/local/etc/letsencrypt/live/www.example.com/`. Copy them to
`~/.local/share/certs` and change permissions to be readable:
|
bbc1c506
Miguel Barão
- documentation u...
|
126
|
|
43785de6
Miguel Barão
- added documenta...
|
127
|
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
128
|
cd ~/.local/share/certs
|
43785de6
Miguel Barão
- added documenta...
|
129
130
131
132
|
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/cert.pem .
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/privkey.pem .
chmod 400 cert.pem privkey.pem
```
|
bbc1c506
Miguel Barão
- documentation u...
|
133
|
|
5d859a41
Miguel Barão
update documentation
|
134
135
136
137
|
## Configuration
### Database
|
443a1eea
Miguel Barão
Update to latest ...
|
138
139
|
User data is maintained in a sqlite3 database which has to be created manually
using the `initdb-aprendizations` command. The database file should be located
|
39126690
Miguel Barão
removes npm and n...
|
140
|
in the same directory as the main YAML configuration file (`courses.yaml`).
|
5d859a41
Miguel Barão
update documentation
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
For example, to run the included demo do:
```sh
cd demo # contains a small example
initdb-aprendizations # show or initialize database
initdb-aprendizations --admin # add admin user
initdb-aprendizations inscricoes.csv # add students from CSV
initdb-aprendizations --add 1184 "Aladino da Silva" # add new user
initdb-aprendizations --update 1184 --pw alibaba # update password
initdb-aprendizations --help # for available options
```
The default password is equal to the user name, if left undefined.
|
93e13002
Miguel Barão
updates README.md.
|
156
|
### Running the demo
|
c55940af
Miguel Barão
- minor change in...
|
157
|
|
39126690
Miguel Barão
removes npm and n...
|
158
|
The application includes a small example in `demo/courses.yaml` that can be used
|
443a1eea
Miguel Barão
Update to latest ...
|
159
|
for initial testing. Run it with
|
f540e673
Miguel Barão
- added README.md
|
160
|
|
43785de6
Miguel Barão
- added documenta...
|
161
|
```sh
|
3ec49458
Miguel Barão
fix README.md and...
|
162
|
cd demo
|
39126690
Miguel Barão
removes npm and n...
|
163
|
aprendizations courses.yaml
|
43785de6
Miguel Barão
- added documenta...
|
164
|
```
|
59213008
Miguel Barão
- fixed user path...
|
165
|
|
443a1eea
Miguel Barão
Update to latest ...
|
166
167
|
Open the browser at [https://127.0.0.1:8443](https://127.0.0.1:8443).
If everything looks good, check at the correct address
|
93e13002
Miguel Barão
updates README.md.
|
168
|
`https://www.example.com:8443`.
|
443a1eea
Miguel Barão
Update to latest ...
|
169
170
|
The option `--debug` provides more verbose logging and might be useful during
testing.
|
c288f8c6
Miguel Barao
- updated documen...
|
171
|
|
59213008
Miguel Barão
- fixed user path...
|
172
173
|
### Firewall configuration
|
443a1eea
Miguel Barão
Update to latest ...
|
174
175
176
|
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
default https port (443), port forwarding must be configured in the firewall.
|
59213008
Miguel Barão
- fixed user path...
|
177
178
179
180
181
|
#### FreeBSD and pf
Edit `/etc/pf.conf`:
|
43785de6
Miguel Barão
- added documenta...
|
182
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
183
|
ext_if="em0" # change em0 to the correct network interface
|
43785de6
Miguel Barão
- added documenta...
|
184
185
186
|
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
```
|
59213008
Miguel Barão
- fixed user path...
|
187
|
|
5d859a41
Miguel Barão
update documentation
|
188
|
Virtualbox with guest additions uses `ext_if="vtnet0"`.
|
59213008
Miguel Barão
- fixed user path...
|
189
|
|
43785de6
Miguel Barão
- added documenta...
|
190
|
Edit `/etc/rc.conf`
|
59213008
Miguel Barão
- fixed user path...
|
191
|
|
43785de6
Miguel Barão
- added documenta...
|
192
193
194
195
|
```sh
pf_enable="YES"
pf_flags=""
pf_rules="/etc/pf.conf"
|
59213008
Miguel Barão
- fixed user path...
|
196
|
|
43785de6
Miguel Barão
- added documenta...
|
197
198
199
200
201
|
# optional logging:
pflog_enable="YES"
pflog_flags=""
pflog_logfile="/var/log/pflog"
```
|
59213008
Miguel Barão
- fixed user path...
|
202
|
|
ea4ff4d2
Miguel Barão
- radio: added su...
|
203
|
Reboot or `sudo service pf start`.
|
59213008
Miguel Barão
- fixed user path...
|
204
|
|
39126690
Miguel Barão
removes npm and n...
|
205
206
|
Example configuration files are in the `freebsd` directory.
|
93e13002
Miguel Barão
updates README.md.
|
207
208
209
210
|
### Testing the system
Make sure the following steps have been done:
|
39126690
Miguel Barão
removes npm and n...
|
211
212
|
* installed python3 and pip
* installed aprendizations using pip
|
443a1eea
Miguel Barão
Update to latest ...
|
213
214
215
|
* initialized database with at least 1 user
* generate and copy certificates to the appropriate place
* (optional) configure the firewall to do port forwarding
|
39126690
Miguel Barão
removes npm and n...
|
216
|
* run `aprendizations courses.yaml --check`
|
a203d3cc
Miguel Barão
- new http server...
|
217
|
|
5d859a41
Miguel Barão
update documentation
|
218
219
220
221
222
|
## Keeping aprendizations updated
To update aprendizations to the latest version do:
```sh
|
39126690
Miguel Barão
removes npm and n...
|
223
|
pip install -U git+https://git.xdi.uevora.pt/mjsb/aprendizations.git
|
5d859a41
Miguel Barão
update documentation
|
224
225
|
```
|
59213008
Miguel Barão
- fixed user path...
|
226
227
|
## Troubleshooting
|
443a1eea
Miguel Barão
Update to latest ...
|
228
229
|
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
|
5dae401a
Miguel Barão
update README.md
|
230
|
errors in the browser.
|
43785de6
Miguel Barão
- added documenta...
|
231
|
|
443a1eea
Miguel Barão
Update to latest ...
|
232
|
Logging levels can be adjusted in `~/.config/aprendizations/logger.yaml` and
|
5dae401a
Miguel Barão
update README.md
|
233
|
`~/.config/aprendizations/logger-debug.yaml`.
|
43785de6
Miguel Barão
- added documenta...
|
234
|
|
443a1eea
Miguel Barão
Update to latest ...
|
235
236
|
If these files do not yet exist, there are examples in `aprendizations/config`
that can be copied to `~/.config/aprendizations`.
|
43785de6
Miguel Barão
- added documenta...
|
237
|
|
443a1eea
Miguel Barão
Update to latest ...
|
238
|
### UnicodeEncodeError
|
59213008
Miguel Barão
- fixed user path...
|
239
|
|
443a1eea
Miguel Barão
Update to latest ...
|
240
241
242
|
The server should not generate this error, but when using external scripts to
generate questions or to correct, these scripts can print unicode strings to
stdout. If the terminal does not support unicode, python will generate an
|
5dae401a
Miguel Barão
update README.md
|
243
|
exception.
|
59213008
Miguel Barão
- fixed user path...
|
244
|
|
443a1eea
Miguel Barão
Update to latest ...
|
245
|
* FreeBSD fix: edit `~/.login_conf` to use UTF-8, for example:
|
59213008
Miguel Barão
- fixed user path...
|
246
|
|
43785de6
Miguel Barão
- added documenta...
|
247
248
249
250
251
|
```sh
me:\
:charset=UTF-8:\
:lang=en_US.UTF-8:
```
|
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
|
* Debian fix: check `locale`...
### The application runs but questions do not show up
Some operating systems have an option to disable animations to try to avoid
motion sickness in some people. Browsers will check this option with the OS and
prevent animate.css library to work. Since questions have several animations,
these will will not work and nothing is shown on the page.
To fix this issue you need to allow animations in the Operating System:
* On windows 10, go to System Preferences, search for "Show animations in
windows" and turn it **ON**.
* On MacOS or iOS search for reduced motion and switch it **OFF**
(Preferences -> Acessibility -> Display -> Reduce motion).
|
db04e658
Miguel Barão
- added option to...
|
268
|
|
43785de6
Miguel Barão
- added documenta...
|
269
|
## FAQ
|
f75a344f
Miguel Barão
- README.md updat...
|
270
|
|
93e13002
Miguel Barão
updates README.md.
|
271
|
Common database manipulations:
|
f75a344f
Miguel Barão
- README.md updat...
|
272
|
|
43785de6
Miguel Barão
- added documenta...
|
273
|
```sh
|
d187aad4
Miguel Barão
- adds courses
|
274
275
|
initdb-aprendizations -u 12345 --pw alibaba # reset student password
initdb-aprendizations -a 007 "James Bond" --pw mi6 # add new student "007"
|
43785de6
Miguel Barão
- added documenta...
|
276
|
```
|
f75a344f
Miguel Barão
- README.md updat...
|
277
|
|
d187aad4
Miguel Barão
- adds courses
|
278
|
Some common database queries:
|
f75a344f
Miguel Barão
- README.md updat...
|
279
|
|
43785de6
Miguel Barão
- added documenta...
|
280
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
281
282
|
# Which students did at least one topic?
sqlite3 students.db "select distinct student_id from studenttopic"
|
f75a344f
Miguel Barão
- README.md updat...
|
283
|
|
93e13002
Miguel Barão
updates README.md.
|
284
|
# How many topics has each student done?
|
443a1eea
Miguel Barão
Update to latest ...
|
285
286
|
sqlite3 students.db "select student_id, count(topic_id) from studenttopic \
group by student_id order by count(topic_id) desc"
|
f75a344f
Miguel Barão
- README.md updat...
|
287
|
|
93e13002
Miguel Barão
updates README.md.
|
288
|
# Which questions have more wrong answers?
|
443a1eea
Miguel Barão
Update to latest ...
|
289
290
|
sqlite3 students.db "select count(ref), ref from answers where grade<1.0 \
group by ref order by count(ref) desc"
|
93e13002
Miguel Barão
updates README.md.
|
291
|
```
|