Skip to content

Commit b7589e5

Browse files
rootrazvancrainea
root
authored andcommitted
add new config module
1 parent 69fab36 commit b7589e5

File tree

5 files changed

+387
-0
lines changed

5 files changed

+387
-0
lines changed

Diff for: config/modules.inc.php

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
"enabled" => true,
112112
"name" => "Clusterer"
113113
),
114+
"config" => array (
115+
"enabled" => true,
116+
"name" => "Config"
117+
),
114118
"keepalived" => array (
115119
"enabled" => true,
116120
"name" => "Keepalived"

Diff for: config/tools/system/config/db.inc.php

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*
3+
* $Id: db.inc.php 287 2011-10-17 09:41:35Z untiptun $
4+
* Copyright (C) 2011 OpenSIPS Project
5+
*
6+
* This file is part of opensips-cp, a free Web Control Panel Application for
7+
* OpenSIPS SIP server.
8+
*
9+
* opensips-cp is free software; you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation; either version 2 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* opensips-cp is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program; if not, write to the Free Software
21+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22+
*/
23+
24+
$module_id = "config";
25+
26+
// define for each submenu item
27+
//database driver
28+
# $custom_config[$module_id][0]['db_driver'] = "mysql";
29+
//database host
30+
# $custom_config[$module_id][0]['db_host'] = "";
31+
//database user
32+
# $custom_config[$module_id][0]['db_user'] = "";
33+
//database name
34+
# $custom_config[$module_id][0]['db_name'] = "";
35+
//database password
36+
# $custom_config[$module_id][0]['db_pass'] = "";
37+
//database port
38+
# $custom_config[$module_id][0]['db_port'] = "";
39+
40+
41+
?>

Diff for: config/tools/system/config/settings.inc.php

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/*
3+
* Copyright (C) 2022 OpenSIPS Solutions
4+
*
5+
* This file is part of opensips-cp, a free Web Control Panel Application for
6+
* OpenSIPS SIP server.
7+
*
8+
* opensips-cp is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* opensips-cp is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21+
*/
22+
23+
// $table_regex is used to validate custom tables names, you can leave this here
24+
// even if you don't add custom tables
25+
global $table_regex;
26+
global $config;
27+
28+
$config->config = array(
29+
"title0" => array(
30+
"type" => "title",
31+
"title" => "Database"
32+
),
33+
"db_config" => array(
34+
"default" => 0,
35+
"name" => "DB configuration",
36+
"type" => "dropdown",
37+
"options" => get_db_configs(),
38+
"tip" => "DB configuration to use for this tool."
39+
),
40+
"talk_to_this_assoc_id" => array(
41+
"default" => 1,
42+
"name" => "Linked system",
43+
"options" => get_assoc_id(),
44+
"type" => "dropdown",
45+
"tip" => "As OCP can manage multiple OpenSIPS instances, this is the association
46+
ID pointing to the group of servers (system) which needs to be provision with this siptrace status (on or off)."
47+
),
48+
49+
"table" => array(
50+
"default" => "config",
51+
"name" => "Table",
52+
"type" => "text",
53+
"validation_regex" => $table_regex,
54+
"tip" => "Table that stores the configuration data."
55+
),
56+
"id" => array(
57+
"default" => "id",
58+
"name" => "ID Column",
59+
"type" => "text",
60+
"validation_regex" => "^[0-9]+$",
61+
"tip" => "The column used as a primary id for a configuration entry."
62+
),
63+
"name" => array(
64+
"default" => "name",
65+
"name" => "Name Column",
66+
"type" => "text",
67+
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
68+
"tip" => "The column used for the configuration's name."
69+
),
70+
"value" => array(
71+
"default" => "value",
72+
"name" => "Value Column",
73+
"type" => "text",
74+
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
75+
"tip" => "The column used for the configuration's value."
76+
),
77+
"description" => array(
78+
"default" => "description",
79+
"name" => "Description Column",
80+
"type" => "text",
81+
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
82+
"tip" => "The column used for configuration entry description.",
83+
),
84+
"config_id" => array(
85+
"default" => "config",
86+
"name" => "Cacher Id",
87+
"type" => "text",
88+
"validation_regex" => "^[a-zA-Z][a-zA-Z0-9]*$",
89+
"tip" => "The name of the sql cacher id used in OpenSIPS configuration file.."
90+
),
91+
);

Diff for: config/tools/system/config/tviewer.inc.php

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
<?php
2+
/*
3+
* Copyright (C) 2014 OpenSIPS Project
4+
*
5+
* This file is part of opensips-cp, a free Web Control Panel Application for
6+
* OpenSIPS SIP server.
7+
*
8+
* opensips-cp is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* opensips-cp is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21+
*/
22+
23+
###############################################################################
24+
# Attention : advanced options !!
25+
26+
//this is a very important parameter
27+
$module_id = "config";
28+
$custom_config[$module_id] = array ();
29+
30+
// a custom global name for the tool
31+
$custom_config[$module_id]['custom_name'] = "Config";
32+
33+
34+
//if you want submenu (horizontal) items add them here:
35+
36+
// $custom_config[$module_id]['submenu_items'] = array(
37+
// "0" => "Submenu1",
38+
// "1" => "Submenu2"
39+
// );
40+
41+
42+
43+
44+
/* config for each submenu item */
45+
46+
/*
47+
Example table: table1
48+
+---------------+------------------+------+-----+---------+----------------+
49+
| Field | Type | Null | Key | Default | Extra |
50+
+---------------+------------------+------+-----+---------+----------------+
51+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
52+
| name | char(128) | NO | UNI | | |
53+
| address | char(128) | NO | | | |
54+
| age | int(10) unsigned | NO | | 0 | |
55+
| married | int(10) unsigned | NO | | 0 | |
56+
+---------------+------------------+------+-----+---------+----------------+
57+
58+
####################################################################################
59+
# #
60+
# Uncomment bellow this line - follow the example and adapt it to your DB table #
61+
# #
62+
####################################################################################
63+
*/
64+
65+
$custom_config[$module_id][0]['custom_table'] = get_settings_value("table");
66+
$custom_config[$module_id][0]['custom_table_primary_key'] = get_settings_value("id");
67+
$custom_config[$module_id][0]['custom_table_order_by'] = $custom_config[$module_id][0]['custom_table_primary_key'];
68+
$custom_config[$module_id][0]['per_page'] = 50;
69+
$custom_config[$module_id][0]['page_range'] = 3;
70+
71+
/*
72+
Columns definition:
73+
- header - the header title used to label this column (mandatory)
74+
- type - how to display/handle the data - text / combo / textarea (mandatory)
75+
- key - the key restrictions for this column (they will be checked prior to DB op) - PRI/UNI (optional)
76+
- tip - tip/explanation to be attached to this column in the add/edit forms (optional)
77+
- validation_regex - a regular expression to check the inserted value; only for text type (optional)
78+
- is_optional - if a value must be provided or not for the column (mandatory)
79+
80+
- show_in_add_form - if to be shown in the add form (optional)
81+
- show_in_edit_form - if to be shown in the edit form (optional)
82+
- searchable - if to be listed as field in the search form (optional)
83+
- disabled - if the disabled attribute should be set to this column (optional)
84+
- readonly - if the readonly attribute should be set to this column (optional)
85+
- visible - if the column should be displayed in the table (optional)
86+
- value_wrapper_func - php function like func($key, $text, $link) to return
87+
a custom string to be displayed instead of the real value; parameters are:
88+
- $key - the name of the column
89+
- $text - the value of the column
90+
- $link - an assoc array with all the values of the DB row( i.e $text = $link[$key] )
91+
This function can be use to build links or images around the values to be displayed (optional).
92+
93+
- default_value - optional default value to pre-populate the column in the add form
94+
- default_display - a default display text corresponding to the default value if the type is COMBO
95+
- combo_default_values - assoc array (value -> display) for definiting static COMBOs
96+
Example: array("1"=>"Yes","0"=>"No")
97+
- combo_table, combo_value_col, combo_display_col, combo_hook_col - set of attributes for
98+
defininig dynamic combos, with data from DB; table and value are mandatory in this
99+
configuration; display may be optionaly used; similar the hook - this has no impact
100+
over the display of the combo; it simply creates a "hook" attribute inside the
101+
"option" html tag, which may be used by JS function to enable/disable/remove
102+
the value during runtime.
103+
104+
- events - a string that optionaly may define JS events for the input/select field
105+
Example: "onChange=\"runJSfunction();\" "
106+
107+
- textarea_display_size - optional value used when a textarea_label_column is not specified, and
108+
indicates how many characters should be shown from the text area content. Default is 50.
109+
*/
110+
111+
$config_name = get_settings_value("name");
112+
$config_value = get_settings_value("value");
113+
$config_desc = get_settings_value("description");
114+
115+
$custom_config[$module_id][0]['custom_table_column_defs'] = array (
116+
$custom_config[$module_id][0]['custom_table_primary_key'] => array (
117+
"header" => "ID",
118+
"type" => "text",
119+
"key" => "PRI",
120+
"show_in_add_form" => false,
121+
"show_in_edit_form" => false,
122+
"searchable" => false,
123+
"visible" => false
124+
),
125+
$config_name => array (
126+
"header" => "Name",
127+
"type" => "text",
128+
"key" => NULL,
129+
"tip" => "Name of the configuration to be used in the OpenSIPS script.",
130+
"validation_regex" => NULL,
131+
"show_in_add_form" => true,
132+
"show_in_edit_form" => true,
133+
"searchable" => true,
134+
"is_optional" => "n",
135+
"validation_regex" => "^[^:]+$",
136+
),
137+
$config_value => array (
138+
"header" => "Value",
139+
"type" => "text",
140+
"key" => NULL,
141+
"tip" => "The value of the configuration. If empty, NULL value is used.",
142+
"validation_regex" => ".*",
143+
"show_in_add_form" => true,
144+
"show_in_edit_form" => true,
145+
"searchable" => false,
146+
"is_optional" => "y",
147+
),
148+
$config_desc => array (
149+
"header" => "Description",
150+
"type" => "text",
151+
"key" => NULL,
152+
"tip" => "Description of what the configuration does.",
153+
"validation_regex" => ".*",
154+
"show_in_add_form" => true,
155+
"show_in_edit_form" => true,
156+
"searchable" => false,
157+
"is_optional" => "y",
158+
"default_value" => "",
159+
"keep_empty_str_val" => true,
160+
),
161+
);
162+
163+
164+
165+
//need to reload 0 or 1
166+
$custom_config[$module_id][0]['reload'] = 1;
167+
168+
//if you need reload please specify the MI command to be ran
169+
$custom_config[$module_id][0]['custom_mi_command'] = "sql_cacher_reload";
170+
171+
if (get_settings_value("config_id") != NULL)
172+
$custom_config[$module_id][0]['custom_mi_command'] .= " " . get_settings_value("config_id");
173+
174+
175+
//the system ID to send the reload MI command to
176+
$talk_to_this_assoc_id = 1;
177+
178+
179+
##############################################
180+
######### CUSTOM SEARCH OPTIONS ##############
181+
##############################################
182+
$custom_config[$module_id][0]['custom_search'] = array ( "enabled" => true,
183+
"action_script" => "custom_actions/search.php"
184+
);
185+
186+
##############################################
187+
####### CUSTOM ACTIONS COLUMNS ###############
188+
##############################################
189+
190+
$custom_config[$module_id][0]['custom_action_columns'] = array (
191+
"0" => array(
192+
"header" => "Edit",
193+
"show_header" => false,
194+
"type" => "link",
195+
"action" => "edit",
196+
"icon" => "../../../images/share/edit.png",
197+
"action_script" => "custom_actions/edit.php",
198+
"action_template" => "template/custom_templates/edit.php"
199+
),
200+
"1" => array(
201+
"header" => "Delete",
202+
"show_header" => false,
203+
"type" => "link",
204+
"action" => "delete",
205+
"icon" => "../../../images/share/delete.png",
206+
"action_script" => "custom_actions/delete.php",
207+
"action_template" => "template/custom_templates/delete.php",
208+
"events" => "onclick=\"return confirmDelete()\""
209+
)
210+
);
211+
##############################################
212+
####### CUSTOM ACTIONS BUTTON ###############
213+
##############################################
214+
215+
$custom_config[$module_id][0]['custom_action_buttons'] = array (
216+
"0" => array(
217+
"text" => "Add",
218+
"action" => "add",
219+
"style" => "formButton",
220+
"action_script" => "custom_actions/add.php",
221+
"action_template" => "template/custom_templates/add.php"
222+
)
223+
);
224+

Diff for: web/tools/system/config/index.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/*
3+
* Copyright (C) 2024 OpenSIPS Solutions
4+
*
5+
* This file is part of opensips-cp, a free Web Control Panel Application for
6+
* OpenSIPS SIP server.
7+
*
8+
* opensips-cp is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation; either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* opensips-cp is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program; if not, write to the Free Software
20+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21+
*/
22+
23+
$branch = "system";
24+
$module_id = "config";
25+
26+
require_once("../../../common/tools/tviewer/redirect.php");
27+
?>

0 commit comments

Comments
 (0)