diff --git a/core.go b/core.go index 1f7ce47e..3418efea 100644 --- a/core.go +++ b/core.go @@ -11,7 +11,7 @@ type Core struct { Key string Secret string Version string - Plugins []*plugin.Plugin + Plugins []*plugin.PluginInfo } func SelectCore() (*Core, error) { diff --git a/html/tmpl/plugins.html b/html/tmpl/plugins.html index 030861e1..a3c6eea7 100644 --- a/html/tmpl/plugins.html +++ b/html/tmpl/plugins.html @@ -18,27 +18,25 @@
- {{ range .Plugins }} - - {{ . }} - - {{end}} -
...
-
{{template "slack"}}
-
...
-
...
+ + {{ range .Plugins }} + +
{{safe .Form }}
+ + {{end}} +
diff --git a/html/tmpl/setup.html b/html/tmpl/setup.html index 15f02ac2..fc7332d2 100644 --- a/html/tmpl/setup.html +++ b/html/tmpl/setup.html @@ -25,7 +25,6 @@
diff --git a/main.go b/main.go index f0fe3604..3ab77d11 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ var ( jsBox *rice.Box tmplBox *rice.Box setupMode bool - allPlugins []*plugin.Plugin + allPlugins []*plugin.PluginInfo ) type Config struct { @@ -40,6 +40,7 @@ type Config struct { func main() { VERSION = "1.1.1" + fmt.Printf("Starting Statup v%v\n", VERSION) RenderBoxes() configs = LoadConfig() if configs == nil { @@ -51,11 +52,6 @@ func main() { } -type Greeter interface { - Greet() -} - - func mainProcess() { var err error DbConnection() @@ -71,52 +67,54 @@ func mainProcess() { } +func ForEachPlugin() { + if len(core.Plugins) > 0 { + //for _, p := range core.Plugins { + // p.OnShutdown() + //} + } +} + + func LoadPlugins() { + ForEachPlugin() + files, err := ioutil.ReadDir("./plugins") if err != nil { fmt.Printf("Plugins directory was not found. Error: %v\n", err) return } - for _, f := range files { - ext := strings.Split(f.Name(), ".") if len(ext) != 2 { continue } - if ext[1] == "so" { - plug, err := plg.Open("plugins/"+f.Name()) if err != nil { fmt.Printf("Plugin '%v' could not load correctly.\n", f.Name()) continue } - symPlugin, err := plug.Lookup("Plugin") var plugActions plugin.PluginActions - plugActions, ok := symPlugin.(plugin.PluginActions) if !ok { fmt.Printf("Plugin '%v' could not load correctly, error: %v\n", f.Name(), "unexpected type from module symbol") continue } - plugin := plugActions.Plugin() + //plugin := plugActions.Plugin() + // + //fmt.Println(plugin.OnLoad) - fmt.Printf("Plugin Loaded '%v' created by: %v\n", plugin.Name, plugin.Creator) plugActions.OnLoad() - fmt.Println(plugActions.Form()) - - allPlugins = append(allPlugins, plugin) - + allPlugins = append(allPlugins, plugActions.Plugin()) } - } - core.Plugins = allPlugins - fmt.Printf("Loaded %v Plugins\n", len(allPlugins)) + + ForEachPlugin() } func RenderBoxes() { diff --git a/plugin/plugin.go b/plugin/plugin.go index 3d159a75..8ca8e842 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -9,12 +9,13 @@ var ( DB *sql.DB ) -type Plugin struct { +type PluginInfo struct { PluginActions Name string Creator string Version string InstallSQL string + Form string Routes []*Routing } @@ -25,22 +26,23 @@ type Routing struct { } type PluginActions interface { - Plugin() *Plugin - OnLoad() - Install() - Uninstall() - Save() - Form() string - OnNewUser() + Plugin() *PluginInfo + SaveForm() + OnInstall() + OnUninstall() OnFailure() OnHit() + OnSettingsSaved() + OnNewUser() + OnShutdown() + OnLoad() } func SetDatabase(db *sql.DB) { DB = db } -func (p *Plugin) InstallPlugin(w http.ResponseWriter, r *http.Request) { +func (p *PluginInfo) InstallPlugin(w http.ResponseWriter, r *http.Request) { //sql := "CREATE TABLE " + p.Name + " (enabled BOOLEAN, api_key text, api_secret text, channel text);" //db.QueryRow(p.InstallSQL()).Scan() @@ -48,11 +50,11 @@ func (p *Plugin) InstallPlugin(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/plugins", http.StatusSeeOther) } -func (p *Plugin) UninstallPlugin(w http.ResponseWriter, r *http.Request) { +func (p *PluginInfo) UninstallPlugin(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/plugins", http.StatusSeeOther) } -func (p *Plugin) SavePlugin(w http.ResponseWriter, r *http.Request) { +func (p *PluginInfo) SavePlugin(w http.ResponseWriter, r *http.Request) { //values := r.PostForm //p.SaveFunc(values) http.Redirect(w, r, "/plugins", http.StatusSeeOther) diff --git a/plugins/slack.so b/plugins/slack.so index 0acea724..aebbc981 100644 Binary files a/plugins/slack.so and b/plugins/slack.so differ diff --git a/web.go b/web.go index 4a05d708..9667cb01 100644 --- a/web.go +++ b/web.go @@ -280,6 +280,9 @@ func Parse(file string) *template.Template { "js": func(html string) template.JS { return template.JS(html) }, + "safe": func(html string) template.HTML { + return template.HTML(html) + }, }) t, _ = t.Parse(nav) t.Parse(render) @@ -298,6 +301,9 @@ func ParsePlugins(file string) *template.Template { "js": func(html string) template.JS { return template.JS(html) }, + "safe": func(html string) template.HTML { + return template.HTML(html) + }, }) t, _ = t.Parse(nav) t.Parse(slack)