| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The configurations of scripts is presented in this file, in the WebScripts project these files return an error because the arguments section is required. For more information on configuring arguments click here (wiki).
To configure a script you can use a specific file. In the main file for configuration (JSON syntax first and second with INI syntax):
{
"scripts": {
"change_my_password.py": "config_change_my_password"
},
"config_change_my_password": {
"configuration_file": "./config/files/change_my_password.json"
},
}[scripts]
change_my_password.py=config_change_my_password # Define the configuration section ("change_my_password.py") for script named "config_change_my_password"
[config_change_my_password]
configuration_file=./config/files/change_my_password.json # Define script configuration in a specific fileThe specific file content (with JSON syntax):
{
"script": {
"launcher": "python",
"minimum_access": 50,
"category": "My Account",
"args": "change_my_password_args",
"description": "This script can change your own password (for all authenticated users).",
"command_generate_documentation": "python \"%(dirname)s/../doc/py_doc.py\" \"%(path)s\""
}
}JSON example:
{
"scripts": {
"delete_user.py": "config_delete_user"
},
"config_delete_user": {
"timeout": null,
"access_users": [],
"no_password": true,
"launcher": "python",
"access_groups": [1000],
"content_type": "text/plain",
"category": "Administration",
"args": "config_delete_user_args",
"documentation_content_type": "text/html",
"path": "./scripts/account/delete_user.py",
"documentation_file": "./doc/delete_user.html",
"description": "This script delete user from ID.",
"command_generate_documentation": "python \"%(dirname)s/../doc/py_doc.py\" \"%(path)s\""
}
}In this configuration:
INI example:
[scripts]
auth.py=config_auth # Define the configuration section ("config_auth") for script named "auth.py"
[config_auth]
launcher=python # Define the launcher for this script (if script is executable this line is not necessary)
no_password=false # If no_password is true the command line will be written to the logs
path=./scripts/account/auth.py # Only necessary if the location of the script is not in "scripts_path"
documentation_file=./doc/auth.html # Only needed if the location of the documentation does not match the paths defined in "documentations_path"
content_type=text/plain # Define the script output content-type (HTTP headers/javascript interpretation)
documentation_content_type=text/html # Define the documentation content-type
minimum_access=0 # If a user's group is greater than "minimum_access", the user can use this script
access_groups=0,1 # If a user's group is in "access_groups", the user can use this script
access_users=0,1,2 # If the user ID is in "access_users", the user can use this script
args=auth_args # The arguments are defined in section named "auth_args"
description=This script authenticates users. # Short description to help users
category=My Account # Add a link on the index page in the "My Account" section
timeout=10 # Timeout for process execution (in seconds)
command_generate_documentation=python "%(dirname)s/../doc/py_doc.py" "%(path)s" # Command line to generate the documentation fileAll users can access the authentication script, permissions are not used for this script (i add it for example). In this configuration:
This configuration makes no sense because with minimum_access=0 all user can access it, (i add it for example).
You can use all attributes of script configuration in this command. Script configuration contains all attributes defined in the configuration file and the dirname attribute (the absolute path without the filename).
Syntax: %(<attribute>)s. Example: python "%(dirname)s/../doc/py_doc.py" "%(path)s".
All administrators (group ID: 1000), the users with ID 5 and 7, all groups with ID greater or equal than 1050 need to acces this script:
{
"access_groups": [1000],
"access_users": [5, 7],
"minimum_access": 1050
}access_users=5,7
access_groups=1000
minimum_access=1050You can add your custom attributes and get it in your script. Be careful with custom attributes as they are sent to the /api/ URL. The secrets custom configuration is not sent in /api/.
In this example i add two keys (secrets is not send in WebScripts API, and web_interface_color is send in WebScripts API).
The configuration:
{
"scripts": {
"example.py": "config_example"
},
"config_example": {
"description": "Python executable file for the example configuration",
"secrets": {
"key": "azerty"
},
"web_interface_color": "orange"
}
}The python script:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from os import environ
from json import loads
config = loads(environ["SCRIPT_CONFIG"])
key = config["secrets"].get("key")
web_interface_color = config.get("web_interface_color")| Back | FazBrowse Home | New Git URL |