2
2
3
3
/*
4
4
* Codefuel Sheperd
5
- * Version 0.2 Reponse via json
6
5
*/
7
6
8
- define ( ' SHEP_PATH ' , dirname ( __FILE__ ) . ' / ' );
7
+
9
8
define ('SHEP_REQUEST ' , __FILE__ );
10
9
11
10
class Wp_Shep {
@@ -28,6 +27,7 @@ function correct_version() {
28
27
function __construct () {
29
28
$ this ->wp_args = array (
30
29
'user-agent ' => 'WordPress/WPShep/ ' . SHEP_VERSION ,
30
+ 'sslverify ' => false ,
31
31
);
32
32
33
33
add_action ( 'plugins_loaded ' , array ( $ this , 'correct_version ' ), 5 );
@@ -57,7 +57,7 @@ public function request() {
57
57
58
58
public function reponse () {
59
59
try {
60
- include (__DIR__ . '/phpseclib/Crypt/RSA.php ' );
60
+ include (SHEP_PATH . '/phpseclib/Crypt/RSA.php ' );
61
61
$ public_key = get_transient ('wpshep_public ' );
62
62
$ md5_check = get_transient ('wpshep_md5 ' );
63
63
$ options = get_option ('shepherd_option_name ' );
@@ -68,20 +68,33 @@ public function reponse() {
68
68
if (strlen ($ public_key )==0 ) {
69
69
// General Response
70
70
$ response = wp_remote_get ('https://www.wpshepherd.com/server/index/api_key/ ' . $ options ['api_key ' ], $ this ->wp_args );
71
+ if (is_wp_error ($ response )) {
72
+ $ messages = $ response ;
73
+ throw new Exception ('113-1 ' );
74
+ }
75
+ $ hand = wp_remote_get ('https://www.wpshepherd.com/server/hand/api_key/ ' . $ options ['api_key ' ], $ this ->wp_args );
76
+ if (is_wp_error ($ hand )) {
77
+ $ messages = $ hand ;
78
+ throw new Exception ('113-2 ' );
79
+ }
80
+
71
81
$ response_data = json_decode ($ response ['body ' ], true );
72
82
73
83
// Lets verify handshake
74
84
$ hand = wp_remote_get ('https://www.wpshepherd.com/server/hand/api_key/ ' . $ options ['api_key ' ], $ this ->wp_args );
75
-
85
+ if (is_wp_error ($ hand )) {
86
+ $ messages = $ hand ;
87
+ throw new Exception ('113-3 ' );
88
+ }
76
89
$ rsa = new Crypt_RSA ();
77
90
$ rsa ->loadKey ($ response_data ['public_key ' ]);
78
91
79
92
if (!$ rsa ->verify ('shake ' , $ hand ['body ' ])) {
80
93
throw new Exception (802 );
81
94
} else {
82
95
// Handshake passed lets just carry on and cache for 24hours / (60 * 60 * 24)
83
- set_transient ('wpshep_public ' , $ response_data ['public_key ' ], 60 );
84
- set_transient ('wpshep_md5 ' , $ response_data ['md5_check ' ], 60 );
96
+ set_transient ('wpshep_public ' , $ response_data ['public_key ' ], ( 60 * 60 * 2 ) );
97
+ set_transient ('wpshep_md5 ' , $ response_data ['md5_check ' ], ( 60 * 60 * 2 ) );
85
98
$ public_key = $ response_data ['public_key ' ];
86
99
$ md5_check = $ response_data ['md5_check ' ];
87
100
}
@@ -107,10 +120,16 @@ public function reponse() {
107
120
foreach (str_split ($ json_data , 3000 ) as $ key => $ str ) {
108
121
$ body_array ['data_ ' . $ key ] = $ rsa_now ->encrypt ($ str );
109
122
}
110
-
111
- wp_remote_post ('https://www.wpshepherd.com/server/post/api_key/ ' . $ options ['api_key ' ], array_merge (array ('body ' => $ body_array , 'user-agent ' => 'WordPress/WPShep/ ' . SHEP_VERSION )));
123
+ $ r = wp_remote_post ('https://www.wpshepherd.com/server/post/api_key/ ' . $ options ['api_key ' ], array_merge (array ('body ' => $ body_array , 'user-agent ' => 'WordPress/WPShep/ ' . SHEP_VERSION , 'sslverify ' => false )));
124
+ if (!is_wp_error ($ r )) {
125
+ throw new Exception ('5 ' );
126
+ } else {
127
+ $ messages = $ r ;
128
+ throw new Exception ('112 ' );
129
+ }
112
130
} catch (Exception $ e ) {
113
- echo json_encode (array ('fault ' => $ e ->getMessage ()));
131
+ if (!is_array ($ messages ))$ r = array ();
132
+ echo json_encode (array ('fault ' => $ e ->getMessage (), 'messages ' => $ messages ));
114
133
}
115
134
exit ;
116
135
}
@@ -168,6 +187,7 @@ public function shep_get_bloginfo(){
168
187
$ aActivePlugins = get_option ('active_plugins ' );
169
188
foreach ( $ aPlugins as $ sSlug => $ aPlugin ) {
170
189
$ aPlugin ['Active ' ] = in_array ($ sSlug , $ aActivePlugins ) ? '1 ' : '0 ' ;
190
+ $ aPlugin ['path ' ] = $ sSlug ;
171
191
$ aRtn ['plugins ' ][$ aPlugin ['Name ' ]] = $ aPlugin ;
172
192
}
173
193
0 commit comments