Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/config.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"callflow_http_port": 4242,
"reception_http_port" : 4000,
"contact_http_port" : 4010,
"user_server_http_port" : 4030,
"management_http_port" : 4100,
"message_dispatcher_http_port" : 4070,
"message_server_http_port" : 4040,
Expand All @@ -33,7 +34,7 @@
"contactServerUri" : "http://localhost:4010",
"messageServerUri" : "http://localhost:4040",
"authServerUri" : "http://localhost:4050",
"notificationSocket": "ws://localhost:4200/notifications",
"notificationSocket": "ws://localhost:4201/notifications",

"authurl": "http://localhost:4050/",
"callflowserver": "http://localhost:4242",
Expand Down
4 changes: 4 additions & 0 deletions bin/spawner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ void main(List<String> arguments) {
'ReceptionServer': {
'path': 'bin/receptionserver.dart',
'args': ['--servertoken', tokens[index++]]
},
'UserServer': {
'path': 'bin/userserver.dart',
'args' : []
}
};

Expand Down
55 changes: 55 additions & 0 deletions bin/userserver.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:path/path.dart';

import 'package:logging/logging.dart';
import '../lib/user_server/configuration.dart' as json;
import '../lib/configuration.dart';
import '../lib/user_server/router.dart' as router;

Logger log = new Logger ('UserServer');
ArgResults parsedArgs;
ArgParser parser = new ArgParser();

void main(List<String> args) {
///Init logging. Inherit standard values.
Logger.root.level = Configuration.userServer.log.level;
Logger.root.onRecord.listen(Configuration.userServer.log.onRecord);

try {
Directory.current = dirname(Platform.script.toFilePath());

registerAndParseCommandlineArguments(args);

if(showHelp()) {
print(parser.usage);
} else {
json.config = new json.Configuration(parsedArgs);
json.config.whenLoaded()
.then((_) => router.connectAuthService())
.then((_) => router.connectNotificationService())
.then((_) => router.startDatabase())
.then((_) => router.start(port : json.config.httpport))
.catchError(log.shout);
}
} catch(error, stackTrace) {
log.shout(error, stackTrace);
}
}

void registerAndParseCommandlineArguments(List<String> arguments) {
parser.addFlag ('help', abbr: 'h', help: 'Output this help');
parser.addOption('configfile', help: 'The JSON configuration file. Defaults to config.json');
parser.addOption('httpport', help: 'The port the HTTP server listens on. Defaults to 8080');
parser.addOption('dbuser', help: 'The database user');
parser.addOption('dbpassword', help: 'The database password');
parser.addOption('dbhost', help: 'The database host. Defaults to localhost');
parser.addOption('dbport', help: 'The database port. Defaults to 5432');
parser.addOption('dbname', help: 'The database name');
parser.addOption('servertoken', help: 'Server-Token');

parsedArgs = parser.parse(arguments);
}

bool showHelp() => parsedArgs['help'];
22 changes: 15 additions & 7 deletions lib/auth_server/db/getuser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ part of authenticationserver.database;

