From cfb6fddac2509cbeb2a0526dba162a4f62f7f2f9 Mon Sep 17 00:00:00 2001
From: Daniel Berteaud
Date: Sun, 12 Oct 2014 21:50:02 +0200
Subject: [PATCH] Switch conf parser to Config::Simple Fix #84
---
.gitignore | 2 +-
conf/settings.ini.dist | 66 +++++++++++++++++
conf/{vroom.conf.sample => vroom.conf} | 26 +++----
templates/default/footer.html.ep | 2 +-
templates/default/join.html.ep | 10 +--
templates/default/owner_password_modal.html.ep | 6 +-
vroom.pl | 99 ++++++++++++++------------
7 files changed, 142 insertions(+), 69 deletions(-)
create mode 100644 conf/settings.ini.dist
rename conf/{vroom.conf.sample => vroom.conf} (72%)
diff --git a/.gitignore b/.gitignore
index 076e65d..a759e9a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
signalmaster/node_modules/
signalmaster/dev_config.json
-conf/vroom.conf
+conf/settings.ini
diff --git a/conf/settings.ini.dist b/conf/settings.ini.dist
new file mode 100644
index 0000000..8947e9e
--- /dev/null
+++ b/conf/settings.ini.dist
@@ -0,0 +1,66 @@
+[database]
+; Database access settings
+;dsn = 'DBI:mysql:database=devroom;host=localhost'
+;user = 'vroom'
+;password = 'password'
+
+[signaling]
+; URI sent to clients where they can find the signaling server
+;uri = 'https://vroom.exmple.com'
+
+[turn]
+; The stun server sent to client. You can set it to your own stun server
+;stun_server = 'stun.l.google.com:19302'
+; The turn server sent to cliet, you should set it to your own server
+;turn_server = ''
+; the realm used for turn accounts. You shouldn't have to change it
+;turn_realm = 'vroom'
+
+[email]
+; Address set in the From field of email sent by VROOM
+;from = 'no-reply@example.com'
+; Recipient of the feedback messages
+;contact = 'admin@example.com'
+; Path to a sendmail compatible binary used to send emails
+;sendmail = '/sbin/sendmail'
+
+[interface]
+; You can customize the "powered by" at the bottom
+;powered_by = 'Firewall Services'
+; Template to use. Must be a directory under the templates dir
+;template = 'default'
+; ID of the chrome extension which will be proposed when sharing screen on Chrome
+;chrome_extension_id = 'ecicdpoejfllflombfanbhfpgcimjddn'
+
+[cookie]
+; Secret passphrase used to sign cookies. You must set this
+;secret = '1zEewX24ZD%2RvtF%e'
+; Cookie name, You shouldn't have to change this
+;name = 'vroom'
+
+[rooms]
+; After this amount of time in minutes, rooms without any activity will be purged
+;inactivity_timeout = '3600'
+; You can also purge reserved rooms
+;reserved_inactivity_imeout = '5184000'
+; A comma separated list of room names you don't want to be reservable
+;common_names = 'test,test1,test123,0,1,2,3,4,5,6,7,8,9,123,1234,12345,a,aa,abc,azerty,qwerty,vroom,foo,bar,baz'
+
+[log]
+; Verbosity of the web interface. Can be debug, info, warn, error or fatal
+;level = 'warn'
+
+[etherpad]
+; If you want to enabled etherpad-lite integratio, you must set
+; the uri of your instance, and the API key
+;uri = 'https://pad.example.com'
+;api_key = 'be0f90cfc412b03c13e956e77d7944352c06a44e5d94da44ebfa79fb63d7e998'
+; If you run vroom and etherpad-llite on different subdomains, you have to set the common part here
+; For exmple, if you use vroom.domain.tld and pad.domain.tld, set domain.tld here
+;base_domain = 'example.com'
+
+[daemon]
+; IP the hypnotoad daemon will listen on. You can use * to bind on every IP/Interface
+;listen_ip = '127.0.0.1'
+; Port used by the hypnotoad daemon
+;listen_port = '8090'
diff --git a/conf/vroom.conf.sample b/conf/vroom.conf
similarity index 72%
rename from conf/vroom.conf.sample
rename to conf/vroom.conf
index 81b7e1f..5b47024 100644
--- a/conf/vroom.conf.sample
+++ b/conf/vroom.conf
@@ -1,24 +1,24 @@
{
# Database
-dbi => 'DBI:mysql:database=vroom;host=localhost',
-dbUser => 'vroom',
-dbPassword => 'vroom',
+dbi => 'DBI:mysql:database=devroom;host=localhost',
+dbUser => 'devroom',
+dbPassword => 'prout',
# Media & signaling
-signalingServer => 'https://signal.example.com',
-stunServer => 'stun.example.com:3478',
-turnServer => 'turn.example.com',
-realm => 'example.com',
+signalingServer => 'https://dev.vroom.im',
+stunServer => 'vroom.im:3478',
+turnServer => 'vroom.im',
+realm => 'vroom.im',
# Web & contact
-emailFrom => 'vroom@example.com',
-feedbackRecipient => 'admin@example.com',
+emailFrom => 'no-reply@vroom.im',
+oeedbackRecipient => 'dani@fws.fr',
poweredBy => 'Firewall Services',
# Templates to use for web pages
template => 'default',
# Used to sign cookies
-secret => 'ChangeMe!',
+secret => 'NtPZDUEqNX68QlQGH5ohqb1ymmqEGJ3xyvLo4Fz3pDqEX/Dxutmp',
# App
# Rooms without any activity for that long (in seconds) will be destroyed
@@ -42,11 +42,11 @@ chromeExtensionId => 'ecicdpoejfllflombfanbhfpgcimjddn',
# For etherpad integration, set the etherpad base url
# and API Key
-#etherpadUri => '',
-#etherpadApiKey => '',
+etherpadUri => 'https://vroom.im/etherpad/',
+etherpadApiKey => 'be0c00cfce12b00c13e956e77d7244352c06a44e5d94ca44ebfa79fb63d7e995',
# You can also set the base domain common to both vroom and etherpad
# For example, if you use vroom.example.com and pad.example.com, the base domain is example.com
-#etherpadBaseDomain => '',
+etherpadBaseDomain => 'vroom.im',
# Various
sendmail => '/sbin/sendmail'
diff --git a/templates/default/footer.html.ep b/templates/default/footer.html.ep
index e219508..50ecb3f 100644
--- a/templates/default/footer.html.ep
+++ b/templates/default/footer.html.ep
@@ -5,7 +5,7 @@
<%=l 'VROOM_IS_FREE_SOFTWARE' %>
-
<%=l 'POWERED_BY' %> <%== $config->{poweredBy} %>
+
<%=l 'POWERED_BY' %> <%= $config->{'interface.powered_by'} %>
diff --git a/templates/default/join.html.ep b/templates/default/join.html.ep
index 7d3be12..b9cc1a8 100644
--- a/templates/default/join.html.ep
+++ b/templates/default/join.html.ep
@@ -700,7 +700,7 @@
<%=l 'VROOM_CHROME_EXTENSION' %>
-
+
@@ -869,7 +869,7 @@
setTimeout(function(){
etherpad = {
enabled: <%= $etherpad %>,
- uri: "<%= $config->{etherpadUri} %>",
+ uri: "<%= $config->{'etherpad.uri'} %>",
group: "<%= $etherpadGroup %>"
};
<% if ($video eq 'false'){ %>
@@ -882,11 +882,11 @@
};
<% } %>
webrtc = new SimpleWebRTC({
- url: "<%= $config->{signalingServer} %>",
+ url: "<%= $config->{'signaling.uri'} %>",
peerConnectionConfig: {
iceServers: [
- {"url":"stun:<%= $config->{stunServer} %>"},
- <%== ($config->{turnServer} && $config->{turnServer} ne '') ? "{\"url\":\"turn:$config->{turnServer}\", \"username\":\"$room\", \"credential\":\"$turnPassword\"}":'' %>
+ {"url":"stun:<%= $config->{'turn.stun_server'} %>"},
+ <%== ($config->{'turn.turn_server'} && $config->{'turn.turn_server'} ne '') ? "{\"url\":\"turn:$config->{'turn.turn_server'}\", \"username\":\"$room\", \"credential\":\"$turnPassword\"}":'' %>
]
},
localVideoEl: 'webRTCVideoLocal',
diff --git a/templates/default/owner_password_modal.html.ep b/templates/default/owner_password_modal.html.ep
index 6af890e..937c8ab 100644
--- a/templates/default/owner_password_modal.html.ep
+++ b/templates/default/owner_password_modal.html.ep
@@ -15,12 +15,12 @@
<%=l 'SET_OWNER_PASS' %>
-
- <%= sprintf($self->l('A_STANDARD_ROOM_EXPIRES_AFTER_d'), int($config->{inactivityTimeout}/3600)) %>
+ <%= sprintf($self->l('A_STANDARD_ROOM_EXPIRES_AFTER_d'), int($config->{'rooms.inactivity_timeout'}/3600)) %>
-
<%=l 'A_RESERVED_ROOM' %>
- <% if ($config->{reservedInactivityTimeout} > 0){ %>
- <%= sprintf($self->l('EXPIRE_AFTER_d'), int($config->{reservedInactivityTimeout}/(3600*24))) %>
+ <% if ($config->{'reserved_inactivity_timeout'} > 0){ %>
+ <%= sprintf($self->l('EXPIRE_AFTER_d'), int($config->{'reserved_inactivity_timeout'}/(3600*24))) %>
<% } else{ %>
<%=l 'WILL_NEVER_EXPIRE' %>
<% } %>
diff --git a/vroom.pl b/vroom.pl
index deefb11..bfc5b38 100755
--- a/vroom.pl
+++ b/vroom.pl
@@ -15,6 +15,7 @@ use File::stat;
use File::Basename;
use Etherpad::API;
use Session::Token;
+use Config::Simple;
# List The different components we rely on.
# Used to generate thanks on the about template
@@ -105,30 +106,37 @@ our $musics = {
app->log->level('info');
# Read conf file, and set default values
-our $config = plugin Config => {
- file => 'conf/vroom.conf',
- default => {
- dbi => 'DBI:mysql:database=vroom;host=localhost',
- dbUser => 'vroom',
- dbPassword => 'vroom',
- signalingServer => 'https://vroom.example.com/',
- stunServer => 'stun.l.google.com:19302',
- realm => 'vroom',
- emailFrom => 'vroom@example.com',
- feedbackRecipient => 'admin@example.com',
- poweredBy => 'Firewall Services',
- template => 'default',
- inactivityTimeout => 3600,
- reservedInactivityTimeout => 5184000,
- commonRoomNames => [ qw() ],
- logLevel => 'info',
- chromeExtensionId => 'ecicdpoejfllflombfanbhfpgcimjddn',
- etherpadUri => '',
- etherpadApiKey => '',
- etherpadBaseDomain => '',
- sendmail => '/sbin/sendmail'
- }
-};
+my $cfg = new Config::Simple();
+$cfg->read('conf/settings.ini');
+our $config = $cfg->vars();
+
+$config->{'database.dsn'} ||= 'DBI:mysql:database=vroom;host=localhost';
+$config->{'database.user'} ||= 'vroom';
+$config->{'database.password'} ||= 'vroom';
+$config->{'signaling.uri'} ||= 'https://vroom.example.com/';
+$config->{'turn.stun_server'} ||= 'stun.l.google.com:19302';
+$config->{'turn.turn_server'} ||= '';
+$config->{'turn.realm'} ||= 'vroom';
+$config->{'email.from '} ||= 'vroom@example.com';
+$config->{'email.contact'} ||= 'admin@example.com';
+$config->{'email.sendmail'} ||= '/sbin/sendmail';
+$config->{'interface.powered_by'} ||= 'Firewall Services';
+$config->{'interface.template'} ||= 'default';
+$config->{'interface.chrome_extension_id'} ||= 'ecicdpoejfllflombfanbhfpgcimjddn';
+$config->{'cookie.secret'} ||= 'secret';
+$config->{'cookie.name'} ||= 'vroom';
+$config->{'rooms.inactivity_timeout'} ||= 3600;
+$config->{'rooms.reserved_inactivity_timeout'} ||= 5184000;
+$config->{'rooms.common_names'} ||= '';
+$config->{'log.level'} ||= 'info';
+$config->{'etherpad.uri'} ||= '';
+$config->{'etherpad.api_key'} ||= '';
+$config->{'etherpad.base_domain'} ||= '';
+$config->{'daemon.listen_ip'} ||= '127.0.0.1';
+$config->{'daemon.listen_port'} ||= '8090';
+
+# Set log level
+app->log->level($config->{'log.level'});
our @js_locales = qw(
ERROR_MAIL_INVALID
@@ -190,15 +198,13 @@ our @js_locales = qw(
# Create etherpad api client if required
our $ec = undef;
-if ($config->{etherpadUri} =~ m/https?:\/\/.*/ && $config->{etherpadApiKey} ne ''){
+if ($config->{'etherpad.uri'} =~ m/https?:\/\/.*/ && $config->{'etherpad.api_key'} ne ''){
$ec = Etherpad::API->new({
- url => $config->{etherpadUri},
- apikey => $config->{etherpadApiKey}
+ url => $config->{'etherpad.uri'},
+ apikey => $config->{'etherpad.api_key'}
});
}
-app->log->level($config->{logLevel});
-
# Load I18N, and declare supported languages
plugin I18N => {
namespace => 'Vroom::I18N',
@@ -207,15 +213,15 @@ plugin I18N => {
# Connect to the database
plugin database => {
- dsn => $config->{dbi},
- username => $config->{dbUser},
- password => $config->{dbPassword},
+ dsn => $config->{'database.dsn'},
+ username => $config->{'database.user'},
+ password => $config->{'database.password'},
options => { mysql_enable_utf8 => 1 }
};
# Load mail plugin with its default values
plugin mail => {
- from => $config->{emailFrom},
+ from => $config->{'email.from'},
type => 'text/html',
};
@@ -256,7 +262,7 @@ helper create_room => sub {
} || return undef;
# Gen a random token. Will be used as a turnPassword
my $tp = $self->get_random(256);
- $sth->execute($name,time(),time(),$owner,$tp,$config->{realm}) || return undef;
+ $sth->execute($name,time(),time(),$owner,$tp,$config->{'turn.realm'}) || return undef;
$self->app->log->info("Room $name created by " . $self->session('name'));
# Etherpad integration ?
if ($ec){
@@ -427,7 +433,7 @@ helper delete_participants => sub {
helper delete_rooms => sub {
my $self = shift;
$self->app->log->debug('Removing unused rooms');
- my $timeout = time()-$config->{inactivityTimeout};
+ my $timeout = time()-$config->{'rooms.inactivity_timeout'};
my $sth = eval {
$self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0' AND `owner_password` IS NULL;")
} || return undef;
@@ -437,8 +443,8 @@ helper delete_rooms => sub {
push @toDeleteName, $room;
}
my @toDeleteId = ();
- if ($config->{reservedInactivityTimeout} > 0){
- $timeout = time()-$config->{reservedInactivityTimeout};
+ if ($config->{'rooms.reserved_inactivity_timeout'} > 0){
+ $timeout = time()-$config->{'rooms.reserved_inactivity_timeout'};
$sth = eval {
$self->db->prepare("SELECT `name` FROM `rooms` WHERE `activity_timestamp` < $timeout AND `persistent`='0' AND `owner_password` IS NOT NULL;")
} || return undef;
@@ -844,9 +850,8 @@ helper create_etherpad_session => sub {
my $etherpadSession = $ec->create_session($data->{etherpad_group}, $id, time + 86400);
$self->session($room)->{etherpadSessionId} = $etherpadSession;
my $etherpadCookieParam = {};
- if ($config->{etherpadBaseDomain} && $config->{etherpadBaseDomain} ne ''){
- $etherpadCookieParam->{domain} = $config->{etherpadBaseDomain};
- $self->app->log->debug("Creating an etherpad SesionID cookie for domaine " . $config->{etherpadBaseDomain});
+ if ($config->{'etherpad.base_domain'} && $config->{'etherpad.base_domain'} ne ''){
+ $etherpadCookieParam->{domain} = $config->{'etherpad.base_domain'};
}
$self->cookie(sessionID => $etherpadSession, $etherpadCookieParam);
};
@@ -905,7 +910,7 @@ post '/feedback' => sub {
my $email = $self->param('email') || '';
my $comment = $self->param('comment');
my $sent = $self->mail(
- to => $config->{feedbackRecipient},
+ to => $config->{'email.contact'},
subject => $self->l("FEEDBACK_FROM_VROOM"),
data => $self->render_mail('feedback',
email => $email,
@@ -1309,7 +1314,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
if ($prefix eq 'admin' || $self->session($room)->{role} eq 'owner'){
if ($type eq 'owner'){
# Forbid a few common room names to be reserved
- if (grep { $room eq $_ } @{$config->{commonRoomNames}}){
+ if (grep { $room eq $_ } (split /[,;]/, $config->{'rooms.common_names'})){
$msg = $self->l('ERROR_COMMON_ROOM_NAME');
}
elsif ($self->set_owner_pass($room,$pass)){
@@ -1577,22 +1582,24 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
};
# use the templates defined in the config
-push @{app->renderer->paths}, 'templates/'.$config->{template};
+push @{app->renderer->paths}, 'templates/'.$config->{'interface.template'};
# Set the secret used to sign cookies
-app->secret($config->{secret});
+app->secret($config->{'cookie.secret'});
app->sessions->secure(1);
-app->sessions->cookie_name('vroom');
+app->sessions->cookie_name($config->{'cookie.name'});
app->hook(before_dispatch => sub {
my $self = shift;
# Switch to the desired language
if ($self->session('language')){
$self->languages($self->session('language'));
}
+ # Stash the configuration hashref
+ $self->stash(config => $config);
});
# Are we running in hypnotoad ?
app->config(
hypnotoad => {
- listen => ['http://127.0.0.1:8090'],
+ listen => ['http://' . $config->{'daemon.listen_ip'} . ':' . $config->{'daemon.listen_port'}],
pid_file => '/tmp/vroom.pid',
proxy => 1
}