-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvChecker.php
More file actions
138 lines (116 loc) · 4.52 KB
/
EnvChecker.php
File metadata and controls
138 lines (116 loc) · 4.52 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
<?php
/**
*
* TextMagic SMS API wrapper
* Environment Checker
*
* PHP version 5
*
* @category SMS
* @package TextMagicSMS
* @author Petrenko Maxim <mpetrenko@me.com>
* @license http://www.opensource.org/licenses/bsd-license.php New BSD license
* @link http://code.google.com/p/textmagic-sms-api-php/
*/
class EnvChecker
{
// error codes
const ERROR_NONE = 1;
const ERROR_OPENSSL = 2;
const ERROR_AUF = 3;
const ERROR_CURL = 4;
// parameters
const PARAM_OPENSSL = 'openssl';
const PARAM_AUF = 'allow_url_fopen';
const PARAM_CURL = 'curl';
/**
* Method for checking server environment capability for use TextMagicAPI
*
* @return string Error code or No Errors code if all checks are passed
*/
public function check($parameter = false)
{
if ($parameter) {
switch($parameter) {
case self::PARAM_OPENSSL:
if ($this->checkOpenSSL()) {
return self::ERROR_OPENSSL;
}
break;
case self::PARAM_AUF:
if (false == ini_get('allow_url_fopen')) {
return self::ERROR_AUF;
}
break;
case self::PARAM_CURL:
if (false == function_exists('curl_version')) {
return self::ERROR_CURL;
}
break;
}
return self::ERROR_NONE;
}
if (ini_get('allow_url_fopen') != 1) {
// checking fopen dependencies fails, it's bad :(
// check cURL ext
if (false == function_exists('curl_version')) {
return self::ERROR_CURL;
} else {
return self::ERROR_AUF;
}
}
// check openssl in php
if ($this->checkOpenSSL()) {
return self::ERROR_OPENSSL;
}
// return that all is ok if all previous checks are passed
return self::ERROR_NONE;
}
/**
* Check openSSL support and version
*
* @return bool true if error detected
*/
public function checkOpenSSL()
{
return (bool) (OPENSSL_VERSION_NUMBER < 0x009080bf);
}
/**
* Method for testing server environment capability for use TextMagicAPI
*
* @return string
*/
public function test()
{
switch ($this->check()) {
case self::ERROR_CURL:
if ($this->check(self::PARAM_AUF) == self::ERROR_AUF) {
print "\033[0;31mERROR: cURL not found and allow_url_fopen is disabled.\033[0m\n";
print "One of this issues should be resolwed before You can use TextMagicAPI.\n\n";
print "\033[1;33mSolution a:\033[0m is installing cURL from pear or from sources.\n";
print "You can use http://php.net/manual/en/book.curl.php for installing cURL.\n\n";
print "\033[1;33mSolution b:\033[0m is enable 'allow_url_fopen' in Your php.ini file.\n";
print "You can check 'allow_url_fopen' settings doing 'php -i | grep allow_url_fopen' (without quotes) from terminal.\n";
} else {
print "\033[1;33mWARNING: cURL not found.\033[0m\n";
print "You will be able to use only 'fopen' sending method.\n";
print "Possible solution is installing cURL from pear or from sources.\n";
print "You can use http://php.net/manual/en/book.curl.php for installing cURL.\n";
}
break;
case self::ERROR_OPENSSL:
print "\033[1;33mWARNING: OpenSSL not found or is outdated.\033[0m\n";
print "HTTP will be used instead of HTTPS.\n";
print "For installing or updating OpenSSL You can use http://www.openssl.org and http://php.net/manual/en/openssl.installation.php\n";
break;
case self::ERROR_AUF:
print "\033[0;31mERROR: allow_url_fopen is disabled.\033[0m\n";
print "Possible solution is enable 'allow_url_fopen' in Your php.ini file.\n";
print "You can check 'allow_url_fopen' settings doing 'php -i | grep allow_url_fopen' (without quotes) from terminal.\n";
break;
case self::ERROR_NONE:
print "\033[0;32mSUCCES: You system is ready to use TextMagicAPI.\033[0m\n";
break;
}
}
}