PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / 4.8.8
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall v4.8.8
4.9 4.8.8 4.8.7 4.8.6 trunk 4.5 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6 4.6.1 4.7 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5
ninjafirewall / lib / class-nfw-database.php
ninjafirewall / lib Last commit date
share 9 years ago .htaccess 11 years ago anti_malware.php 5 years ago class-coupon.php 7 months ago class-email-sodium.php 1 month ago class-firewall-log.php 1 month ago class-helpers.php 9 months ago class-import-export.php 5 months ago class-ip.php 5 months ago class-nfw-database.php 7 months ago class-nfw-session.php 1 month ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 month ago class_mail.php 1 month ago event_updates.php 11 months ago firewall.php 5 months ago fw_centlog.php 1 month ago fw_fileguard.php 5 months ago fw_livelog.php 1 year ago help.php 1 month ago helpers.php 1 month ago i18n-extra.php 1 month ago i18n.php 1 year ago index.html 13 years ago init_update.php 2 years ago install.php 1 year ago install_default.php 7 months ago loader.php 7 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 2 months ago scheduled_tasks.php 3 years ago settings_dashboard.php 2 months ago settings_dashboard_about.php 1 month ago settings_dashboard_statistics.php 2 months ago settings_event_notifications.php 2 months ago settings_events.php 2 months ago settings_firewall_options.php 2 months ago settings_firewall_policies.php 1 month ago settings_login_protection.php 2 months ago settings_logs.php 2 months ago settings_logs_firewall_log.php 1 month ago settings_logs_live_log.php 2 months ago settings_monitoring.php 1 month ago settings_monitoring_file_check.php 2 months ago settings_monitoring_file_guard.php 2 months ago settings_network.php 2 months ago settings_security_rules.php 2 months ago settings_security_rules_editor.php 2 months ago settings_security_rules_update.php 1 month ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 5 months ago
class-nfw-database.php
77 lines
1 <?php
2 /*
3 +=====================================================================+
4 | _ _ _ _ _____ _ _ _ |
5 | | \ | (_)_ __ (_) __ _| ___(_)_ __ _____ ____ _| | | |
6 | | \| | | '_ \ | |/ _` | |_ | | '__/ _ \ \ /\ / / _` | | | |
7 | | |\ | | | | || | (_| | _| | | | | __/\ V V / (_| | | | |
8 | |_| \_|_|_| |_|/ |\__,_|_| |_|_| \___| \_/\_/ \__,_|_|_| |
9 | |__/ |
10 | (c) NinTechNet Limited ~ https://nintechnet.com/ |
11 +=====================================================================+
12 */
13
14 if ( class_exists('NinjaFirewall_fwdatabase') ) {
15 return;
16 }
17
18 class NinjaFirewall_fwdatabase {
19
20
21 /**
22 * This is a fork of the WordPress parse_db_host() method.
23 * We use it when NF is loaded in "Full WAF Mode" only, i.e., before WordPress loads.
24 */
25 public static function parse_db_host( $host ) {
26
27 $socket = null;
28 $is_ipv6 = false;
29
30 // First peel off the socket parameter from the right, if it exists.
31 $socket_pos = strpos( $host, ':/' );
32 if ( false !== $socket_pos ) {
33 $socket = substr( $host, $socket_pos + 1 );
34 $host = substr( $host, 0, $socket_pos );
35 }
36
37 /*
38 * We need to check for an IPv6 address first.
39 * An IPv6 address will always contain at least two colons.
40 */
41 if ( substr_count( $host, ':' ) > 1 ) {
42 $pattern = '#^(?:\[)?(?P<host>[0-9a-fA-F:]+)(?:\]:(?P<port>[\d]+))?#';
43 $is_ipv6 = true;
44 } else {
45 // We seem to be dealing with an IPv4 address.
46 $pattern = '#^(?P<host>[^:/]*)(?::(?P<port>[\d]+))?#';
47 }
48
49 $matches = [];
50 $result = preg_match( $pattern, $host, $matches );
51
52 if ( 1 !== $result ) {
53 // Couldn't parse the address, bail.
54 return false;
55 }
56
57 $host = ! empty( $matches['host'] ) ? $matches['host'] : '';
58 // Port cannot be a string; must be null or an integer.
59 $port = ! empty( $matches['port'] ) ? abs( (int) $matches['port'] ) : null;
60
61 /*
62 * If using the `mysqlnd` library, the IPv6 address needs to be enclosed
63 * in square brackets, whereas it doesn't while using the `libmysqlclient` library.
64 * @see https://bugs.php.net/bug.php?id=67563
65 */
66 if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
67 $host = "[$host]";
68 }
69
70 return [ $host, $port, $socket ];
71 }
72
73 }
74
75 // =====================================================================
76 // EOF
77