diff --git a/doc/Plugin_System.md b/doc/Plugin_System.md new file mode 100644 index 000000000..3d0c41ce9 --- /dev/null +++ b/doc/Plugin_System.md @@ -0,0 +1,61 @@ +# Developing for the Plugin System + +This documentation will hopefully give you a basis for how to write a plugin for LibreNMS. + +A test plugin is available on GitHib: https://github.com/laf/Test + +Plugins need to be installed into html/plugins + +The structure of a plugin is follows: + +``` +html/plugins + /PluginName + /PluginName.php + /PluginName.inc.php +``` + +The above structure is checked before a plugin can be installed. + +All files / folder names are case sensitive and must match. + +PluginName - This is a directory and needs to be named as per the plugin you are creating. + +PluginName.php - This file is used to process calls into the plugin from the main LibreNMS install. + Here only functions within the class for your plugin that LibreNMS calls will be executed. + For a list of currently enabled system hooks, please see further down. + The minimum code required in this file is (replace Test with the name of your plugin): +``` + +``` + +PluginName.inc.php - This file is the main included file when browsing to the plugin itself. + You can use this to display / edit / remove whatever you like. + The minimum code required in this file is: +``` + +``` + +### System Hooks ### + +System hooks are called as functions within your plugin class, so for example to create a menu entry within the PLugin dropdown you would do: + +``` + public function menu() { + echo('
System
diff --git a/html/index.php b/html/index.php
index 583ceb573..fd90a7ea3 100755
--- a/html/index.php
+++ b/html/index.php
@@ -17,6 +17,8 @@ include("../config.php");
include_once("../includes/definitions.inc.php");
include("../includes/functions.php");
include("includes/functions.inc.php");
+include('includes/plugins.inc.php');
+Plugins::start();
// Check for install.inc.php
if (!file_exists('../config.php') && $_SERVER['PATH_INFO'] != '/install.php') {
diff --git a/html/pages/plugin.inc.php b/html/pages/plugin.inc.php
new file mode 100644
index 000000000..dcae4aacb
--- /dev/null
+++ b/html/pages/plugin.inc.php
@@ -0,0 +1,20 @@
+ 'plugin');
+
+$pagetitle[] = "Plugin";
+
+if ($vars['view'] == "admin")
+{
+ include_once('pages/plugin/admin.inc.php');
+}
+else
+{
+ $plugin = dbFetchRow("SELECT `plugin_name` FROM `plugins` WHERE `plugin_name` = '".$vars['p']."'");
+ if(!empty($plugin))
+ {
+ require('plugins/'.$plugin['plugin_name'].'/'.$plugin['plugin_name'].'.inc.php');
+ }
+}
+
+?>
diff --git a/html/pages/plugin/admin.inc.php b/html/pages/plugin/admin.inc.php
new file mode 100644
index 000000000..ce92d906c
--- /dev/null
+++ b/html/pages/plugin/admin.inc.php
@@ -0,0 +1,95 @@
+= '10')
+{
+
+ // Scan for new plugins and add to the database
+ $new_plugins = scan_new_plugins();
+
+
+ // Check if we have to toggle enabled / disable a particular module
+ $plugin_id = $_POST['plugin_id'];
+ $plugin_active = $_POST['plugin_active'];
+ if(is_numeric($plugin_id) && is_numeric($plugin_active))
+ {
+ if( $plugin_active == '0')
+ {
+ $plugin_active = 1;
+ }
+ elseif( $plugin_active == '1')
+ {
+ $plugin_active = 0;
+ }
+ else
+ {
+ $plugin_active = 0;
+ }
+
+ dbUpdate(array('plugin_active' => $plugin_active), 'plugins', '`plugin_id` = ?', array($plugin_id));
+
+ }
+
+?>
+
+| Name | +Action | ++ '. $plugins['plugin_name'] . ' + | ++ + | + '); + } + +?> +
|---|