Skip to content

Commit

Permalink
Merge pull request #2531 from sysown/v2.0.9-web2
Browse files Browse the repository at this point in the history
V2.0.9 web2
  • Loading branch information
renecannao authored Feb 17, 2020
2 parents b3e9459 + 9bdab2e commit 7ee01a0
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 27 deletions.
15 changes: 15 additions & 0 deletions include/Web_Interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef CLASS_WEB_INTERFACE
#define CLASS_WEB_INTERFACE

class Web_Interface {
public:
Web_Interface() {};
virtual ~Web_Interface() {};
virtual void start(int p) {};
virtual void stop() {};
virtual void print_version() {};
};

typedef Web_Interface * create_Web_Interface_t();

#endif /* CLASS_WEB_INTERFACE */
1 change: 1 addition & 0 deletions include/proxysql_glovars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/proxysql_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
1 change: 1 addition & 0 deletions include/query_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
62 changes: 39 additions & 23 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "MySQL_Logger.hpp"
#include "SQLite3_Server.h"

#include "Web_Interface.hpp"

#include <search.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -5342,29 +5346,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);
Expand All @@ -5378,6 +5360,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;
}
Expand Down
57 changes: 53 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "MySQL_Authentication.hpp"
#include "MySQL_LDAP_Authentication.hpp"
#include "proxysql_restapi.h"
#include "Web_Interface.hpp"


#include <libdaemon/dfork.h>
Expand All @@ -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;
Expand Down Expand Up @@ -526,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;
Expand Down Expand Up @@ -695,7 +700,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;
Expand Down Expand Up @@ -819,6 +824,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;
Expand Down Expand Up @@ -966,6 +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();
// }
}

void ProxySQL_Main_init_MySQL_Threads_Handler_module() {
Expand Down Expand Up @@ -1184,6 +1200,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;
Expand Down Expand Up @@ -1218,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();
Expand All @@ -1234,7 +1281,6 @@ void ProxySQL_Main_init_phase2___not_started() {
GloVars.confFile->CloseFile();
}

LoadPlugins();

ProxySQL_Main_init_Auth_module();

Expand Down Expand Up @@ -1814,6 +1860,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);
}
Expand Down
1 change: 1 addition & 0 deletions src/proxysql.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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="../../proxysql_web_interface_plugin/src/Web_Interface_plugin.so"

admin_variables=
{
Expand Down

0 comments on commit 7ee01a0

Please sign in to comment.