Explorar o código

version 1.4 - see README for release notes

flashmob %!s(int64=9) %!d(string=hai) anos
pai
achega
3919be7280
Modificáronse 7 ficheiros con 141 adicións e 102 borrados
  1. 81 31
      README.md
  2. 0 26
      config.go
  3. 40 21
      goguerrilla.conf.sample
  4. 4 6
      goguerrilla.go
  5. 2 2
      save_mail.go
  6. 8 10
      smtpd.go
  7. 6 6
      util.go

+ 81 - 31
README.md

@@ -131,33 +131,66 @@ The configuration is in strict JSON format. Here is an annotated configuration.
 Copy goguerrilla.conf.sample to goguerrilla.conf
 Copy goguerrilla.conf.sample to goguerrilla.conf
 
 
 
 
-	{
-	    "GM_ALLOWED_HOSTS":"example.com,sample.com,foo.com,bar.com", // which domains accept mail
-	    "GM_MAIL_TABLE":"new_mail", // name of new email table
-	    "GM_PRIMARY_MAIL_HOST":"mail.example.com", // given in the SMTP greeting
-	    "GSMTP_HOST_NAME":"mail.example.com", // given in the SMTP greeting
-	    "GSMTP_LOG_FILE":"/dev/stdout", // not used yet
-	    "GSMTP_MAX_SIZE":"131072", // max size of DATA command
-	    "GSMTP_PRV_KEY":"/etc/ssl/private/example.com.key", // private key for TLS
-	    "GSMTP_PUB_KEY":"/etc/ssl/certs/example.com.crt", // public key for TLS
-	    "GSMTP_TIMEOUT":"100", // tcp connection timeout
-	    "GSMTP_VERBOSE":"N", // set to Y for debugging
-	    "GSTMP_LISTEN_INTERFACE":"5.9.7.183:25",
-	    "MYSQL_DB":"gmail_mail", // database name
-	    "MYSQL_HOST":"127.0.0.1:3306", // database connect
-	    "MYSQL_PASS":"$ecure1t", // database connection pass
-	    "MYSQL_USER":"gmail_mail", // database username
-	    "GM_MAX_CLIENTS":"500", // max clients that can be handled
-		"NGINX_AUTH_ENABLED":"N",// Y or N
-		"NGINX_AUTH":"127.0.0.1:8025", // If using Nginx proxy, choose an ip and port to serve Auth requsts for Nginx
-	    "PID_FILE":		  "/var/run/go-guerrilla.pid",
-	    "GM_SAVE_WORKERS : "3" // how many workers saving email to the storage
-	}
+{
+    "allowed_hosts": "guerrillamail.com,guerrillamailblock.com,sharklasers.com,guerrillamail.net,guerrillamail.org" // What hosts to accept mail for
+    "primary_mail_host":"sharklasers.com", // main domain
+    "verbose":false, // report all events to log
+    "mysql_db":"gmail_mail", // name of mysql database
+    "mysql_host":"127.0.0.1:3306", // mysql host and port (tcp)
+    "mysql_pass":"ok", // mysql password
+    "mysql_user":"gmail_mail", // mysql username
+    "mail_table":"new_mail", // mysql save table. Email meta-data is saved there
+    "redis_interface" : "127.0.0.1:6379", // redis host and port, email data payload is saved there
+	"redis_expire_seconds" : 3600, // how long to keep in redis
+	"save_workers_size" : 3, // number workers saving email from all servers
+	"pid_file" : "/var/run/go-guerrilla.pid", // pid = process id, so that other programs can send signals to our server
+    	"servers" : [ // the following is an array of objects, each object represents a new server that will be spawned
+    	    {
+                "is_enabled" : true, // boolean
+                "host_name":"mail.test.com", // the hostname of the server as set by MX record
+                "max_size": 1000000, // maximum size of an email in bytes
+                "private_key_file":"/path/to/pem/file/test.com.key",  // full path to pem file private key
+                "public_key_file":"/path/to/pem/file/test.com.crt", // full path to pem file certificate
+                "timeout":180, // timeout in number of seconds before an idle connection is closed
+                "listen_interface":"127.0.0.1:25", // listen on ip and port
+                "start_tls_on":true, // supports the STARTTLS command?
+                "tls_always_on":false, // always connect using TLS? If true, start_tls_on will be false
+                "max_clients": 1000, // max clients at one time
+                "log_file":"/dev/stdout" // where to log to
+    	    },
+    	    // the following is a second server, but listening on port 465 and always using TLS
+    	    {
+                "is_enabled" : true,
+                "host_name":"mail.test.com",
+                "max_size":1000000,
+                "private_key_file":"/path/to/pem/file/test.com.key",
+                "public_key_file":"/path/to/pem/file/test.com.crt",
+                "timeout":180,
+                "listen_interface":"127.0.0.1:465",
+                "start_tls_on":false,
+                "tls_always_on":true,
+                "max_clients":500,
+                "log_file":"/dev/stdout"
+            }
+            // repeat as many servers as you need
+    	]
+}
+
+	
 
 
 Releases
 Releases
 =========================================================
 =========================================================
 
 
