diff --git a/Dockerfile b/Dockerfile index 4813fb2..c4be211 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,3 @@ FROM xena/lapis - +RUN moonrocks install xml diff --git a/app.moon b/app.moon index 20233ba..92f6855 100644 --- a/app.moon +++ b/app.moon @@ -37,12 +37,14 @@ class App extends lapis.Application @params.password_again = nil @params.csrf_token = nil @params.extension = "9001" + @params.registrar_password = encoding.encode_base64 encoding.hmac_sha1(@params.email, os.time!) if Users\find email: @params.email return status: 500, "User with that email already exists" user = Users\create @params user\write_session @ + @session.sippw = @params.registrar_password "Hi " .. user.name } @@ -70,3 +72,11 @@ class App extends lapis.Application else return status: 500, "bad password" } + + [freeswitch: "/freeswitch"]: respond_to { + POST: => + uid = @params["user"] or @params["sip_auth_username"] + @user = Users\find id: uid + + render: true, layout: false + } diff --git a/migrations.moon b/migrations.moon index 65d1349..eb95135 100644 --- a/migrations.moon +++ b/migrations.moon @@ -23,4 +23,7 @@ import add_column, create_table, types from require "lapis.db.schema" [5]: => add_column "users", "is_agent", types.boolean + + [6]: => + add_column "users", "registrar_password", types.text } diff --git a/views/freeswitch.moon b/views/freeswitch.moon new file mode 100644 index 0000000..6828c35 --- /dev/null +++ b/views/freeswitch.moon @@ -0,0 +1,18 @@ +import Widget from require "lapis.html" + +class Freeswitch extends Widget + content: => + document type: "freeswitch/xml", -> + section name: "directory", -> + domain name: "$${domain}", -> + params -> + param name: "dial-string", value: "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}" + groups -> + group name: "default", -> + users -> + user id: "#{@user.id}", -> + params -> + param name: "password", value: "#{@user.registrar_password}" + variables -> + variable name: "accountcode", value: "#{@user.id}" + variable name: "user_context", value: "default"