How to call a custom webpage from application section in cockpit
Subtitle: Call custom webpage from application section
Version and revision: V1.0 / R 0.0.
For Nethserver 7.7 cockpit edition
Accessible to: Novice / Beginner
Date of presentation: Released on 2019-11-24
Description
This how to describes how you can add a custom link to a webpage to the application section in cockpit. In this example I'll add a link to a software called “Omada Controller” which is a webbased application to controll and configure TP-Link Wlan-accesspoint. It should be easy to adapt that to your own needs. At the end you have a link like it's shown in the example below:
Steps to do
1. Place a file called read in /usr/libexec/nethserver/api/nethserver-omada and give right 755 (chmod a+x)
#!/bin/bash
#
# Copyright (C) 2018 Nethesis S.r.l.
# http://www.nethesis.it - nethserver@nethesis.it
#
# This script is part of NethServer.
#
# NethServer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License,
# or any later version.
#
# NethServer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NethServer. If not, see COPYING.
#
input=$(cat)
action=$(jq -r .action <<<"$input")
protocol=$(jq -r .location.protocol <<<"$input")
host=$(jq -r .location.hostname <<<"$input")
if [[ $action == "app-info" ]]; then
# static url
# printf '{"url":"https://nethserver.domain.tld:8043/login"}'
# dynamic url
printf '{"url":"%s"}' "${protocol}//${host}:8043/login"
fi
chmod a+x /usr/libexec/nethserver/api/nethserver-omada
2. Place a file called nethserver-omada.json in /usr/share/cockpit/nethserver/applications (please change “omada” to your needs).
In the file, please also make any changes to your needs.
{
"id": "nethserver-omada",
"name": "TP-Link Omada Webinterface",
"summary": "TP-Link Omada Controller Webinterface",
"description": "TP-Link Omada Controller Webinterface",
"url": "",
"provides": ["nethserver-omada"],
"release": {
"version": "1.0"
},
"author": {
"name": "R. Jeckel"
},
"infoapi": {
"path": "nethserver-omada/read"
},
"icon": "logo.png",
"external": true
}
You can test your json-file with
cat /path/to/jsonFile.json | jq
3. Place a file called 50_nsapi_nethserver_omada in /etc/sudoers.d (again please change “omada” to your needs, also in the file)
#
# nsapi_nethserver_omada
#
Cmnd_Alias NSAPI_NETHSERVER_OMADA = \
/usr/libexec/nethserver/api/nethserver-omada/read
Defaults!NSAPI_NETHSERVER_OMADA !requiretty
4. Place manifest.json with logo.png in /usr/share/cockpit/nethserver-omada (again please change “omada” to your needs)
{
"version": 0,
"content-security-policy": "style-src 'self' 'unsafe-inline'"
}
5. Restart cockpit with
signal-event nethserver-cockpit-update
Last but not least, I want to say thanks to stephdl, who helped me with this guide with his expertize on webdevelopment!