-1.3
+1.4 - 25th Oct 2016
+- New Feature: multiple servers!
+- Changed the configuration file format to support multiple servers,
+this means that a new configuration file would need to be created form the
+sample (goguerrilla.conf.sample)
+- Organised code into separate files. Config is now strongly typed, etc
+- Deprecated nginx proxy support
+
+
+1.3 14th July 2016
 - Number of saveMail workers added to config (GM_SAVE_WORKERS) 
 - Number of saveMail workers added to config (GM_SAVE_WORKERS) 
 - convenience function for reading int values form config
 - convenience function for reading int values form config
 - advertise PIPELINING
 - advertise PIPELINING
@@ -165,7 +198,7 @@ Releases
 - rcpt to host validation: now case insensitive and done earlier (after DATA)
 - rcpt to host validation: now case insensitive and done earlier (after DATA)
 - iconv switched to: go get gopkg.in/iconv.v1
 - iconv switched to: go get gopkg.in/iconv.v1
 
 
-1.2
+1.2 1st July 2016
 - Reload config on SIGHUP
 - Reload config on SIGHUP
 - Write current process id (pid) to a file, /var/run/go-guerrilla.pid by default
 - Write current process id (pid) to a file, /var/run/go-guerrilla.pid by default
 
 
@@ -176,7 +209,7 @@ Nginx can be used to proxy SMTP traffic for GoGuerrilla SMTPd
 
 
 Why proxy SMTP with Nginx?
 Why proxy SMTP with Nginx?
 
 
- *	Terminate TLS connections: Early Golang was not there yet when it came to TLS.
+ *	Terminate TLS connections: (eg. Early Golang versions were not there yet when it came to TLS.)
  OpenSSL on the other hand, used in Nginx, has a complete implementation of TLS with familiar configuration.
  OpenSSL on the other hand, used in Nginx, has a complete implementation of TLS with familiar configuration.
  *	Nginx could be used for load balancing and authentication
  *	Nginx could be used for load balancing and authentication
 
 
@@ -186,12 +219,11 @@ Why proxy SMTP with Nginx?
 
 
 
 
 		mail {
 		mail {
-	        auth_http 127.0.0.1:8025/; # This is the URL to GoGuerrilla's http service which tells Nginx where to proxy the traffic to
 	        server {
 	        server {
 	                listen  15.29.8.163:25;
 	                listen  15.29.8.163:25;
 	                protocol smtp;
 	                protocol smtp;
 	                server_name  ak47.example.com;
 	                server_name  ak47.example.com;
-	
+	                auth_http smtpauth.local:80/auth.txt;
 	                smtp_auth none;
 	                smtp_auth none;
 	                timeout 30000;
 	                timeout 30000;
 	                smtp_capabilities "SIZE 15728640";
 	                smtp_capabilities "SIZE 15728640";
@@ -210,13 +242,31 @@ Why proxy SMTP with Nginx?
 	                proxy on;
 	                proxy on;
 	        }
 	        }
 		}
 		}
