PluginProbe
DoLogin Security / trunk
DoLogin Security vtrunk
5.0.10 4.8.3 trunk 1.0 1.1 1.1.1 1.2 1.2.1 1.2.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.6 All 64 releases
dologin / src / rest.cls.php

rest.cls.php in DoLogin Security trunk, at src/rest.cls.php

130 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Rest class
5 *
6 * @since 1.0
7 */
8
9 namespace dologin;
10
11 defined( 'WPINC' ) || exit;
12
13 class REST extends Instance {
14
15 /**
16 * Init
17 *
18 * @since 1.0
19 * @access public
20 */
21 public function init() {
22 add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
23 }
24
25 /**
26 * Register REST hooks
27 *
28 * @since 1.0
29 * @access public
30 */
31 public function rest_api_init() {
32 register_rest_route(
33 'dologin/v1',
34 '/myip',
35 array(
36 'methods' => 'GET',
37 'callback' => __CLASS__ . '::geoip',
38 'permission_callback' => function () {
39 return current_user_can( 'manage_network_options' ) || current_user_can( 'manage_options' );
40 },
41 )
42 );
43
44 register_rest_route(
45 'dologin/v1',
46 '/2fa',
47 array(
48 'methods' => 'POST',
49 'callback' => array( $this, 'twofa' ),
50 'permission_callback' => '__return_true',
51 )
52 );
53
54 register_rest_route(
55 'dologin/v1',
56 '/kl_sso/start',
57 array(
58 'methods' => 'POST',
59 'callback' => array( $this->cls( 'KLSso' ), 'start' ),
60 'permission_callback' => '__return_true',
61 )
62 );
63
64 register_rest_route(
65 'dologin/v1',
66 '/kl_sso/frame',
67 array(
68 'methods' => 'POST',
69 'callback' => array( $this->cls( 'KLSso' ), 'frame' ),
70 'permission_callback' => '__return_true',
71 )
72 );
73
74 register_rest_route(
75 'dologin/v1',
76 '/kl_sso/unbind',
77 array(
78 'methods' => 'POST',
79 'callback' => array( $this->cls( 'KLSso' ), 'unbind' ),
80 'permission_callback' => 'is_user_logged_in',
81 )
82 );
83
84 register_rest_route(
85 'dologin/v1',
86 '/kl_sso/reset_keys',
87 array(
88 'methods' => 'POST',
89 'callback' => array( $this->cls( 'KLSso' ), 'reset_site_keys' ),
90 'permission_callback' => function () {
91 return current_user_can( apply_filters( 'dologin_admin_menu_access', 'manage_options' ) );
92 },
93 )
94 );
95 }
96
97 /**
98 * Get GeoIP info
99 */
100 public static function geoip() {
101 return IP::geo();
102 }
103
104 /**
105 * Check 2fa
106 */
107 public function twofa() {
108 return $this->cls( 'TwoFA' )->check();
109 }
110
111 /**
112 * Return content
113 */
114 public static function ok( $data ) {
115 $data['_res'] = 'ok';
116 return $data;
117 }
118
119 /**
120 * Return error
121 */
122 public static function err( $msg ) {
123 defined( 'debug' ) && debug( '❌ [err] ' . $msg );
124 return array(
125 '_res' => 'err',
126 '_msg' => $msg,
127 );
128 }
129 }
130