7b1f27bf41
I'm slowly rolling this feature out to the various routes and doing tests. Added the notice system. Added the "You are banned" notice. Added the Sendmail experimental plugin for sending emails without needing a SMTP server. Added the debug flag for tuning down the amount of noise in the console. Converted a system notice over to the notice system. Changed the Activation Function signature to allow it to return errors which abort the process of plugin activation. Plugins can now set tags. These will be visible in the Plugin Manager at a later date to specify a small snippet of additional information. Variadic hooks are now first class citizens of the Plugin API rather than just an experiment. SessionCheck() and the new SimpleSessionCheck() can now halt further processing of a route. Deleted plugins are no longer shown on the Plugin Manager. The registration form no longer allows users with blank names, emails or passwords to register. The registration form now blocks some extremely common passwords. Added the new status CSS to the /forum/ route. Simplified some of the range loops in the templates.
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
package main
|
|
|
|
import "io"
|
|
import "os/exec"
|
|
import "errors"
|
|
import "runtime"
|
|
|
|
/*
|
|
Sending emails in a way you really shouldn't be sending them.
|
|
This method doesn't require a SMTP server, but has higher chances of an email being rejected or being seen as spam. Use at your own risk. Only for Linux as Windows doesn't have Sendmail.
|
|
*/
|
|
func init() {
|
|
plugins["sendmail"] = Plugin{"sendmail","Sendmail","Azareal","http://github.com/Azareal","",false,"Linux Only","",init_sendmail,activate_sendmail,deactivate_sendmail}
|
|
}
|
|
|
|
func init_sendmail() {
|
|
add_vhook("email_send_intercept", send_sendmail)
|
|
}
|
|
|
|
// Sendmail is only available on Linux
|
|
func activate_sendmail() error {
|
|
if !enable_emails {
|
|
return errors.New("You have emails disabled in your configuration file")
|
|
}
|
|
if runtime.GOOS != "linux" {
|
|
return errors.New("This plugin only supports Linux")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func deactivate_sendmail() {
|
|
remove_vhook("email_send_intercept")
|
|
}
|
|
|
|
func send_sendmail(data ...interface{}) interface{} {
|
|
to := data[0].(string)
|
|
subject := data[1].(string)
|
|
body := data[2].(string)
|
|
|
|
msg := "From: " + site_email + "\n"
|
|
msg += "To: " + to + "\n"
|
|
msg += "Subject: " + subject + "\n\n"
|
|
msg += body + "\n"
|
|
|
|
sendmail := exec.Command("/usr/sbin/sendmail","-t","-i")
|
|
stdin, err := sendmail.StdinPipe()
|
|
if err != nil {
|
|
return false // Possibly disable the plugin and show an error to the admin on the dashboard? Plugin log file?
|
|
}
|
|
|
|
err = sendmail.Start()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
io.WriteString(stdin, msg)
|
|
|
|
err = stdin.Close()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
err = sendmail.Wait()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return true
|
|
} |