PluginProbe ʕ •ᴥ•ʔ
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall / trunk
NinjaFirewall (WP Edition) – Advanced Security Plugin and Firewall vtrunk
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 8 years ago .htaccess 11 years ago anti_malware.php 4 years ago class-coupon.php 6 months ago class-email-sodium.php 3 weeks ago class-firewall-log.php 1 week ago class-helpers.php 7 months ago class-import-export.php 3 months ago class-ip.php 4 months ago class-nfw-database.php 6 months ago class-nfw-session.php 1 week ago class-php-session.php 1 year ago class-plugin-upgrade.php 1 week ago class_mail.php 3 weeks ago event_updates.php 9 months ago firewall.php 4 months ago fw_centlog.php 1 week ago fw_fileguard.php 4 months ago fw_livelog.php 1 year ago help.php 3 weeks ago helpers.php 1 week ago i18n-extra.php 3 weeks ago i18n.php 1 year ago index.html 13 years ago init_update.php 1 year ago install.php 1 year ago install_default.php 6 months ago loader.php 6 months ago mail_template_firewall.php 1 year ago mail_template_plugin.php 1 month ago scheduled_tasks.php 3 years ago settings_dashboard.php 1 month ago settings_dashboard_about.php 3 weeks ago settings_dashboard_statistics.php 1 month ago settings_event_notifications.php 1 month ago settings_events.php 1 month ago settings_firewall_options.php 1 month ago settings_firewall_policies.php 1 week ago settings_login_protection.php 1 month ago settings_logs.php 1 month ago settings_logs_firewall_log.php 3 weeks ago settings_logs_live_log.php 1 month ago settings_monitoring.php 3 weeks ago settings_monitoring_file_check.php 1 month ago settings_monitoring_file_guard.php 1 month ago settings_network.php 1 month ago settings_security_rules.php 1 month ago settings_security_rules_editor.php 1 month ago settings_security_rules_update.php 1 week ago sign.pub 7 years ago thickbox.php 4 years ago widget.php 3 years ago wpplus.php 3 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