diff options
author | arf20 <aruizfernandez05@gmail.com> | 2024-04-28 14:15:23 +0200 |
---|---|---|
committer | arf20 <aruizfernandez05@gmail.com> | 2024-04-28 14:15:23 +0200 |
commit | ebb17203d4cc11cc674d5a7959d9158cf3ccc8f5 (patch) | |
tree | b33340aae2e10120c219c8d9f8a12c919005e87a /publishannouncement.php | |
parent | 0d733500b8a5e94eafc31b45a9015220d85ea8c2 (diff) | |
download | arfnet2-cstims-ebb17203d4cc11cc674d5a7959d9158cf3ccc8f5.tar.gz arfnet2-cstims-ebb17203d4cc11cc674d5a7959d9158cf3ccc8f5.zip |
IRC announce notification
Diffstat (limited to 'publishannouncement.php')
-rw-r--r-- | publishannouncement.php | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/publishannouncement.php b/publishannouncement.php index 1225670..d190e7e 100644 --- a/publishannouncement.php +++ b/publishannouncement.php @@ -35,13 +35,16 @@ $users = $result->fetch_all(MYSQLI_ASSOC); // POST actions if ($_SERVER["REQUEST_METHOD"] == "POST") { // Send email - $mailer->addAddress(ANNOUNCE_MAIL); - $mailer->addReplyTo(getuserbyid($id)["email"]); - $mailer->Subject = "[ARFNET Announcement] ".$_POST["subject"]; - $mailer->Body = $_POST["body"]; - - if (!$mailer->send()) { - echo 'Mailer Error [ask arf20]: ' . $mailer->ErrorInfo; + if (defined("ANNOUNCE_MAIL")) { + echo "email "; + $mailer->addAddress(ANNOUNCE_MAIL); + $mailer->addReplyTo(getuserbyid($id)["email"]); + $mailer->Subject = "[ARFNET Announcement] ".$_POST["subject"]; + $mailer->Body = $_POST["body"]; + + if (!$mailer->send()) { + echo 'Mailer Error [ask arf20]: ' . $mailer->ErrorInfo; + } else echo "ok<br>"; } // Send discord message @@ -66,6 +69,37 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { } else echo "ok<br>"; } + // Send IRC notification + if (defined("ANNOUNCE_IRCSERVER")) { + echo "irc "; + $fd = fsockopen(ANNOUNCE_IRCSERVER, 6667, $errno, $errstr, 5); + $read = fread($fd, 1024); // flush + + // send login + fwrite($fd, "NICK system\r\n"); + fwrite($fd, "USER system 0 * ARFNET CSTIMS Announcement System\r\n"); + + // read ping + do { + $read = fread($fd, 1024); + } while (!str_contains($read, "PING")); + $rndstr = substr($read, strpos($read, ":", 1) + 1); + // answer ping + fwrite($fd, "PONG :".$rndstr."\r\n"); + + // join channel + fwrite($fd, "JOIN ".ANNOUNCE_IRCCHANNEL."\r\n"); + + $read = fread($fd, 1024); // flush + + // send message + fwrite($fd, "PRIVMSG ".ANNOUNCE_IRCCHANNEL." :New announcement: ".$_POST["subject"]."\r\n"); + + fclose($fd); + + echo "ok"; + } + die(); } |