{ 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';"; }; }; }; }; }; }