From a35d4293d6864f6efe14f5f70db7c65b8cabc9e4 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 24 May 2021 14:38:56 -0500 Subject: [PATCH] Hidden command to allow jmp-register to start a web registration This is the command jmp-register will use to tell use a certain claimed JID wants a certain tel. We relay that to cheogram and save in web_register_manager the tel associated with the JID cheogram assigns to the target. --- config.dhall.sample | 4 ++++ sgx_jmp.rb | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/config.dhall.sample b/config.dhall.sample index c56d6fb..9e22c41 100644 --- a/config.dhall.sample +++ b/config.dhall.sample @@ -19,6 +19,10 @@ secret = "", application_id = "" }, + web_register = { + to = "cheogram", + from = "jmp-register@localhost" + }, bandwidth_site = "", braintree = { environment = "sandbox", diff --git a/sgx_jmp.rb b/sgx_jmp.rb index 810153e..d06f062 100644 --- a/sgx_jmp.rb +++ b/sgx_jmp.rb @@ -225,6 +225,28 @@ command :execute?, node: "buy-credit", sessionid: nil do |iq| }.catch(&method(:panic)) end +command :execute?, node: "web-register", sessionid: nil do |iq| + jid = iq.form.field("jid")&.value.to_s.strip + tel = iq.form.field("tel")&.value.to_s.strip + if iq.from.stripped != CONFIG[:web_register][:from] + BLATHER << iq.as_error("forbidden", :auth) + elsif jid == "" || tel !~ /\A\+\d+\Z/ + reply_with_note(iq, "Invalid JID or telephone number.", type: :error) + else + IQ_MANAGER.write(Blather::Stanza::Iq::Command.new.tap { |cmd| + cmd.to = CONFIG[:web_register][:to] + cmd.from = CONFIG[:component][:jid] + cmd.node = "push-register" + cmd.form.fields = [var: "to", value: jid] + cmd.form.type = "submit" + }).then do |result| + final_jid = result.form.field("from")&.value.to_s.strip + web_register_manager[final_jid] = tel + BLATHER << iq.reply.tap { |reply| reply.status = :completed } + end + end +end + command sessionid: /./ do |iq| COMMAND_MANAGER.fulfill(iq) end -- 2.45.2