Future<Map> getUser(String userEmail) {
String sql = '''
SELECT u.id, u.name, u.extension, u.send_from as address,
SELECT
u.id,
u.name,
u.extension,
u.google_username,
u.google_appcode,
u.send_from AS address,
coalesce (
(SELECT array_to_json(array_agg(name))
FROM user_groups JOIN groups ON user_groups.group_id = groups.id
Expand All @@ -21,12 +27,14 @@ WHERE identity = @email;''';
if(rows.length == 1) {
var row = rows.first;
data =
{'id' : row.id,
'name' : row.name,
'address' : row.address,
'extension' : row.extension,
'groups' : row.groups,
'identities': row.identities};
{'id' : row.id,
'name' : row.name,
'address' : row.address,
'extension' : row.extension,
'groups' : row.groups,
'google_username' : row.google_username,
'google_appcode' : row.google_appcode,
'identities' : row.identities};
}

return data;
Expand Down
2 changes: 2 additions & 0 deletions lib/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ConfigServer extends StandardConfig {
class ContactServer extends StandardConfig {}
class CDRServer extends StandardConfig {}
class MessageDispatcher extends StandardConfig {}
class UserServer extends StandardConfig {}
class ManagementServer extends StandardConfig {}
class MessageServer extends StandardConfig {}
class NotificationServer extends StandardConfig {}
Expand All @@ -55,5 +56,6 @@ abstract class Configuration {
static final MessageServer messageServer= new MessageServer();
static final NotificationServer notificationServer= new NotificationServer();
static final ReceptionServer receptionServer= new ReceptionServer();
static final UserServer userServer= new UserServer();

}
184 changes: 184 additions & 0 deletions lib/user_server/configuration.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
library userserver.configuration;

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';

import 'package:openreception_framework/common.dart';

Configuration config;


/**
* Default configuration values.
*/
abstract class Default {
static final String configFile = 'config.json';
static final int httpport = 4030;
static final Uri notificationServer = Uri.parse("http://localhost:4200");
static final Uri authenticationServer = Uri.parse("http://localhost:8080");
static final String serverToken = 'feedabbadeadbeef0';
}

class Configuration {
static Configuration _configuration;

ArgResults _args;
Uri _authUrl = Default.authenticationServer;
Uri _notificationServer = Default.notificationServer;
String _configfile = Default.configFile;
String _dbuser;
String _dbpassword;
String _dbhost = 'localhost';
int _dbport = 5432;
String _dbname;
int _httpport = Default.httpport;
String _serverToken = Default.serverToken;

Uri get authUrl => _authUrl;
Uri get notificationServer => _notificationServer;
String get configfile => _configfile;
String get dbuser => _dbuser;
String get dbpassword => _dbpassword;
String get dbhost => _dbhost;
int get dbport => _dbport;
String get dbname => _dbname;
int get httpport => _httpport;
String get serverToken => _serverToken;

String emailUsername;
String emailPassword;
String emailFromName;
String emailFrom;
List<String> recipients = [];

factory Configuration(ArgResults args) {
if(_configuration == null) {
_configuration = new Configuration._internal(args);
}

return _configuration;
}

Configuration._internal(ArgResults args) {
_args = args;
if(hasArgument('configfile')) {
_configfile = args['configfile'];
}
}

bool hasArgument(String name) {
try {
return _args[name] != null && _args[name].trim() != '';
} catch(e) {
return false;
}
}

Future _parseConfigFile() {
File file = new File(_configfile);

return file.readAsString().then((String data) {
Map config = JSON.decode(data);

if(config.containsKey('authurl')) {
_authUrl = Uri.parse(config['authurl']);
}

if(config.containsKey('user_server_http_port')) {
_httpport = config['user_server_http_port'];
}

if(config.containsKey('serverToken')) {
_serverToken = config['serverToken'];
}

if(config.containsKey('dbuser')) {
_dbuser = config['dbuser'];
}

if(config.containsKey('dbpassword')) {
_dbpassword = config['dbpassword'];
}

if(config.containsKey('dbhost')) {
_dbhost = config['dbhost'];
}

if(config.containsKey('notificationServer')) {
_notificationServer = Uri.parse(config['notificationServer']);
}

if(config.containsKey('dbport')) {
_dbport = config['dbport'];
}

if(config.containsKey('dbname')) {
_dbname = config['dbname'];
}
})
.catchError((err) {
log('Failed to read "$configfile". Error: $err');
});
}

Future _parseArgument() {
return new Future(() {
if(hasArgument('authurl')) {
_authUrl = Uri.parse(_args['authurl']);
}

if(hasArgument('httpport')) {
_httpport = int.parse(_args['httpport']);
}

if(hasArgument('dbuser')) {
_dbuser = _args['dbuser'];
}

if(hasArgument('dbpassword')) {
_dbpassword = _args['dbpassword'];
}

if(hasArgument('dbhost')) {
_dbhost = _args['dbhost'];
}

if(hasArgument('dbport')) {
_dbport = int.parse(_args['dbport']);
}

if(hasArgument('dbname')) {
_dbname = _args['dbname'];
}

if(hasArgument('servertoken')) {
_serverToken = _args['servertoken'];
}

}).catchError((error) {
log('Failed loading commandline arguments. $error');
throw error;
});
}

@override
String toString() =>'''
httpport: $httpport
dbuser: $dbuser
dbpassword: ${dbpassword != null && dbpassword.isNotEmpty ? dbpassword.split('').first +
dbpassword.split('').skip(1).take(dbpassword.length-2).map((_) => '*').join('') +
dbpassword.substring(dbpassword.length -1) : ''}
dbhost: $dbhost
dbport: $dbport
dbname: $dbname
emailfrom: $emailFromName <$emailFrom>
mailuser: $emailUsername
mailpass: $emailPassword''';

Future whenLoaded() {
return _parseConfigFile().whenComplete(_parseArgument);
}
}
Loading