+		
+		http {
+		
+		    # Add somewhere inside your http block..
+		    # make sure that you have added smtpauth.local to /etc/hosts
+		    # What this block does is tell the above stmp server to connect
+		    # to our golang server configured to run on 127.0.0.1:2525
+		    
+		    server {
+                    listen 15.29.8.163:80;
+                    server_name 15.29.8.163 smtpauth.local;
+                    root /home/user/http/auth/;
+                    access_log off;
+                    location /auth.txt {
+                        add_header Auth-Status OK;
+                        # where to find your smtp server?
+                        add_header Auth-Server 127.0.0.1;
+                        add_header Auth-Port 2525;
+                    }
+                   
+                }
 
 
+		}
 
 
-Assuming that Guerrilla SMTPd has the following configuration settings:
 
 
-	"GSMTP_MAX_SIZE"		  "15728640",
-	"NGINX_AUTH_ENABLED":     "Y",
-	"NGINX_AUTH":             "127.0.0.1:8025", 
 
 
 
 
 Starting / Command Line usage
 Starting / Command Line usage

+ 0 - 26
config.go

@@ -40,32 +40,6 @@ type ServerConfig struct {
 	Log_file         string `json:"log_file"`
 	Log_file         string `json:"log_file"`
 }
 }
 
 
-// defaults. Overwrite any of these in the configure() function which loads them from a json file
-/*
-var gConfig = map[string]interface{}{
-	"GSMTP_MAX_SIZE":            "131072",
-	"GSMTP_HOST_NAME":           "server.example.com", // This should also be set to reflect your RDNS
-	"GSMTP_VERBOSE":             "Y",
-	"GSMTP_LOG_FILE":            "",    // Eg. /var/log/goguerrilla.log or leave blank if no logging
-	"GSMTP_TIMEOUT":             "100", // how many seconds before timeout.
-	"MYSQL_HOST":                "127.0.0.1:3306",
-	"MYSQL_USER":                "gmail_mail",
-	"MYSQL_PASS":                "ok",
-	"MYSQL_DB":                  "gmail_mail",
-	"GM_MAIL_TABLE":             "new_mail",
-	"GSTMP_LISTEN_INTERFACE":    "0.0.0.0:25",
-	"GSMTP_PUB_KEY":             "/etc/ssl/certs/ssl-cert-snakeoil.pem",
-	"GSMTP_PRV_KEY":             "/etc/ssl/private/ssl-cert-snakeoil.key",
-	"GM_ALLOWED_HOSTS":          "guerrillamail.de,guerrillamailblock.com",
-	"GM_PRIMARY_MAIL_HOST":      "guerrillamail.com",
-	"GM_MAX_CLIENTS":            "500",
-	"NGINX_AUTH_ENABLED":        "N",              // Y or N
-	"NGINX_AUTH":                "127.0.0.1:8025", // If using Nginx proxy, ip and port to serve Auth requsts
-	"PID_FILE":                  "/var/run/go-guerrilla.pid",
-	"GSMTP_MAIL_EXPIRE_SECONDS": "72000",
-}
-
-*/
 var mainConfig GlobalConfig
 var mainConfig GlobalConfig
 var flagVerbose, flagIface, flagConfigFile string
 var flagVerbose, flagIface, flagConfigFile string
 
 

+ 40 - 21
goguerrilla.conf.sample

