Skip to content

Commit 707f03c

Browse files
Merge pull request #4 from mrrobot47/develop
Update variable name and success msgs
2 parents 438ff59 + f01a3a3 commit 707f03c

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

src/Auth_Command.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class Auth_Command extends EE_Command {
2525
private $fs;
2626

2727
/**
28-
* @var array $db Object containing essential site related information.
28+
* @var array $site_data Object containing essential site related information.
2929
*/
30-
private $db;
30+
private $site_data;
3131

3232
public function __construct() {
3333

@@ -54,7 +54,7 @@ public function create( $args, $assoc_args ) {
5454

5555
$global = $this->populate_info( $args, __FUNCTION__ );
5656

57-
EE::debug( sprintf( 'ee auth start, Site: %s', $this->db->site_url ) );
57+
EE::debug( sprintf( 'ee auth start, Site: %s', $this->site_data->site_url ) );
5858

5959
$user = EE\Utils\get_flag_value( $assoc_args, 'user', 'easyengine' );
6060
$pass = EE\Utils\get_flag_value( $assoc_args, 'pass', EE\Utils\random_password() );
@@ -64,14 +64,14 @@ public function create( $args, $assoc_args ) {
6464
if ( ! $check_htpasswd_present ) {
6565
EE::error( sprintf( 'Could not find apache2-utils installed in %s.', EE_PROXY_TYPE ) );
6666
}
67-
$file = $global ? 'default' : $this->db->site_url;
67+
$file = $global ? 'default' : $this->site_data->site_url;
6868
$params = $this->fs->exists( EE_CONF_ROOT . '/nginx/htpasswd/' . $file ) ? 'b' : 'bc';
6969
EE::exec( sprintf( 'docker exec %s htpasswd -%s /etc/nginx/htpasswd/%s %s %s', EE_PROXY_TYPE, $params, $file, $user, $pass ) );
7070

7171
EE::log( 'Reloading global reverse proxy.' );
7272
$this->reload();
7373

74-
EE::log( sprintf( 'Auth successfully updated for `%s` scope. New values added/updated:', $this->db->site_url ) );
74+
EE::success( sprintf( 'Auth successfully updated for `%s` scope. New values added/updated:', $this->site_data->site_url ) );
7575
EE::log( 'User:' . $user );
7676
EE::log( 'Pass:' . $pass );
7777
}
@@ -91,14 +91,14 @@ public function create( $args, $assoc_args ) {
9191
public function delete( $args, $assoc_args ) {
9292

9393
$global = $this->populate_info( $args, __FUNCTION__ );
94-
$file = $global ? 'default' : $this->db->site_url;
94+
$file = $global ? 'default' : $this->site_data->site_url;
9595
$user = EE\Utils\get_flag_value( $assoc_args, 'user' );
9696

9797
if ( $user ) {
98-
EE::exec( sprintf( 'docker exec %s htpasswd -D /etc/nginx/htpasswd/%s %s', EE_PROXY_TYPE, $this->db->site_url, $user ), true, true );
98+
EE::exec( sprintf( 'docker exec %s htpasswd -D /etc/nginx/htpasswd/%s %s', EE_PROXY_TYPE, $this->site_data->site_url, $user ), true, true );
9999
} else {
100100
$this->fs->remove( EE_CONF_ROOT . '/nginx/htpasswd/' . $file );
101-
EE::log( sprintf( 'http auth removed for `%s` scope', $this->db->site_url ) );
101+
EE::success( sprintf( 'http auth removed for `%s` scope', $this->site_data->site_url ) );
102102
}
103103
$this->reload();
104104
}
@@ -127,7 +127,7 @@ public function delete( $args, $assoc_args ) {
127127
public function list( $args, $assoc_args ) {
128128

129129
$global = $this->populate_info( $args, __FUNCTION__ );
130-
$file = EE_CONF_ROOT . '/nginx/htpasswd/' . ( $global ? 'default' : $this->db->site_url );
130+
$file = EE_CONF_ROOT . '/nginx/htpasswd/' . ( $global ? 'default' : $this->site_data->site_url );
131131
$format = EE\Utils\get_flag_value( $assoc_args, 'format' );
132132
if ( $this->fs->exists( $file ) ) {
133133
$user_lines = explode( PHP_EOL, trim( file_get_contents( $file ) ) );
@@ -144,7 +144,7 @@ public function list( $args, $assoc_args ) {
144144
$formatter->display_items( $users );
145145
}
146146
} else {
147-
EE::error( sprintf( 'http auth not enabled on %s', $this->db->site_url ) );
147+
EE::error( sprintf( 'http auth not enabled on %s', $this->site_data->site_url ) );
148148
}
149149
}
150150

@@ -190,7 +190,7 @@ public function whitelist( $args, $assoc_args ) {
190190
$ip = EE\Utils\get_flag_value( $assoc_args, 'ip' );
191191

192192
$file = EE_CONF_ROOT . '/nginx/vhost.d/';
193-
$file .= $global ? 'default_acl' : $this->db->site_url . '_acl';
193+
$file .= $global ? 'default_acl' : $this->site_data->site_url . '_acl';
194194
$user_ips = array_filter( explode( ',', $ip ), 'strlen' );
195195
$existing_ips = $this->get_ips_from_file( $global );
196196

@@ -213,7 +213,7 @@ private function whitelist_create( $file, $user_ips, $existing_ips ) {
213213
$file_content .= "allow $ip;" . PHP_EOL;
214214
}
215215
$this->fs->dumpFile( $file, $file_content );
216-
EE::log( sprintf( 'Created whitelist for `%s` scope with %s IP\'s.', $this->db->site_url, implode( ',', $user_ips ) ) );
216+
EE::success( sprintf( 'Created whitelist for `%s` scope with %s IP\'s.', $this->site_data->site_url, implode( ',', $user_ips ) ) );
217217
}
218218

219219
/**
@@ -231,7 +231,7 @@ private function whitelist_append( $file, $user_ips, $existing_ips ) {
231231
$file_content .= "allow $individual_ip;" . PHP_EOL;
232232
}
233233
$this->fs->dumpFile( $file, $file_content );
234-
EE::log( sprintf( 'Appended %s IP\'s to whitelist of `%s` scope', implode( ',', $user_ips ), $this->db->site_url ) );
234+
EE::success( sprintf( 'Appended %s IP\'s to whitelist of `%s` scope', implode( ',', $user_ips ), $this->site_data->site_url ) );
235235
}
236236

237237
/**
@@ -244,10 +244,10 @@ private function whitelist_append( $file, $user_ips, $existing_ips ) {
244244
private function whitelist_list( $file, $user_ips, $existing_ips ) {
245245

246246
if ( empty( $existing_ips ) ) {
247-
EE::error( sprintf( 'No Whitelisted IP\'s found for %s scope', $this->db->site_url ) );
247+
EE::error( sprintf( 'No Whitelisted IP\'s found for %s scope', $this->site_data->site_url ) );
248248
}
249249

250-
EE::log( sprintf( 'Whitelisted IP\'s for %s scope', $this->db->site_url ) );
250+
EE::log( sprintf( 'Whitelisted IP\'s for %s scope', $this->site_data->site_url ) );
251251
foreach ( $existing_ips as $ips ) {
252252
EE::log( $ips );
253253
}
@@ -275,10 +275,10 @@ private function whitelist_remove( $file, $user_ips, $existing_ips ) {
275275
$this->fs->dumpFile( $file, $file_content );
276276
}
277277
if ( empty( $removed_ips ) ) {
278-
EE::error( sprintf( '%s IP\'s not found in whitelist of `%s` scope', implode( ',', $user_ips ), $this->db->site_url ) );
278+
EE::error( sprintf( '%s IP\'s not found in whitelist of `%s` scope', implode( ',', $user_ips ), $this->site_data->site_url ) );
279279
}
280-
EE::warning( sprintf( 'Could not find %s IP\'s from whitelist of `%s` scope', implode( ',', $leftover_ips ), $this->db->site_url ) );
281-
EE::log( sprintf( 'Removed %s IP\'s from whitelist of `%s` scope', implode( ',', $removed_ips ), $this->db->site_url ) );
280+
EE::warning( sprintf( 'Could not find %s IP\'s from whitelist of `%s` scope', implode( ',', $leftover_ips ), $this->site_data->site_url ) );
281+
EE::success( sprintf( 'Removed %s IP\'s from whitelist of `%s` scope', implode( ',', $removed_ips ), $this->site_data->site_url ) );
282282
}
283283

284284
/**
@@ -299,7 +299,7 @@ private function reload() {
299299
private function get_ips_from_file( $global ) {
300300

301301
$file = EE_CONF_ROOT . '/nginx/vhost.d/';
302-
$file .= $global ? 'default_acl' : $this->db->site_url . '_acl';
302+
$file .= $global ? 'default_acl' : $this->site_data->site_url . '_acl';
303303
$existing_ips = [];
304304
if ( $this->fs->exists( $file ) ) {
305305
$existing_ips_in_file = array_filter( explode( PHP_EOL, trim( file_get_contents( $file ) ) ), 'strlen' );
@@ -323,12 +323,12 @@ private function populate_info( $args, $command ) {
323323

324324
$global = false;
325325
if ( isset( $args[0] ) && 'global' === $args[0] ) {
326-
$this->db = (object) [ 'site_url' => $args[0] ];
327-
$global = true;
326+
$this->site_data = (object) [ 'site_url' => $args[0] ];
327+
$global = true;
328328
} else {
329-
$args = EE\SiteUtils\auto_site_name( $args, 'auth', $command );
330-
$this->db = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
331-
if ( ! $this->db || ! $this->db->site_enabled ) {
329+
$args = EE\SiteUtils\auto_site_name( $args, 'auth', $command );
330+
$this->site_data = Site::find( EE\Utils\remove_trailing_slash( $args[0] ) );
331+
if ( ! $this->site_data || ! $this->site_data->site_enabled ) {
332332
EE::error( sprintf( 'Site %s does not exist / is not enabled.', $args[0] ) );
333333
}
334334
}

0 commit comments

Comments
 (0)