Advertisement
Guest User

Untitled

a guest
Mar 19th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. module.exports = function(req, res, next) {
  2. SSH = require('simple-ssh');
  3.  
  4. BOTlogic = true;
  5. var slackText = req.body.text;
  6. var userName = req.body.user_name;
  7. if (slackText === "Shutdown") {
  8. JSONtext = "Good night!";
  9. shutdown1 = true;
  10. }
  11. else if (slackText === "Startup" && shutdown2 === true) {
  12. JSONtext = "Good morning!"
  13. shutdown2 = false;
  14. }
  15. else if (SSHconfig === true && userName !== 'slackbot') {
  16. HOST = slackText;
  17. JSONtext = "USER:"
  18. SSHconfig2 = true;
  19. SSHconfig = false;
  20. }
  21. else if (SSHconfig2 === true && userName !== 'slackbot') {
  22. USER = slackText;
  23. JSONtext = "PASS:"
  24. SSHconfig2 = false;
  25. SSHconfig3 = true;
  26. }
  27. else if (SSHconfig3 === true && userName !== 'slackbot') {
  28. PASS = slackText;
  29. JSONtext = "HOST:" + HOST.toString() + "\nUSER:" + USER.toString() + "\nPASS:" + PASS.toString() + "\nCONFIRM?"
  30. SSHconfig3 = false;
  31. SSHconfig4 = true;
  32. }
  33. else if (SSHconfig4 === true && userName !== 'slackbot') {
  34. JSONtext = "The setup is complete, SSH is now ready to be launched.";
  35. SSHconfig4 = false;
  36. SSHconfig5 = true;
  37. }
  38. else if (SSHconfig5 === true && slackText === "SSH launch") {
  39. JSONtext = "Uh-oh, something went horribly wrong! Please try again or contact @gilbert-gobbels"
  40. ssh = new SSH({
  41. host: HOST,
  42. user: USER,
  43. pass: PASS
  44. });
  45. //And then we use linux screen to start the server, easy peasy lemon squeezy.
  46. ssh.exec('This_command_does_not_exist', {
  47. //And of course; debugging!
  48. out: function(stdout) {
  49. JSONtext = stdout.toString();
  50. },
  51. err: function(stderr) {
  52. console.log(stderr); // this-does-not-exist: command not found
  53. JSONtext = stderr.toString()
  54. }
  55. }).start();
  56.  
  57.  
  58. }
  59. else if (slackText === "Hello!") {
  60. JSONtext = "Hello there!"
  61. } else if (slackText === "Optic sucks.") {
  62. JSONtext = "Dude, I like, totaly agree with you."
  63. } else if (slackText === "Sweet!" || slackText === "Great!" || slackText === "Nice!") {
  64. JSONtext = "I know right? Totaly amazing!"
  65. // } 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(); }}') {
  66. // JSONtext = "Look daddy! It's me!"
  67. }
  68.  
  69. else if (slackText === "Initiate shell" || slackText === "Start shell" || slackText === "/shell") {
  70. JSONtext = "The shell has been launched. Exit by typing 'Exit shell'";
  71. ShellOpen = true;
  72. }
  73. else if (ShellOpen === true && slackText === "Exit shell") {
  74. JSONtext = "The shell has been shutdown."
  75. ShellOpen = false;
  76. }
  77. else if (slackText === "Print Shell Status") {
  78. JSONtext = ShellOpen.toString()
  79. }
  80. else if (slackText === "Debug" && ShellOpen === true) {
  81. JSONtext = "LibraryLOAD: " + LibraryLOAD.toString() + "\nPOST_IO: " + POST_IO.toString() + "\nBOTlogic: " + BOTlogic.toString() + "\nEND"
  82. }
  83. else if (slackText === "SSH config" && ShellOpen === true) {
  84. SSHconfig = true;
  85. JSONtext = "Starting SSH config wizzard... HOST: "
  86. }
  87. else {
  88. console.log("ERROR_302: Logic error.")
  89. userName = 'slackbot';
  90. }
  91.  
  92. var botPayload = {
  93. text: JSONtext
  94.  
  95. };
  96.  
  97. if (shutdown2 === true) {
  98. return console.log("Shh! I'm sleeping. Restart the script to wake me up.")
  99. }
  100. else {
  101. if (shutdown1 === true) {
  102. shutdown2 = true;
  103. shutdown1 = false;
  104. }
  105. else {shutdown2 = false}
  106. }
  107. // avoid infinite loop
  108. if (userName !== 'slackbot') {
  109. return res.status(200).json(botPayload);
  110. } else {
  111. return res.status(200).end();
  112. } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement