Skip to content
Open
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
27 changes: 27 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "SIP Trunk IP Auth",
"call_settings": {
"limit": 5,
"timeout": 3600
},
"auth": {
"type": "ip"
},
"endpoints": [
{
"host": "50.192.97.226",
"port": 5060,
"signalling": "proxy",
"media": "proxy",
"description": "SIP Trunk Endpoint",
"rweight": 1
}
],
"strip": 0,
"prefix": "",
"notifications": {
"overmaxcalllimit": "email@example.com",
"endpointfailure": "email@example.com"
}
}

21 changes: 17 additions & 4 deletions dsipclient/data_endpointgrouprequest.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
package dsipclient

type EndpointGroupRequest struct {
Name string `json:"name"`
Calllimit string `json:"calllimit"`
Auth Auth `json:"auth"`
Endpoints []Endpoints `json:"endpoints"`
Name string `json:"name"`
CallSettings *CallSettings `json:"call_settings"`
Auth Auth `json:"auth"`
Endpoints []Endpoint `json:"endpoints"`
Strip int `json:"strip"`
Prefix string `json:"prefix"`
Notifications *NotificationSettings `json:"notifications"`
}

type CallSettings struct {
Limit int `json:"limit"`
Timeout int `json:"timeout"`
}

type NotificationSettings struct {
OverMaxCallLimit string `json:"overmaxcalllimit"`
EndpointFailure string `json:"endpointfailure"`
}
9 changes: 6 additions & 3 deletions dsipclient/data_endpoints.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dsipclient

type Endpoints struct {
Hostname string `json:"hostname"`
type Endpoint struct {
Host string `json:"host"`
Port int `json:"port"`
Signalling string `json:"signalling"`
Media string `json:"media"`
Description string `json:"description"`
Maintmode string `json:"maintmode"`
RWeight int `json:"rweight"`
}
78 changes: 69 additions & 9 deletions dsiprouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"html"
"os"
"strings"
"encoding/json"
"flag"

_ "github.com/go-sql-driver/mysql"
)
Expand Down Expand Up @@ -81,18 +83,21 @@ func main() {

switch os.Args[1] {

case "lease":
case "lease":
processCommandLease(dsipClient)

processCommandLease(dsipClient)
case "inboundmapping":
processCommandInboundMapping(dsipClient)

case "inboundmapping":

processCommandInboundMapping(dsipClient)

case "agent":

processCommandAgent(dsipClient)
case "agent":
processCommandAgent(dsipClient)

case "endpointgroup":
processCommandEndpointGroup(dsipClient, os.Args[2:])

default:
fmt.Printf("Unknown command: %s\n", os.Args[1])
os.Exit(1)
}
}
func createConnection() *dsipclient.Client {
Expand Down Expand Up @@ -156,6 +161,7 @@ func processCommandLease(dsipClient *dsipclient.Client) {
fmt.Println("Arg(s):")
fmt.Println("\temail\t\tA valid email address")
fmt.Println("\tttl\t\tAmount of time for the SIP credentials to be available. 30 minute maximum for the Free plan")
fmt.Println("\tendpointgroup\t Manage Endpoint Groups via config or CLI flags")
//fmt.Printf("\tsipdomain\tThe name of sipdomain . The default is %s for the Free plan\n", DEFAULT_SIP_DOMAIN)
os.Exit(1)

Expand Down Expand Up @@ -322,6 +328,60 @@ func processCommandAgent(dsipClient *dsipclient.Client) {
}
}

func processCommandEndpointGroup(dsipClient *dsipclient.Client, args []string) {

// Set up flags
fs := flag.NewFlagSet("endpointgroup", flag.ExitOnError)

// Define CLI flags
configFile := fs.String("file", "", "Path to JSON config file")
overrideName := fs.String("name", "", "Override endpoint group name")
overrideIP := fs.String("ip", "", "Override endpoint IP address")
overridePort := fs.Int("port", 0, "Override endpoint port")

fs.Parse(args)

if *configFile == "" {
fmt.Println("Usage: dsiprouter-cli endpointgroup --file=config.json [--name=...] [--ip=...] [--port=...]")
os.Exit(1)
}

// Read the config file
data, err := os.ReadFile(*configFile)
if err != nil {
fmt.Printf("Error reading config file: %v\n", err)
os.Exit(1)
}

// Parse JSON into request struct
var req dsipclient.EndpointGroupRequest
if err := json.Unmarshal(data, &req); err != nil {
fmt.Printf("Error parsing JSON: %v\n", err)
os.Exit(1)
}

// Apply CLI overrides if present
if *overrideName != "" {
req.Name = *overrideName
}
if *overrideIP != "" && len(req.Endpoints) > 0 {
req.Endpoints[0].Host = *overrideIP
}
if *overridePort != 0 && len(req.Endpoints) > 0 {
req.Endpoints[0].Port = *overridePort
}

// Call the API
resp, err := dsipClient.CreateEndpointGroup(&req)
if err != nil {
fmt.Printf("\033[31m Error: %v\033[0m\n", err)
os.Exit(1)
}

fmt.Printf("Endpoint Group '%s' created for %s:%d — Response: %v\n",
req.Name, req.Endpoints[0].Host, req.Endpoints[0].Port, resp)
}

func getFreePBXDIDS() ([]DID, error) {

var dids []DID
Expand Down