From 9695b125a2388f76ef7e1fd4bbd15e9182796508 Mon Sep 17 00:00:00 2001 From: stephen Date: Fri, 1 Apr 2022 09:40:37 -0400 Subject: [PATCH 1/7] Removing invite. Just adding user to channel as member. removing white space. --- index.js | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 6ea6cac..11e4caf 100755 --- a/index.js +++ b/index.js @@ -455,7 +455,7 @@ try { lang: 'en', mam: 'true', members_only: 'true', - persistent: 'true', + persistent: 'false', public: 'false', public_list: 'false', title: 'Secure channel generated by https://vxmppb.tk', @@ -491,31 +491,10 @@ try { }, 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(); @@ -556,12 +535,13 @@ try { debug(); } - - // Shutsdown bot if admin sends shutdown command (linux) else if (message === "sudo shutdown now -h") { if (from != user_jid) { - xmpp.send(from, pc); + xmpp.send(from, from + " is not in the sudoers file. This incident will be reported."); + setTimeout(() => { + xmpp.send(from, "lol...get it!?"); + }, 2000); } else { // send shutdown message xmpp.send(from, "Alrighty, shutting down. Goodbye!"); From 7f6cbd36a06a526fd36272595ae1db3f846a1ebd Mon Sep 17 00:00:00 2001 From: stephen Date: Fri, 1 Apr 2022 21:32:45 -0400 Subject: [PATCH 2/7] Readding invite code. Send meeting messages to friends, as admin starts it. Removing second message for failed admin shutdown. Changing status message. --- index.js | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 11e4caf..3604e39 100755 --- a/index.js +++ b/index.js @@ -106,6 +106,9 @@ try { return directions[index]; } + // setup friends list + const friends = Object.keys(config.friends); + xmpp.on('online', function(data, to) { // once we're online, we'll send a message alerting xmpp admins console.log('Connected with JID: ' + bot_jid); @@ -128,8 +131,6 @@ try { console.log('-------------'); }; } - // setup friends list - const friends = Object.keys(config.friends); // setup gotify url let gotifyURL = `${gotify_api_url}/message?token=${gotify_key}&message=${from} ${gotify_message}&title=${gotify_title}&priority=${gotify_priority}`; let gotifyEUrl = encodeURI(gotifyURL); @@ -429,7 +430,9 @@ try { } - // Share-A-Command (#13?) + // Share-A-Command which was #13, but kinda turned into a different command + // This will generate a private channel, and add the users in the friends + // secion from config.ini else if (message === '!meet') { if (from != user_jid) { xmpp.send(from, pc); @@ -474,7 +477,7 @@ try { // 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: " + xmpp_muc_name + "@" + xmpp_muc_server); + xmpp.send(key, "Meeting started"); // authorize users const addMember = { method: 'POST', @@ -491,10 +494,31 @@ try { }, 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(); @@ -525,10 +549,8 @@ try { if (error) throw new Error(error); console.log(body); }); - // send meeting ended to user_jid - xmpp.send(from, "Meeting ended"); - // send meeting ended to friends for (const key in config.friends) { + // alert friends meeting has ended xmpp.send(key, "Meeting ended"); } } @@ -539,9 +561,7 @@ try { else if (message === "sudo shutdown now -h") { if (from != user_jid) { xmpp.send(from, from + " is not in the sudoers file. This incident will be reported."); - setTimeout(() => { - xmpp.send(from, "lol...get it!?"); - }, 2000); + console.log(from + ' tried to shut me down!'); } else { // send shutdown message xmpp.send(from, "Alrighty, shutting down. Goodbye!"); @@ -577,7 +597,7 @@ try { }); // Set XMPP status - xmpp.setPresence('chat', 'Asterisk,Mastodon, and MQTT. Oh my!'); + xmpp.setPresence('chat', 'https://vxmppb.tk'); // Alas, we connect to XMPP! xmpp.connect({ @@ -587,12 +607,8 @@ try { port: bot_port }); - // Checks the XMPP server for new 'friend' requests - console.log(xmpp.getRoster()); - - } catch (e) { console.log("Please create a config.ini"); console.log("See https://wiki.vanderwarker.family/doku.php?id=code:vxmppb:install:start"); - console.log("and choose your prefered install method.") + console.log("and choose your prefered install method."); } From 9b41de2e5196eb085d599a1ec8a9611d41ae8c7a Mon Sep 17 00:00:00 2001 From: stephen Date: Mon, 4 Apr 2022 20:48:51 -0400 Subject: [PATCH 3/7] Adding subscription back as it will only accept ones from [friends] in config.ini --- index.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 3604e39..7a56c1a 100755 --- a/index.js +++ b/index.js @@ -115,7 +115,7 @@ try { xmpp.send(user_jid, "[ONLINE]", false); // send mqtt online message client.publish(mqtt_topic, mqtt_message); - // toot online message + // toot online message M.post('statuses', { status: `${mastodon_toot}` }); @@ -606,6 +606,21 @@ try { host: bot_hostname, port: bot_port }); + // subscribe to friends + xmpp.on('subscribe', function(from) { + if (from in config.friends == true) { + console.log('accepting subsciption request from ' + from); + // accept pending subscription requests + xmpp.acceptSubscription(from); + // check for incoming subscription requests + xmpp.getRoster(); + // subscribe to any incoming subscription requests + console.log('requesting subscription to ' + from); + xmpp.subscribe(from); + } else { + console.log('denied subscription request from: ' + from + " as they are not in the friends section of config.ini"); + } + }); } catch (e) { console.log("Please create a config.ini"); From 30fd59b4f6de9025f1ef7604bb7d50612e62fb77 Mon Sep 17 00:00:00 2001 From: stephen Date: Sat, 23 Apr 2022 22:50:59 -0400 Subject: [PATCH 4/7] Changing issue template. --- .gitea/ISSUE_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/ISSUE_TEMPLATE.md b/.gitea/ISSUE_TEMPLATE.md index 9ba6531..a40ceed 100644 --- a/.gitea/ISSUE_TEMPLATE.md +++ b/.gitea/ISSUE_TEMPLATE.md @@ -11,6 +11,6 @@ ## Specifications - - Version: + - Node JS Version: - Platform: - - Subsystem: + - vXMPPb Version: \ No newline at end of file From b48e0397830a4cac3d8e3a957e8ce2c069d2c7c1 Mon Sep 17 00:00:00 2001 From: stephen Date: Sat, 23 Apr 2022 23:27:14 -0400 Subject: [PATCH 5/7] Fixing weather. Seems like an odd an incorrect way to fix, but alas...it works. --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 7a56c1a..862ccfe 100755 --- a/index.js +++ b/index.js @@ -399,11 +399,11 @@ try { let wmc = weather_city_name + " Weather: Tempature: " + w.main.temp + " degrees. Conditions: " + w.weather[0].main + ". Pressure: " + w.main.pressure + ". Wind Direction: " + getDirection(w.wind.deg) + ". Wind Speed: " + w.wind.speed + " miles per hour \r\n"; // send weather to mqtt - client.publish('weather/temp', 'w.main.temp'); - client.publish('weather/conditions', 'w.weather[0].main'); - client.publish('weather/pressure', 'w.main.pressure'); - client.publish('weather/wind/direction', 'getDirection(w.wind.deg)'); - client.publish('weather/wind/speed', 'w.wind.speed'); + client.publish('weather/temp', '' + w.main.temp + ''); + client.publish('weather/conditions', '' + w.weather[0].main + ''); + client.publish('weather/pressure', '' + w.main.pressure + ''); + client.publish('weather/wind/direction', '' + getDirection(w.wind.deg) + ''); + client.publish('weather/wind/speed', '' + w.wind.speed + ''); // send weather to xmpp admin xmpp.send(from, wm); // call admin with latest weather report From 71f9d6eb9a09917ef7f3f92d4c19aa073add3ffb Mon Sep 17 00:00:00 2001 From: stephen Date: Sat, 23 Apr 2022 23:30:47 -0400 Subject: [PATCH 6/7] Version bump mqtt --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 860ab73..145499b 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "asterisk-manager": "0.1.16", "ini": "2.0.0", "mastodon": "1.2.2", - "mqtt": "4.2.6", + "mqtt": "4.3.7", "request": "2.88.0", "rgb-color": "2.1.2", "simple-xmpp": "1.3.0" From d61d7682156dc4e93591df6affa534d6f9a99e54 Mon Sep 17 00:00:00 2001 From: stephen Date: Sun, 24 Apr 2022 08:02:20 -0400 Subject: [PATCH 7/7] Adding mastodon user, commented out posting toot. --- index.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 862ccfe..6e2669b 100755 --- a/index.js +++ b/index.js @@ -44,6 +44,7 @@ try { const mastodon_api_url = config.mastodon.api_url; const mastodon_token = config.mastodon.token; const mastodon_toot = config.mastodon.toot; + const mastodon_user = config.mastodon.user; // MQTT config const mqtt_message = config.mqtt.message; @@ -116,9 +117,12 @@ try { // send mqtt online message client.publish(mqtt_topic, mqtt_message); // toot online message +/* M.post('statuses', { status: `${mastodon_toot}` }); +*/ + }); // wait for incoming messages xmpp.on('chat', function(from, message) { @@ -184,6 +188,53 @@ try { debug(); } } + // Toot Unlocks + else if (message === '!tootunlocks') { + if (from != user_jid) { + xmpp.send(from, pc); + } else { + var d = new Date(); + var weekday = new Array(7); + weekday[0] = "Sunday"; + weekday[1] = "Monday"; + weekday[2] = "Tuesday"; + weekday[3] = "Wednesday"; + weekday[4] = "Thursday"; + weekday[5] = "Friday"; + weekday[6] = "Saturday"; + var n = weekday[d.getDay()]; + // get latest unlocks + request(unlocks_api_url + "?columns=" + n, (error, res, body) => { + if (error) { + return console.log(error) + }; + + if (!error && res.statusCode == 200) { + var unlockBody = new RegExp(':(.*)}'); + var unlockBodyMatch = body.match(unlockBody); + const unlockFinalMessage = "@" + config.mastodon.user + " has " + unlockBodyMatch[1] + " unlocks for " + n; + M.post('statuses', { + status: unlockFinalMessage + }); + debug(); + } + if (!error && res.statusCode == 401) { + console.log('Invalid credentials'); + xmpp.send(from, 'Invalid credentials'); + } + if (!error && res.statusCode == 404) { + console.log('Record not found'); + xmpp.send(from, 'Record not found'); + } + if (!error && res.statusCode == 500) { + console.log('Server error.'); + xmpp.send(from, 'Server error. Please ping admin'); + } + }); + debug(); + } + } + // Tuya light control else if (message === '!lights') { if (from != user_jid) { @@ -219,7 +270,7 @@ try { } if (!error && res.statusCode == 500) { console.log('Server error.'); - xmpp.send(from, 'Server error. Please ping admin'); + xmpp.send(from, 'Server error. Please !ping'); } }); debug(); @@ -430,9 +481,12 @@ try { } - // Share-A-Command which was #13, but kinda turned into a different command + // Share-A-Command which was #13, but kinda turned into a different command // This will generate a private channel, and add the users in the friends // secion from config.ini + // Please not this section requires you to have an Ejabberd server. + // I am welcome to pull requests for other servers (maybe set type in config.ini) + else if (message === '!meet') { if (from != user_jid) { xmpp.send(from, pc);