1 include
1.1 global_arrays_php
后期的汉化工作可以从此入手
global先引入项目基础数组,在通过api_plugin_hook('config_arrays')引入pa以及plugin自定义的数组,具体调用过程是去plugin_hooks表中查询处所有hook=config_arrays的记录,然后调用他们的function字段的方法。
其中pa的例子如下:
调用了plugin_config_arrays方法,添加了$menu['Configuration']['plugins.php'] = 'Plugin Management';
以及api_plugin_load_realms();用户插件的认证范围
array_name | chinese | position |
---|---|---|
$menu | 菜单 | |
$messages | ||
$cdef_operators | cdef操作符 | |
$cdef_functions | cdef数学函数 | |
$input_types | dataInput类型 | |
$reindex_types | dataQuery类型 | |
$snmp_query_field_actions | snmp查询字段行为 | |
$consolidation_functions | 合并方法 | |
$data_source_types | dataSource类型 | |
$graph_item_types | 绘制图片类型 | |
$image_types | 图片格式 | |
$snmp_versions | snmp版本 | |
$snmp_auth_protocols | snmp认证协议 | |
$snmp_priv_protocols | snmp权限协议 | |
$banned_snmp_strings | 禁止snmp的提示字符串 | |
$logfile_options | 日志文件选项 | |
$availability_options | 可用选项 | |
$ping_methods | ping方法 | |
$logfile_verbosity | 日志文件常用提示 | |
$poller_options | 轮训选项 | |
$poller_intervals | 轮训间隔 | |
$device_threads | 设备线程 | |
$cron_intervals | 定时任务间隔 | |
$registered_cacti_names | 注册cacti名称 | |
$graph_views | 图片视图 | |
$graph_tree_views | 图片树形视图 | |
$auth_methods | 认证方式 | |
$auth_realms | 认证范围 | |
$ldap_versions | ldap版本 | |
$ldap_encryption | ldap加密方式 | |
$ldap_modes | ldap模式 | |
$snmp_implimentations | snmp连接方式 | |
$rrdtool_versions | rrdtool版本 | |
$cdef_item_types | cdef选项类型 | |
$graph_color_alpha | 图片颜色透明度 | |
$tree_sort_types | 树形排序类型 | |
$tree_item_types | 树形节点类型 | |
$host_group_types | host分组类型 | |
$custom_data_source_types | 自定义dataSource类型 | |
$log_tail_lines | 日志文件结尾行数 | |
$item_rows | 行数选项 | |
$graphs_per_page | 每页图片数 | |
$page_refresh_interval | 页面刷新间隔 | |
$user_auth_realms | 用户认证范围 | |
$user_auth_realm_filenames | 用户认证范围文件名 | |
$hash_type_codes | 散列类型代码 | |
$hash_version_codes | 散列版本代码 | |
$hash_type_names | 散列类型名称 | |
$host_struc | host结构 | |
$graph_timespans | 图片时间元素 | |
$graph_timeshifts | 图片时间切换 | |
$graph_weekdays | 图片周日期 | |
$graph_dateformats | 图片日期格式 | |
$graph_datechar | 图片日期间隔符 | |
$plugin_architecture | pa版本 |
1.2 global_settings_php
与global_arrays类似,
global先引入项目settings基础数组,在通过api_plugin_hook('config_settings')引入pa以及plugin的settings数组,
name | chinese | position |
---|---|---|
$tabs | setting的tab | setting页面 |
$tabs_graphs | setting的tag图片 | setting页面 |
$settings | 所有设置选项 | setting页面 |
$settings_graphs | 所有设置选项控件类型等 | setting页面 |
1.3 global_form_php
定义了一个VALID_HOST_FIELDS
有效的host字段
包括
(hostname|host_id|snmp_community|snmp_username|snmp_password|snmp_auth_protocol|snmp_priv_passphrase|snmp_priv_protocol|snmp_context|snmp_version|snmp_port|snmp_timeout)
通过定义所有的form数组好处是:可以统一一套array,真正绘制input的时候可以调用inject_form_variables()来防止input的所有属性的inject注入,过滤非法字符等,然后通过定义的draw_edit_form,来统一绘制form表单的所有input
最后调用了一个api_plugin_hook(‘config_form’);
此过程和grobal_array以及global_form相同,这里不再赘述;
name | chinese | position |
---|---|---|
$fields_cdef_edit | file: cdef.php, action: edit | |
$fields_color_edit | file: color.php, action: edit | |
$fields_data_input_edit | file: data_input.php, action: edit | |
$fields_data_input_field_edit_1 | file: data_input.php, action: field_edit (dropdown) | |
$fields_data_input_field_edit_2 | file: data_input.php, action: field_edit (textbox) | |
$fields_data_input_field_edit | file: data_input.php, action: field_edit | |
$fields_data_template_template_edit | file: data_templates.php, action: template_edit | |
$struct_data_source | file: (data_sources.php|data_templates.php), action: (ds/template)_edit | |
$struct_data_source_item | file: (data_sources.php|data_templates.php), action: (ds/template)_edit | |
$fields_grprint_presets_edit | file: grprint_presets.php, action: edit | |
$struct_graph | file: (graphs.php/graph_templates.php), action: (graph/template)_edit | |
$struct_graph_item | file: (graphs.php/graph_templates.php), action: item_edit | |
$fields_graph_template_template_edit | file: graph_templates.php, action: template_edit | |
$fields_graph_template_input_edit | file: graph_templates.php, action: input_edit | |
$fields_host_edit | file: host.php, action: edit | |
$fields_host_template_edit | file: host_templates.php, action: edit | |
$fields_rra_edit | file: rra.php, action: edit | |
$fields_data_query_edit | file: data_queries.php, action: edit | |
$fields_data_query_item_edit | file: data_queries.php, action: item_edit | |
$fields_tree_edit | file: tree.php, action: edit | |
$fields_user_user_edit_host | file: user_admin.php, action: user_edit (host) | |
$export_types | all | |
$fields_template_import | all |
2 lib
2.1 html_php
包含了所有组装控件的方法,即function
name | param | function |
---|---|---|
html_start_box | $title, $width, $background_color, $cell_padding, $align, $add_text | draws the start of an HTML box with an optional title |
html_end_box | $trailing_br = true | draws the end of an HTML box |
html_graph_start_box | $cellpadding = 3, $leading_br = true | draws the start of an HTML graph view box |
html_graph_end_box | / | draws the end of an HTML graph view box |
html_graph_area | &$graph_array, $no_graphs_message = “”, $extra_url_args = “”, $header = “” | draws an area the contains full sized graphs |
html_graph_thumbnail_area | &$graph_array, $no_graphs_message = “”, $extra_url_args = “”, $header = “” | draws an area the contains thumbnail sized graphs |
html_nav_bar | $background_color, $colspan, $current_page, $rows_per_page, $total_rows, $nav_url | draws a navigation bar which includes previous/next links as well as currentpage information |
html_header_sort | $header_items, $sort_column, $sort_direction, $last_item_colspan = 1 | draws a header row suitable for display inside of a box element. When a user selects a column header, the collback function “filename” will be called to handle the sort the column and display the altered results. |
html_header_sort_checkbox | $header_items, $sort_column, $sort_direction, $include_form = true, $form_action = “” | draws a header row with a ‘select all’ checkbox in the last cell suitable for display inside of a box element. When a user selects a column header, the collback function “filename” will be called to handle the sort the column and display the altered results. |
html_header | $header_items, $last_item_colspan = 1 | draws a header row suitable for display inside of a box element |
html_header_checkbox | $header_items, $include_form = true, $form_action = “” | draws a header row with a ‘select all’ checkbox in the last cell suitable for display inside of a box element |
html_create_list | $form_data, $column_display, $column_id, $form_previous_value | draws the items for an html dropdown given an array of data |
html_split_string | $string, $length = 70, $forgiveness = 10 | takes a string and breaks it into a number of separated segments |
draw_graph_items_list | $item_list, $filename, $url_data, $disable_controls | draws a nicely formatted list of graph items for display on an edit form |
draw_menu | / | draw_menu - draws the cacti menu for display in the console |
draw_actions_dropdown | $actions_array | draws a table the allows the user to select an action to perform on one or more data elements |
DrawMatrixHeaderItem | $matrix_name, $matrix_text_color, $column_span = 1 | Deprecated functions |
form_area | / | / |
2.2 html_form_php
包含了所有组装包含form控件的方法,即function
name | param | function |
---|---|---|
draw_edit_form | $array | draws an html edit form |
draw_edit_control | $field_name, &$field_array | draws a single control to be used on an html edit form |
form_file | $form_name, $form_size = 30 | draws a standard html file input element |
form_filepath_box | $form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = “text”, $current_id = 0 | draws a standard html textbox and provides status of a files existence |
form_dirpath_box | $form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = “text”, $current_id = 0 | draws a standard html textbox and provides status of a directories existence |
form_text_box | $form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = “text”, $current_id = 0 | draws a standard html textbox |
form_hidden_box | $form_name, $form_previous_value, $form_default_value | draws a standard html hidden element |
form_dropdown | $form_name, $form_data, $column_display, $column_id, $form_previous_value, $form_none_entry, $form_default_value, $class = “”, $on_change = “” | draws a standard html dropdown box |
form_checkbox | $form_name, $form_previous_value, $form_caption, $form_default_value, $current_id = 0, $class = “”, $on_change = “” | draws a standard html checkbox |
form_radio_button | $form_name, $form_previous_value, $form_current_value, $form_caption, $form_default_value, $class = “”, $on_change = “” | draws a standard html radio button |
form_text_area | $form_name, $form_previous_value, $form_rows, $form_columns, $form_default_value, $class = “”, $on_change = “” | draws a standard html text area box |
form_multi_dropdown | $form_name, $array_display, $sql_previous_values, $column_id, $class = “”, $on_change = “” | draws a standard html multiple select dropdown |
form_color_dropdown | $form_name, $form_previous_value, $form_none_entry, $form_default_value, $class = “”, $on_change = “” | draws a dropdown containing a list of colors that uses a bit of css magic to make the dropdown item background color represent each color in the list |
form_font_box | $form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = “text”, $current_id = 0 | draws a standard html textbox and provides status of a fonts existence |
form_confirm | $title_text, $body_text, $cancel_url, $action_url | draws a table presenting the user with some choice and allowing them to either proceed (delete) or cancel |
form_confirm_buttons | $action_url, $cancel_url | draws a cancel and delete button suitable for display on a confirmation form |
form_save_button | $cancel_url, $force_type = “”, $key_field = “id” | draws a (save/create) and cancel button at the bottom of an html edit form |
2.3 html_utility_php
name | param | function |
---|---|---|
inject_form_variables | &$form_array, $arg1=array(), $arg2=array(), $arg3=array(), $arg4=array() | replaces all variables contained in $form_array with their actual values |
form_alternate_row_color | $row_color1, $row_color2, $row_value, $row_id = “” | starts an HTML row with an alternating color scheme |
form_selectable_cell | $contents, $id, $width=”“, $style=”“ | format’s a table row such that it can be highlighted using cacti’s js actions |
form_checkbox_cell | $title, $id | format’s a tables checkbox form element so that the cacti js actions work on it |
form_end_row | / | ends a table row that is started with form_alternate_row |
html_boolean | $html_boolean | returns the boolean equivalent of an HTML checkbox value |
html_boolean_friendly | $html_boolean | returns the natural language equivalent of an HTML checkbox value |
get_checkbox_style | / | finds the proper CSS padding to apply based on the current client browser in use |
get_request_var | $name, $default = “” | returns the current value of a PHP $_GET variable, optionallyreturning a default value if the request variable does not exist |
get_request_var_post | $name, $default = “” | returns the current value of a PHP $_POST variable, optionally returning a default value if the request variable does not exist |
get_request_var_request | $name, $default = “” | returns the current value of a PHP $_POST variable, optionally returning a default value if the request variable does not exist |
load_current_session_value | $request_var_name, $session_var_name, $default_value | finds the correct value of a variable that is being cached as a session variable on an HTML form |
get_colored_device_status | $disabled, $status | given a device’s status, return the colored text in HTML format suitable for display |
get_current_graph_start | / | determine the correct graph start time selected using the timespan selector |
get_current_graph_end | / | determine the correct graph end time selected using the timespan selector |
get_page_list | $current_page, $pages_per_screen, $rows_per_page, $total_rows, $url, $page_var = “page” | generates the html necessary to present the user with a list of pages limited in length and number of rows per page |
2.4 html_validate_php
html表单验证类
name | param | function |
---|---|---|
input_validate_input_equals | $value, $c_value | 验证两个input的值是否相等,使用的是!=,是strict比较 |
input_validate_input_number | $value | 验证是否是数字 |
input_validate_input_regex | $value, $regex | 验证value是否匹配传入的正则 |
die_html_input_error | / | 输出Validation error |
2.5 variables_php
variables.php浅析:
正如它内部的function name一样,它的功能就是更新的data_source_title_cache以及graph_title_cache。
data_source_title_cache就是data_template_data表中的name_cache字段,至于更新的原因则是与name字段解析同步。(具体参考表中对该字段的注释)
同理graph_title_cache就是graph_template_graph表中的title和title_cache字段。
name | param | function |
---|---|---|
update _data_source_title_cache _from_template | $data_template_id | updates the title cache for all data sources that match a given data template |
update _data_source_title_cache _from_query | $snmp_query_id, $snmp_index | updates the title cache for all data sources that match a given data query/index combination |
update _data_source_title_cache _from_host | $host_id | updates the title cache for all data sources that match a given host |
update _data_source_title_cache | $local_data_id | updates the title cache for a single data source |
update _graph_title_cache _from_template | $graph_template_id | updates the title cache for all graphs that match a given graph template |
update _graph_title_cache _from_query | $snmp_query_id, $snmp_index | updates the title cache for all graphs that match a given data query/index combination |
update_graph_title_cache _from_host | $host_id | updates the title cache for all graphs that match a given host |
update _graph_title_cache | $local_graph_id | updates the title cache for a single graph |
null_out_substitutions | $string | takes a string and cleans out any host variables that do not have values |
expand_title | $host_id, $snmp_query_id, $snmp_index, $title | takes a string and substitutes all data query variables contained in it or cleans them out if no data query is in use |
substitute _script_query_path | $path | takes a string and substitutes all path variables contained in it |
substitute _host_data | $string, $l_escape_string, $r_escape_string, $host_id | takes a string and substitutes all host variables contained in it |
substitute _snmp_query_data | $string, $host_id, $snmp_query_id, $snmp_index, $max_chars = 0 | takes a string and substitutes all data query variables contained in it |
substitute _data_input_data | $string, $graph, $local_data_id, $max_chars = 0 | takes a string and substitutes all data input variables contained in it |
2.6 auth.php
name | param | function |
---|---|---|
user_copy | $template_user, $new_user, $template_realm = 0, $new_realm = 0, $overwrite = false, $data_override = array() | copies user account |
user_remove | $user_id | remove a user account |
user_disable | $user_id | disable a user account |
user_enable | $user_id | enable a user account |
get_graph_permissions_sql | $policy_graphs, $policy_hosts, $policy_graph_templates | creates SQL that reprents the current graph, host and graph template policies |
is_graph_allowed | $local_graph_id | determines whether the current user is allowed to view a certain graph |
is_tree_allowed | $tree_id | determines whether the current user is allowed to view a certain graph tree |