add fieldpoc-dect module
This commit is contained in:
@@ -3,5 +3,6 @@
|
||||
{
|
||||
imports = [
|
||||
./yate
|
||||
./fieldpoc
|
||||
];
|
||||
}
|
||||
|
80
modules/fieldpoc/default.nix
Normal file
80
modules/fieldpoc/default.nix
Normal file
@@ -0,0 +1,80 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let cfg = config.services.fieldpoc;
|
||||
in {
|
||||
imports = [
|
||||
./dhcp.nix
|
||||
];
|
||||
|
||||
options = {
|
||||
services.fieldpoc = {
|
||||
enable = mkEnableOption "fieldpoc";
|
||||
# TODO: config
|
||||
#config = mkOption {
|
||||
# type = with types; attrsOf anything;
|
||||
# default = { };
|
||||
#};
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
initialScript = pkgs.writeText "backend-initScript" ''
|
||||
CREATE ROLE nixcloud WITH LOGIN PASSWORD 'nixcloud' CREATEDB;
|
||||
CREATE DATABASE nixcloud;
|
||||
GRANT ALL PRIVILEGES ON DATABASE nixcloud TO nixcloud;
|
||||
'';
|
||||
};
|
||||
|
||||
services.yate = {
|
||||
enable = true;
|
||||
config = {
|
||||
extmodule."listener ywsd" = {
|
||||
type = "tcp";
|
||||
addr = "127.0.0.1";
|
||||
port = "5039";
|
||||
};
|
||||
cdrbuild.parameters.X-Eventphone-Id = "false";
|
||||
pgsqldb.default = {
|
||||
host = "localhost";
|
||||
port = "5432";
|
||||
database = "fieldpoc";
|
||||
user = "fieldpoc";
|
||||
password = "fieldpoc";
|
||||
};
|
||||
register = {
|
||||
general = {
|
||||
expires = 30;
|
||||
"user.auth" = "yes";
|
||||
"user.register" = "yes";
|
||||
"user.unregister" = "yes";
|
||||
"engine.timer" = "yes";
|
||||
"call.cdr" = "yes";
|
||||
"linetracker" = "yes";
|
||||
};
|
||||
default = {
|
||||
priority = 30;
|
||||
account = "default";
|
||||
};
|
||||
"user.auth" = {
|
||||
query = "SELECT password FROM users WHERE username='\${username}' AND password IS NOT NULL AND password<>'' AND type='user' LIMIT 1;";
|
||||
result = "password";
|
||||
};
|
||||
"user.register".query = "INSERT INTO registrations (username, location, oconnection_id, expires) VALUES ('\${username}', '\${data}', '\${oconnection_id}', NOW() + INTERVAL '\${expires} s') ON CONFLICT ON CONSTRAINT uniq_registrations DO UPDATE SET expires = NOW() + INTERVAL '\${expires} s'";
|
||||
"user.unregister".query = "DELETE FROM registrations WHERE (username = '\${username}' AND location = '\${data}' AND oconnection_id = '\${connection_id}') OR ('\${username}' = '' AND '\${data}' = '' AND oconnection_id = '\${connection_id}')";
|
||||
"engine.timer".query = "DELETE FROM registrations WHERE expires<=CURRENT_TIMESTAMP;";
|
||||
"call.cdr".critial = "no";
|
||||
"linetracker" = {
|
||||
critical = "yes";
|
||||
initquery = "UPDATE users SET inuse=0 WHERE inuse is not NULL;DELETE from active_calls;";
|
||||
cdr_initialize = "UPDATE users SET inuse=inuse+1 WHERE username='\${external}';INSERT INTO active_calls SELECT username, x_eventphone_id FROM (SELECT '\${external}' as username, '\${X-Eventphone-Id}' as x_eventphone_id, '\${direction}' as direction) as active_call WHERE x_eventphone_id != '' AND x_eventphone_id IS NOT NULL and direction = 'outgoing';";
|
||||
cdr_finalize = "UPDATE users SET inuse=(CASE WHEN inuse>0 THEN inuse-1 ELSE 0 END) WHERE username='\${external}';DELETE FROM active_calls WHERE username = '\${external}' AND x_eventphone_id = '\${X-Eventphone-Id}' AND '\${direction}' = 'outgoing';";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
139
modules/fieldpoc/dhcp.nix
Normal file
139
modules/fieldpoc/dhcp.nix
Normal file
@@ -0,0 +1,139 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let cfg = config.services.fieldpoc.dhcp;
|
||||
in {
|
||||
options.services.fieldpoc.dhcp = {
|
||||
enable = mkEnableOption "fieldpoc-dhcp";
|
||||
interface = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
subnet = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
pool = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
router = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
dnsServers = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
omm = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
reservations = mkOption {
|
||||
type = with types; listOf (submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
macAddress = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
ipAddress = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.kea.dhcp4 = {
|
||||
enable = true;
|
||||
settings = {
|
||||
interfaces-config = {
|
||||
interfaces = [ cfg.interface ];
|
||||
};
|
||||
option-def = [
|
||||
{
|
||||
space = "dhcp4";
|
||||
name = "vendor-encapsulated-options";
|
||||
code = 43;
|
||||
type = "empty";
|
||||
encapsulate = "sipdect";
|
||||
}
|
||||
{
|
||||
space = "sipdect";
|
||||
name = "ommip1";
|
||||
code = 10;
|
||||
type = "ipv4-address";
|
||||
}
|
||||
{
|
||||
space = "sipdect";
|
||||
name = "ommip2";
|
||||
code = 19;
|
||||
type = "ipv4-address";
|
||||
}
|
||||
{
|
||||
space = "sipdect";
|
||||
name = "syslogip";
|
||||
code = 14;
|
||||
type = "ipv4-address";
|
||||
}
|
||||
{
|
||||
space = "sipdect";
|
||||
name = "syslogport";
|
||||
code = 15;
|
||||
type = "int16";
|
||||
}
|
||||
{
|
||||
space = "dhcp4";
|
||||
name = "magic_str";
|
||||
code = 224;
|
||||
type = "string";
|
||||
}
|
||||
];
|
||||
|
||||
subnet4 = [
|
||||
{
|
||||
subnet = cfg.subnet;
|
||||
pools = [
|
||||
{
|
||||
pool = cfg.pool;
|
||||
}
|
||||
];
|
||||
option-data = [
|
||||
{
|
||||
name = "routers";
|
||||
data = cfg.router;
|
||||
}
|
||||
{
|
||||
name = "domain-name-servers";
|
||||
data = cfg.dnsServers;
|
||||
}
|
||||
{
|
||||
name = "vendor-encapsulated-options";
|
||||
}
|
||||
{
|
||||
space = "sipdect";
|
||||
name = "ommip1";
|
||||
data = cfg.omm;
|
||||
}
|
||||
{
|
||||
name = "magic_str";
|
||||
data = "OpenMobilitySIP-DECT";
|
||||
}
|
||||
];
|
||||
|
||||
reservations = map (r: {
|
||||
hostname = r.name;
|
||||
hw-address = r.macAddress;
|
||||
ip-address = r.ipAddress;
|
||||
option-data = [
|
||||
{
|
||||
name = "host-name";
|
||||
data = r.name;
|
||||
}
|
||||
];
|
||||
}) cfg.reservations;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user