-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhooks.php
More file actions
51 lines (38 loc) · 1.09 KB
/
hooks.php
File metadata and controls
51 lines (38 loc) · 1.09 KB
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
<?php
if ( ! class_exists( 'EE' ) ) {
return;
}
use EE\Model\Auth;
use EE\Model\Site;
use EE\Model\Whitelist;
use Symfony\Component\Filesystem\Filesystem;
use EE\Site\Utils as Site_Utils;
/**
* Hook to cleanup auth entries and whitelisted ips if any.
*
* @param string $site_url The site to be cleaned up.
*/
function cleanup_auth_and_whitelist( $site_url ) {
if ( ! Site::find( $site_url ) ) {
return;
}
$fs = new Filesystem();
$auths = Auth::where( [ 'site_url' => $site_url ] );
if ( ! empty( $auths ) ) {
foreach ( $auths as $auth ) {
$auth->delete();
}
$site_auth_file = EE_ROOT_DIR . '/services/nginx-proxy/htpasswd/' . $site_url;
$fs->remove( $site_auth_file );
}
$whitelists = Whitelist::where( [ 'site_url' => $site_url ] );
if ( ! empty( $whitelists ) ) {
foreach ( $whitelists as $whitelist ) {
$whitelist->delete();
}
$site_whitelist_file = EE_ROOT_DIR . '/services/nginx-proxy/vhost.d/' . $site_url . '_acl';
$fs->remove( $site_whitelist_file );
}
Site_Utils\reload_global_nginx_proxy();
}
EE::add_hook( 'site_cleanup', 'cleanup_auth_and_whitelist' );