17
17
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
18
18
// ---------- END RUNBOX LICENSE ----------
19
19
import { Component , Output , EventEmitter , ViewChild , OnInit } from '@angular/core' ;
20
+ import { FormControl , FormGroup } from '@angular/forms' ;
21
+ import { MatTableDataSource } from '@angular/material/table' ;
20
22
import { MatPaginator } from '@angular/material/paginator' ;
21
23
import { MatSnackBar } from '@angular/material/snack-bar' ;
22
24
import { MatDialog } from '@angular/material/dialog' ;
23
25
import { MobileQueryService } from '../mobile-query.service' ;
24
26
import { RMM } from '../rmm' ;
25
27
import { ModalPasswordComponent } from './account.security.component' ;
28
+ import { RunboxWebmailAPI } from '../rmmapi/rbwebmail' ;
26
29
27
30
@Component ( {
28
31
selector : 'app-last-logins' ,
29
32
styleUrls : [ 'account.security.component.scss' ] ,
30
33
templateUrl : 'last-logins.component.html' ,
31
34
} )
32
- export class LastLoginsComponent implements OnInit {
35
+ export class LastLoginsComponent implements OnInit {
33
36
panelOpenState = false ;
34
- @ViewChild ( MatPaginator , { static : false } ) paginator : MatPaginator ;
37
+ @ViewChild ( MatPaginator ) paginator : MatPaginator ;
35
38
@Output ( ) Close : EventEmitter < string > = new EventEmitter ( ) ;
36
39
dialog_ref : any ;
37
40
acl_service = '' ;
@@ -41,13 +44,26 @@ export class LastLoginsComponent implements OnInit {
41
44
acl_ip = '' ;
42
45
acl_overwrite_subaccount_rules = '0' ;
43
46
is_acl_clear_enabled = false ;
44
- acl_manage_ip_rule = 'deny ' ;
47
+ acl_manage_ip_rule = '' ;
45
48
acl_manage_ip_range = '' ;
46
49
acl_manage_ip_label = '' ;
47
50
is_busy_list_logins = false ;
51
+ is_overwrite_subaccount_ip_rules = '' ;
48
52
modal_password_ref ;
49
53
50
- constructor ( public snackBar : MatSnackBar , public dialog : MatDialog , public mobileQuery : MobileQueryService , public rmm : RMM ) {
54
+ rulesColumns : string [ ] = [ 'rule' , 'ip' , 'label' , 'action' ] ;
55
+ blockedIpsColumns : string [ ] = [ 'service' , 'ip' , 'username' , 'failed' , 'action' ] ;
56
+ lastLoginsColumns : string [ ] = [ 'service' , 'login' , 'ip' , 'hostname' , 'time' , 'status' , 'actions' ] ;
57
+
58
+ addRuleForm ;
59
+
60
+ constructor (
61
+ public snackBar : MatSnackBar ,
62
+ public dialog : MatDialog ,
63
+ public mobileQuery : MobileQueryService ,
64
+ public rmm : RMM ,
65
+ public rmmapi : RunboxWebmailAPI
66
+ ) {
51
67
this . rmm . me . load ( ) ;
52
68
}
53
69
@@ -57,6 +73,15 @@ export class LastLoginsComponent implements OnInit {
57
73
this . rmm . account_security . acl . blocked_list ( ) ;
58
74
this . rmm . account_security . acl . accounts_affected ( ) ;
59
75
this . rmm . account_security . acl . list ( { } ) ;
76
+ this . rmm . account_security . tfa . get ( ) . subscribe ( ( ) => {
77
+ this . is_overwrite_subaccount_ip_rules = this . rmm . account_security . tfa . settings . is_overwrite_subaccount_ip_rules ;
78
+ } ) ;
79
+
80
+ this . addRuleForm = new FormGroup ( {
81
+ rule : new FormControl ( '' ) ,
82
+ ip : new FormControl ( '' ) ,
83
+ label : new FormControl ( '' )
84
+ } ) ;
60
85
61
86
if ( ! this . rmm . account_security . user_password ) {
62
87
this . show_modal_password ( ) ;
@@ -142,6 +167,8 @@ export class LastLoginsComponent implements OnInit {
142
167
. subscribe ( ( res ) => {
143
168
if ( res . status === 'success' ) {
144
169
this . rmm . account_security . acl . list ( { } ) ;
170
+ this . show_error ( 'Rule added' , 'Dismiss' ) ;
171
+ this . addRuleForm . reset ( ) ;
145
172
}
146
173
} ) ;
147
174
}
@@ -172,6 +199,7 @@ export class LastLoginsComponent implements OnInit {
172
199
if ( res . status === 'error' ) {
173
200
this . show_error ( res . error || res . errors . join ( '' ) , 'Dismiss' ) ;
174
201
}
202
+ this . rmm . account_security . acl . blocked_list ( ) ;
175
203
} ) ;
176
204
}
177
205
@@ -191,11 +219,27 @@ export class LastLoginsComponent implements OnInit {
191
219
if ( res . status === 'error' ) {
192
220
this . show_error ( res . error || res . errors . join ( '' ) , 'Dismiss' ) ;
193
221
}
194
- this . rmm . account_security . acl . logins_list ( { } ) ;
222
+ if ( res . status === 'success' ) {
223
+ this . show_error ( 'IP ' + result . ip + ' blocked' , 'Dismiss' ) ;
224
+ }
195
225
this . rmm . account_security . acl . blocked_list ( ) ;
226
+ this . rmm . account_security . acl . list ( { } ) ;
196
227
} ) ;
197
228
}
198
229
230
+ update_overwride_subaccount_rules ( ) {
231
+ if ( ! this . rmm . account_security . user_password ) {
232
+ this . show_modal_password ( ) ;
233
+ return ;
234
+ }
235
+ const data = {
236
+ action : 'update_status' ,
237
+ is_overwrite_subaccount_ip_rules : this . is_overwrite_subaccount_ip_rules ,
238
+ password : this . rmm . account_security . user_password ,
239
+ } ;
240
+ this . rmm . account_security . tfa . update ( data ) ;
241
+ }
242
+
199
243
ip_never_block ( result ) {
200
244
if ( ! this . rmm . account_security . user_password ) {
201
245
this . show_modal_password ( ) ;
@@ -204,16 +248,26 @@ export class LastLoginsComponent implements OnInit {
204
248
this . rmm . account_security . acl
205
249
. update ( {
206
250
ip : result . ip ,
251
+ label : 'Never Block' ,
207
252
rule : 'allow' ,
208
253
password : this . rmm . account_security . user_password ,
209
254
} )
210
255
. subscribe ( ( res ) => {
211
256
if ( res . status === 'error' ) {
212
257
this . show_error ( res . error || res . errors . join ( '' ) , 'Dismiss' ) ;
213
258
}
259
+ this . rmm . account_security . acl . blocked_list ( ) ;
260
+ this . rmm . account_security . acl . list ( { } ) ;
214
261
} ) ;
215
262
}
216
263
264
+ submit_rule_form ( data ) {
265
+ this . acl_manage_ip_rule = data . rule ;
266
+ this . acl_manage_ip_range = data . ip ;
267
+ this . acl_manage_ip_label = data . label ;
268
+ this . acl_create_rule ( ) ;
269
+ }
270
+
217
271
show_modal_password ( ) {
218
272
this . modal_password_ref = this . dialog . open ( ModalPasswordComponent , {
219
273
width : '600px' ,
0 commit comments