@@ -1,23 +1,42 @@
 {
 {
-    "GM_ALLOWED_HOSTS":"example.com,sample.com,foo.com,bar.com",
-    "GM_MAIL_TABLE":"new_mail",
-    "GM_PRIMARY_MAIL_HOST":"mail.example.com",
-    "GSMTP_HOST_NAME":"mail.example.com",
-    "GSMTP_LOG_FILE":"",
-    "GSMTP_MAX_SIZE":"15728640",
-    "GSMTP_PRV_KEY":"/etc/ssl/private/example.com.key",
-    "GSMTP_PUB_KEY":"/etc/ssl/certs/example.com.crt",
-    "GSMTP_TIMEOUT":"100",
-    "GSMTP_VERBOSE":"N",
-    "GSTMP_LISTEN_INTERFACE":"33.1.2.133:25",
-    "MAX_SMTP_CLIENTS":"10000",
-    "MYSQL_DB":"gmail_mail",
-    "MYSQL_HOST":"127.0.0.1:3306",
-    "MYSQL_PASS":"$ecure1t",
-    "MYSQL_USER":"gmail_mail",
-    "GM_MAX_CLIENTS":"500",
-	"NGINX_AUTH_ENABLED":"N",
-	"NGINX_AUTH":"127.0.0.1:8025",
-    "PID_FILE":		  "/var/run/go-guerrilla.pid",
-    GM_SAVE_WORKERS : "3"
+    "allowed_hosts": "guerrillamail.com,guerrillamailblock.com,sharklasers.com,guerrillamail.net,guerrillamail.org"
+    "primary_mail_host":"sharklasers.com",
+    "verbose":false,
+    "mysql_db":"gmail_mail",
+    "mysql_host":"127.0.0.1:3306",
+    "mysql_pass":"ok",
+    "mysql_user":"gmail_mail",
+    "mail_table":"new_mail",
+    "redis_interface" : "127.0.0.1:6379",
+	"redis_expire_seconds" : 3600,
+	"save_workers_size" : 3,
+	"pid_file" : "/var/run/go-guerrilla.pid",
+    	"servers" : [
+    	    {
+                "is_enabled" : true,
+                "host_name":"mail.test.com",
+                "max_size": 1000000,
+                "private_key_file":"/path/to/pem/file/test.com.key",
+                "public_key_file":"/path/to/pem/file/test.com.crt",
+                "timeout":180,
+                "listen_interface":"127.0.0.1:25",
+                "start_tls_on":true,
+                "tls_always_on":false,
+                "max_clients": 1000,
+                "log_file":"/dev/stdout"
+    	    },
+    	    {
+                "is_enabled" : true,
+                "host_name":"mail.test.com",
+                "max_size":1000000,
+                "private_key_file":"/path/to/pem/file/test.com.key",
+                "public_key_file":"/path/to/pem/file/test.com.crt",
+                "timeout":180,
+                "listen_interface":"127.0.0.1:465",
+                "start_tls_on":false,
+                "tls_always_on":true,
+                "max_clients":500,
+                "log_file":"/dev/stdout"
+            }
+    	]
 }
 }

+ 4 - 6
goguerrilla.go

@@ -29,11 +29,9 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-
-
 var allowedHosts = make(map[string]bool, 15)
 var allowedHosts = make(map[string]bool, 15)
 
 
-//var sem chan int // currently active clients
+
 var signalChannel = make(chan os.Signal, 1) // for trapping SIG_HUB
 var signalChannel = make(chan os.Signal, 1) // for trapping SIG_HUB
 
 
 func sigHandler() {
 func sigHandler() {
@@ -62,7 +60,7 @@ func initialise() {
 	}
 	}
 	// handle SIGHUP for reloading the configuration while running
 	// handle SIGHUP for reloading the configuration while running
 	signal.Notify(signalChannel, syscall.SIGHUP)
 	signal.Notify(signalChannel, syscall.SIGHUP)
-	//go sigHandler()
+
 	return
 	return
 }
 }
 
 
@@ -130,5 +128,5 @@ func main() {
 			go runServer(mainConfig.Servers[serverId])
 			go runServer(mainConfig.Servers[serverId])
 		}
 		}
 	}
 	}
-	sigHandler();
-}
+	sigHandler()
+}

