Guest User

Untitled

a guest
Dec 3rd, 2017
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. # IRC Config
  4. $myNick = 'Mailbot';
  5. $myIdentd = 'Mailbot';
  6. $myGecos = 'IRC<->Mail list Gateway';
  7. // PCRE regex of masks to ignore.
  8. $ignores = Array(
  9. '/(qwebirc|cgiirc)/i',
  10. );
  11.  
  12. # IMAP Config
  13. $imapBox = '{imap.gmail.com:993/imap/ssl}';
  14. $imapUser = 'Mailbot@honk-honk.org';
  15. $imapPass = 'mailb0tp4ss';
  16.  
  17. # Program Config
  18. # Higher number = more debug
  19. $debugLvl = 0;
  20.  
  21.  
  22. # Code
  23.  
  24. function ircWrite($str) {
  25. global $irc;
  26. debug('Out: '.$str);
  27. fwrite($irc,$str."\n");
  28. }
  29. function debug ($msg,$lvl = 1) {
  30. global $debugLvl;
  31. if ($lvl <= $debugLvl) {
  32. print 'Debug'.$lvl.': '.$msg."\n";
  33. }
  34. }
  35. function printLine($msg) {
  36. print $msg."\n";
  37. }
  38. $mBox = imap_open( $imapBox, $imapUser, $imapPass );
  39. if ($mBox === FALSE) {
  40. die('IMAP failure! '. imap_last_error()."\n");
  41. }
  42. $irc = fsockopen('tcp://irc.ext3.net',6667,$en,$es,30);
  43. if (!$irc) {
  44. die('IRC failure! '.$en.' - '.$es."\n");
  45. }
  46. ircWrite('USER '.$myIdentd.' 1 1 :'.$myGecos);
  47. ircWrite('NICK '.$myNick);
  48.  
  49. if (pcntl_fork() == 0) {
  50. while (1) {
  51. if (feof($irc) == TRUE) {
  52. fclose($irc);
  53. die('Not connected to IRC.'."\n");
  54. }
  55. $data = str_replace(array("\n","\r"),'',fgets($irc,1024));
  56. debug('IRC: '.$data,4);
  57. $d = explode(' ',$data);
  58. if (strtolower($d[0]) == 'ping') {
  59. ircWrite('PONG '.$d[1]);
  60. debug('Ping? Pong!',2);
  61. } elseif ((strtolower($d[1]) == '422') or (strtolower($d[1]) == '376')) {
  62. printLine('>> Successfully connected to IRC!');
  63. sleep(5);
  64. ircWrite('MODE '.$myNick.' +ipxBRT');
  65. ircWrite('JOIN #AndChat');
  66. ircWrite('PRIVMSG NickServ :id p4ssw0rd');
  67. } elseif (strtolower($d[1]) == 'join') {
  68. // :SnoFox!~SnoFox@SnoFox.net JOIN :#clueirc
  69. $src = explode('!',$d[0],2);
  70. $src = substr($src[0],1);
  71. $chan = substr($d[2],1);
  72. }
  73. } elseif (strtolower($d[1]) == 'privmsg') {
  74. $cmd = substr(strtolower($d[3]),1);
  75. $src = explode('!',$d[0],2);
  76. }
  77. $check = imap_ping($mBox);
  78. if ($check === FALSE) {
  79. // ircWrite('QUIT :No IMAP connection?');
  80. // die('No IMAP connection?'."\n");
  81. ircWrite('PRIVMSG #FoxDen :IMAP connection died? Trying to reconnect...');
  82. $mBox = imap_open( $imapBox, $imapUser, $imapPass);
  83. $bootWait = TRUE;
  84. continue;
  85. }
  86. $msgs = imap_sort($mBox, SORTDATE, 0);
  87. $imapInfo = imap_fetch_overview($mBox, '1:'.count($msgs));
  88. debug('Checking for messages...',4);
  89. for($x = 0; $x < count($imapInfo); $x++) {
  90. debug('New message from '.$imapInfo[$x]->from,4);
  91. if (strtolower($imapInfo[$x]->from) == 'Mailbot@Honk-Honk.org') {
  92. debug('Found message from my owner!',3);
  93. //$data = base64_decode(imap_fetchbody($mBox, $x+1,1));
  94. $data = imap_fetchbody($mBox, $x+1, 2);
  95. debug('New SMS body: ' . $data,3);
  96. //$data = explode(' ',substr($data,0,strpos($data,"\n")));
  97. $data = explode(' ', $data );
  98. $cmd = strtolower($data[0]);
  99. $target = $data[1];
  100. $msg = implode(' ',array_slice($data,2));
  101. debug('Command: ' . $cmd . ' Target: ' . $target . ' Msg: ' . $msg, 3);
  102. switch ($cmd) {
  103. case 'msg':
  104. case 'privmsg':
  105. ircWrite('PRIVMSG '.$target.' :[From Mailing List] '.$msg);
  106. break;
  107. case 'qmsg':
  108. ircWrite('PRIVMSG '.$target.' :'.$msg);
  109. break;
  110. case 'notice':
  111. ircWrite('NOTICE '.$target.' :[From Mailing List] '.$msg);
  112. break;
  113. case 'join':
  114. ircWrite('JOIN '.$target.' '.$msg);
  115. sms('MailBot/IRC','Attempting to join '.$target.'...');
  116. break;
  117. case 'part':
  118. ircWrite('PART '.$target.' :'.$msg);
  119. sms('MailBot/IRC','Parted '.$target.'.');
  120. break;
  121. case 'quit':
  122. case 'die':
  123. imap_delete($mBox,$x+1);
  124. imap_expunge($mBox);
  125. sms('MailBot','MailBot terminating...');
  126. ircWrite('QUIT :(Terminating) '.$target.' '.$msg);
  127. die('Terminated'."\n");
  128. break;
  129. case 'xyzzy':
  130. sms('MailBot','Nothing happens.');
  131. break;
  132. default:
  133. sms('MailBot','Dunno about that one.');
  134. } //switch
  135. } //if $from == $me
  136. imap_delete($mBox,$x+1);
  137. } // for-loop through msgs
  138. debug('Done looping through messages, deleting them now...',4);
  139. imap_expunge($mBox);
  140. sleep(20);
  141. } // while(1)
  142. ?>
Add Comment
Please, Sign In to add comment