-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhosts.php
108 lines (98 loc) · 3.14 KB
/
hosts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
require __DIR__ . '/config.php';
$alert = new \VSP\Laragon\Modules\Alert();
if ( isset( $_POST['action'] ) ) {
$instance = \VSP\Laragon\Modules\Hosts\Parse::instance();
if ( 'update-status' === $_POST['action'] && isset( $_POST['host_id'] ) && isset( $_POST['status'] ) ) {
$new_id = $instance->update_hosts_data( $_POST['host_id'], array(
'is_disabled' => ( 'false' === $_POST['status'] ),
) );
if ( false !== $new_id ) {
$instance->save();
echo json_encode( array( 'host_id' => $new_id ) );
}
}
if ( 'delete' === $_POST['action'] && isset( $_POST['host_id'] ) ) {
$status = $instance->remove_host( $_POST['host_id'] );
echo json_encode( array( 'status' => $status ) );
}
exit;
}
if ( isset( $_POST['addnewhost'] ) ) {
$instance = \VSP\Laragon\Modules\Hosts\Parse::instance();
$issue = false;
if ( ! isset( $_POST['host_ip'] ) || isset( $_POST['host_ip'] ) && empty( $_POST['host_ip'] ) ) {
$alert->danger( 'Host IP Required.' );
$issue = true;
}
if ( ! isset( $_POST['domains'] ) || isset( $_POST['domains'] ) && empty( $_POST['domains'] ) ) {
$alert->danger( 'Domains Required.' );
$issue = true;
}
if ( false === $issue ) {
$domain = $_POST['domains'];
$host_ip = $_POST['host_ip'];
$comments = $_POST['comments'];
$status = ( isset( $_POST['new_hosts_status'] ) ) ? true : false;
$is_added = $instance->add( array(
'is_disabled' => ( false === $status ) ? true : false,
'ip' => $host_ip,
'domain' => explode( ',', $domain ),
'comment' => trim( $comments ),
'by_tool' => true,
) );
if ( $is_added ) {
$alert->success( 'Host Entry Added.' );
$instance->save();
}
}
}
echo $alert->alerts();
echo hosts_file_checks();
template( 'add-new-hosts' );
if ( is_hosts_file_readable() ) {
$instance = \VSP\Laragon\Modules\Hosts\Parse::instance();
?>
<div class="col-xs-12 mb-4 text-right">
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#add_new_hosts">Add (+)</button>
</div>
<table id="hostslisting" class="table table-striped">
<thead class="thead-dark">
<tr>
<th scope="col" style="width:50px;">Status</th>
<th scope="col" style="width:100px;">Host</th>
<th scope="col">Domains</th>
<th scope="col">Comments</th>
<th scope="col" style="width:50px;">Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ( $instance->get_list() as $id => $host ) {
$is_enabled = ( true === $host['is_disabled'] ) ? false : true;
$enh = ( true === $is_enabled ) ? 'checked' : '';
?>
<tr>
<td>
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="<?php echo $id; ?>" <?php echo $enh; ?>>
<label class="custom-control-label" for="<?php echo $id; ?>"></label>
</div>
</td>
<td><?php echo $host['ip']; ?></td>
<td><?php echo implode( '<br/>', $host['domain'] ); ?></td>
<td><?php echo trim( ltrim( $host['comment'], '#' ) ); ?></td>
<td>
<button type="button" class="btn btn-danger host-delete btn-sm" id="<?php echo $id; ?>">Delete
</button>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
template( 'footer' );
?>