PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.0.1
Defender Security – Malware Scanner, Login Security & Firewall v6.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / controller / class-audit-logging.php

class-audit-logging.php in Defender Security – Malware Scanner, Login Security & Firewall 6.0.1, at src/controller/class-audit-logging.php

230 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle Audit Logging module.
4 *
5 * @package WP_Defender\Controller
6 */
7
8 namespace WP_Defender\Controller;
9
10 use WP_Defender\Event;
11 use Calotes\Component\Response;
12 use WP_Defender\Model\Setting\Audit_Logging as Model_Audit_Logging;
13
14 /**
15 * Handle Audit Logging module.
16 */
17 class Audit_Logging extends Event {
18
19 /**
20 * The slug identifier for this controller.
21 *
22 * @var string
23 */
24 public $slug = 'wdf-logging';
25
26 /**
27 * The model for handling the data.
28 *
29 * @var Model_Audit_Logging
30 */
31 public $model;
32
33 /**
34 * Initializes the model, registers the menu page and routes.
35 */
36 public function __construct() {
37 $this->register_page(
38 esc_html__( 'Audit Log', 'defender-security' ),
39 $this->slug,
40 array( $this, 'main_view' ),
41 $this->parent_slug
42 );
43 add_action( 'defender_enqueue_assets', array( $this, 'enqueue_assets' ) );
44 $this->model = wd_di()->get( Model_Audit_Logging::class );
45 $this->register_routes();
46 }
47
48 /**
49 * Enqueues scripts and styles for this page.
50 */
51 public function enqueue_assets(): void {
52 if ( ! $this->is_page_active() ) {
53 return;
54 }
55
56 $handle = 'defender-ui-audit-logging';
57 wp_enqueue_script(
58 $handle,
59 WP_DEFENDER_BASE_URL . 'assets/js/audit-logging-ui.js',
60 array( 'def-vue', 'def-manifest', 'def-core-ui', 'defender', 'wp-i18n' ),
61 DEFENDER_VERSION,
62 true
63 );
64
65 wp_localize_script(
66 $handle,
67 'defenderUIData',
68 array_merge(
69 $this->get_shared_data(),
70 $this->data_frontend()
71 )
72 );
73
74 wp_enqueue_style(
75 $handle,
76 WP_DEFENDER_BASE_URL . 'assets/css/showcase.css',
77 array(),
78 DEFENDER_VERSION
79 );
80
81 $this->enqueue_main_assets();
82 }
83
84 /**
85 * Render the root element for frontend.
86 *
87 * @return void
88 */
89 public function main_view(): void {
90 $this->render( 'main' );
91 }
92
93 /**
94 * Dummy — returns empty logs response.
95 *
96 * @return Response
97 * @defender_route
98 */
99 public function pull_logs(): Response {
100 return new Response( false, array() );
101 }
102
103 /**
104 * Dummy — no-op CSV export.
105 *
106 * @defender_route
107 */
108 public function export_as_csv(): void {
109 }
110
111 /**
112 * Dummy — returns empty summary.
113 *
114 * @defender_route
115 */
116 public function summary(): void {
117 wp_send_json_success( array() );
118 }
119
120 /**
121 * Dummy — returns empty summary data.
122 *
123 * @param bool $for_hub Default false.
124 *
125 * @return array
126 */
127 public function summary_data( bool $for_hub = false ): array {
128 return array();
129 }
130
131 /**
132 * Dummy — save settings no-op.
133 *
134 * @return Response
135 * @defender_route
136 */
137 public function save_settings(): Response {
138 return new Response( true, array() );
139 }
140
141 /**
142 * All the variables that we will show on frontend.
143 *
144 * @return array
145 */
146 public function data_frontend(): array {
147 return array(
148 'auditLogging' => array_merge(
149 array(
150 'model' => $this->model->export(),
151 'logs' => array(),
152 'events_type' => array(),
153 'summary' => array(
154 'count_7_days' => 0,
155 'report' => '',
156 ),
157 'paging' => array(
158 'paged' => 1,
159 'total_pages' => 1,
160 'count' => 0,
161 ),
162 ),
163 $this->dump_routes_and_nonces()
164 ),
165 'antibot' => wd_di()->get( \WP_Defender\Controller\Antibot_Global_Firewall::class )->data_frontend(),
166 );
167 }
168
169 /**
170 * Converts the current state of the object to an array.
171 *
172 * @return array
173 */
174 public function to_array(): array {
175 return array_merge(
176 array(
177 'enabled' => false,
178 'report' => false,
179 ),
180 $this->dump_routes_and_nonces()
181 );
182 }
183
184 /**
185 * Dummy — import data no-op.
186 *
187 * @param array $data Data to import.
188 */
189 public function import_data( array $data ) {
190 }
191
192 /**
193 * Remove all settings.
194 */
195 public function remove_settings(): void {
196 }
197
198 /**
199 * Dummy — remove data no-op.
200 */
201 public function remove_data(): void {
202 }
203
204 /**
205 * Export strings.
206 *
207 * @return array
208 */
209 public function export_strings(): array {
210 return array(
211 sprintf(
212 /* translators: %s: Html for Pro-tag. */
213 esc_html__( 'Inactive %s', 'defender-security' ),
214 '<span class="sui-tag sui-tag-pro">Pro</span>'
215 ),
216 );
217 }
218
219 /**
220 * Config strings — always returns inactive.
221 *
222 * @param array $config Configuration data.
223 *
224 * @return array
225 */
226 public function config_strings( array $config ): array {
227 return $this->export_strings();
228 }
229 }
230