Kudos! Getting the component to install is most of the battle.
This snippet would place the component link in the Home Menu under Maps
Code: Select all
/*
* Adds the index page to the menu
*/
function saturationreport_component_addmenu()
{
global $saturationreport_component_name;
$component_url = get_component_url_base($saturationreport_component_name);
// find the location of menu of network status map
$menu_section = find_menu_item(MENU_HOME, "menu-home-section-maps", "id");
if ($menu_section == null) {
return false;
}
$order = grab_array_var($menu_section, "order", "");
// Make this the top item in the maps section
$new_order = $order + 0.1;
if ($new_order < 0) {
return false;
}
add_menu_item(MENU_HOME, array(
"type" => "link",
"title" => _("Storage Saturation Report"),
"id" => "menu-home-section-saturationreport",
"order" => $new_order,
"opts" => array(
"href" => $component_url . "/index.php",
"icon" => "fa-file-text-o",
)
));
add_menu_item(MENU_HOME, array(
"type" => "linkspacer",
"id" => "menu-home-section-saturationreport-spacer",
"order" => $new_order+0.1
));
}
In XI you would see this in the Home menu under Maps
menu_maps.PNG
Authentication functions and order of operation are important.
Code: Select all
<?php
// Required includes for web-accessible component scripts
require_once(dirname(__FILE__).'/../../common.inc.php');
// Initialization sequence (in order)
pre_init(); // Initialization stuff
init_session(); // Start session
grab_request_vars(); // Grab GET or POST variables
check_prereqs(); // Check prerequisites
check_authentication(false); // Check authentication (false = don't redirect for API)
```
Why This Order Matters:
- `pre_init()`: Sets up basic environment
- `init_session()`: Starts PHP session (must be before any output)
- `grab_request_vars()`: Safely retrieves form variables
- `check_prereqs()`: Verifies system prerequisites
- `check_authentication()`: Validates user is logged in
### Authentication Functions
check_authentication($redirect = true):
- Checks if user is authenticated
- If not authenticated and `$redirect` is `true`, redirects to login page
- If `$redirect` is `false`, returns without redirecting (useful for API endpoints)
- Must be called after `init_session()`
is_authenticated():
- Returns `true` if user is logged in, `false` otherwise
- Does not redirect
- Useful for conditional logic
is_admin():
- Returns `true` if current user has admin privileges
- Useful for restricting access to admin-only features
get_user_id():
- Returns the current user's ID
- Useful for user-specific data
### Example: Protected Page
<?php
require_once(dirname(__FILE__).'/../../common.inc.php');
pre_init();
init_session();
grab_request_vars();
check_prereqs();
check_authentication(); // Redirects to login if not authenticated
// Check for admin privileges
if (!is_admin()) {
echo "Access denied. Admin privileges required.";
exit;
}
// Page content here
Happy Monitoring!
--SN
You do not have the required permissions to view the files attached to this post.