Update the experimental plugins sendmail and hyperdrive to work with the new Plugin APIs.

This commit is contained in:
Azareal 2019-02-17 15:38:49 +10:00
parent d5a58421a7
commit 37ce6165c8
2 changed files with 33 additions and 24 deletions

View File

@ -13,13 +13,13 @@ func init() {
common.Plugins.Add(&common.Plugin{UName: "hyperdrive", Name: "Hyperdrive", Author: "Azareal", Init: initHyperdrive, Deactivate: deactivateHyperdrive}) common.Plugins.Add(&common.Plugin{UName: "hyperdrive", Name: "Hyperdrive", Author: "Azareal", Init: initHyperdrive, Deactivate: deactivateHyperdrive})
} }
func initHyperdrive() error { func initHyperdrive(plugin *common.Plugin) error {
hyperPageCache = newHyperPageCache() hyperPageCache = newHyperPageCache()
common.Plugins["hyperdrive"].AddHook("somewhere", deactivateHyperdrive) plugin.AddHook("somewhere", deactivateHyperdrive)
return nil return nil
} }
func deactivateHyperdrive() { func deactivateHyperdrive(plugin *common.Plugin) {
hyperPageCache = nil hyperPageCache = nil
} }

View File

@ -1,25 +1,34 @@
package main package main
import "io" import (
import "os/exec" "errors"
import "errors" "io"
import "runtime" "os/exec"
"runtime"
"github.com/Azareal/Gosora/common"
)
/* /*
Sending emails in a way you really shouldn't be sending them. 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. 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() { func init() {
plugins["sendmail"] = Plugin{"sendmail","Sendmail","Azareal","http://github.com/Azareal","",false,"Linux Only","",init_sendmail,activate_sendmail,deactivate_sendmail} // Don't bother registering this plugin on platforms other than Linux
if runtime.GOOS != "linux" {
return
}
common.Plugins.Add(&common.Plugin{UName: "sendmail", Name: "Sendmail", Author: "Azareal", URL: "http://github.com/Azareal", Tag: "Linux Only", Init: initSendmail, Activate: activateSendmail, Deactivate: deactivateSendmail})
} }
func init_sendmail() { func initSendmail(plugin *common.Plugin) error {
add_hook("email_send_intercept", send_sendmail) plugin.AddHook("email_send_intercept", sendSendmail)
return nil
} }
// Sendmail is only available on Linux // /usr/sbin/sendmail is only available on Linux
func activate_sendmail() error { func activateSendmail(plugin *common.Plugin) error {
if !site.EnableEmails { if !common.Site.EnableEmails {
return errors.New("You have emails disabled in your configuration file") return errors.New("You have emails disabled in your configuration file")
} }
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
@ -28,21 +37,21 @@ func activate_sendmail() error {
return nil return nil
} }
func deactivate_sendmail() { func deactivateSendmail(plugin *common.Plugin) {
remove_vhook("email_send_intercept") plugin.RemoveHook("email_send_intercept", sendSendmail)
} }
func send_sendmail(data ...interface{}) interface{} { func sendSendmail(data ...interface{}) interface{} {
to := data[0].(string) to := data[0].(string)
subject := data[1].(string) subject := data[1].(string)
body := data[2].(string) body := data[2].(string)
msg := "From: " + site.Email + "\n" msg := "From: " + common.Site.Email + "\n"
msg += "To: " + to + "\n" msg += "To: " + to + "\n"
msg += "Subject: " + subject + "\n\n" msg += "Subject: " + subject + "\n\n"
msg += body + "\n" msg += body + "\n"
sendmail := exec.Command("/usr/sbin/sendmail","-t","-i") sendmail := exec.Command("/usr/sbin/sendmail", "-t", "-i")
stdin, err := sendmail.StdinPipe() stdin, err := sendmail.StdinPipe()
if err != nil { if err != nil {
return false // Possibly disable the plugin and show an error to the admin on the dashboard? Plugin log file? return false // Possibly disable the plugin and show an error to the admin on the dashboard? Plugin log file?