summaryrefslogtreecommitdiff
path: root/sqlgrey
diff options
context:
space:
mode:
authorTristan Zur <tzur@web.web.ccwn.org>2014-03-27 22:27:47 +0100
committerTristan Zur <tzur@web.web.ccwn.org>2014-03-27 22:27:47 +0100
commitb62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch)
tree86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /sqlgrey
Initial commit of intern.ccwn.org contentsHEADmaster
Diffstat (limited to 'sqlgrey')
-rw-r--r--sqlgrey/awl.php251
-rw-r--r--sqlgrey/connect.php231
-rw-r--r--sqlgrey/includes/awl.inc.php64
-rw-r--r--sqlgrey/includes/config.inc.php41
-rw-r--r--sqlgrey/includes/connect.inc.php50
-rw-r--r--sqlgrey/includes/copyright.inc.php28
-rw-r--r--sqlgrey/includes/functions.inc.php132
-rw-r--r--sqlgrey/includes/opt_in_out.inc.php31
-rw-r--r--sqlgrey/index.php146
-rw-r--r--sqlgrey/license.txt16
-rw-r--r--sqlgrey/main.css78
-rw-r--r--sqlgrey/opt_in_out.php106
-rw-r--r--sqlgrey/readme.txt24
13 files changed, 1198 insertions, 0 deletions
diff --git a/sqlgrey/awl.php b/sqlgrey/awl.php
new file mode 100644
index 0000000..ef6290c
--- /dev/null
+++ b/sqlgrey/awl.php
@@ -0,0 +1,251 @@
+<?php
+
+/********************************************
+SQLgrey Web Interface
+Filename: awl.php
+Purpose: Renders the greylist page
+Version: 1.1.6
+*********************************************/
+
+ require "includes/functions.inc.php";
+ require "includes/awl.inc.php";
+
+ (isset($_GET["mode"])) ? $mode = $_GET["mode"] : $mode = "email";
+ (isset($_GET["action"])) ? $action = $_GET["action"] : $action = "";
+
+ // For sort order.
+ (isset($_GET["csort"])) ? $csort = $_GET["csort"] : $csort = "";
+ (isset($_GET["sort"])) ? $sort = $_GET["sort"] : $sort = "";
+ if ($sort==null || $sort=="") {
+ if ($mode == "email") {
+ $sort = "sender_name";
+ } else {
+ $sort = "sender_domain";
+ }
+ }
+ $dir = "asc";
+ $ndir = "desc";
+ if ($sort == $csort && $_GET["order"] == "desc") {
+ $dir = "desc";
+ $ndir = "asc";
+ }
+
+ // Perform demanded action.
+ $clearit = '<br /><br /><a class="navlike" href="awl.php?mode='.$mode.'">Clear this report</a>';
+ switch ($action) {
+ case "del_selection":
+ // For batch deleting.
+ (isset($_POST["chk"])) ? $chk = $_POST["chk"] : $chk = "";
+ if ($chk == "") {
+ $report = '<br />Nothing was selected - nothing has been deleted.'.$clearit;
+ } else {
+ foreach ($chk as $args) {
+ $parts = explode("@@", $args);
+ delete_entry($mode, $parts[0], $parts[1], $parts[2]);
+ }
+ $report = $deleted.$clearit;
+ }
+ $report2 = "";
+ break;
+ case "del_undef":
+ delete_undef($mode);
+ $report = "";
+ $report2 = $message;
+ break;
+ case "add_sender":
+ (isset($_POST["sender_name"])) ? $sn = $_POST["sender_name"] : $sn = "";
+ add_sender($mode, $sn, $_POST["sender_domain"], $_POST["src"]);
+ $report = "";
+ $report2 = $added;
+ break;
+ case "":
+ $report = "";
+ $report2 = "";
+ break;
+ }
+
+ // Make a nice header.
+ if ($mode=="email") {
+ $query = "SELECT COUNT(*) AS count FROM from_awl";
+ $title = "e-mail addresses (";
+ } else {
+ $query = "SELECT COUNT(*) AS count FROM domain_awl";
+ $title = "domains (";
+ }
+ $result = do_query($query);
+ $n = fetch_row($result);
+ $title .= $n["count"].")";
+
+ /*
+ mysql> describe from_awl;
+ +---------------+---------------+------+-----+----------------+-------+
+ | Field | Type | Null | Key | Default | Extra |
+ +---------------+---------------+------+-----+----------------+-------+
+ | sender_name | varchar(64) | | PRI | | |
+ | sender_domain | varchar(255) | | PRI | | |
+ | src | varchar(39) | | PRI | | |
+ | first_seen | timestamp(14) | YES | | NULL | |
+ | last_seen | timestamp(14) | YES | MUL | 00000000000000 | |
+ +---------------+---------------+------+-----+----------------+-------+
+
+ mysql> describe domain_awl;
+ +---------------+---------------+------+-----+----------------+-------+
+ | Field | Type | Null | Key | Default | Extra |
+ +---------------+---------------+------+-----+----------------+-------+
+ | sender_domain | varchar(255) | | PRI | | |
+ | src | varchar(39) | | PRI | | |
+ | first_seen | timestamp(14) | YES | | NULL | |
+ | last_seen | timestamp(14) | YES | MUL | 00000000000000 | |
+ +---------------+---------------+------+-----+----------------+-------+
+ */
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <title>Whitelisted <?php if ($mode=="email") echo "e-mail addresses"; else echo "domains"; ?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
+</head>
+
+<body>
+
+<div id="page">
+
+ <div class="navcontainer">
+ <?php shownav('white', $mode, '', ''); ?>
+ </div>
+
+ <table width="100%" summary="header">
+ <tr>
+ <td>
+ <h1>Whitelisted <?php echo $title; ?></h1>
+ </td>
+ <td align="right">
+ <a class="navlike" href="#end" title="End of List">EoL</a>
+ </td>
+ </tr>
+ </table>
+
+ <table border="0" summary="sortbar"><?php echo ('
+ <tr>
+ <td width="20">&nbsp;</td>');
+ if ($mode=="email") echo ('
+ <td width="300">&nbsp;<b><a href="awl.php?mode='.$mode.'&amp;sort=sender_name&amp;csort='.$sort.'&amp;order='.$ndir.'">Sender name</a></b></td>');
+ echo ('
+ <td width="240"><b><a href="awl.php?mode='.$mode.'&amp;sort=sender_domain&amp;csort='.$sort.'&amp;order='.$ndir.'">Sender domain</a></b></td>
+ <td width="100"><b><a href="awl.php?mode='.$mode.'&amp;sort=src&amp;csort='.$sort.'&amp;order='.$ndir.'">Source</a></b></td>
+ <td width="120"><b><a href="awl.php?mode='.$mode.'&amp;sort=first_seen&amp;csort='.$sort.'&amp;order='.$ndir.'">First seen</a></b></td>
+ <td width="120"><b><a href="awl.php?mode='.$mode.'&amp;sort=last_seen&amp;csort='.$sort.'&amp;order='.$ndir.'">Last seen</a></b></td>
+ </tr>');
+ ?></table>
+
+ <form method="post" action="awl.php?mode=<?php echo $mode; ?>&amp;action=del_selection">
+ <div id="table_awl">
+ <table border="0" summary="data">
+ <tr><td><a name="top"></a></td></tr>
+ <?php
+ if ($mode=="email") {
+ if ($sort == "sender_name") {
+ $order = "sender_name ".$dir.", sender_domain ".$dir;
+ }
+ else if ($sort == "sender_domain") {
+ $order = "sender_domain ".$dir.", sender_name ".$dir;
+ } else {
+ $order = $sort." ".$dir;
+ }
+ $query = "SELECT sender_name, sender_domain, src, first_seen, last_seen FROM from_awl ORDER BY ".$order;
+ } else {
+ $order = $sort." ".$dir;
+ $query = "SELECT sender_domain, src, first_seen, last_seen FROM domain_awl ORDER BY ".$order;
+ }
+ $result = do_query($query);
+
+ while($line = fetch_row($result)) {
+ $sd = $line["sender_domain"];
+ $src = $line["src"];
+ $fs = $line["first_seen"];
+ $ls = $line["last_seen"];
+ if ($mode == "email") {
+ $sn = $line["sender_name"];
+ echo ('
+ <tr>
+ <td width="20"><input type="checkbox" name="chk[]" value="'.$sn.'@@'.$sd.'@@'.$src.'" /></td>
+ <td width="300"><span title="'.$sn.'">'.shorten_it($sn, 42).'</span></td>
+ ');
+ } else {
+ $sn = "noname";
+ echo ('
+ <tr>
+ <td width="20"><input type="checkbox" name="chk[]" value="'.$sn.'@@'.$sd.'@@'.$src.'" /></td>
+ ');
+ }
+ echo ('
+ <td width="240"><span title="'.$sd.'">'.shorten_it($sd, 35).'</span></td>
+ <td width="100">'.$src.'</td>
+ <td width="120">'.strip_millisecs($fs).'</td>
+ <td width="120">'.strip_millisecs($ls).'</td>
+ </tr>
+ ');
+ }
+ ?>
+ <tr><td><a name="end"></a></td></tr>
+ </table>
+ </div>
+
+ <br />
+
+ <table width="100%" summary="buttons">
+ <tr>
+ <td>
+ <input class="btn" type="submit" value="Delete selected entries" />
+ </td>
+ <td align="right">
+ <a class="navlike" href="#top" title="Top of List">ToL</a>
+ </td>
+ </tr>
+ </table>
+ </form>
+
+ <?php if (! $report == '' ) echo '<span class="alert">'.$report.'</span>'; ?>
+
+ <div id="form">
+ <h2>Add to whitelist</h2>
+ <form action="awl.php?mode=<?php echo $mode; ?>&amp;action=add_sender" method="post">
+ <table width="100%" border="0" summary="add form">
+ <?php if ($mode == "email") { ?>
+ <tr>
+ <td width="120">Sender name:</td>
+ <td width="240"><input class="txt" type="text" name="sender_name" /></td>
+ <td colspan="2">&nbsp;</td>
+ </tr>
+ <?php } ?>
+ <tr>
+ <td width="120">Sender domain:</td>
+ <td width="240"><input class="txt" type="text" name="sender_domain" /></td>
+ <td colspan="2">&nbsp;</td>
+ </tr>
+ <tr>
+ <td width="120">Source (class c or d):</td>
+ <td width="240"><input class="txt" type="text" name="src" /></td>
+ <td align="left"><input class="btn" type="submit" value="Add" /></td>
+ <td align="right">
+ <a class="navlike" href="awl.php?mode=<?php echo $mode; ?>&amp;action=del_undef">Delete '-undef-' entries</a>
+ </td>
+ </tr>
+ </table>
+ </form>
+ </div>
+
+ <?php if (! $report2 == '' ) echo '<span class="alert">'.$report2.'</span>'; ?>
+
+ <div id="footer">
+ <?php require "includes/copyright.inc.php" ?>
+ </div>
+
+</div>
+
+</body>
+
+</html>
diff --git a/sqlgrey/connect.php b/sqlgrey/connect.php
new file mode 100644
index 0000000..cb477b3
--- /dev/null
+++ b/sqlgrey/connect.php
@@ -0,0 +1,231 @@
+<?php
+
+/***********************************************
+SQLgrey Web Interface
+Filename: connect.php
+Purpose: Renders the email/domains pages
+Version: 1.1.6
+************************************************/
+
+ require "includes/functions.inc.php";
+ require "includes/connect.inc.php";
+
+ (isset($_GET["action"])) ? $action = $_GET["action"] : $action = "";
+
+ // For sort order.
+ (isset($_GET["csort"])) ? $csort = $_GET["csort"] : $csort = "";
+ (isset($_GET["sort"])) ? $sort = $_GET["sort"] : $sort = "";
+ if ($sort==null || $sort=="") {
+ $sort = "sender_name";
+ }
+ $dir = "asc";
+ $ndir = "desc";
+ if ($sort == $csort && $_GET["order"] == "desc") {
+ $dir = "desc";
+ $ndir = "asc";
+ }
+
+ // Perform demanded action.
+ $clearit = '<br /><br /><a class="navlike" href="connect.php">Clear this report</a>';
+ $report2 = "";
+ switch ($action) {
+ case "act":
+ (isset($_POST["acttype"])) ? $acttype = $_POST["acttype"] : $acttype = "";
+ (isset($_POST["chk"])) ? $chk = $_POST["chk"] : $chk = "";
+ switch ($acttype) {
+ case "dodelete":
+ // For batch deleting.
+ if ($chk == '') {
+ $report = '<br />Nothing was selected - nothing has been deleted.'.$clearit;
+ } else {
+ foreach ($chk as $args) {
+ $parts = explode("@@", $args);
+ forget_entry($parts[0], $parts[1], $parts[2], $parts[3]);
+ }
+ $report = $deleted.$clearit;
+ }
+ break;
+ case "domove":
+ // For batch moving to whitelist.
+ if ($chk == '') {
+ $report = '<br />Nothing was selected - nothing has been moved.'.$clearit;
+ } else {
+ foreach ($chk as $args) {
+ $parts = explode("@@", $args);
+ move_entry($parts[0], $parts[1], $parts[2], $parts[3]);
+ }
+ $report = $moved.$clearit;
+ }
+ break;
+ case "":
+ $report = '<br />Please select Forget... or Move...';
+ break;
+ }
+ break;
+ case "del_old":
+ $year = $_POST["year"];
+ $month = $_POST["month"];
+ $day = $_POST["day"];
+ $hour = $_POST["hour"];
+ $minute = $_POST["minute"];
+ $seconds = $_POST["seconds"];
+ $err = 0;
+
+ if ($year < 2000 || $year > 9999) $err = 1;
+ else if ($month < 1 || $month > 12) $err = 1;
+ else if ($day < 1 || $day > 31) $err = 1;
+ else if ($hour < 0 || $hour > 23) $err = 1;
+ else if ($minute < 0 || $minute > 59) $err = 1;
+ else if ($seconds < 0 || $seconds > 60) $err = 1; # indeed, 60
+
+ del_older_than($year, $month, $day, $hour, $minute, $seconds, $err);
+ $report2 = $message.$warning;
+ $report = "";
+ break;
+ case "":
+ $report = "";
+ break;
+ }
+
+ // For the header.
+ $query = "SELECT COUNT(*) AS count FROM connect";
+ $result = do_query($query);
+ $n = fetch_row($result);
+
+ /* mysql> describe connect;
+ +---------------+---------------+------+-----+---------+-------+
+ | Field | Type | Null | Key | Default | Extra |
+ +---------------+---------------+------+-----+---------+-------+
+ | sender_name | varchar(64) | | | | |
+ | sender_domain | varchar(255) | | | | |
+ | src | varchar(39) | | MUL | | |
+ | rcpt | varchar(255) | | | | |
+ | first_seen | timestamp(14) | YES | MUL | NULL | |
+ +---------------+---------------+------+-----+---------+-------+
+ */
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <title>Greylisted hosts/domains</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
+</head>
+
+<body>
+
+<div id="page">
+ <div class="navcontainer">
+ <?php shownav('grey','','con','con'); ?>
+ </div>
+
+ <table width="100%" border="0" summary="header">
+ <tr>
+ <td>
+ <h1>Greylisted hosts/domains (<?php echo $n["count"] . ")" ?></h1>
+ </td>
+ <td align="right">
+ <a class="navlike" href="#end" title="End of List">EoL</a>
+ </td>
+ </tr>
+ </table>
+
+ <table border="0" summary="sortbar"><?php echo ('
+ <tr>
+ <td width="20">&nbsp;</td>
+ <td width="210"><b><a href="connect.php?sort=sender_name&amp;csort='.$sort.'&amp;order='.$ndir.'">Sender name</a></b></td>
+ <td width="190"><b><a href="connect.php?sort=sender_domain&amp;csort='.$sort.'&amp;order='.$ndir.'">Sender domain</a></b></td>
+ <td width="100"><b><a href="connect.php?sort=src&amp;csort='.$sort.'&amp;order='.$ndir.'">IP address</a></b></td>
+ <td width="260"><b><a href="connect.php?sort=rcpt&amp;csort='.$sort.'&amp;order='.$ndir.'">Recipient</a></b></td>
+ <td width="120"><b><a href="connect.php?sort=first_seen&amp;csort='.$sort.'&amp;order='.$ndir.'">Seen at</a></b></td>
+ </tr>
+ ')?></table>
+
+ <form method="post" action="connect.php?action=act">
+ <div id="table_con">
+ <table border="0" summary="data">
+ <tr><td><a name="top"></a></td></tr>
+ <?php
+ if ($sort == "sender_name")
+ $order = "sender_name ".$dir.", sender_domain ".$dir;
+ else if ($sort == "sender_domain")
+ $order = "sender_domain ".$dir.", sender_name ".$dir;
+ else
+ $order = $sort." ".$dir;
+ $query = "SELECT sender_name, sender_domain, src, rcpt, first_seen FROM connect ORDER BY ".$order;
+ $result = do_query($query);
+ while($line = fetch_row($result)) {
+ $sn = $line["sender_name"];
+ $sd = $line["sender_domain"];
+ $src = $line["src"];
+ $sr = $line["rcpt"];
+ $fs = $line["first_seen"];
+ echo ('
+ <tr>
+ <td width="20"><input type="checkbox" name="chk[]" value="'.$sn.'@@'.$sd.'@@'.$src.'@@'.$sr.'" /></td>
+ <td width="210"><span title="'.$sn.'">'.shorten_it($sn, 30).'</span></td>
+ <td width="190"><span title="'.$sd.'">'.shorten_it($sd, 30).'</span></td>
+ <td width="100">'.$src.'&nbsp;</td>
+ <td width="260"><span title="'.$sr.'">'.shorten_it($sr, 40).'</span></td>
+ <td width="120">'.strip_millisecs($fs).'</td>
+ </tr>
+ ');
+ }
+ ?>
+ <tr><td><a name="end"></a></td></tr>
+ </table>
+ </div>
+
+ <br />
+
+ <table width="100%" summary="options">
+ <tr>
+ <td>
+ <input type="radio" name="acttype" value="dodelete" /> Forget (delete) selected entries<br />
+ <input type="radio" name="acttype" value="domove" /> Move selected entries to whitelist
+ </td>
+ <td align="right">
+ <a class="navlike" href="#top" title="Top of List">ToL</a>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2"><input class="btn" type="submit" value="Submit" /></td>
+ </tr>
+ </table>
+ </form>
+
+ <?php if (! $report == '' ) echo '<span class="alert">'.$report.'</span>'; ?>
+
+ <div id="form">
+ <h2>Delete older than...</h2>
+ <form method="post" action="connect.php?action=del_old&amp;sort=first_seen&amp;csort=first_seen&amp;order=asc">
+ <table summary="date">
+ <tr>
+ <td>y</td><td>m</td><td>d</td><td>h</td><td>m</td><td>s</td>
+ </tr>
+ <tr class="datefld">
+ <td><input type="text" value="0" name="year" />-</td>
+ <td><input type="text" value="0" name="month" />-</td>
+ <td><input type="text" value="0" name="day" /> </td>
+ <td><input type="text" value="0" name="hour" />:</td>
+ <td><input type="text" value="0" name="minute" />:</td>
+ <td><input type="text" value="0" name="seconds" /></td>
+ <td><input class="btn" type="submit" value="Delete" /></td>
+ </tr>
+ </table>
+ </form>
+ </div>
+
+ <?php if (! $report2 == '' ) echo '<span class="alert">'.$report2.'</span>'; ?>
+
+ <div id="footer">
+ <?php require "includes/copyright.inc.php" ?>
+ </div>
+
+</div>
+
+</body>
+
+</html>
diff --git a/sqlgrey/includes/awl.inc.php b/sqlgrey/includes/awl.inc.php
new file mode 100644
index 0000000..5fbc3c9
--- /dev/null
+++ b/sqlgrey/includes/awl.inc.php
@@ -0,0 +1,64 @@
+<?php
+
+/***************************************************
+SQLgrey Web Interface
+Filename: awl.inc.php
+Purpose: Functions for awl.php (whitelists)
+Version: 1.1.6
+****************************************************/
+
+function add_sender($mode, $sendername, $senderdomain, $src) {
+ global $added;
+ if ($mode == "email") {
+ if ($sendername == '' || $senderdomain == '' || $src == '') {
+ $added = "<br />WARNING: Insufficient data - nothing was added !";
+ } else {
+ $query = "INSERT INTO from_awl(sender_name, sender_domain, src, first_seen, last_seen)
+ VALUES('".addslashes($sendername)."', '".addslashes($senderdomain)."', '".addslashes($src)."', now(), now())";
+ $added = "<br />E-mail address ".$sendername."@".$senderdomain." (".$src.") added.";
+ do_query($query);
+ }
+ } else {
+ if ($senderdomain == '' || $src == '') {
+ $added = "<br />WARNING: Insufficient data - nothing was added!";
+ } else {
+ $query = "INSERT INTO domain_awl(sender_domain, src, first_seen, last_seen)
+ VALUES('".addslashes($senderdomain)."', '".addslashes($src)."', now(), now())";
+ $added = "<br />Domain ".$senderdomain." (".$src.") added.";
+ do_query($query);
+ }
+ }
+}
+
+function delete_undef($mode) {
+ global $message;
+ if ($mode == "email") {
+ $query_cnt = "SELECT COUNT(*) AS count FROM from_awl WHERE sender_name='-undef-' AND sender_domain='-undef-'";
+ $query = "DELETE FROM from_awl WHERE sender_name='-undef-' AND sender_domain='-undef-'";
+ } else {
+ $query_cnt = "SELECT COUNT(*) AS count FROM domain_awl WHERE sender_domain='-undef-'";
+ $query = "DELETE FROM domain_awl WHERE sender_domain='-undef-'";
+ }
+ $result = do_query($query_cnt);
+ $n = fetch_row($result);
+ if ($n["count"] > 0) {
+ do_query($query);
+ $message = '<br />-undef- entries ('.$n["count"].') deleted.';
+ } else {
+ $message = "<br />No -undef- entries found - nothing was deleted.";
+ }
+}
+
+function delete_entry($mode, $sendername, $senderdomain, $src) {
+ global $deleted;
+ if ($mode == "email") {
+ $query = "DELETE FROM from_awl WHERE sender_name='".addslashes($sendername)."' AND sender_domain='".addslashes($senderdomain)."' AND src='".addslashes($src)."'";
+ $deleted .= "<br />".$sendername."@".$senderdomain." (".$src.") deleted.";
+ } else {
+ $query = "DELETE FROM domain_awl WHERE sender_domain='".addslashes($senderdomain)."' AND src='".addslashes($src)."'";
+ $deleted .= "<br />".$senderdomain." (".$src.") deleted.";
+ }
+ do_query($query);
+}
+
+?> \ No newline at end of file
diff --git a/sqlgrey/includes/config.inc.php b/sqlgrey/includes/config.inc.php
new file mode 100644
index 0000000..a18caa0
--- /dev/null
+++ b/sqlgrey/includes/config.inc.php
@@ -0,0 +1,41 @@
+<?php
+
+/***************************************************
+SQLgrey Web Interface
+Filename: config.inc.php
+Purpose: Configuration database and options
+Version: 1.1.6
+****************************************************/
+
+/* Database settings */
+$db_db = "ccwn_sqlgrey";
+$db_hostname = "database";
+$db_user = "sqlgrey";
+$db_pass = "YfDWm3PzTR35QWuD";
+$db_type = "mysql"; // mysql or pg (pg=postgress)
+
+/* Set close_btn to 'yes' to enable the close button in index.php (main menu)
+ the button action = ../ which could be a security issue
+ default = no
+*/
+$close_btn = "no";
+
+/* Set no_millisecs to 'no' if your server's dbase shows milliseconds
+ and you do want these to be displayed - this will take two lines per entry.
+ Also set this to 'no' if you encounter problems with displaying the timestamps
+ ('no' used to be the default and leaves the date format untouched).
+ When set to 'yes' timestamps will be formatted as 'yyyy-mm-dd hh:mm:ss'
+ which doubles the amount of visible entries.
+ default = yes
+*/
+$no_millisecs = "yes";
+
+/* Depending on your PHP version you may have to set default timezone to avoid warnings.
+ Remove the comment (//) and change the default to your region.
+ See http://www.php.net/manual/en/timezones.php to determine the syntax of your region.
+ Examples are: 'America/Los_Angeles', 'Europe/Berlin' etc.
+ default = 'UTC'
+*/
+//date_default_timezone_set('UTC');
+
+?>
diff --git a/sqlgrey/includes/connect.inc.php b/sqlgrey/includes/connect.inc.php
new file mode 100644
index 0000000..d72a674
--- /dev/null
+++ b/sqlgrey/includes/connect.inc.php
@@ -0,0 +1,50 @@
+<?php
+
+/***************************************************
+SQLgrey Web Interface
+Filename: connect.inc.php
+Purpose: Functions for connect.php (greylist)
+Version: 1.1.6
+****************************************************/
+
+function forget_entry($sendername, $senderdomain, $src, $rcpt) {
+ global $deleted;
+ $query = "DELETE FROM connect WHERE sender_name='".addslashes($sendername)."' AND sender_domain='".addslashes($senderdomain)."' AND src='".addslashes($src)."' AND rcpt='".addslashes($rcpt)."'";
+ do_query($query);
+ $deleted .= '<br />'.$sendername.'@'.$senderdomain.' ['.$src.'] for '.$rcpt.' deleted.';
+}
+
+function move_entry($sendername, $senderdomain, $src, $rcpt) {
+ global $moved;
+ $query = "SELECT first_seen FROM connect WHERE sender_name='".addslashes($sendername)."' AND sender_domain='".addslashes($senderdomain)."' AND src='".addslashes($src)."' AND rcpt='".addslashes($rcpt)."'";
+ $result = do_query($query);
+ $line = fetch_row($result);
+ # add to 'from_awl'
+ $query = "INSERT INTO from_awl(sender_name, sender_domain, src, first_seen, last_seen) VALUES('".
+ addslashes($sendername)."', '".
+ addslashes($senderdomain)."', '".
+ addslashes($src)."', '".
+ $line["first_seen"]."', '".
+ $line["first_seen"]."')";
+ do_query($query);
+ # and remove from 'connect'
+ $query = "DELETE FROM connect WHERE sender_name='".addslashes($sendername)."' AND sender_domain='".addslashes($senderdomain)."' AND src='".addslashes($src)."' AND rcpt='".addslashes($rcpt)."'";
+ do_query($query);
+ $moved .= '<br />'.$sendername.'@'.$senderdomain.' ['.$src.'] for '.$rcpt.' moved to whitelist.';
+}
+
+function del_older_than($year, $month, $day, $hour, $minute, $seconds, $err) {
+ global $warning, $message;
+ if ($err) {
+ $warning = "Aborted: invalid date.";
+ } else {
+ $nicedate = $year.'-'.substr("00".$month, -2, 2).'-'.substr("00".$day, -2, 2).' '.substr("00".$hour, -2, 2).':'.substr("00".$minute, -2, 2).':'.substr("00".$seconds, -2, 2);
+ $query = "DELETE FROM connect WHERE first_seen < ".$year.substr("00".$month, -2, 2).substr("00".$day, -2, 2).substr("00".$hour, -2, 2).substr("00".$minute, -2, 2).substr("00".$seconds, -2, 2);
+ do_query($query);
+ $message = 'Entries older than '.$nicedate.' deleted.';
+ $warning = "<br />Sorting set to &#39;Seen at&#39; (ascending).";
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/sqlgrey/includes/copyright.inc.php b/sqlgrey/includes/copyright.inc.php
new file mode 100644
index 0000000..c6d2524
--- /dev/null
+++ b/sqlgrey/includes/copyright.inc.php
@@ -0,0 +1,28 @@
+<?php
+
+/***************************************************
+SQLgrey Web Interface
+Filename: copyright.inc.php
+Purpose: Inserting copyright notice
+Version: 1.1.6
+
+ *** Please do not alter these references! ***
+
+****************************************************/
+
+?>
+<table width="100%" summary="footer">
+ <tr>
+ <td>
+ <hr />
+ <font size="-1">
+ <a href="http://www.vanheusden.com/sgwi/" target="_blank">SQLGrey webinterface v 1.1.6</a>
+ by
+ <a href="http://www.vanheusden.com/feedbackform.php?subject=SQLGrey%20webinterface" target="_blank">folkert@vanheusden.com</a>
+ and Jan Ceulen |
+ <a href="http://www.beebeec.nl/sgwi/" target="_blank">BeeBeeC</a>
+ </font>
+ <hr />
+ </td>
+ </tr>
+</table> \ No newline at end of file
diff --git a/sqlgrey/includes/functions.inc.php b/sqlgrey/includes/functions.inc.php
new file mode 100644
index 0000000..cf5933e
--- /dev/null
+++ b/sqlgrey/includes/functions.inc.php
@@ -0,0 +1,132 @@
+<?php
+
+/***********************************************************
+SQLgrey Web Interface
+Filename: awl.inc.php
+Purpose: Database and navigation and other functions
+Version: 1.1.6
+************************************************************/
+
+require "config.inc.php";
+
+// Globally used phrases.
+
+$dom_out = 'domains of recipients for whom messages are never greylisted';
+$email_out = 'e-mail addresses of recipients for whom messages are never greylisted';
+$dom_in = 'domains of recipients for whom messages are always greylisted unless they are in the optout domain table';
+$email_in = 'e-mail addresses of recipients for whom messages are always greylisted unless they are in the optout e-mail table';
+
+
+// Database functions.
+
+function do_query($query) {
+ global $db_hostname, $db_user, $db_pass, $db_db, $db_type;
+ /* Connecting, selecting database */
+ if ($db_type == "mysql") {
+ $link = mysql_connect($db_hostname, $db_user, $db_pass) or die("Could not connect to database");
+ mysql_select_db($db_db) or die("Could not select database");
+
+ $result = mysql_query($query) or die("Query failed");
+
+ /* Closing connection */
+ mysql_close($link);
+ } else {
+ $link = pg_connect("host=$db_hostname dbname=$db_db user=$db_user password=$db_pass") or die("Could not connect to database");
+
+ $result = pg_query($link, $query) or die("Query failed");
+
+ /* Closing connection */
+ pg_close($link);
+ }
+ return $result;
+}
+
+function fetch_row($result) {
+ global $db_type;
+ if ($db_type == "mysql") {
+ return mysql_fetch_array($result, MYSQL_ASSOC);
+ } else {
+ return pg_fetch_assoc($result);
+ }
+}
+
+
+// Navigation functions.
+
+function shownav($colour, $mode, $direction, $what) {
+ // Menubar setup for all pages
+ global $dom_out, $email_out, $dom_in, $email_in;
+ if ($colour == 'white') {
+ // only awl.php
+ echo ('
+ <ul id="navlist">
+ <li><a href="index.php">Main menu</a></li>
+ <li><a href="connect.php" title="hosts/domains that are currently greylisted">Waiting (greylist)</a></li>
+ <li><a href="awl.php?mode=email"'.is_active1("email", $mode).
+ 'title="auto-whitelisted e-mailadresses (that have passed greylisting)">E-mail addresses</a></li>
+ <li><a href="awl.php?mode=domains"'.is_active1('domains', $mode).
+ 'title="auto-whitelisted domains (that have passed greylisting)">Domains</a></li>
+ <li><a href="opt_in_out.php?direction=out&amp;what=domain" title="&nbsp;'.$dom_out.'">Optout domain</a></li>
+ <li><a href="opt_in_out.php?direction=out&amp;what=email" title="&nbsp;'.$email_out.'">Optout e-mail</a></li>
+ <li><a href="opt_in_out.php?direction=in&amp;what=domain" title="&nbsp;'.$dom_in.'">Optin domain</a></li>
+ <li><a href="opt_in_out.php?direction=in&amp;what=email" title="&nbsp;'.$email_in .'">Optin e-mail</a></li>
+ </ul>
+ ');
+ } else {
+ // index and connect (with dummies) and opt_in_out.
+ echo ('
+ <ul id="navlist">
+ <li><a href="index.php"'.is_active2("ind", $direction, "ind", $what).'>Main menu</a></li>
+ <li><a href="connect.php"'.is_active2("con", $direction, "con", $what).
+ 'title="hosts/domains that are currently greylisted">Waiting (greylist)</a></li>
+ <li><a href="awl.php?mode=email" title="auto-whitelisted e-mailadresses (that have passed greylisting)">E-mail addresses</a></li>
+ <li><a href="awl.php?mode=domains" title="auto-whitelisted domains (that have passed greylisting)">Domains</a></li>
+ <li><a href="opt_in_out.php?direction=out&amp;what=domain"'.is_active2("out", $direction, "domain", $what).' title="'.$dom_out.'">Optout domain</a></li>
+ <li><a href="opt_in_out.php?direction=out&amp;what=email"'.is_active2("out", $direction, "email", $what).' title="'.$email_out.'">Optout e-mail</a></li>
+ <li><a href="opt_in_out.php?direction=in&amp;what=domain"'.is_active2('in',$direction,'domain',$what).' title="'.$dom_in.'">Optin domain</a></li>
+ <li><a href="opt_in_out.php?direction=in&amp;what=email"'.is_active2('in',$direction,'email',$what).' title="'.$email_in.'">Optin e-mail</a></li>
+ </ul>
+ ');
+ }
+}
+
+function is_active1($mode, $get) {
+ // For awl menubar items - sets item active.
+ if ($mode == $get) {
+ return ' id="current" ';
+ } else {
+ return ' ';
+ }
+}
+
+function is_active2($direction, $getdir, $what, $getwhat) {
+ // For index, connect and opt_in_out menubar items - sets item active.
+ if (($direction == $getdir) && ($what == $getwhat)) {
+ return ' id="current" ';
+ } else {
+ return ' ';
+ }
+}
+
+
+// Other functions.
+
+function shorten_it($sendername, $nr) {
+ // For managing the width of the Sender name, Sender domain and Recipient columns.
+ if (strlen($sendername) > $nr) {
+ $sendername = substr($sendername, 0, $nr ).'<b>...</b>';
+ }
+ return $sendername;
+}
+
+function strip_millisecs($ts) {
+ // Formats timestamp without milliseconds.
+ global $no_millisecs;
+ if ($no_millisecs == "yes") {
+ $ts = date_create($ts);
+ $ts = date_format($ts, 'Y-m-d H:i:s');
+ }
+ return $ts;
+}
+
+?> \ No newline at end of file
diff --git a/sqlgrey/includes/opt_in_out.inc.php b/sqlgrey/includes/opt_in_out.inc.php
new file mode 100644
index 0000000..236687f
--- /dev/null
+++ b/sqlgrey/includes/opt_in_out.inc.php
@@ -0,0 +1,31 @@
+<?php
+
+/**************************************
+SQLgrey Web Interface
+Filename: opt_in_out.inc.php
+Purpose: Opt in/out functions
+Version: 1.1.6
+***************************************/
+
+ if ($_GET["direction"] == "out") {
+ $title = "Opt-out";
+ $helptag_dir = "<br />(recipients for whom messages are never greylisted)";
+ $table = "optout_";
+ } else {
+ $title = "Opt-in";
+ $helptag_dir = "<br />(recipients for whom messages are always greylisted unless they are in the ";
+ $table = "optin_";
+ }
+
+ if ($_GET["what"] == "domain") {
+ $title .= " domains";
+ $helptag_what = "optout domain table)";
+ $table .= "domain";
+ $field = "domain";
+ } else {
+ $title .= " e-mail addresses";
+ $helptag_what = "optout e-mail table)";
+ $table .= "email";
+ $field = "email";
+ }
+?> \ No newline at end of file
diff --git a/sqlgrey/index.php b/sqlgrey/index.php
new file mode 100644
index 0000000..3b0cbd8
--- /dev/null
+++ b/sqlgrey/index.php
@@ -0,0 +1,146 @@
+<?php
+
+/********************************************
+SQLgrey Web Interface
+Filename: index.php
+Purpose: Renders the main menu page
+Version: 1.1.6
+*********************************************/
+
+ require "includes/functions.inc.php";
+
+ $query = "SELECT COUNT(*) AS count FROM connect";
+ $result = do_query($query);
+ $line = fetch_row($result);
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <title>SQLGrey Webinterface</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
+ <style type="text/css">
+ input { width: 150px; height: 25px; font-size: 13px; }
+ </style>
+</head>
+
+<body>
+
+<div id="page">
+
+ <div class="navcontainer">
+ <?php shownav('grey','','ind','ind'); ?>
+ </div>
+
+ <table width="77%" summary="main">
+ <tr>
+ <td>
+ <table width="820" border="0" summary="header">
+ <tr>
+ <td>
+ <h1>SQLGrey Webinterface (Main menu)</h1>
+ </td>
+ <?php if ($close_btn == "yes") echo ('
+ <td align="right">
+ <form action="../" method="post">
+ <input type="submit" value="Close" />
+ </form>
+ </td>');
+ ?>
+ </tr>
+ </table>
+
+ <table border="0" summary="sub">
+ <tr>
+ <td colspan="3">
+ Hosts / domains that are currently greylisted: [<?php echo $line["count"]; ?>]
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3">
+ <form action="connect.php" method="post">
+ <input style="width:150px;" type="submit" value="Waiting (greylist)" />
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+
+ <td colspan="3">Auto-whitelisted (hosts / domains that have passed greylisting)</td>
+ </tr>
+ <tr>
+ <td>
+ <form action="awl.php?mode=email" method="post">
+ <input type="submit" value="E-mail addresses" />
+ </form>
+ </td>
+ <td>
+ <form action="awl.php?mode=domains" method="post">
+ <input type="submit" value="Domains" />
+ </form>
+ </td>
+ <td width="40%">&nbsp;</td>
+ </tr>
+ <tr>
+ <td colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+ <td colspan="3">
+ <form action="opt_in_out.php?direction=out&amp;what=domain" method="post">
+ <input type="submit" value="Optout domain" />
+ &nbsp;(<?php echo $dom_out; ?>)
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+ <td colspan="3">
+ <form action="opt_in_out.php?direction=out&amp;what=email" method="post">
+ <input type="submit" value="Optout e-mail" />
+ &nbsp;(<?php echo $email_out; ?>)
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+ <td colspan="3">
+ <form action="opt_in_out.php?direction=in&amp;what=domain" method="post">
+ <input type="submit" value="Optin domain" />
+ &nbsp;(<?php echo $dom_in; ?>)
+ </form>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="3">&nbsp;</td>
+ </tr>
+ <tr>
+ <td colspan="3">
+ <form action="opt_in_out.php?direction=in&amp;what=email" method="post">
+ <input type="submit" value="Optin e-mail" />
+ &nbsp;(<?php echo $email_in; ?>)
+ </form>
+ </td>
+ </tr>
+ </table>
+ <br />
+ </td>
+ </tr>
+ </table>
+
+ <div id="footer" style="width: 800px;">
+ <?php require "includes/copyright.inc.php" ?>
+ </div>
+
+</div>
+
+</body>
+
+</html>
diff --git a/sqlgrey/license.txt b/sqlgrey/license.txt
new file mode 100644
index 0000000..9044b4e
--- /dev/null
+++ b/sqlgrey/license.txt
@@ -0,0 +1,16 @@
+The license of this program can be obtained from: http://www.vanheusden.com/license.txt
+It is actually the GNU Public License.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+
diff --git a/sqlgrey/main.css b/sqlgrey/main.css
new file mode 100644
index 0000000..423752f
--- /dev/null
+++ b/sqlgrey/main.css
@@ -0,0 +1,78 @@
+/* Stylesheet SQLgrey Web Interface */
+
+* {
+ font-family: Arial, Verdana, Helvetica, sans-serif;
+ font-size: 12px;
+}
+
+.alert { color: red; }
+h1 { font-size: 20px; }
+h2 { font-size: 16px; }
+
+span.h1 {
+ font-size: 20px;
+ font-weight: bold;
+}
+span.h2 {
+ font-size: 16px;
+ font-weight: normal;
+}
+
+div#page {
+ width: 950px;
+ margin: auto;
+}
+
+div#table_awl {
+ width: 950px;
+ height: 418px;
+ overflow: auto;
+}
+
+div#table_con {
+ width: 950px;
+ height: 444px;
+ overflow: auto;
+}
+
+
+/* forms */
+input.txt {
+ height: 15px;
+ width: 220px;
+}
+
+tr.datefld td input {
+ height: 15px;
+ width: 40px;
+}
+
+tr.datefld td input.btn {
+ height: 25px;
+ width: 60px;
+ font-size: 13px;
+}
+
+
+/* navigation */
+ul {
+ padding-left: 0;
+ margin-left: 0;
+}
+
+ul li { display: inline; }
+
+ul li a, a.navlike {
+ padding: 0.2em 1em;
+ background-color: #ffa042;
+ color: #000;
+ text-decoration: none;
+ border-right: 1px solid #fff;
+}
+
+ul.navlist li a { float: left; }
+
+ul li a:hover, ul li #current, a.navlike:hover {
+ background-color: #000;
+ color: #fff;
+}
diff --git a/sqlgrey/opt_in_out.php b/sqlgrey/opt_in_out.php
new file mode 100644
index 0000000..7b09b0b
--- /dev/null
+++ b/sqlgrey/opt_in_out.php
@@ -0,0 +1,106 @@
+<?php
+
+/********************************************
+SQLgrey Web Interface
+Filename: opt_in_out.php
+Purpose: Renders the optin/out pages
+Version: 1.1.6
+*********************************************/
+
+ require "includes/functions.inc.php";
+ require "includes/opt_in_out.inc.php";
+
+ (isset($_GET["direction"])) ? $direction = $_GET["direction"] : $direction = "out";
+ (isset($_GET["what"])) ? $what = $_GET["what"] : $what = "domain";
+ (isset($_GET["action"])) ? $action = $_GET["action"] : $action = "";
+
+ // Add some explanation.
+ if ($direction == "out") {
+ $helptag = $helptag_dir;
+ } else {
+ $helptag = $helptag_dir.$helptag_what;
+ }
+
+ // Perform demanded action.
+ switch ($action) {
+ case "del":
+ $entry = $_GET["field"];
+ if ($entry == '') {
+ $report = '<br />Nothing was entered.';
+ } else {
+ do_query("DELETE FROM ".$table." WHERE ".$field."='".addslashes($entry)."'");
+ $report = '<br />'.$entry.' deleted.';
+ }
+ break;
+ case "add":
+ $entry = $_POST[$field];
+ if ($entry == '') {
+ $report = '<br />Nothing was entered.';
+ } else {
+ do_query("INSERT INTO ".$table."(".$field.") VALUES('".addslashes(strtolower($entry))."')");
+ $report = '<br />'.$entry.' added.';
+ }
+ break;
+ case "":
+ $report = "";
+ break;
+ }
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+
+<head>
+ <title><?php echo $title; ?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <link rel="stylesheet" href="main.css" type="text/css" charset="utf-8" />
+</head>
+
+<body>
+
+<div id="page">
+
+ <div class="navcontainer">
+ <?php shownav('grey','', $direction, $what); ?>
+ </div>
+
+ <table width="100%" summary="main">
+ <tr>
+ <td>
+ <p><span class="h1"><?php echo $title; ?></span>&nbsp;&nbsp;<span class="h2"><?php echo $helptag; ?></span></p>
+ <table border="0" summary="data"><tr><td> </td></tr><?php
+ $query = "SELECT ".$field." FROM ".$table." ORDER BY ".$field;
+ $result = do_query($query);
+ while($line = fetch_row($result)) {
+ echo ('
+ <tr>
+ <td>'.$line[$field].'</td>
+ <td><a href="opt_in_out.php?direction='.$direction.'&amp;what='.$what.'&amp;field='.$line[$field].'&amp;action=del">delete</a></td>
+ </tr>');
+ }
+ echo "\n";
+ ?>
+ </table>
+
+ <br /><br />
+
+ <form action="opt_in_out.php?direction=<?php echo $direction.'&amp;what='.$what; ?>&amp;action=add" method="post">
+ <input type="text" name="<?php echo $field; ?>" size="40" />
+ <input class="btn" type="submit" value="Add" />
+ </form>
+ <?php if (! $report == '' ) echo '<span class="alert">'.$report.'</span>'; ?>
+ </td>
+ </tr>
+ </table>
+
+ <br />
+
+ <div id="footer" style="width: 800px">
+ <?php require "includes/copyright.inc.php" ?>
+ </div>
+
+</div>
+
+</body>
+
+</html>
diff --git a/sqlgrey/readme.txt b/sqlgrey/readme.txt
new file mode 100644
index 0000000..fd8ce86
--- /dev/null
+++ b/sqlgrey/readme.txt
@@ -0,0 +1,24 @@
+What you should do:
+- put the files somewhere in your website;
+- edit includes/config.inc.php to your needs;
+- make sure you shield things with a .htaccess file!
+
+
+History:
+v.1.1.6 PHP code now compatible with PHP 5.4.xx.
+v.1.1.5 Bugfix: optin-optout did not show tables when using postgresql.
+v.1.1.4 Explanation of optin-optout improved.
+v.1.1.3 HTML code now tidy and W3C markup valid.
+v.1.1.2 Option included to suppress milliseconds in dates to avoid line breaks in lists.
+v.1.1.1 PHP code cleaned (no more Undefined Variable and Undefined Index errors).
+v.1.1.0 Multiple delete, forget and whitelisting (by checkboxes).
+ More sophisticated routines for adding, deleting etc. (inline reporting
+ instead of reports on separate pages).
+v.1.0.1 Added missing main.css (sorry).
+v.1.0.0 Improved interface by Jan Ceulen (menubar, nice table layout).
+v.0.8 Last stable version by Folkert van Heusden.
+
+Good luck!
+
+For any questions and/or suggestions, contact folkert@vanheusden.com or jan@beebeec.nl
+Consider using PGP (Folkert's key-ID is 0x1f28d8ae).