Skip to content

Commit

Permalink
add new config module
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and razvancrainea committed Sep 20, 2024
1 parent 69fab36 commit b7589e5
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/modules.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
"enabled" => true,
"name" => "Clusterer"
),
"config" => array (
"enabled" => true,
"name" => "Config"
),
"keepalived" => array (
"enabled" => true,
"name" => "Keepalived"
Expand Down
41 changes: 41 additions & 0 deletions config/tools/system/config/db.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/*
* $Id: db.inc.php 287 2011-10-17 09:41:35Z untiptun $
* Copyright (C) 2011 OpenSIPS Project
*
* This file is part of opensips-cp, a free Web Control Panel Application for
* OpenSIPS SIP server.
*
* opensips-cp 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 2 of the License, or
* (at your option) any later version.
*
* opensips-cp 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

$module_id = "config";

// define for each submenu item
//database driver
# $custom_config[$module_id][0]['db_driver'] = "mysql";
//database host
# $custom_config[$module_id][0]['db_host'] = "";
//database user
# $custom_config[$module_id][0]['db_user'] = "";
//database name
# $custom_config[$module_id][0]['db_name'] = "";
//database password
# $custom_config[$module_id][0]['db_pass'] = "";
//database port
# $custom_config[$module_id][0]['db_port'] = "";


?>
91 changes: 91 additions & 0 deletions config/tools/system/config/settings.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
/*
* Copyright (C) 2022 OpenSIPS Solutions
*
* This file is part of opensips-cp, a free Web Control Panel Application for
* OpenSIPS SIP server.
*
* opensips-cp 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 2 of the License, or
* (at your option) any later version.
*
* opensips-cp 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

// $table_regex is used to validate custom tables names, you can leave this here
// even if you don't add custom tables
global $table_regex;
global $config;

$config->config = array(
"title0" => array(
"type" => "title",
"title" => "Database"
),
"db_config" => array(
"default" => 0,
"name" => "DB configuration",
"type" => "dropdown",
"options" => get_db_configs(),
"tip" => "DB configuration to use for this tool."
),
"talk_to_this_assoc_id" => array(
"default" => 1,
"name" => "Linked system",
"options" => get_assoc_id(),
"type" => "dropdown",
"tip" => "As OCP can manage multiple OpenSIPS instances, this is the association
ID pointing to the group of servers (system) which needs to be provision with this siptrace status (on or off)."
),

"table" => array(
"default" => "config",
"name" => "Table",
"type" => "text",
"validation_regex" => $table_regex,
"tip" => "Table that stores the configuration data."
),
"id" => array(
"default" => "id",
"name" => "ID Column",
"type" => "text",
"validation_regex" => "^[0-9]+$",
"tip" => "The column used as a primary id for a configuration entry."
),
"name" => array(
"default" => "name",
"name" => "Name Column",
"type" => "text",
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
"tip" => "The column used for the configuration's name."
),
"value" => array(
"default" => "value",
"name" => "Value Column",
"type" => "text",
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
"tip" => "The column used for the configuration's value."
),
"description" => array(
"default" => "description",
"name" => "Description Column",
"type" => "text",
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
"tip" => "The column used for configuration entry description.",
),
"config_id" => array(
"default" => "config",
"name" => "Cacher Id",
"type" => "text",
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
"tip" => "The name of the sql cacher id used in OpenSIPS configuration file.."
),
);
224 changes: 224 additions & 0 deletions config/tools/system/config/tviewer.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<?php
/*
* Copyright (C) 2014 OpenSIPS Project
*
* This file is part of opensips-cp, a free Web Control Panel Application for
* OpenSIPS SIP server.
*
* opensips-cp 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 2 of the License, or
* (at your option) any later version.
*
* opensips-cp 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

###############################################################################
# Attention : advanced options !!

//this is a very important parameter
$module_id = "config";
$custom_config[$module_id] = array ();

// a custom global name for the tool
$custom_config[$module_id]['custom_name'] = "Config";


//if you want submenu (horizontal) items add them here:

// $custom_config[$module_id]['submenu_items'] = array(
// "0" => "Submenu1",
// "1" => "Submenu2"
// );




/* config for each submenu item */

/*
Example table: table1
+---------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | char(128) | NO | UNI | | |
| address | char(128) | NO | | | |
| age | int(10) unsigned | NO | | 0 | |
| married | int(10) unsigned | NO | | 0 | |
+---------------+------------------+------+-----+---------+----------------+
####################################################################################
# #
# Uncomment bellow this line - follow the example and adapt it to your DB table #
# #
####################################################################################
*/

$custom_config[$module_id][0]['custom_table'] = get_settings_value("table");
$custom_config[$module_id][0]['custom_table_primary_key'] = get_settings_value("id");
$custom_config[$module_id][0]['custom_table_order_by'] = $custom_config[$module_id][0]['custom_table_primary_key'];
$custom_config[$module_id][0]['per_page'] = 50;
$custom_config[$module_id][0]['page_range'] = 3;

/*
Columns definition:
- header - the header title used to label this column (mandatory)
- type - how to display/handle the data - text / combo / textarea (mandatory)
- key - the key restrictions for this column (they will be checked prior to DB op) - PRI/UNI (optional)
- tip - tip/explanation to be attached to this column in the add/edit forms (optional)
- validation_regex - a regular expression to check the inserted value; only for text type (optional)
- is_optional - if a value must be provided or not for the column (mandatory)
- show_in_add_form - if to be shown in the add form (optional)
- show_in_edit_form - if to be shown in the edit form (optional)
- searchable - if to be listed as field in the search form (optional)
- disabled - if the disabled attribute should be set to this column (optional)
- readonly - if the readonly attribute should be set to this column (optional)
- visible - if the column should be displayed in the table (optional)
- value_wrapper_func - php function like func($key, $text, $link) to return
a custom string to be displayed instead of the real value; parameters are:
- $key - the name of the column
- $text - the value of the column
- $link - an assoc array with all the values of the DB row( i.e $text = $link[$key] )
This function can be use to build links or images around the values to be displayed (optional).
- default_value - optional default value to pre-populate the column in the add form
- default_display - a default display text corresponding to the default value if the type is COMBO
- combo_default_values - assoc array (value -> display) for definiting static COMBOs
Example: array("1"=>"Yes","0"=>"No")
- combo_table, combo_value_col, combo_display_col, combo_hook_col - set of attributes for
defininig dynamic combos, with data from DB; table and value are mandatory in this
configuration; display may be optionaly used; similar the hook - this has no impact
over the display of the combo; it simply creates a "hook" attribute inside the
"option" html tag, which may be used by JS function to enable/disable/remove
the value during runtime.
- events - a string that optionaly may define JS events for the input/select field
Example: "onChange=\"runJSfunction();\" "
- textarea_display_size - optional value used when a textarea_label_column is not specified, and
indicates how many characters should be shown from the text area content. Default is 50.
*/

$config_name = get_settings_value("name");
$config_value = get_settings_value("value");
$config_desc = get_settings_value("description");

$custom_config[$module_id][0]['custom_table_column_defs'] = array (
$custom_config[$module_id][0]['custom_table_primary_key'] => array (
"header" => "ID",
"type" => "text",
"key" => "PRI",
"show_in_add_form" => false,
"show_in_edit_form" => false,
"searchable" => false,
"visible" => false
),
$config_name => array (
"header" => "Name",
"type" => "text",
"key" => NULL,
"tip" => "Name of the configuration to be used in the OpenSIPS script.",
"validation_regex" => NULL,
"show_in_add_form" => true,
"show_in_edit_form" => true,
"searchable" => true,
"is_optional" => "n",
"validation_regex" => "^[^:]+$",
),
$config_value => array (
"header" => "Value",
"type" => "text",
"key" => NULL,
"tip" => "The value of the configuration. If empty, NULL value is used.",
"validation_regex" => ".*",
"show_in_add_form" => true,
"show_in_edit_form" => true,
"searchable" => false,
"is_optional" => "y",
),
$config_desc => array (
"header" => "Description",
"type" => "text",
"key" => NULL,
"tip" => "Description of what the configuration does.",
"validation_regex" => ".*",
"show_in_add_form" => true,
"show_in_edit_form" => true,
"searchable" => false,
"is_optional" => "y",
"default_value" => "",
"keep_empty_str_val" => true,
),
);



//need to reload 0 or 1
$custom_config[$module_id][0]['reload'] = 1;

//if you need reload please specify the MI command to be ran
$custom_config[$module_id][0]['custom_mi_command'] = "sql_cacher_reload";

if (get_settings_value("config_id") != NULL)
$custom_config[$module_id][0]['custom_mi_command'] .= " " . get_settings_value("config_id");


//the system ID to send the reload MI command to
$talk_to_this_assoc_id = 1;


##############################################
######### CUSTOM SEARCH OPTIONS ##############
##############################################
$custom_config[$module_id][0]['custom_search'] = array ( "enabled" => true,
"action_script" => "custom_actions/search.php"
);

##############################################
####### CUSTOM ACTIONS COLUMNS ###############
##############################################

$custom_config[$module_id][0]['custom_action_columns'] = array (
"0" => array(
"header" => "Edit",
"show_header" => false,
"type" => "link",
"action" => "edit",
"icon" => "../../../images/share/edit.png",
"action_script" => "custom_actions/edit.php",
"action_template" => "template/custom_templates/edit.php"
),
"1" => array(
"header" => "Delete",
"show_header" => false,
"type" => "link",
"action" => "delete",
"icon" => "../../../images/share/delete.png",
"action_script" => "custom_actions/delete.php",
"action_template" => "template/custom_templates/delete.php",
"events" => "onclick=\"return confirmDelete()\""
)
);
##############################################
####### CUSTOM ACTIONS BUTTON ###############
##############################################

$custom_config[$module_id][0]['custom_action_buttons'] = array (
"0" => array(
"text" => "Add",
"action" => "add",
"style" => "formButton",
"action_script" => "custom_actions/add.php",
"action_template" => "template/custom_templates/add.php"
)
);

27 changes: 27 additions & 0 deletions web/tools/system/config/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* Copyright (C) 2024 OpenSIPS Solutions
*
* This file is part of opensips-cp, a free Web Control Panel Application for
* OpenSIPS SIP server.
*
* opensips-cp 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 2 of the License, or
* (at your option) any later version.
*
* opensips-cp 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

$branch = "system";
$module_id = "config";

require_once("../../../common/tools/tviewer/redirect.php");
?>

0 comments on commit b7589e5

Please sign in to comment.