Skip to content

Conversation

@areguera
Copy link
Owner

@areguera areguera commented Dec 4, 2016

- This enhancement was suggested by Emiliano Vavassori
  (@syntaxerrormmm).
@areguera
Copy link
Owner Author

areguera commented Dec 4, 2016

@syntaxerrormmm I would like to merge this change you proposed in #13 but your pull request conflicts with @stephdl last changes so I created a new one based on it so as to introduce your idea. Is anything else you would like to add?

- Previously, it was possible to change the alias use to refer the
  moodle application by setting the 'path' property to moodle's
  database configuration. However, when doing so, there was no
  validation about how the path value should look like. This update
  changes the path declaration to introduce a path validator as
  suggested by @stephdl.
- Previously, the path validator didn't work becasue a wrong
  writing construction (from myself). This update changes the
  config.php 10base template to use Perl's one-line-if-statement which
  seems to do the expected validation (i.e., allowing the db
  configuration value of path property when it isn't a dot or a
  slash).

- Previously, the dot and the slash were not scaped so this prevented
  the validator from working as expected. Both special charactes were
  scaped in order to represent their literal value.
@stephdl
Copy link
Contributor

stephdl commented Dec 4, 2016

I'm not sure that your code is good, I have had some warnings when I expanded the template, for now we just need this modification like @syntaxerrormmm proposed


my $url = $moodle{'url'} || '\'.$_SERVER["HTTP_HOST"].\'';
my $path = $moodle{'path'} || 'moodle';
...

\$CFG->wwwroot   = 'https://$url/$path';

I thought for the moment we don't need the validator but it could be nice that the solution of @syntaxerrormmm could be implemented

- Previously, it wasn't possible to choose between alias-like and
  virtualhost-like configuraitons. This update changes
  nethserver-moodle to allow the adminsitrator to choose between these
  sort of configurations by using db configuration tool once the
  moodle package has been installed and the web interface
  configuration finished.

- Update README.rst documentation to better describe the changes.
@areguera
Copy link
Owner Author

areguera commented Dec 5, 2016

@stephdl thanks for noticing this issue. The commit ee2d94e should fix it and also add a way to alternate between alias-like and virtualhost-like configuration using db configuration tool. So for wwwroot to be more dynamic. The README.rst file was also updated to describe these changes. Reviews and tests are needed.

@areguera areguera mentioned this pull request Dec 5, 2016
- Add semicolons at the end of db configuration commands.
- Remove rst markup :: characters from db configuration commands.
@stephdl
Copy link
Contributor

stephdl commented Dec 5, 2016

https://github.com/areguera/nethserver-moodle/pull/17/files#diff-fb7661a599a679beb1865771f38297f0

 /usr/sbin/e-smith/expand-template /var/www/moodle/web/config.php
+/usr/sbin/e-smith/expand-template /etc/httpd/conf.d/moodle.conf

this code should be in the createlinks, in rare case you might need to expand manually, but the good habit is to expand your template ion the createlinks

event_templates("nethserver-moodle-update", qw(
/etc/httpd/conf.d/default-virtualhost.inc
/etc/httpd/conf.d/moodle.conf
/var/www/moodle/web/config.php
));

here we expand all this templates on nethserver-moodle-update which is triggered after the rpm installation

@stephdl
Copy link
Contributor

stephdl commented Dec 5, 2016

Nice code @areguera, specially in the dashboard :), I suppose you work in IT or even you are a developer ????

I was yesterday also working on the virtualhost, and I noticed something wrong also in my code

I don't know why but we must write the full path to the ssl certificate in the virtualhost, I was worked on this last night, and I found the same issue.

+    SSLEngine on
+    SSLCertificateFile "/etc/pki/tls/certs/NSRV.crt"
+    SSLCertificateKeyFile "/etc/pki/tls/private/NSRV.key"

my concern is this is something valuable when we use this certificate, but what about when another certificate will be in use.

EDIT:

we can retrieve the good path to the the ssl certificate

+  my $cert = $pki{'CrtFile'} || "/etc/pki/tls/certs/NSRV.crt";
+  my $key = $pki{'KeyFile'}|| /etc/pki/tls/private/NSRV.key;
....

+    SSLEngine on
+    SSLCertificateFile "$cert"
+    SSLCertificateKeyFile "$key"

we must also expand the template following the event 'certificate-update'

in the createlink add

event_templates("certificate-update", qw(
 /etc/httpd/conf.d/moodle.conf
));
event_templates("certificate-upload", qw(
 /etc/httpd/conf.d/moodle.conf
));
event_templates("nethserver-letsencrypt-update", qw(
 /etc/httpd/conf.d/moodle.conf
));

or

foreach my $event (qw ( certificate-update certificate-upload nethserver-letsencrypt-update)) {
    templates2events( " /etc/httpd/conf.d/moodle.conf" , $event );
}

not tested with letsencrypt

@stephdl
Copy link
Contributor

stephdl commented Dec 5, 2016

the documentation to the createlinks http://wiki.nethserver.org/doku.php?id=esmith:build:createlinks

@stephdl
Copy link
Contributor

stephdl commented Dec 5, 2016

http://community.nethserver.org/t/moodle-virtualhost-and-letsencrypt/5138

if letsencrypt is set as the default certificate we can retrieve also with the code

+  my $cert = $pki{'CrtFile'} || "/etc/pki/tls/certs/NSRV.crt";
+  my $key = $pki{'KeyFile'}|| /etc/pki/tls/private/NSRV.key;
....

+    SSLEngine on
+    SSLCertificateFile "$cert"
+    SSLCertificateKeyFile "$key"

- The createlink file already contains lines for expanding both
  moodle.conf and config.php files when the nethserver-moodle-update
  command is executed. There is no need to expand-template twice by
  setting it at nethserver-moodle-conf file. So this update changes
  nethserver-moodle-conf file to remove expand-template commands from
  it.
- Previously, both SSL certificate and SSL key in moodle.conf template
  were specified using the default certificate absolute path.  As
  consequence, when a different certificate and key were set in
  NethServer configuration database, they were not apply. This update
  changes the moodle.conf template to retrieve both SSL certificate
  and SSL key based on NethServer configuration database.  When
  database values aren't set, the default certificate and key values
  are used instead.
- Previously, certificate-related actions were not included in the
  createlinks file. As consequence, when new certificate files were
  set in the configuration database, the template files including
  references to them didn't point to the correct certificate
  information. This update changes the createlinks file to re-expand
  the /etc/httpd/conf.d/moodle.conf file when certificate-related
  actions are triggered.

- Reorder action blocks by similar meaning.
@areguera
Copy link
Owner Author

areguera commented Dec 6, 2016

Nice code @areguera, specially in the dashboard :),

Thanks @stephdl . It's motivating to hear that from the experts :)

I suppose you work in IT or even you are a developer ????

I administer small LANs and, from time to time, write scripts to automate tasks on them.


What do you think about merging the changes committed so far?

@stephdl
Copy link
Contributor

stephdl commented Dec 6, 2016

What do you think about merging the changes committed so far?

I'm fetching your branch for real tests with a rpm

@stephdl
Copy link
Contributor

stephdl commented Dec 6, 2016

see my last commits in #18 normally you can apply this MR and after my MR...

@areguera areguera merged commit c02f34f into master Dec 7, 2016
@areguera areguera deleted the next/make-wwwroot-dynamic-based-on-request branch December 7, 2016 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants