From d266e296a65e7d49bc428ce4ebde7506b33dc124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 7 Feb 2020 16:00:58 +1100 Subject: [PATCH 1/5] Preparing skelethon for web ui --- include/Web_Interface.hpp | 13 ++++++++++ include/proxysql_glovars.hpp | 1 + src/main.cpp | 49 +++++++++++++++++++++++++++++++++++- src/proxysql.cfg | 1 + 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 include/Web_Interface.hpp diff --git a/include/Web_Interface.hpp b/include/Web_Interface.hpp new file mode 100644 index 0000000000..03eb2ef9e8 --- /dev/null +++ b/include/Web_Interface.hpp @@ -0,0 +1,13 @@ +#ifndef CLASS_WEB_INTERFACE +#define CLASS_WEB_INTERFACE + +class Web_Interface { + public: + Web_Interface() {}; + virtual ~Web_Interface() {}; + virtual void print_version() {}; +}; + +typedef Web_Interface * create_Web_Interface_t(); + +#endif /* CLASS_WEB_INTERFACE */ diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index b2ec57e352..6c4f0f46f9 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -57,6 +57,7 @@ class ProxySQL_GlobalVariables { char *pid; int restart_on_missing_heartbeats; char * execute_on_exit_failure; + char * web_interface_plugin; char * ldap_auth_plugin; struct { unsigned long long start_time; diff --git a/src/main.cpp b/src/main.cpp index 6009f88942..2798d23fe2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include "MySQL_Authentication.hpp" #include "MySQL_LDAP_Authentication.hpp" #include "proxysql_restapi.h" +#include "Web_Interface.hpp" #include @@ -40,6 +41,9 @@ extern "C" MySQL_LDAP_Authentication * create_MySQL_LDAP_Authentication_func() { volatile create_MySQL_LDAP_Authentication_t * create_MySQL_LDAP_Authentication = NULL; void * __mysql_ldap_auth; +volatile create_Web_Interface_t * create_Web_Interface = NULL; +void * __web_interface; + // absolute path of ssl files char *ssl_key_fp = NULL; char *ssl_cert_fp = NULL; @@ -695,7 +699,7 @@ ClickHouse_Authentication *GloClickHouseAuth; Query_Processor *GloQPro; ProxySQL_Admin *GloAdmin; MySQL_Threads_Handler *GloMTH = NULL; - +Web_Interface *GloWebInterface; MySQL_STMT_Manager_v14 *GloMyStmt; MySQL_Monitor *GloMyMon; @@ -819,6 +823,14 @@ void ProxySQL_Main_process_global_variables(int argc, const char **argv) { GloVars.errorlog = strdup(errorlog_path.c_str()); } } + if (root.exists("web_interface_plugin")==true) { + string web_interface_plugin; + bool rc; + rc=root.lookupValue("web_interface_plugin", web_interface_plugin); + if (rc==true) { + GloVars.web_interface_plugin=strdup(web_interface_plugin.c_str()); + } + } if (root.exists("ldap_auth_plugin")==true) { string ldap_auth_plugin; bool rc; @@ -966,6 +978,9 @@ void ProxySQL_Main_init_Query_module() { GloQPro->print_version(); GloAdmin->init_mysql_query_rules(); GloAdmin->init_mysql_firewall(); + if (GloWebInterface) { + GloWebInterface->print_version(); + } } void ProxySQL_Main_init_MySQL_Threads_Handler_module() { @@ -1184,6 +1199,35 @@ void ProxySQL_Main_init() { static void LoadPlugins() { + if (GloVars.web_interface_plugin) { + dlerror(); + char * dlsym_error = NULL; + dlerror(); + dlsym_error=NULL; + __web_interface = dlopen(GloVars.web_interface_plugin, RTLD_NOW); + if (!__web_interface) { + cerr << "Cannot load library: " << dlerror() << '\n'; + exit(EXIT_FAILURE); + } else { + dlerror(); + create_Web_Interface = (create_Web_Interface_t *) dlsym(__web_interface, "create_Web_Interface_func"); + dlsym_error = dlerror(); + if (dlsym_error!=NULL) { + cerr << "Cannot load symbol create_Web_Interface: " << dlsym_error << '\n'; + exit(EXIT_FAILURE); + } + } + if (__web_interface==NULL || dlsym_error) { + proxy_error("Unable to load Web_Interface from %s\n", GloVars.web_interface_plugin); + exit(EXIT_FAILURE); + } else { + GloWebInterface = create_Web_Interface(); + if (GloWebInterface) { + //GloAdmin->init_WebInterfacePlugin(); + //GloAdmin->load_ldap_variables_to_runtime(); + } + } + } if (GloVars.ldap_auth_plugin) { dlerror(); char * dlsym_error = NULL; @@ -1814,6 +1858,9 @@ int main(int argc, const char * argv[]) { #ifdef RUNNING_ON_VALGRIND if (RUNNING_ON_VALGRIND==0) { + if (__web_interface) { + dlclose(__web_interface); + } if (__mysql_ldap_auth) { dlclose(__mysql_ldap_auth); } diff --git a/src/proxysql.cfg b/src/proxysql.cfg index e3fe5cd4d0..480b811d2f 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -8,6 +8,7 @@ restart_on_missing_heartbeats=10 datadir="/var/lib/proxysql" //execute_on_exit_failure="/path/to/script" //ldap_auth_plugin="../../proxysql_ldap_plugin/MySQL_LDAP_Authentication_plugin.so" +//web_interface_plugin="../web_interface_plugin/Web_Interface_Plugin.so admin_variables= { From 238aeb87980dca494f5a080a886f72e8acbe1e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 9 Feb 2020 15:11:23 +1100 Subject: [PATCH 2/5] Preparing the API for web interface plugin --- include/Web_Interface.hpp | 2 ++ lib/ProxySQL_Admin.cpp | 62 ++++++++++++++++++++++++--------------- src/main.cpp | 14 +++++---- src/proxysql.cfg | 2 +- 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/include/Web_Interface.hpp b/include/Web_Interface.hpp index 03eb2ef9e8..65640f67e2 100644 --- a/include/Web_Interface.hpp +++ b/include/Web_Interface.hpp @@ -5,6 +5,8 @@ class Web_Interface { public: Web_Interface() {}; virtual ~Web_Interface() {}; + virtual void start(int p) {}; + virtual void stop() {}; virtual void print_version() {}; }; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index f76ec125cc..f4d9ee790e 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -20,6 +20,8 @@ #include "MySQL_Logger.hpp" #include "SQLite3_Server.h" +#include "Web_Interface.hpp" + #include #include #include @@ -236,6 +238,8 @@ extern MySQL_Logger *GloMyLogger; extern MySQL_STMT_Manager_v14 *GloMyStmt; extern MySQL_Monitor *GloMyMon; +extern Web_Interface *GloWebInterface; + extern ProxySQL_Cluster *GloProxyCluster; #ifdef PROXYSQLCLICKHOUSE extern ClickHouse_Authentication *GloClickHouseAuth; @@ -5290,29 +5294,7 @@ void ProxySQL_Admin::flush_admin_variables___database_to_runtime(SQLite3DB *db, } if (variables.web_enabled != variables.web_enabled_old) { if (variables.web_enabled) { - char *key_pem; - char *cert_pem; - key_pem = load_file(ssl_key_fp); - cert_pem = load_file(ssl_cert_fp); - Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_SSL, - variables.web_port, - NULL, NULL, http_handler, NULL, - MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, - MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 4, - MHD_OPTION_NONCE_NC_SIZE, (unsigned int) 300, - MHD_OPTION_HTTPS_MEM_KEY, key_pem, - MHD_OPTION_HTTPS_MEM_CERT, cert_pem, - MHD_OPTION_END); - } else { - MHD_stop_daemon(Admin_HTTP_Server); - Admin_HTTP_Server = NULL; - } - variables.web_enabled_old = variables.web_enabled; - } else { - if (variables.web_port != variables.web_port_old) { - if (variables.web_enabled) { - MHD_stop_daemon(Admin_HTTP_Server); - Admin_HTTP_Server = NULL; + if (GloVars.web_interface_plugin == NULL) { char *key_pem; char *cert_pem; key_pem = load_file(ssl_key_fp); @@ -5326,6 +5308,40 @@ void ProxySQL_Admin::flush_admin_variables___database_to_runtime(SQLite3DB *db, MHD_OPTION_HTTPS_MEM_KEY, key_pem, MHD_OPTION_HTTPS_MEM_CERT, cert_pem, MHD_OPTION_END); + } else { + GloWebInterface->start(variables.web_port); + } + } else { + if (GloVars.web_interface_plugin == NULL) { + MHD_stop_daemon(Admin_HTTP_Server); + Admin_HTTP_Server = NULL; + } else { + GloWebInterface->stop(); + } + } + variables.web_enabled_old = variables.web_enabled; + } else { + if (variables.web_port != variables.web_port_old) { + if (variables.web_enabled) { + if (GloVars.web_interface_plugin == NULL) { + MHD_stop_daemon(Admin_HTTP_Server); + Admin_HTTP_Server = NULL; + char *key_pem; + char *cert_pem; + key_pem = load_file(ssl_key_fp); + cert_pem = load_file(ssl_cert_fp); + Admin_HTTP_Server = MHD_start_daemon(MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_SSL, + variables.web_port, + NULL, NULL, http_handler, NULL, + MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, + MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) 4, + MHD_OPTION_NONCE_NC_SIZE, (unsigned int) 300, + MHD_OPTION_HTTPS_MEM_KEY, key_pem, + MHD_OPTION_HTTPS_MEM_CERT, cert_pem, + MHD_OPTION_END); + } else { + GloWebInterface->start(variables.web_port); + } } variables.web_port_old = variables.web_port; } diff --git a/src/main.cpp b/src/main.cpp index 2798d23fe2..005c3fd770 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -530,9 +530,10 @@ int ssl_mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days) { proxy_error("Unable to run EVP_PKEY_assign_RSA()\n"); exit(EXIT_SUCCESS); // we exit gracefully to avoid being restarted } - x1 = generate_x509(pk, (const unsigned char *)"ProxySQL_Auto_Generated_CA_Certificate", 2, 3650, NULL, NULL); + time_t t = time(NULL); + x1 = generate_x509(pk, (const unsigned char *)"ProxySQL_Auto_Generated_CA_Certificate", t, 3650, NULL, NULL); write_x509(ssl_ca_fp, x1); - x2 = generate_x509(pk, (const unsigned char *)"ProxySQL_Auto_Generated_Server_Certificate", 3, 3650, x1, pk); + x2 = generate_x509(pk, (const unsigned char *)"ProxySQL_Auto_Generated_Server_Certificate", t, 3650, x1, pk); write_x509(ssl_cert_fp, x2); rsa = NULL; @@ -978,9 +979,9 @@ void ProxySQL_Main_init_Query_module() { GloQPro->print_version(); GloAdmin->init_mysql_query_rules(); GloAdmin->init_mysql_firewall(); - if (GloWebInterface) { - GloWebInterface->print_version(); - } +// if (GloWebInterface) { +// GloWebInterface->print_version(); +// } } void ProxySQL_Main_init_MySQL_Threads_Handler_module() { @@ -1262,6 +1263,8 @@ static void LoadPlugins() { void ProxySQL_Main_init_phase2___not_started() { + LoadPlugins(); + ProxySQL_Main_init_main_modules(); ProxySQL_Main_init_Admin_module(); GloMTH->print_version(); @@ -1278,7 +1281,6 @@ void ProxySQL_Main_init_phase2___not_started() { GloVars.confFile->CloseFile(); } - LoadPlugins(); ProxySQL_Main_init_Auth_module(); diff --git a/src/proxysql.cfg b/src/proxysql.cfg index 480b811d2f..d210cc56ea 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -8,7 +8,7 @@ restart_on_missing_heartbeats=10 datadir="/var/lib/proxysql" //execute_on_exit_failure="/path/to/script" //ldap_auth_plugin="../../proxysql_ldap_plugin/MySQL_LDAP_Authentication_plugin.so" -//web_interface_plugin="../web_interface_plugin/Web_Interface_Plugin.so +web_interface_plugin="../../proxysql_web_interface_plugin/src/Web_Interface_plugin.so" admin_variables= { From c4607d94fea4eadd3cd0309e33a5e092fc43d0a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sun, 9 Feb 2020 23:25:32 +1100 Subject: [PATCH 3/5] class Web_Interface_plugin friends Query_Processor --- include/proxysql_structs.h | 1 + include/query_processor.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/proxysql_structs.h b/include/proxysql_structs.h index 8e61c23999..efa51eed30 100644 --- a/include/proxysql_structs.h +++ b/include/proxysql_structs.h @@ -409,6 +409,7 @@ class ProxySQL_Cluster; class MySQL_ResultSet; class Query_Processor_Output; class MySrvC; +class Web_Interface_plugin; #endif /* PROXYSQL_CLASSES */ //#endif /* __cplusplus */ diff --git a/include/query_processor.h b/include/query_processor.h index 41c7318f91..3166768c51 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -374,6 +374,7 @@ class Query_Processor { SQLite3_result * get_mysql_firewall_whitelist_rules(); SQLite3_result * get_mysql_firewall_whitelist_sqli_fingerprints(); bool whitelisted_sqli_fingerprint(char *); + friend Web_Interface_plugin; }; typedef Query_Processor * create_Query_Processor_t(); From bc65ceeac60ffda20cd920b98056cbb80b571491 Mon Sep 17 00:00:00 2001 From: Valentin Rakush Date: Mon, 17 Feb 2020 09:55:26 +0000 Subject: [PATCH 4/5] added configuration data from web interface plugin testing --- Makefile | 2 +- src/proxysql.cfg | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9a485a79f1..2a7ec040a6 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ EXTRALINK=#-pg ALL_DEBUG=-ggdb -DDEBUG NO_DEBUG= DEBUG=${ALL_DEBUG} -#export DEBUG +export DEBUG #export OPTZ #export EXTRALINK export MAKE diff --git a/src/proxysql.cfg b/src/proxysql.cfg index d210cc56ea..d947189bd3 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -94,6 +94,51 @@ mysql_replication_hostgroups= } ) +mysql_galera_hostgroups= +( + { + writer_hostgroup=10 + backup_writer_hostgroup=20 + reader_hostgroup=30 + offline_hostgroup=40 + active=0 + max_writers=3 + writer_is_also_readder=0 + max_transactions_behind=10 + comment="comment aws 1" + }, + { + writer_hostgroup=110 + backup_writer_hostgroup=120 + reader_hostgroup=130 + offline_hostgroup=140 + active=0 + max_writers=3 + writer_is_also_readder=0 + max_transactions_behind=10 + comment="comment aws 2" + } +) + +mysql_aws_aurora_hostgroups= +( + { + writer_hostgroup=10 + reader_hostgroup=20 + active=0 + aurora_port=3306 + domain_name=".aws1.com" + max_lag_ms=30000 + check_interval_ms=6000 + check_timeout_ms=700 + writer_is_also_readder=0 + new_reader_weight=100 + add_lag_ms=100 + min_lag_ms=200 + lag_num_checks=10 + comment="comment aws 1" + } +) mysql_group_replication_hostgroups= ( From 9bdab2e8f083abc0af4cf69bf747ddd50b2ed788 Mon Sep 17 00:00:00 2001 From: val Date: Mon, 17 Feb 2020 18:16:56 +0000 Subject: [PATCH 5/5] revert previous commit --- Makefile | 2 +- src/proxysql.cfg | 45 --------------------------------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 2a7ec040a6..9a485a79f1 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ EXTRALINK=#-pg ALL_DEBUG=-ggdb -DDEBUG NO_DEBUG= DEBUG=${ALL_DEBUG} -export DEBUG +#export DEBUG #export OPTZ #export EXTRALINK export MAKE diff --git a/src/proxysql.cfg b/src/proxysql.cfg index d947189bd3..d210cc56ea 100644 --- a/src/proxysql.cfg +++ b/src/proxysql.cfg @@ -94,51 +94,6 @@ mysql_replication_hostgroups= } ) -mysql_galera_hostgroups= -( - { - writer_hostgroup=10 - backup_writer_hostgroup=20 - reader_hostgroup=30 - offline_hostgroup=40 - active=0 - max_writers=3 - writer_is_also_readder=0 - max_transactions_behind=10 - comment="comment aws 1" - }, - { - writer_hostgroup=110 - backup_writer_hostgroup=120 - reader_hostgroup=130 - offline_hostgroup=140 - active=0 - max_writers=3 - writer_is_also_readder=0 - max_transactions_behind=10 - comment="comment aws 2" - } -) - -mysql_aws_aurora_hostgroups= -( - { - writer_hostgroup=10 - reader_hostgroup=20 - active=0 - aurora_port=3306 - domain_name=".aws1.com" - max_lag_ms=30000 - check_interval_ms=6000 - check_timeout_ms=700 - writer_is_also_readder=0 - new_reader_weight=100 - add_lag_ms=100 - min_lag_ms=200 - lag_num_checks=10 - comment="comment aws 1" - } -) mysql_group_replication_hostgroups= (