+ 2 - 2
save_mail.go

@@ -1,11 +1,11 @@
 package main
 package main
 
 
 import (
 import (
+	"fmt"
 	"github.com/garyburd/redigo/redis"
 	"github.com/garyburd/redigo/redis"
 	"github.com/ziutek/mymysql/autorc"
 	"github.com/ziutek/mymysql/autorc"
 	_ "github.com/ziutek/mymysql/godrv"
 	_ "github.com/ziutek/mymysql/godrv"
 	"log"
 	"log"
-	"fmt"
 	"strconv"
 	"strconv"
 	"time"
 	"time"
 )
 )
@@ -15,7 +15,7 @@ type savePayload struct {
 	server *SmtpdServer
 	server *SmtpdServer
 }
 }
 
 
-var SaveMailChan chan *savePayload          // workers for saving mail
+var SaveMailChan chan *savePayload // workers for saving mail
 
 
 type redisClient struct {
 type redisClient struct {
 	count int
 	count int

+ 8 - 10
smtpd.go

@@ -1,18 +1,18 @@
 package main
 package main
 
 
 import (
 import (
-	"net"
 	"bufio"
 	"bufio"
+	"bytes"
 	"crypto/tls"
 	"crypto/tls"
-	"time"
-	"log"
+	"errors"
 	"fmt"
 	"fmt"
-	"bytes"
+	"io"
+	"log"
+	"net"
 	"os"
 	"os"
 	"strconv"
 	"strconv"
-	"io"
 	"strings"
 	"strings"
-	"errors"
+	"time"
 )
 )
 
 
 type Client struct {
 type Client struct {
@@ -47,7 +47,6 @@ type SmtpdServer struct {
 	logger       *log.Logger
 	logger       *log.Logger
 }
 }
 
 
-
 func (server *SmtpdServer) logln(level int, s string) {
 func (server *SmtpdServer) logln(level int, s string) {
 
 
 	if mainConfig.Verbose {
 	if mainConfig.Verbose {
@@ -88,15 +87,14 @@ func (server *SmtpdServer) upgradeToTls(client *Client) bool {
 		client.bufin = bufio.NewReader(client.conn)
 		client.bufin = bufio.NewReader(client.conn)
 		client.bufout = bufio.NewWriter(client.conn)
 		client.bufout = bufio.NewWriter(client.conn)
 		client.tls_on = true
 		client.tls_on = true
-		return true;
+		return true
 	} else {
 	} else {
 		server.logln(1, fmt.Sprintf("Could not TLS handshake:%v", err))
 		server.logln(1, fmt.Sprintf("Could not TLS handshake:%v", err))
-		return false;
+		return false
 	}
 	}
 
 
 }
 }
 
 
-
 func (server *SmtpdServer) handleClient(client *Client) {
 func (server *SmtpdServer) handleClient(client *Client) {
 	defer server.closeClient(client)
 	defer server.closeClient(client)
 	advertiseTls := "250-STARTTLS\r\n"
 	advertiseTls := "250-STARTTLS\r\n"

+ 6 - 6
util.go

@@ -1,17 +1,17 @@
 package main
 package main
 
 
 import (
 import (
-	"strings"
+	"bytes"
+	"compress/zlib"
 	"crypto/md5"
 	"crypto/md5"
+	"encoding/base64"
 	"encoding/hex"
 	"encoding/hex"
 	"errors"
 	"errors"
-	"regexp"
-	"bytes"
-	"encoding/base64"
-	"io/ioutil"
 	"github.com/sloonz/go-qprintable"
 	"github.com/sloonz/go-qprintable"
-	"compress/zlib"
 	"gopkg.in/iconv.v1"
 	"gopkg.in/iconv.v1"
+	"io/ioutil"
+	"regexp"
+	"strings"
 )
 )
 
 
 func validateEmailData(client *Client) (user string, host string, addr_err error) {
 func validateEmailData(client *Client) (user string, host string, addr_err error) {