PluginProbe ʕ •ᴥ•ʔ
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) / 9.5.0.1
Really Simple Security – Simple and Performant Security (formerly Really Simple SSL) v9.5.0.1
9.5.11 9.5.10.1 9.5.10 trunk 9.4.0 9.4.1 9.4.2 9.4.3 9.5.0 9.5.0.1 9.5.0.2 9.5.1 9.5.2 9.5.2.2 9.5.2.3 9.5.3 9.5.3.1 9.5.3.2 9.5.4 9.5.5 9.5.6 9.5.7 9.5.8 9.5.9
really-simple-ssl / class-server.php
really-simple-ssl Last commit date
assets 9 months ago languages 9 months ago lets-encrypt 9 months ago lib 1 year ago mailer 10 months ago modal 9 months ago onboarding 10 months ago placeholders 9 months ago progress 1 year ago security 9 months ago settings 9 months ago testssl 5 years ago upgrade 9 months ago .wp-env.json 10 months ago SECURITY.md 9 months ago class-admin.php 9 months ago class-cache.php 2 years ago class-certificate.php 2 years ago class-front-end.php 1 year ago class-installer.php 10 months ago class-mixed-content-fixer.php 3 years ago class-multisite.php 1 year ago class-server.php 1 year ago class-site-health.php 1 year ago class-wp-cli.php 11 months ago compatibility.php 1 year ago force-deactivate.txt 1 year ago functions.php 10 months ago index.php 2 years ago readme.txt 9 months ago rector.php 1 year ago rlrsssl-really-simple-ssl.php 9 months ago rsssl-auto-loader.php 1 year ago sbom.json.gz 9 months ago ssl-test-page.php 2 years ago system-status.php 9 months ago uninstall.php 9 months ago upgrade.php 9 months ago
class-server.php
190 lines
1 <?php
2 defined( 'ABSPATH' ) or die( 'you do not have access to this page!' );
3
4 if ( ! class_exists( 'rsssl_server' ) ) {
5 class rsssl_server {
6 private static $_this;
7 private $sapi = false;
8
9 public function __construct() {
10 if ( isset( self::$_this ) ) {
11 wp_die( 'you cannot create a second instance.' );
12 }
13 self::$_this = $this;
14 }
15
16 public static function this() {
17 return self::$_this;
18 }
19
20 /**
21 * @Since 2.5.1
22 * Checks if the server uses .htaccess
23 * @return bool
24 */
25
26 public function uses_htaccess() {
27 // No .htaccess on WP Engine
28 if ( function_exists( 'is_wpe' ) && is_wpe() ) {
29 return false;
30 }
31
32 if ( $this->get_server() === 'apache' || $this->get_server() === 'litespeed' ) {
33 return true;
34 }
35
36 return false;
37 }
38
39 /**
40 * Returns the server type of the plugin user.
41 *
42 * @return string|bool server type the user is using of false if undetectable.
43 */
44
45 public function get_server() {
46 //Allows to override server authentication for testing or other reasons.
47 if ( defined( 'RSSSL_SERVER_OVERRIDE' ) ) {
48 return RSSSL_SERVER_OVERRIDE;
49 }
50
51 $server_raw = strtolower( htmlspecialchars( $_SERVER['SERVER_SOFTWARE'] ) );
52 if ( strpos( $server_raw, 'apache' ) !== false ) {
53 return 'apache';
54 } elseif ( strpos( $server_raw, 'nginx' ) !== false ) {
55 return 'nginx';
56 } elseif ( strpos( $server_raw, 'litespeed' ) !== false ) {
57 return 'litespeed';
58 } elseif ( strpos( $server_raw, 'openresty' ) !== false ) {
59 return 'openresty';
60 } elseif ( strpos( $server_raw, 'microsoft-iis' ) !== false ) {
61 return 'microsoft-iis';
62 } else { //unsupported server
63 return false;
64 }
65 }
66
67 /**
68 * Get the Auto prepend configuration
69 *
70 * @return string
71 */
72 public function auto_prepend_config(): string
73 {
74 $return = '';
75 if ( $this->isApacheModPHP() ){
76 $return = "apache-mod_php"; //Apache _ modphp
77 } else if ( $this->isApacheSuPHP() ) {
78 $return = "apache-suphp"; //Apache + SuPHP
79 } else if ( $this->isApache() && !$this->isApacheSuPHP() && ($this->isCGI() || $this->isFastCGI()) ) {
80 $return = "cgi"; //Apache + CGI/FastCGI
81 } else if ($this->isLiteSpeed()){
82 $return = "litespeed";
83 } else if ( $this->isNGINX() ) {
84 $return = "nginx";
85 } else if ( $this->isIIS() ) {
86 $return = "iis";
87 } else {
88 $return = "apache-mod_php";
89 }
90 update_option('rsssl_auto_prepend_config', $return, true);
91 return $return;
92 }
93
94 /**
95 * If Apache
96 * @return bool
97 */
98 public function isApache():bool {
99 return $this->get_server() === 'apache';
100 }
101
102 /**
103 * If NGINX
104 * @return bool
105 */
106 public function isNGINX():bool {
107 return $this->get_server() === 'nginx';
108 }
109
110 /**
111 * If Litespeed
112 * @return bool
113 */
114 public function isLiteSpeed():bool {
115 return $this->get_server() === 'litespeed';
116 }
117
118 /**
119 * If IIS
120 * @return bool
121 */
122 public function isIIS():bool {
123 return $this->get_server() === 'iis';
124 }
125
126 /**
127 * If ModPHP
128 * @return bool
129 */
130 public function isApacheModPHP():bool {
131 return $this->isApache() && function_exists('apache_get_modules');
132 }
133
134 /**
135 * If SupPHP
136 * Not sure if this can be implemented at the PHP level.
137 * @return bool
138 */
139 public function isApacheSuPHP():bool {
140 return $this->isApache() && $this->isCGI() &&
141 function_exists('posix_getuid') &&
142 getmyuid() === posix_getuid();
143 }
144
145 /**
146 * If CGI
147 * @return bool
148 */
149 public function isCGI():bool {
150 return !$this->isFastCGI() && stripos($this->sapi(), 'cgi') !== false;
151 }
152
153 /**
154 * If FastCGI
155 * @return bool
156 */
157 public function isFastCGI():bool {
158 return stripos($this->sapi(), 'fastcgi') !== false || stripos($this->sapi(), 'fpm-fcgi') !== false;
159 }
160
161
162 /**
163 * If Sapi
164 * @return bool|string
165 */
166 private function sapi(){
167 if ( !$this->sapi ) {
168 $this->sapi = function_exists('php_sapi_name') ? php_sapi_name() : 'false';
169 }
170 if ( 'false' === $this->sapi ) {
171 return false;
172 }
173 return $this->sapi;
174 }
175
176 /**
177 * Check if the apache version is at least 2.4
178 * @return bool
179 */
180 public function apache_version_min_24() {
181 $version = $_SERVER['SERVER_SOFTWARE'] ?? false;
182 //check if version is higher then 2.4.
183 if ( preg_match( '/Apache\/(2\.[4-9])/', $version, $matches ) ) {
184 return true;
185 }
186 return false;
187 }
188 } //class closure
189 }
190