From da3390bc899e79b06dc73b2f483c88aa7368088b Mon Sep 17 00:00:00 2001 From: stephen Date: Thu, 2 Jun 2022 21:48:12 -0400 Subject: [PATCH] Creating files for prosidy, and openfire #20 Moved ejabberd to it's own file as well. --- index.js | 102 ++++++-------------------------------------- servers/ejabberd.js | 84 ++++++++++++++++++++++++++++++++++++ servers/openfire.js | 30 +++++++++++++ servers/prosidy.js | 30 +++++++++++++ 4 files changed, 156 insertions(+), 90 deletions(-) create mode 100644 servers/ejabberd.js create mode 100644 servers/openfire.js create mode 100644 servers/prosidy.js diff --git a/index.js b/index.js index 4ff83cb..b7ea449 100755 --- a/index.js +++ b/index.js @@ -450,96 +450,18 @@ try { xmpp.send(from, pc); } else { if (xmpp_server_type === "ejabberd"){ - // Create private XMPP room - const createRoom = { - method: 'POST', - url: xmpp_api_url + '/create_room_with_opts', - headers: { - 'Content-Type': 'application/json', - Authorization: xmpp_auth - }, - body: { - name: xmpp_muc_name, - service: xmpp_muc_server, - host: bot_hostname, - options: { - allow_change_subj: 'false', - allow_private_messages: 'false', - allow_private_messages_from_visitors: 'false', - allow_visitor_nickchange: 'false', - allow_visitor_status: 'false', - lang: 'en', - mam: 'true', - members_only: 'true', - persistent: 'false', - public: 'false', - public_list: 'false', - title: 'Secure channel generated by https://vxmppb.tk', - allow_subscription: 'true' - } - }, - json: true - }; - // send request to create room - request(createRoom, function (error, response, body) { - if (error) throw new Error(error); - console.log(body); - }); - // wait 2 seconds until room has been created (http issues) - setTimeout(() => { - // loop through friends, authorize users, and send invites - for (const key in config.friends) { - // send xmpp message to friends alerting of new room - xmpp.send(key, "Meeting started"); - // authorize users - const addMember = { - method: 'POST', - url: xmpp_api_url + 'set_room_affiliation', - headers: { - 'Content-Type': 'application/json', - Authorization: xmpp_auth - }, - body: { - name: xmpp_muc_name, - service: xmpp_muc_server, - jid: key, - affiliation: 'member' - }, - json: true - }; - // invite users - const inviteMember = { - method: 'POST', - url: xmpp_api_url + '/send_direct_invitation', - headers: { - 'Content-Type': 'application/json', - Authorization: xmpp_auth - }, - body: { - name: xmpp_muc_name, - service: xmpp_muc_server, - password: '', - reason: 'vXMPPb Meeting Invite', - users: key - }, - json: true - }; - request(addMember, function (error, response, body) { - if (error) throw new Error(error); - console.log(body); - }); - request(inviteMember, function (error, response, body) { - if (error) throw new Error(error); - console.log(body); - }); - } - }, 2000); - debug(); - xmpp.send(from, "Alright. Starting a new meeting: " + xmpp_muc_name + "@" + xmpp_muc_server + " and inviting friends"); - } else { - xmpp.send(from, "Ejabberd is the only supported server at the moment.") - xmpp.send(from, "Please see https://git.vanderwarker.family/vxmppb/vxmppb/issues/20") - }} + fs.readFileSync('./servers/ejabberd.js', 'utf-8'); + debug(); + xmpp.send(from, "Alright. Starting a new meeting: " + xmpp_muc_name + "@" + xmpp_muc_server + " and inviting friends"); + } + else if (xmpp_server_type === "prosidy"){ + xmpp.send(from, "Ejabberd is the only supported server at the moment.") + xmpp.send(from, "Please see https://git.vanderwarker.family/vxmppb/vxmppb/issues/20") + } + else if (xmpp_server_type === "openfire"){ + fs.readFileSync('./servers/openfire.js', 'utf-8'); + } + } } // End meeting diff --git a/servers/ejabberd.js b/servers/ejabberd.js new file mode 100644 index 0000000..1383170 --- /dev/null +++ b/servers/ejabberd.js @@ -0,0 +1,84 @@ +const createRoom = { + method: 'POST', + url: xmpp_api_url + '/create_room_with_opts', + headers: { + 'Content-Type': 'application/json', + Authorization: xmpp_auth + }, + body: { + name: xmpp_muc_name, + service: xmpp_muc_server, + host: bot_hostname, + options: { + allow_change_subj: 'false', + allow_private_messages: 'false', + allow_private_messages_from_visitors: 'false', + allow_visitor_nickchange: 'false', + allow_visitor_status: 'false', + lang: 'en', + mam: 'true', + members_only: 'true', + persistent: 'false', + public: 'false', + public_list: 'false', + title: 'Secure channel generated by https://vxmppb.tk', + allow_subscription: 'true' + } + }, + json: true +}; + +// send request to create room + request(createRoom, function (error, response, body) { + if (error) throw new Error(error); + console.log(body); + }); + // wait 2 seconds until room has been created (http issues) + setTimeout(() => { + // loop through friends, authorize users, and send invites + for (const key in config.friends) { + // send xmpp message to friends alerting of new room + xmpp.send(key, "Meeting started"); + // authorize users + const addMember = { + method: 'POST', + url: xmpp_api_url + 'set_room_affiliation', + headers: { + 'Content-Type': 'application/json', + Authorization: xmpp_auth + }, + body: { + name: xmpp_muc_name, + service: xmpp_muc_server, + jid: key, + affiliation: 'member' + }, + json: true + }; + // invite users + const inviteMember = { + method: 'POST', + url: xmpp_api_url + '/send_direct_invitation', + headers: { + 'Content-Type': 'application/json', + Authorization: xmpp_auth + }, + body: { + name: xmpp_muc_name, + service: xmpp_muc_server, + password: '', + reason: 'vXMPPb Meeting Invite', + users: key + }, + json: true + }; + request(addMember, function (error, response, body) { + if (error) throw new Error(error); + console.log(body); + }); + request(inviteMember, function (error, response, body) { + if (error) throw new Error(error); + console.log(body); + }); + } + }, 2000); \ No newline at end of file diff --git a/servers/openfire.js b/servers/openfire.js new file mode 100644 index 0000000..2991a11 --- /dev/null +++ b/servers/openfire.js @@ -0,0 +1,30 @@ +const createRoom = { + method: 'POST', + // This requires to install a plugin! Please check list on openfire + // admin dashboard. Search for HTTP API + url: xmpp_api_url + '/plugins/restapi/v1/chatrooms', + headers: { + 'Content-Type': 'application/json', + Authorization: xmpp_auth + }, + body: { + options: { + roomName: xmpp_muc_name, + naturalName: xmpp_muc_name, + description: "Secure channel generated by https://vxmppb.tk", + subject: "Secure channel generated by https://vxmppb.tk", + persistent: "false", + publicRoom: "false", + registrationEnabled: "false", + canOccupantsChangeSubject: "false", + membersOnly: "true", + moderated: "true", + members: { + // Member!? MEMBER?!? Ooo ooo! Member?! + "member": [ + config.friends + ] + }, + } + } +} \ No newline at end of file diff --git a/servers/prosidy.js b/servers/prosidy.js new file mode 100644 index 0000000..3564ff8 --- /dev/null +++ b/servers/prosidy.js @@ -0,0 +1,30 @@ +const createRoom = { + method: 'GET', + url: xmpp_api_url + '/muc/config?jid=' + user_jid, + headers: { + 'Content-Type': 'application/json', + Authorization: xmpp_auth + }, + body: { + name: xmpp_muc_name, + service: xmpp_muc_server, + host: bot_hostname, + options: { + affliations: [ + { + affliation: "member", + jid: config.friends, + } + ], + config: { + description: "", + members_only: true, + moderated: true, + name: xmpp_muc_name, + persistent: false, + subject: "Secure channel generated by https://vxmppb.tk", + public: false + } + } + } +} \ No newline at end of file