@@ -10,6 +10,8 @@ final class gourlclass
10
10
private $ hash_url = "" ; // security; save your gourl public/private keys sha1 hash in file (db and file)
11
11
private $ errors = array (); // global setting errors
12
12
private $ payments = array (); // global activated payments (bitcoin, litecoin, etc)
13
+ private $ adminform = "gourl_adminform " ;
14
+ private $ admin_form_key = "" ; // unique form key
13
15
14
16
private $ options2 = array (); // pay-per-view settings
15
17
private $ options3 = array (); // pay-per-membership settings
@@ -78,11 +80,14 @@ public function __construct()
78
80
// security data hash; you can change path / file location
79
81
$ this ->hash_url = GOURL_PHP ."/gourl.hash " ;
80
82
83
+ // admin form
84
+ $ this ->adminform = "gourl_adminform_ " . md5 (sha1 (AUTH_KEY .NONCE_KEY .AUTH_KEY ));
85
+ $ this ->admin_form_key = 'gourl_adminformkey_ ' . sha1 (md5 (AUTH_KEY .NONCE_KEY ));
81
86
82
87
$ this ->coin_names = self ::coin_names ();
83
88
$ this ->coin_chain = self ::coin_chain ();
84
- $ this ->coin_www = self ::coin_www ();
85
- $ this ->languages = self ::languages ();
89
+ $ this ->coin_www = self ::coin_www ();
90
+ $ this ->languages = self ::languages ();
86
91
87
92
// compatible test
88
93
$ ver = get_option (GOURL .'version ' );
@@ -892,12 +897,14 @@ private function get_settings()
892
897
$ txt = (is_readable ($ this ->hash_url )) ? file_get_contents ($ this ->hash_url ) : "" ;
893
898
$ arr = json_decode ($ txt , true );
894
899
900
+ /*
895
901
if (isset($arr["nonce"]) && $arr["nonce"] != sha1(md5(NONCE_KEY)))
896
902
{
897
903
$this->save_cryptokeys_hash(); // admin changed NONCE_KEY
898
904
$txt = (is_readable($this->hash_url)) ? file_get_contents($this->hash_url) : "";
899
905
$arr = json_decode($txt, true);
900
906
}
907
+ */
901
908
902
909
foreach ($ this ->coin_names as $ k => $ v )
903
910
{
@@ -925,7 +932,8 @@ private function get_settings()
925
932
* 20.
926
933
*/
927
934
private function post_settings ()
928
- {
935
+ {
936
+
929
937
foreach ($ this ->options as $ key => $ value )
930
938
{
931
939
$ this ->options [$ key ] = (isset ($ _POST [GOURL .$ key ])) ? stripslashes ($ _POST [GOURL .$ key ]) : "" ;
@@ -1046,7 +1054,8 @@ private function check_settings()
1046
1054
*/
1047
1055
private function save_settings ()
1048
1056
{
1049
- $ arr = array ();
1057
+ $ arr = array ();
1058
+ $ editable = (!file_exists ($ this ->hash_url ) || is_writable ($ this ->hash_url )) ? true : false ;
1050
1059
1051
1060
if (!(is_admin () && is_user_logged_in () && current_user_can ('administrator ' )))
1052
1061
{
@@ -1058,21 +1067,23 @@ private function save_settings()
1058
1067
foreach ($ this ->options as $ key => $ value )
1059
1068
{
1060
1069
$ boxkey = (strpos ($ key , "public_key " ) || strpos ($ key , "private_key " )) ? true : false ;
1061
- if (!( file_exists ( $ this -> hash_url ) && ! is_writable ( $ this -> hash_url ) && $ boxkey) )
1070
+ if ($ editable || ! $ boxkey )
1062
1071
{
1063
- $ oldval = get_option (GOURL .$ key );
1072
+ $ oldval = get_option (GOURL .$ key );
1064
1073
if ($ boxkey && $ oldval != $ value ) $ arr [$ key ] = array ("old_key " => ($ oldval ? substr ($ oldval , 0 , -20 )."..... " : "-empty- " ), "new_key " => ($ value ? substr ($ value , 0 , -20 )."..... " : "-empty- " ));
1065
1074
update_option (GOURL .$ key , $ value );
1066
1075
}
1067
1076
}
1068
1077
1069
1078
if ($ arr )
1070
- {
1071
- wp_mail (get_bloginfo ('admin_email ' ), 'Notification - GoUrl Bitcoin Payment Gateway Plugin - Cryptobox Keys Changed ' ,
1072
- date ("r " )."\n\nGoUrl Bitcoin Payment Gateway for Wordpress plugin \n\nFollowing crypto payment box/es keys was changed on your website - \n\n" .print_r ($ arr , true ));
1079
+ {
1080
+ wp_mail (get_bloginfo ('admin_email ' ), 'Notification - GoUrl Bitcoin Payment Gateway Plugin - Cryptobox Keys Changed ' ,
1081
+ date ("r " )."\n\nGoUrl Bitcoin Payment Gateway for Wordpress plugin \n\nFollowing crypto payment box/es keys was changed on your website - \n\n" .print_r ($ arr , true ));
1082
+
1083
+ $ this ->save_cryptokeys_hash ();
1073
1084
}
1074
1085
1075
- $ this -> save_cryptokeys_hash ();
1086
+
1076
1087
}
1077
1088
1078
1089
return true ;
@@ -1107,14 +1118,35 @@ private function save_cryptokeys_hash()
1107
1118
}
1108
1119
1109
1120
1121
+ /*
1122
+ * Notice for non-admin users
1123
+ */
1124
+ private function is_nonadmin_user ()
1125
+ {
1126
+ if (!(is_admin () && is_user_logged_in () && current_user_can ('administrator ' )))
1127
+ {
1128
+ $ tmp = "<div class='wrap " .GOURL ."admin'> " ;
1129
+ $ tmp .= $ this ->page_title (__ ('Admin Area ' , GOURL ));
1130
+ $ tmp .= "<br><br><br><br><h2><center> " .__ ('Only Admin users can access to this page ! ' , GOURL )."</center></h2><br><br><br> " ;
1131
+ $ tmp .= "</div> " ;
1132
+
1133
+ echo $ tmp ;
1134
+
1135
+ return true ;
1136
+ }
1137
+ else return false ;
1138
+ }
1110
1139
1111
1140
1112
1141
1113
1142
/*
1114
1143
* 24.
1115
1144
*/
1116
1145
public function page_settings ()
1117
- {
1146
+ {
1147
+
1148
+ if ($ this ->is_nonadmin_user ()) return true ;
1149
+
1118
1150
$ readonly = (file_exists ($ this ->hash_url ) && !is_writable ($ this ->hash_url )) ? 'readonly ' : '' ;
1119
1151
1120
1152
if ($ readonly )
@@ -1173,7 +1205,8 @@ public function page_settings()
1173
1205
$ tmp .= "<h3 class='hndle'> " .__ ('General Settings ' , GOURL )."</h3> " ;
1174
1206
$ tmp .= "<div class='inside'> " ;
1175
1207
1176
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_settings" /> ' ;
1208
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_settings" /> ' ;
1209
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
1177
1210
1178
1211
$ tmp .= '<p> ' .sprintf (__ ( "If you use multiple websites online, please create separate <a target='_blank' href='%s'>GoUrl Payment Box</a> records (with unique payment box public/private keys) for each of your websites. Do not use the same GoUrl Payment Box with the same public/private keys on your different websites. " , GOURL ), "https://gourl.io/editrecord/coin_boxes/0 " ) . '</p> ' ;
1179
1212
$ tmp .= '<p> ' .sprintf (__ ( "If you want to use plugin in a language other than English, see the page <a href='%s'>Languages and Translations</a>.   This enables you to easily customize the texts of all the labels visible to your users. " , GOURL ), "https://gourl.io/languages.html " , "https://gourl.io/languages.html " ) . '</p> ' ;
@@ -1684,6 +1717,7 @@ private function save_download()
1684
1717
*/
1685
1718
public function page_newfile ()
1686
1719
{
1720
+ if ($ this ->is_nonadmin_user ()) return true ;
1687
1721
1688
1722
$ preview = ($ this ->id && isset ($ _GET ["preview " ]) && $ _GET ["preview " ] == "true " ) ? true : false ;
1689
1723
@@ -1727,7 +1761,8 @@ public function page_newfile()
1727
1761
$ tmp .= "<h3 class='hndle'> " .__ (($ this ->id ?'Edit file ' :'Upload New File, Music, Picture, Video ' ), GOURL )."</h3> " ;
1728
1762
$ tmp .= "<div class='inside'> " ;
1729
1763
1730
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_download" /> ' ;
1764
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_download" /> ' ;
1765
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
1731
1766
1732
1767
$ tmp .= '<div class="alignright"> ' ;
1733
1768
$ tmp .= '<img id="gourlsubmitloading" src=" ' .plugins_url ('/images/loading.gif ' , __FILE__ ).'" border="0"> ' ;
@@ -1951,6 +1986,7 @@ public function page_files()
1951
1986
{
1952
1987
global $ wpdb ;
1953
1988
1989
+ if ($ this ->is_nonadmin_user ()) return true ;
1954
1990
1955
1991
if (isset ($ _GET ["intro " ]))
1956
1992
{
@@ -2459,6 +2495,8 @@ private function save_view()
2459
2495
*/
2460
2496
public function page_view ()
2461
2497
{
2498
+ if ($ this ->is_nonadmin_user ()) return true ;
2499
+
2462
2500
$ example = 0 ;
2463
2501
$ preview = (isset ($ _GET ["preview " ]) && $ _GET ["preview " ] == "true " ) ? true : false ;
2464
2502
@@ -2557,7 +2595,8 @@ public function page_view()
2557
2595
$ tmp .= "<h3 class='hndle'> " .__ ('Paid Access to Premium Webages for Unregistered Visitors ' , GOURL )."</h3> " ;
2558
2596
$ tmp .= "<div class='inside'> " ;
2559
2597
2560
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_view" /> ' ;
2598
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_view" /> ' ;
2599
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
2561
2600
2562
2601
$ tmp .= '<div class="alignright"> ' ;
2563
2602
$ tmp .= '<input type="submit" class=" ' .GOURL .'button button-primary" name="submit" value=" ' .__ ('Save Settings ' , GOURL ).'"> ' ;
@@ -3281,6 +3320,8 @@ public function page_membership()
3281
3320
{
3282
3321
global $ current_user ;
3283
3322
3323
+ if ($ this ->is_nonadmin_user ()) return true ;
3324
+
3284
3325
$ example = 0 ;
3285
3326
$ preview = (isset ($ _GET ["preview " ]) && $ _GET ["preview " ] == "true " ) ? true : false ;
3286
3327
@@ -3396,7 +3437,8 @@ public function page_membership()
3396
3437
$ tmp .= "<h3 class='hndle'> " .__ ('Paid Access to Premium Pages for Registered Users ' , GOURL )."</h3> " ;
3397
3438
$ tmp .= "<div class='inside'> " ;
3398
3439
3399
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_membership" /> ' ;
3440
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_membership" /> ' ;
3441
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
3400
3442
3401
3443
$ tmp .= '<div class="alignright"> ' ;
3402
3444
$ tmp .= '<input type="submit" class=" ' .GOURL .'button button-primary" name="submit" value=" ' .__ ('Save Settings ' , GOURL ).'"> ' ;
@@ -4017,6 +4059,8 @@ public function page_membership_users()
4017
4059
{
4018
4060
global $ wpdb ;
4019
4061
4062
+ if ($ this ->is_nonadmin_user ()) return true ;
4063
+
4020
4064
$ dt = gmdate ('Y-m-d H:i:s ' );
4021
4065
4022
4066
$ search = "" ;
@@ -4104,6 +4148,8 @@ public function page_membership_user()
4104
4148
{
4105
4149
global $ wpdb ;
4106
4150
4151
+ if ($ this ->is_nonadmin_user ()) return true ;
4152
+
4107
4153
if ($ this ->record_errors ) $ message = "<div class='error'> " .__ ('Please fix errors below: ' , GOURL )."<ul><li>- " .implode ("</li><li>- " , $ this ->record_errors )."</li></ul></div> " ;
4108
4154
else $ message = "" ;
4109
4155
@@ -4127,7 +4173,8 @@ public function page_membership_user()
4127
4173
$ tmp .= "<h3 class='hndle'> " .__ ('Manually create Premium Membership ' , GOURL )."</h3> " ;
4128
4174
$ tmp .= "<div class='inside'> " ;
4129
4175
4130
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_membership_newuser" /> ' ;
4176
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_membership_newuser" /> ' ;
4177
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
4131
4178
4132
4179
$ tmp .= '<div class="alignright"> ' ;
4133
4180
$ tmp .= '<img id="gourlsubmitloading" src=" ' .plugins_url ('/images/loading.gif ' , __FILE__ ).'" border="0"> ' ;
@@ -4421,6 +4468,8 @@ public function save_product()
4421
4468
public function page_newproduct ()
4422
4469
{
4423
4470
4471
+ if ($ this ->is_nonadmin_user ()) return true ;
4472
+
4424
4473
$ preview = ($ this ->id && isset ($ _GET ["preview " ]) && $ _GET ["preview " ] == "true " ) ? true : false ;
4425
4474
$ preview_final = ($ this ->id && isset ($ _GET ["previewfinal " ]) && $ _GET ["previewfinal " ] == "true " ) ? true : false ;
4426
4475
$ preview_email = ($ this ->id && isset ($ _GET ["previewemail " ]) && $ _GET ["previewemail " ] == "true " ) ? true : false ;
@@ -4502,7 +4551,8 @@ public function page_newproduct()
4502
4551
$ tmp .= "<h3 class='hndle'> " .__ ($ this ->id ?__ ('Edit Product ' , GOURL ):__ ('Create New Product ' , GOURL ))."</h3> " ;
4503
4552
$ tmp .= "<div class='inside'> " ;
4504
4553
4505
- $ tmp .= '<input type="hidden" name="ak_action" value=" ' .GOURL .'save_product" /> ' ;
4554
+ $ tmp .= '<input type="hidden" name=" ' .$ this ->adminform .'" value=" ' .GOURL .'save_product" /> ' ;
4555
+ $ tmp .= wp_nonce_field ( $ this ->admin_form_key );
4506
4556
4507
4557
$ tmp .= '<div class="alignright"> ' ;
4508
4558
$ tmp .= '<img id="gourlsubmitloading" src=" ' .plugins_url ('/images/loading.gif ' , __FILE__ ).'" border="0"> ' ;
@@ -4700,6 +4750,8 @@ public function page_products()
4700
4750
{
4701
4751
global $ wpdb ;
4702
4752
4753
+ if ($ this ->is_nonadmin_user ()) return true ;
4754
+
4703
4755
if (isset ($ _GET ["intro " ]))
4704
4756
{
4705
4757
$ intro = intval ($ _GET ["intro " ]);
@@ -5073,7 +5125,9 @@ public function shortcode_product($arr, $preview_final = false)
5073
5125
public function page_payments ()
5074
5126
{
5075
5127
global $ wpdb ;
5076
-
5128
+
5129
+ if ($ this ->is_nonadmin_user ()) return true ;
5130
+
5077
5131
$ search = $ sql_where = "" ;
5078
5132
5079
5133
if (isset ($ _GET ["s " ]) && trim ($ _GET ["s " ]))
@@ -5394,9 +5448,11 @@ public function admin_init()
5394
5448
5395
5449
// Actions POST
5396
5450
5397
- if (isset ($ _POST [' ak_action ' ]) && strpos ($ this ->page , GOURL ) === 0 )
5451
+ if (isset ($ _POST [$ this -> adminform ]) && strpos ($ this ->page , GOURL ) === 0 )
5398
5452
{
5399
- switch ($ _POST ['ak_action ' ])
5453
+ check_admin_referer ( $ this ->admin_form_key );
5454
+
5455
+ switch ($ _POST [$ this ->adminform ])
5400
5456
{
5401
5457
case GOURL .'save_settings ' :
5402
5458
@@ -5515,7 +5571,7 @@ public function admin_init()
5515
5571
5516
5572
// Actions GET
5517
5573
5518
- if (!isset ($ _POST [' ak_action ' ]) && strpos ($ this ->page , GOURL ) === 0 && is_admin () && is_user_logged_in () && current_user_can ('administrator ' ))
5574
+ if (!isset ($ _POST [$ this -> adminform ]) && strpos ($ this ->page , GOURL ) === 0 && is_admin () && is_user_logged_in () && current_user_can ('administrator ' ))
5519
5575
{
5520
5576
5521
5577
switch ($ this ->page )
0 commit comments