Skip to content

Commit aed6719

Browse files
author
Jason Mountcastle
committed
Bug fixes
1 parent 53f1bd7 commit aed6719

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

readme.txt

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ Contributors: wpshepherd
33
Tags: monitoring
44
Requires at least: 3.0.1
55
Tested up to: 3.4
6-
Stable tag: 0.4
7-
License: GPLv2 or later
8-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
6+
Stable tag: 1.0.1
7+
License: Apache License 2.0
98

109
Complete WordPress version tracking - made simple. Making life a little easier for WordPress lovers all over.
1110

@@ -26,4 +25,4 @@ Complete WordPress version tracking - made simple. Making life a little easier f
2625
== Changelog ==
2726

2827
= 0.4 =
29-
Initial WP Sheperd Plugin.
28+
Initial WP Shepherd Plugin.

request.php

+29-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
/*
44
* Codefuel Sheperd
5-
* Version 0.2 Reponse via json
65
*/
76

8-
define('SHEP_PATH', dirname(__FILE__) .'/');
7+
98
define('SHEP_REQUEST', __FILE__);
109

1110
class Wp_Shep {
@@ -28,6 +27,7 @@ function correct_version() {
2827
function __construct() {
2928
$this->wp_args = array(
3029
'user-agent' => 'WordPress/WPShep/' . SHEP_VERSION,
30+
'sslverify' => false,
3131
);
3232

3333
add_action( 'plugins_loaded', array( $this, 'correct_version' ), 5);
@@ -57,7 +57,7 @@ public function request() {
5757

5858
public function reponse() {
5959
try {
60-
include(__DIR__ . '/phpseclib/Crypt/RSA.php');
60+
include(SHEP_PATH . '/phpseclib/Crypt/RSA.php');
6161
$public_key = get_transient('wpshep_public');
6262
$md5_check = get_transient('wpshep_md5');
6363
$options = get_option('shepherd_option_name');
@@ -68,20 +68,33 @@ public function reponse() {
6868
if(strlen($public_key)==0) {
6969
// General Response
7070
$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+
7181
$response_data = json_decode($response['body'], true);
7282

7383
// Lets verify handshake
7484
$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+
}
7689
$rsa = new Crypt_RSA();
7790
$rsa->loadKey($response_data['public_key']);
7891

7992
if(!$rsa->verify('shake', $hand['body'])) {
8093
throw new Exception(802);
8194
} else {
8295
// 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));
8598
$public_key = $response_data['public_key'];
8699
$md5_check = $response_data['md5_check'];
87100
}
@@ -107,10 +120,16 @@ public function reponse() {
107120
foreach(str_split($json_data, 3000) as $key => $str) {
108121
$body_array['data_' . $key] = $rsa_now->encrypt($str);
109122
}
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+
}
112130
} 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));
114133
}
115134
exit;
116135
}
@@ -168,6 +187,7 @@ public function shep_get_bloginfo(){
168187
$aActivePlugins = get_option('active_plugins');
169188
foreach ( $aPlugins as $sSlug => $aPlugin ) {
170189
$aPlugin['Active'] = in_array($sSlug, $aActivePlugins) ? '1' : '0';
190+
$aPlugin['path'] = $sSlug;
171191
$aRtn['plugins'][$aPlugin['Name']] = $aPlugin;
172192
}
173193

wpshepherd.php

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
11
<?php
22

33
/*
4-
Plugin Name: Shepherd
4+
Plugin Name: WP Shepherd
55
Plugin URI: http://www.wpshepherd.com
66
Description: The Shepherd you always wanted.
7-
Version: 1.0.1
7+
Version: 1.0.5
88
Author: 8th Avenue
99
Author URI: http://www.wpshepherd.com
1010
License: -
1111
*/
12-
define('SHEP_VERSION', '1.0.1');
13-
require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-admin/includes/plugin.php' );
12+
define('SHEP_VERSION', '1.0.5');
13+
define('SHEP_ABSPATH', dirname(__FILE__) . '/../../../');
14+
//define('SHEP_PATH', plugin_dir_path( __FILE__ ));
15+
define('SHEP_PATH', dirname(__FILE__) .'/');
16+
$wp_args = array('user-agent' => 'WordPress/WPShep/' . SHEP_VERSION, 'sslverify' => false);
17+
require_once( SHEP_ABSPATH . '/wp-admin/includes/plugin.php' );
1418

15-
if ( file_exists(__DIR__ . '/api.key') ) {
16-
$options = get_option('shepherd_option_name');
17-
if(!$options['api_key']) {
19+
function wpshep_activate() {
20+
if ( file_exists(SHEP_PATH . '/api.key') ) {
21+
$options = get_option('shepherd_option_name');
1822
$url = str_replace(array('http://', 'www.', '/'), '', get_bloginfo('url'));;
19-
$api_key_contents = stripslashes_deep(file_get_contents(__DIR__ . '/api.key'));
23+
$api_key_contents = stripslashes_deep(file_get_contents(SHEP_PATH . '/api.key'));
2024
$save_arr = array('api_key' => $api_key_contents);
2125
update_option( 'shepherd_option_name', $save_arr );
2226
$data_arr = array('name' => get_bloginfo('name'));
23-
$response = wp_remote_post('https://www.wpshepherd.com/server/wpsave/api_key/' . $api_key_contents . '/url/' . $url . '/type/auto', array('body' => $data_arr, 'user-agent' => 'WordPress/WPShep/'.SHEP_VERSION));
27+
$response = wp_remote_post('https://www.wpshepherd.com/server/wpsave/api_key/' . $api_key_contents . '/url/' . $url . '/version/' . SHEP_VERSION . '/type/auto', array('body' => $data_arr, 'user-agent' => 'WordPress/WPShep/' . SHEP_VERSION, 'sslverify' => false));
28+
if(is_wp_error($hand)) {
29+
wp_remote_get('https://www.wpshepherd.com/server/wpsave/api_key/' . $api_key_contents . '/url/' . $url . '/version/' . SHEP_VERSION . '/type/failed', $wp_args);
30+
}
2431
}
2532
}
33+
register_activation_hook( __FILE__, 'wpshep_activate' );
2634

27-
require_once( __DIR__ . '/request.php' );
35+
if ( function_exists('register_uninstall_hook') )
36+
register_uninstall_hook(__FILE__, 'wpshep_deinstall');
37+
38+
function wpshep_deinstall() {
39+
delete_option('shepherd_option_name');
40+
}
41+
42+
require_once( SHEP_PATH . '/request.php' );
2843

2944
if ( is_admin() )
3045
require_once dirname( __FILE__ ) . '/admin.php';

0 commit comments

Comments
 (0)