clanService/phonebox: phonebook feature
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
{ clanLib, ... }:
|
||||
{
|
||||
clanLib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
_class = "clan.service";
|
||||
manifest.name = "phonebox";
|
||||
@@ -14,6 +17,11 @@
|
||||
description = "An Ethernet interface that connect to ATA box.";
|
||||
default = "enp2s0";
|
||||
};
|
||||
options.ownerName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "";
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
perInstance =
|
||||
{
|
||||
@@ -22,6 +30,7 @@
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
||||
nixosModule =
|
||||
{
|
||||
lib,
|
||||
@@ -34,12 +43,57 @@
|
||||
propagatedNativeBuildInputs = [ pkgs.spandsp3 ];
|
||||
});
|
||||
|
||||
machines = lib.attrNames roles.default.machines;
|
||||
|
||||
user = "asterisk";
|
||||
faxDir = "/run/asterisk/fax";
|
||||
rtpPortFrom = 10000;
|
||||
rtpPortTo = 20000;
|
||||
ata-interface = settings.ata-ethernet-iface;
|
||||
|
||||
contactList = builtins.map (machineName: {
|
||||
name = "${clanLib.getPublicValue {
|
||||
flake = config.clan.core.settings.directory;
|
||||
machine = machineName;
|
||||
generator = "phonebox";
|
||||
file = "owner-name";
|
||||
default = null;
|
||||
}}";
|
||||
number = "${
|
||||
clanLib.getPublicValue {
|
||||
flake = config.clan.core.settings.directory;
|
||||
machine = machineName;
|
||||
generator = "phonebox";
|
||||
file = "server-prefix-number";
|
||||
default = null;
|
||||
}
|
||||
}${
|
||||
clanLib.getPublicValue {
|
||||
flake = config.clan.core.settings.directory;
|
||||
machine = machineName;
|
||||
generator = "phonebox";
|
||||
file = "ata-local-number";
|
||||
default = null;
|
||||
}
|
||||
}";
|
||||
}) machines;
|
||||
|
||||
createContactListTiff =
|
||||
let
|
||||
contactTXT = lib.concatStringsSep "\n" (
|
||||
builtins.map (contact: "${contact.number}\t\t: \t\t${contact.name}") contactList
|
||||
);
|
||||
in
|
||||
pkgs.writeShellApplication {
|
||||
name = "create-contact-tiff";
|
||||
text = ''
|
||||
magick -background white -fill black -pointsize 20 -font DejaVu-Sans label:"${contactTXT}" "$1"
|
||||
magick "$1" -border 20x50 -bordercolor white "$1"
|
||||
magick "$1" -resize 1728x -units PixelsPerInch -compress Group4 -density 204x196 -monochrome -depth 1 "$1"
|
||||
'';
|
||||
runtimeInputs = [ pkgs.imagemagick ];
|
||||
};
|
||||
|
||||
genServerSIPEndpoint =
|
||||
{ hostname, address }:
|
||||
''
|
||||
@@ -102,26 +156,35 @@
|
||||
throw "clanService/yggdrasil is required";
|
||||
in
|
||||
{
|
||||
clan.core.vars.generators.phonebox = {
|
||||
clan.core.vars.generators.phonebox = builtins.break {
|
||||
files = {
|
||||
server-prefix-number.secret = false;
|
||||
ata-local-number.secret = false;
|
||||
owner-name.secret = false;
|
||||
};
|
||||
|
||||
prompts = {
|
||||
server-prefix-number = {
|
||||
type = "line";
|
||||
persist = true;
|
||||
description = "Server prefix number: indicate server to connect to [10XX]";
|
||||
};
|
||||
ata-local-number = {
|
||||
persist = true;
|
||||
type = "line";
|
||||
description = "Local suffix number: indicate local number on the server [XX00]";
|
||||
};
|
||||
owner-name = {
|
||||
persist = true;
|
||||
type = "line";
|
||||
description = "The owner's name for this unit";
|
||||
};
|
||||
};
|
||||
|
||||
script = ''
|
||||
cat $prompts/server-prefix-number > $out/server-prefix-number
|
||||
cat $prompts/ata-local-number > $out/ata-local-number
|
||||
cat $prompts/owner-name > $out/owner-name
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -199,7 +262,6 @@
|
||||
package = lib.mkDefault asterisk;
|
||||
confFiles =
|
||||
let
|
||||
machines = lib.attrNames roles.default.machines;
|
||||
nodes = builtins.foldl' (
|
||||
nodes: name:
|
||||
nodes
|
||||
@@ -275,6 +337,13 @@
|
||||
same => n,Set(FAXFILE=${faxDir}/echo-''${UNIQUEID}.tiff)
|
||||
same => n,Set(FAXECHO=true)
|
||||
|
||||
exten => 888,1,Answer()
|
||||
same => n,Set(FAXFILE=${faxDir}/contact.tiff)
|
||||
same => n,System(${lib.getExe createContactListTiff} ''${FAXFILE})
|
||||
same => n,Set(FAXECHO=true)
|
||||
same => n,Playback(vm-goodbye)
|
||||
same => n,Wait(3)
|
||||
|
||||
exten => h,1,GotoIf($[''${FAXECHO}]?sendfax)
|
||||
same => n,Hangup()
|
||||
same => n(sendfax),Originate(PJSIP/00,app,SendFAX,''${FAXFILE})
|
||||
@@ -341,6 +410,10 @@
|
||||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = [
|
||||
createContactListTiff
|
||||
];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d ${faxDir} 0755 ${user} ${user} - -"
|
||||
];
|
||||
|
||||
1
vars/per-machine/adhil/phonebox/owner-name/value
Normal file
1
vars/per-machine/adhil/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
w-office
|
||||
1
vars/per-machine/almach/phonebox/owner-name/value
Normal file
1
vars/per-machine/almach/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
usa-1
|
||||
1
vars/per-machine/alpheratz/phonebox/owner-name/value
Normal file
1
vars/per-machine/alpheratz/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
usa-2
|
||||
1
vars/per-machine/buna/phonebox/owner-name/value
Normal file
1
vars/per-machine/buna/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
whitehouse
|
||||
1
vars/per-machine/mirach/phonebox/owner-name/value
Normal file
1
vars/per-machine/mirach/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
usa-3
|
||||
1
vars/per-machine/neptune/phonebox/owner-name/value
Normal file
1
vars/per-machine/neptune/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
vi
|
||||
1
vars/per-machine/rigel/phonebox/owner-name/value
Normal file
1
vars/per-machine/rigel/phonebox/owner-name/value
Normal file
@@ -0,0 +1 @@
|
||||
b4l
|
||||
Reference in New Issue
Block a user