Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- # IRC Config
- $myNick = 'Mailbot';
- $myIdentd = 'Mailbot';
- $myGecos = 'IRC<->Mail list Gateway';
- // PCRE regex of masks to ignore.
- $ignores = Array(
- '/(qwebirc|cgiirc)/i',
- );
- # IMAP Config
- $imapBox = '{imap.gmail.com:993/imap/ssl}';
- $imapUser = 'Mailbot@honk-honk.org';
- $imapPass = 'mailb0tp4ss';
- # Program Config
- # Higher number = more debug
- $debugLvl = 0;
- # Code
- function ircWrite($str) {
- global $irc;
- debug('Out: '.$str);
- fwrite($irc,$str."\n");
- }
- function debug ($msg,$lvl = 1) {
- global $debugLvl;
- if ($lvl <= $debugLvl) {
- print 'Debug'.$lvl.': '.$msg."\n";
- }
- }
- function printLine($msg) {
- print $msg."\n";
- }
- $mBox = imap_open( $imapBox, $imapUser, $imapPass );
- if ($mBox === FALSE) {
- die('IMAP failure! '. imap_last_error()."\n");
- }
- $irc = fsockopen('tcp://irc.ext3.net',6667,$en,$es,30);
- if (!$irc) {
- die('IRC failure! '.$en.' - '.$es."\n");
- }
- ircWrite('USER '.$myIdentd.' 1 1 :'.$myGecos);
- ircWrite('NICK '.$myNick);
- if (pcntl_fork() == 0) {
- while (1) {
- if (feof($irc) == TRUE) {
- fclose($irc);
- die('Not connected to IRC.'."\n");
- }
- $data = str_replace(array("\n","\r"),'',fgets($irc,1024));
- debug('IRC: '.$data,4);
- $d = explode(' ',$data);
- if (strtolower($d[0]) == 'ping') {
- ircWrite('PONG '.$d[1]);
- debug('Ping? Pong!',2);
- } elseif ((strtolower($d[1]) == '422') or (strtolower($d[1]) == '376')) {
- printLine('>> Successfully connected to IRC!');
- sleep(5);
- ircWrite('MODE '.$myNick.' +ipxBRT');
- ircWrite('JOIN #AndChat');
- ircWrite('PRIVMSG NickServ :id p4ssw0rd');
- } elseif (strtolower($d[1]) == 'join') {
- // :SnoFox!~SnoFox@SnoFox.net JOIN :#clueirc
- $src = explode('!',$d[0],2);
- $src = substr($src[0],1);
- $chan = substr($d[2],1);
- }
- } elseif (strtolower($d[1]) == 'privmsg') {
- $cmd = substr(strtolower($d[3]),1);
- $src = explode('!',$d[0],2);
- }
- $check = imap_ping($mBox);
- if ($check === FALSE) {
- // ircWrite('QUIT :No IMAP connection?');
- // die('No IMAP connection?'."\n");
- ircWrite('PRIVMSG #FoxDen :IMAP connection died? Trying to reconnect...');
- $mBox = imap_open( $imapBox, $imapUser, $imapPass);
- $bootWait = TRUE;
- continue;
- }
- $msgs = imap_sort($mBox, SORTDATE, 0);
- $imapInfo = imap_fetch_overview($mBox, '1:'.count($msgs));
- debug('Checking for messages...',4);
- for($x = 0; $x < count($imapInfo); $x++) {
- debug('New message from '.$imapInfo[$x]->from,4);
- if (strtolower($imapInfo[$x]->from) == 'Mailbot@Honk-Honk.org') {
- debug('Found message from my owner!',3);
- //$data = base64_decode(imap_fetchbody($mBox, $x+1,1));
- $data = imap_fetchbody($mBox, $x+1, 2);
- debug('New SMS body: ' . $data,3);
- //$data = explode(' ',substr($data,0,strpos($data,"\n")));
- $data = explode(' ', $data );
- $cmd = strtolower($data[0]);
- $target = $data[1];
- $msg = implode(' ',array_slice($data,2));
- debug('Command: ' . $cmd . ' Target: ' . $target . ' Msg: ' . $msg, 3);
- switch ($cmd) {
- case 'msg':
- case 'privmsg':
- ircWrite('PRIVMSG '.$target.' :[From Mailing List] '.$msg);
- break;
- case 'qmsg':
- ircWrite('PRIVMSG '.$target.' :'.$msg);
- break;
- case 'notice':
- ircWrite('NOTICE '.$target.' :[From Mailing List] '.$msg);
- break;
- case 'join':
- ircWrite('JOIN '.$target.' '.$msg);
- sms('MailBot/IRC','Attempting to join '.$target.'...');
- break;
- case 'part':
- ircWrite('PART '.$target.' :'.$msg);
- sms('MailBot/IRC','Parted '.$target.'.');
- break;
- case 'quit':
- case 'die':
- imap_delete($mBox,$x+1);
- imap_expunge($mBox);
- sms('MailBot','MailBot terminating...');
- ircWrite('QUIT :(Terminating) '.$target.' '.$msg);
- die('Terminated'."\n");
- break;
- case 'xyzzy':
- sms('MailBot','Nothing happens.');
- break;
- default:
- sms('MailBot','Dunno about that one.');
- } //switch
- } //if $from == $me
- imap_delete($mBox,$x+1);
- } // for-loop through msgs
- debug('Done looping through messages, deleting them now...',4);
- imap_expunge($mBox);
- sleep(20);
- } // while(1)
- ?>
Add Comment
Please, Sign In to add comment