Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function(req, res, next) {
- SSH = require('simple-ssh');
- BOTlogic = true;
- var slackText = req.body.text;
- var userName = req.body.user_name;
- if (slackText === "Shutdown") {
- JSONtext = "Good night!";
- shutdown1 = true;
- }
- else if (slackText === "Startup" && shutdown2 === true) {
- JSONtext = "Good morning!"
- shutdown2 = false;
- }
- else if (SSHconfig === true && userName !== 'slackbot') {
- HOST = slackText;
- JSONtext = "USER:"
- SSHconfig2 = true;
- SSHconfig = false;
- }
- else if (SSHconfig2 === true && userName !== 'slackbot') {
- USER = slackText;
- JSONtext = "PASS:"
- SSHconfig2 = false;
- SSHconfig3 = true;
- }
- else if (SSHconfig3 === true && userName !== 'slackbot') {
- PASS = slackText;
- JSONtext = "HOST:" + HOST.toString() + "\nUSER:" + USER.toString() + "\nPASS:" + PASS.toString() + "\nCONFIRM?"
- SSHconfig3 = false;
- SSHconfig4 = true;
- }
- else if (SSHconfig4 === true && userName !== 'slackbot') {
- JSONtext = "The setup is complete, SSH is now ready to be launched.";
- SSHconfig4 = false;
- SSHconfig5 = true;
- }
- else if (SSHconfig5 === true && slackText === "SSH launch") {
- JSONtext = "Uh-oh, something went horribly wrong! Please try again or contact @gilbert-gobbels"
- ssh = new SSH({
- host: HOST,
- user: USER,
- pass: PASS
- });
- //And then we use linux screen to start the server, easy peasy lemon squeezy.
- ssh.exec('This_command_does_not_exist', {
- //And of course; debugging!
- out: function(stdout) {
- JSONtext = stdout.toString();
- },
- err: function(stderr) {
- console.log(stderr); // this-does-not-exist: command not found
- JSONtext = stderr.toString()
- }
- }).start();
- }
- else if (slackText === "Hello!") {
- JSONtext = "Hello there!"
- } else if (slackText === "Optic sucks.") {
- JSONtext = "Dude, I like, totaly agree with you."
- } else if (slackText === "Sweet!" || slackText === "Great!" || slackText === "Nice!") {
- JSONtext = "I know right? Totaly amazing!"
- // } else if (slackText === 'module.exports = function (req, res, next) { var slackText = req.body.text; var userName = req.body.user_name; if (slackText === "Hello!") {JSONtext = "Hello there!"} else if (slackText === "Optic sucks.") {JSONtext = "Dude, I like, totaly agree with you."} else if (slackText === "Sweet!" || slackText === "Great!" || slackText === "Nice!") {JSONtext = "I know right? Totaly amazing!"} else {JSONtext = "Please do not talk much in this channel, this place is under construction!"} var botPayload = { text : JSONtext }; // avoid infinite loop if (userName !== "slackbot") { return res.status(200).json(botPayload); } else { return res.status(200).end(); }}') {
- // JSONtext = "Look daddy! It's me!"
- }
- else if (slackText === "Initiate shell" || slackText === "Start shell" || slackText === "/shell") {
- JSONtext = "The shell has been launched. Exit by typing 'Exit shell'";
- ShellOpen = true;
- }
- else if (ShellOpen === true && slackText === "Exit shell") {
- JSONtext = "The shell has been shutdown."
- ShellOpen = false;
- }
- else if (slackText === "Print Shell Status") {
- JSONtext = ShellOpen.toString()
- }
- else if (slackText === "Debug" && ShellOpen === true) {
- JSONtext = "LibraryLOAD: " + LibraryLOAD.toString() + "\nPOST_IO: " + POST_IO.toString() + "\nBOTlogic: " + BOTlogic.toString() + "\nEND"
- }
- else if (slackText === "SSH config" && ShellOpen === true) {
- SSHconfig = true;
- JSONtext = "Starting SSH config wizzard... HOST: "
- }
- else {
- console.log("ERROR_302: Logic error.")
- userName = 'slackbot';
- }
- var botPayload = {
- text: JSONtext
- };
- if (shutdown2 === true) {
- return console.log("Shh! I'm sleeping. Restart the script to wake me up.")
- }
- else {
- if (shutdown1 === true) {
- shutdown2 = true;
- shutdown1 = false;
- }
- else {shutdown2 = false}
- }
- // avoid infinite loop
- if (userName !== 'slackbot') {
- return res.status(200).json(botPayload);
- } else {
- return res.status(200).end();
- } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement