-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathauth-utils.php
More file actions
62 lines (48 loc) · 1.7 KB
/
auth-utils.php
File metadata and controls
62 lines (48 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace EE\Auth\Utils;
use EE;
use EE\Model\Auth;
use EE\Utils as EE_Utils;
use EE\Service\Utils as Service_Utils;
/**
* Initialize global admin tools auth if it's not present.
*
* @param string $display_log Wether to display log message or not.
*
* @throws \EE\ExitException
* @throws \Exception
*/
function init_global_admin_tools_auth( $display_log = true ) {
if ( ! empty( Auth::get_global_admin_tools_auth() ) || ! empty( Auth::get_global_auths() ) ) {
if ( $display_log ) {
EE::log( 'Global auth exists on admin-tools. Use `ee auth list global` to view credentials.' );
}
return;
}
verify_htpasswd_is_present();
$pass = EE_Utils\random_password();
$auth_data = [
'site_url' => 'default_admin_tools',
'username' => 'easyengine',
'password' => $pass,
];
Auth::create( $auth_data );
EE::exec( sprintf( 'docker exec %s htpasswd -bc /etc/nginx/htpasswd/default_admin_tools %s %s', EE_PROXY_TYPE, $auth_data['username'], $auth_data['password'] ) );
if ( $display_log ) {
EE::success( sprintf( 'Global admin-tools auth added. Use `ee auth list global` to view credentials.' ) );
}
$launch = EE::launch( 'docker inspect -f "{{range .IPAM.Config}}{{.Gateway}}{{end}}" ee-global-frontend-network' );
$ip = trim( $launch->stdout );
EE::runcommand( "auth create global --ip='$ip'" );
}
/**
* Check if htpasswd is present in the global-container.
*/
function verify_htpasswd_is_present() {
Service_Utils\nginx_proxy_check();
EE::debug( 'Verifying htpasswd is present.' );
if ( EE::exec( sprintf( 'docker exec %s sh -c \'command -v htpasswd\'', EE_PROXY_TYPE ) ) ) {
return;
}
EE::error( sprintf( 'Could not find apache2-utils installed in %s.', EE_PROXY_TYPE ) );
}