-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathclass-server.php
More file actions
177 lines (156 loc) · 4.12 KB
/
class-server.php
File metadata and controls
177 lines (156 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
defined( 'ABSPATH' ) or die( 'you do not have access to this page!' );
if ( ! class_exists( 'rsssl_server' ) ) {
class rsssl_server {
private static $_this;
private $sapi = false;
public function __construct() {
if ( isset( self::$_this ) ) {
wp_die( 'you cannot create a second instance.' );
}
self::$_this = $this;
}
public static function this() {
return self::$_this;
}
/**
* @Since 2.5.1
* Checks if the server uses .htaccess
* @return bool
*/
public function uses_htaccess() {
// No .htaccess on WP Engine
if ( function_exists( 'is_wpe' ) && is_wpe() ) {
return false;
}
if ( $this->get_server() === 'apache' || $this->get_server() === 'litespeed' ) {
return true;
}
return false;
}
/**
* Returns the server type of the plugin user.
*
* @return string|bool server type the user is using of false if undetectable.
*/
public function get_server() {
//Allows to override server authentication for testing or other reasons.
if ( defined( 'RSSSL_SERVER_OVERRIDE' ) ) {
return RSSSL_SERVER_OVERRIDE;
}
$server_raw = strtolower( htmlspecialchars( $_SERVER['SERVER_SOFTWARE'] ) );
if ( strpos( $server_raw, 'apache' ) !== false ) {
return 'apache';
} elseif ( strpos( $server_raw, 'nginx' ) !== false ) {
return 'nginx';
} elseif ( strpos( $server_raw, 'litespeed' ) !== false ) {
return 'litespeed';
} elseif ( strpos( $server_raw, 'openresty' ) !== false ) {
return 'openresty';
} elseif ( strpos( $server_raw, 'microsoft-iis' ) !== false ) {
return 'microsoft-iis';
} else { //unsupported server
return false;
}
}
/**
* Get the Auto prepend configuration
*
* @return string
*/
public function auto_prepend_config(): string
{
$return = '';
if ( $this->isApacheModPHP() ){
$return = "apache-mod_php"; //Apache _ modphp
} else if ( $this->isApacheSuPHP() ) {
$return = "apache-suphp"; //Apache + SuPHP
} else if ( $this->isApache() && !$this->isApacheSuPHP() && ($this->isCGI() || $this->isFastCGI()) ) {
$return = "cgi"; //Apache + CGI/FastCGI
} else if ($this->isLiteSpeed()){
$return = "litespeed";
} else if ( $this->isNGINX() ) {
$return = "nginx";
} else if ( $this->isIIS() ) {
$return = "iis";
} else {
$return = "apache-mod_php";
}
update_option('rsssl_auto_prepend_config', $return, true);
return $return;
}
/**
* If Apache
* @return bool
*/
public function isApache():bool {
return $this->get_server() === 'apache';
}
/**
* If NGINX
* @return bool
*/
public function isNGINX():bool {
return $this->get_server() === 'nginx';
}
/**
* If Litespeed
* @return bool
*/
public function isLiteSpeed():bool {
return $this->get_server() === 'litespeed';
}
/**
* If IIS
* @return bool
*/
public function isIIS():bool {
return $this->get_server() === 'iis';
}
/**
* If ModPHP
* @return bool
*/
public function isApacheModPHP():bool {
return $this->isApache() && function_exists('apache_get_modules');
}
/**
* If SupPHP
* Not sure if this can be implemented at the PHP level.
* @return bool
*/
public function isApacheSuPHP():bool {
return $this->isApache() && $this->isCGI() &&
function_exists('posix_getuid') &&
function_exists('getmyuid') &&
getmyuid() === posix_getuid();
}
/**
* If CGI
* @return bool
*/
public function isCGI():bool {
return !$this->isFastCGI() && stripos($this->sapi(), 'cgi') !== false;
}
/**
* If FastCGI
* @return bool
*/
public function isFastCGI():bool {
return stripos($this->sapi(), 'fastcgi') !== false || stripos($this->sapi(), 'fpm-fcgi') !== false;
}
/**
* If Sapi
* @return bool|string
*/
private function sapi(){
if ( !$this->sapi ) {
$this->sapi = function_exists('php_sapi_name') ? php_sapi_name() : 'false';
}
if ( 'false' === $this->sapi ) {
return false;
}
return $this->sapi;
}
} //class closure
}