began new go version to lessen resource requirements

This commit is contained in:
Paul Wilde 2021-08-15 22:16:07 +01:00
parent 1df0b80c1f
commit acef6e76d7
10 changed files with 223 additions and 20 deletions

31
src/global/global.go Normal file
View file

@ -0,0 +1,31 @@
package global
import (
. "mailautoconf/structs"
"github.com/vaughan0/go-ini"
"fmt"
)
// Global variables
var ThisSession Session
var MainConfig Config
const defaultConfigDir string = "default-config/"
const configDir string = "config/"
func NewConfig() Config {
fmt.Println("Loading Config…")
cfg := "default-config/config.default.ini"
conf, err := ini.LoadFile(cfg)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(conf)
fmt.Println("Loading Services…")
srv := "default-config/services.default.ini"
serv, err2 := ini.LoadFile(srv)
if err2 != nil {
fmt.Println(err2.Error())
}
fmt.Println(serv)
newcfg := Config{}
return newcfg
}

7
src/go.mod Normal file
View file

@ -0,0 +1,7 @@
module mailautoconf
go 1.16
require (
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect
)

2
src/go.sum Normal file
View file

@ -0,0 +1,2 @@
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks=
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw=

16
src/mailautoconf.go Normal file
View file

@ -0,0 +1,16 @@
package main
import (
"fmt"
"net/http"
"log"
"mailautoconf/web/handler"
. "mailautoconf/global"
)
func main() {
MainConfig = NewConfig()
http.HandleFunc("/", handler.WebHandler)
fmt.Println("Starting up Web Listener on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}

View file

@ -1,20 +0,0 @@
package main
import (
"fmt"
"net/http"
"log"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
func do_this(){
fmt.Println("doing this")
}

18
src/structs/structs.go Normal file
View file

@ -0,0 +1,18 @@
package structs
// I don't like the name of this package, consider naming it "core" or
// separating out the structs and core functions
import "net/http"
type Session struct {
ResponseWriter http.ResponseWriter
Request *http.Request
Path string
WebContent string
}
type Config struct {
Services []Service
}
type Service struct {
}

View file

@ -0,0 +1,58 @@
<!-- The below link has config-v1.1.xml information
https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat -->
<clientConfig version="1.1">
<emailProvider id="<?php echo Core::$Config["PrimaryDomain"]?>">
<?php foreach (Core::$Config["Domain"] as $domain){ ?>
<domain><?php echo $domain; ?></domain>
<?php } ?>
<displayName>%EMAILADDRESS%</displayName>
<?php if($services["InMail"]&& $services["InMail"]["Enabled"]){
$service = $services["InMail"]; ?>
<incomingServer type="<?php echo strtolower($service["Type"]);?>">
<hostname><?php echo $service["Server"];?></hostname>
<port><?php echo $service["Port"];?></port>
<socketType><?php echo $service["SocketType"];?></socketType>
<username><?php echo $this->get_username($service,$email_address); ?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
</incomingServer>
<?php }
if($services["OutMail"]&& $services["OutMail"]["Enabled"]){
$service = $services["OutMail"]; ?>
<outgoingServer type="<?php echo strtolower($service["Type"]);?>">
<hostname><?php echo $service["Server"];?></hostname>
<port><?php echo $service["Port"];?></port>
<socketType><?php echo $service["SocketType"];?></socketType>
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
</outgoingServer>
<?php }
if ($services["AddressBook"] && $services["AddressBook"]["Enabled"]) {
$service = $services["AddressBook"]; ?>
<addressBook type="<?php echo strtolower($service["Type"]); ?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
<serverURL><?php echo $service["Server"];?></serverURL>
</addressBook>
<?php }
if ($services["Calendar"] && $services["Calendar"]["Enabled"]){
$service = $services["Calendar"] ;?>
<calendar type="<?php echo strtolower($service["Type"]);?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
<serverURL><?php echo $service["Server"];?></serverURL>
</calendar>
<?php }
if ($services["WebMail"] && $services["WebMail"]["Enabled"]) {
$service = $services["WebMail"]; ?>
<webMail>
<loginPage url="<?php echo $service["Server"];?>" />
<loginPageInfo url="<?php echo $service["Server"];?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<usernameField id="<?php echo $service["UsernameDivID"];?>" name="<?php echo $service["UsernameDivName"];?>" />
<passwordField name="<?php echo $service["PasswordDivName"];?>" />
<loginButton id="<?php echo $service["SubmitButtonID"];?>" name="<?php echo $service["SubmitButtonName"];?>"/>
</loginPageInfo>
</webMail>
<?php } ?>
</emailProvider>
</clientConfig>

View file

@ -0,0 +1,45 @@
<!-- Example POST Request (sent from client) :
<?xml version="1.0" \?\>
<Autodiscover xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request>
<EMailAddress>your@email.address</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request>
</Autodiscover> -->
<?xml version="1.0" encoding="utf-8" ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<Account>
<AccountType>email</AccountType>
<Action>settings</Action>
<?php if ($conf["InMail"] && $conf["InMail"]["Enabled"]){
$in = $conf["InMail"];?>
<Protocol>
<Type><?php echo $in["Type"];?></Type>
<Server><?php echo $in["Server"];?></Server>
<Port><?php echo $in["Port"];?></Port>
<DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo isset($matches[1]) ? $matches[1] : false ; ?></LoginName>
<SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<SSL><?php echo $in["SocketType"] == "SSL" ? "on" : "off";?></SSL>
<AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
</Protocol>
<?php }
if ($conf["OutMail"]&& $conf["OutMail"]["Enabled"]) {
$out = $conf["OutMail"];?>
<Protocol>
<Type><?php echo $out["Type"];?></Type>
<Server><?php echo $out["Server"];?></Server>
<Port><?php echo $out["Port"];?></Port>
<DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo isset($matches[1]) ? $matches[1] : false ; ?></LoginName>
<SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<Encryption><?php echo $in["SocketType"];?></Encryption>
<AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
<UsePOPAuth><?php echo $in["POPAuth"] ? "on" : "off";?></UsePOPAuth>
<SMTPLast><?php echo $in["SMTPLast"] ? "on" : "off";?></SMTPLast>
</Protocol>
<?php } ?>
</Account>
</Response>
</Autodiscover>

View file

@ -0,0 +1,32 @@
package handler
import (
. "mailautoconf/structs"
. "mailautoconf/global"
"mailautoconf/web/responses"
"strings"
"net/http"
"fmt"
)
func WebHandler(w http.ResponseWriter, r *http.Request) {
ThisSession = Session{}
ThisSession.ResponseWriter = w
ThisSession.Request = r
ThisSession.Path = strings.ToLower(r.URL.Path[1:])
switch ThisSession.Path {
case "mail/config-v1.1.xml":
ThisSession.WebContent = responses.MozAutoconfig()
case "autodiscover/autodiscover.xml":
ThisSession.WebContent = responses.MsAutoDiscoverXML()
case "autodiscover/autodiscover.json":
ThisSession.WebContent = responses.MsAutoDiscoverJSON()
default:
ThisSession.WebContent = responses.DefaultResponse()
}
writeWebOutput()
}
func writeWebOutput () {
fmt.Fprintf(ThisSession.ResponseWriter, ThisSession.WebContent)
}

View file

@ -0,0 +1,14 @@
package responses
func MozAutoconfig() string {
return ""
}
func MsAutoDiscoverXML() string {
return ""
}
func MsAutoDiscoverJSON() string {
return ""
}
func DefaultResponse() string {
return ""
}