|
3 | 3 | name = "dolibarr"; |
4 | 4 | meta.maintainers = [ ]; |
5 | 5 |
|
6 | | - nodes.machine = |
7 | | - { ... }: |
8 | | - { |
9 | | - services.dolibarr = { |
10 | | - enable = true; |
11 | | - domain = "localhost"; |
12 | | - nginx = { |
13 | | - forceSSL = false; |
14 | | - enableACME = false; |
| 6 | + nodes = { |
| 7 | + nginx_mysql = |
| 8 | + { ... }: |
| 9 | + { |
| 10 | + services.dolibarr = { |
| 11 | + enable = true; |
| 12 | + domain = "localhost"; |
| 13 | + nginx = { |
| 14 | + forceSSL = false; |
| 15 | + enableACME = false; |
| 16 | + }; |
| 17 | + database.type = "mysql"; |
15 | 18 | }; |
| 19 | + |
| 20 | + networking.firewall.allowedTCPPorts = [ 80 ]; |
| 21 | + }; |
| 22 | + h2o_postgresql = |
| 23 | + { ... }: |
| 24 | + { |
| 25 | + services.dolibarr = { |
| 26 | + enable = true; |
| 27 | + domain = "localhost"; |
| 28 | + h2o = { |
| 29 | + acme.enable = false; |
| 30 | + }; |
| 31 | + database.type = "postgresql"; |
| 32 | + }; |
| 33 | + |
| 34 | + networking.firewall.allowedTCPPorts = [ 80 ]; |
16 | 35 | }; |
| 36 | + }; |
| 37 | + |
| 38 | + testScript = # python |
| 39 | + '' |
| 40 | + from html.parser import HTMLParser |
| 41 | + start_all() |
| 42 | +
|
| 43 | + csrf_token = None |
| 44 | + class TokenParser(HTMLParser): |
| 45 | + def handle_starttag(self, tag, attrs): |
| 46 | + attrs = dict(attrs) # attrs is an assoc list originally |
| 47 | + if tag == 'input' and attrs.get('name') == 'token': |
| 48 | + csrf_token = attrs.get('value') |
| 49 | + print(f'[+] Caught CSRF token: {csrf_token}') |
| 50 | + def handle_endtag(self, tag): pass |
| 51 | + def handle_data(self, data): pass |
| 52 | +
|
| 53 | + # wait for app |
| 54 | + for machine in (nginx_mysql, h2o_postgresql): |
| 55 | + machine.wait_for_unit("phpfpm-dolibarr.service") |
| 56 | +
|
| 57 | + # wait for web servers |
| 58 | + nginx_mysql.wait_for_unit("nginx.service") |
| 59 | + nginx_mysql.wait_for_open_port(80) |
| 60 | + h2o_postgresql.wait_for_unit("h2o.service") |
| 61 | + h2o_postgresql.wait_for_open_port(80) |
17 | 62 |
|
18 | | - networking.firewall.allowedTCPPorts = [ 80 ]; |
19 | | - }; |
20 | | - |
21 | | - testScript = '' |
22 | | - from html.parser import HTMLParser |
23 | | - start_all() |
24 | | -
|
25 | | - csrf_token = None |
26 | | - class TokenParser(HTMLParser): |
27 | | - def handle_starttag(self, tag, attrs): |
28 | | - attrs = dict(attrs) # attrs is an assoc list originally |
29 | | - if tag == 'input' and attrs.get('name') == 'token': |
30 | | - csrf_token = attrs.get('value') |
31 | | - print(f'[+] Caught CSRF token: {csrf_token}') |
32 | | - def handle_endtag(self, tag): pass |
33 | | - def handle_data(self, data): pass |
34 | | -
|
35 | | - machine.wait_for_unit("phpfpm-dolibarr.service") |
36 | | - machine.wait_for_unit("nginx.service") |
37 | | - machine.wait_for_open_port(80) |
38 | | - # Sanity checks on URLs. |
39 | | - # machine.succeed("curl -fL http://localhost/index.php") |
40 | | - # machine.succeed("curl -fL http://localhost/") |
41 | | - # Perform installation. |
42 | | - machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto') |
43 | | - machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto') |
44 | | - # First time is to write the configuration file correctly. |
45 | | - machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"') |
46 | | - # Now, we have a proper conf.php in $stateDir. |
47 | | - assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
48 | | - machine.succeed('curl -fL -X POST http://localhost/install/step2.php --data "testpost=ok&action=set&dolibarr_main_db_character_set=utf8&dolibarr_main_db_collation=utf8_unicode_ci&selectlang=auto"') |
49 | | - machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"') |
50 | | - machine.succeed('curl -fL -X POST http://localhost/install/step5.php --data "testpost=ok&action=set&login=root&pass=hunter2&pass_verif=hunter2&selectlang=auto"') |
51 | | - # Now, we have installed the machine, let's verify we still have the right configuration. |
52 | | - assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
53 | | - # We do not want any redirect now as we have installed the machine. |
54 | | - machine.succeed('curl -f -X GET http://localhost') |
55 | | - # Test authentication to the webservice. |
56 | | - parser = TokenParser() |
57 | | - parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root')) |
58 | | - machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2') |
59 | | - ''; |
| 63 | + for machine in (nginx_mysql, h2o_postgresql): |
| 64 | + # Sanity checks on URLs. |
| 65 | + machine.succeed("curl -fL http://localhost/index.php") |
| 66 | + machine.succeed("curl -fL http://localhost/") |
| 67 | + # Perform installation. |
| 68 | + machine.succeed('curl -fL -X POST http://localhost/install/check.php -F selectlang=auto') |
| 69 | + machine.succeed('curl -fL -X POST http://localhost/install/fileconf.php -F selectlang=auto') |
| 70 | + # First time is to write the configuration file correctly. |
| 71 | + machine.succeed('curl -fL -X POST http://localhost/install/step1.php -F "testpost=ok" -F "action=set" -F "selectlang=auto"') |
| 72 | + # Now, we have a proper conf.php in $stateDir. |
| 73 | + assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
| 74 | + machine.succeed('curl -fL -X POST http://localhost/install/step2.php --data "testpost=ok&action=set&dolibarr_main_db_character_set=utf8&dolibarr_main_db_collation=utf8_unicode_ci&selectlang=auto"') |
| 75 | + machine.succeed('curl -fL -X POST http://localhost/install/step4.php --data "testpost=ok&action=set&selectlang=auto"') |
| 76 | + machine.succeed('curl -fL -X POST http://localhost/install/step5.php --data "testpost=ok&action=set&login=root&pass=hunter2&pass_verif=hunter2&selectlang=auto"') |
| 77 | + # Now, we have installed the machine, let's verify we still have the right configuration. |
| 78 | + assert 'nixos' in machine.succeed("cat /var/lib/dolibarr/conf.php") |
| 79 | + # We do not want any redirect now as we have installed the machine. |
| 80 | + machine.succeed('curl -f -X GET http://localhost') |
| 81 | + # Test authentication to the webservice. |
| 82 | + parser = TokenParser() |
| 83 | + parser.feed(machine.succeed('curl -f -X GET http://localhost/index.php?mainmenu=login&username=root')) |
| 84 | + machine.succeed(f'curl -f -X POST http://localhost/index.php?mainmenu=login&token={csrf_token}&username=root&password=hunter2') |
| 85 | + ''; |
60 | 86 | } |
0 commit comments