Skip to content

Commit

Permalink
via UI, allow default rules to be edited/deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
objective-see committed Jan 15, 2021
1 parent f90e60c commit 4e2096b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -38,3 +38,4 @@ Carthage/Build
Carthage/Checkouts
DMG/Release/*
DMG/LuLu.app
DMG/*.dmg
32 changes: 4 additions & 28 deletions LuLu/App/RulesTable.m
Expand Up @@ -82,20 +82,8 @@ -(NSMenu*)menuForEvent:(NSEvent *)event
//set tag
menu.itemArray.lastObject.tag = MENU_DELETE_RULE;

//rule not editable?
// disable delete then
if(RULE_TYPE_DEFAULT == rule.type.intValue)
{
//set state
menu.itemArray.lastObject.enabled = NO;
}
//otherwise
// ok to enable
else
{
//enable
menu.itemArray.lastObject.enabled = YES;
}
//enable
menu.itemArray.lastObject.enabled = YES;
}

//rule row
Expand All @@ -116,20 +104,8 @@ -(NSMenu*)menuForEvent:(NSEvent *)event
//set tag
menu.itemArray.lastObject.tag = MENU_DELETE_RULE;

//disable menu for default (system) rules
// these should not be edited via normal users!
if(RULE_TYPE_DEFAULT == rule.type.intValue)
{
//disable
toggleMenu(menu, NO);
}
//otherwise
// ok to enable
else
{
//enable
toggleMenu(menu, YES);
}
//enable
toggleMenu(menu, YES);
}

bail:
Expand Down
108 changes: 81 additions & 27 deletions LuLu/App/RulesWindowController.m
Expand Up @@ -351,7 +351,7 @@ -(IBAction)filterBoxHandler:(id)sender {
}

//double-click handler
// if it's an (editable) rule, bring up add/edit box
// bring up add/edit box
-(void)doubleClickHandler:(id)object
{
//clicked row
Expand All @@ -373,18 +373,30 @@ -(void)doubleClickHandler:(id)object
os_log_debug(logHandle, "row: %ld, item: %{public}@", (long)row, item);

//item row?
// show paths
// ...show paths
if(YES == [item isKindOfClass:[NSArray class]])
{
//show paths
[self showItemPaths:((NSArray*)item).firstObject];
}

//rule row
// ...only allowed editable ones
else if( (YES == [item isKindOfClass:[Rule class]]) &&
(RULE_TYPE_DEFAULT != ((Rule*)item).type.intValue) )
// ...edit!
else if(YES == [item isKindOfClass:[Rule class]])
{
//default rule?
//show alert/warning
if(RULE_TYPE_DEFAULT == ((Rule*)item).type.intValue)
{
//show alert
// ...and bail if user cancels
if(NSModalResponseCancel == [self showDefaultRuleAlert:item action:@"Editing"])
{
//bail
goto bail;
}
}

//add (edit) rule
[self addRule:item];
}
Expand All @@ -395,6 +407,42 @@ -(void)doubleClickHandler:(id)object

}

//warn user the modifying default rules might break things
-(NSModalResponse)showDefaultRuleAlert:(Rule*)rule action:(NSString*)action
{
//alert
NSAlert* alert = nil;

//response
NSModalResponse response = 0;

//init alert
alert = [[NSAlert alloc] init];

//set style
alert.alertStyle = NSAlertStyleWarning;

//main text
alert.messageText = [NSString stringWithFormat:@"%@ is legitimate macOS process", rule.name];

//details
alert.informativeText = [NSString stringWithFormat:@"%@ this rule, may impact legitimate system functionalty ...continue?", action];;

//add button
[alert addButtonWithTitle:@"Continue"];

//add button
[alert addButtonWithTitle:@"Cancel"];

//make app active
[NSApp activateIgnoringOtherApps:YES];

//show
response = [alert runModal];

return response;
}

//show paths in sheet
-(void)showItemPaths:(Rule*)rule
{
Expand Down Expand Up @@ -431,13 +479,26 @@ -(IBAction)addRule:(id)sender
//invoked with existing rule (to edit)
if(YES == [sender isKindOfClass:[Rule class]])
{
//default rule?
//show alert/warning
if(RULE_TYPE_DEFAULT == ((Rule*)sender).type.intValue)
{
//show alert
// ...and bail if user cancels
if(NSModalResponseCancel == [self showDefaultRuleAlert:sender action:@"Editing"])
{
//bail
goto bail;
}
}

//set rule
self.addRuleWindowController.rule = (Rule*)sender;
}

//show it
// on close/OK, invoke XPC to add rule, then reload
[self.window beginSheet:self.addRuleWindowController.window completionHandler:^(NSModalResponse returnCode) {
{[self.window beginSheet:self.addRuleWindowController.window completionHandler:^(NSModalResponse returnCode) {

//(existing) rule
Rule* rule = nil;
Expand Down Expand Up @@ -479,7 +540,9 @@ -(IBAction)addRule:(id)sender
//unset add rule window controller
self.addRuleWindowController = nil;

}];
}];}

bail:

return;
}
Expand Down Expand Up @@ -772,20 +835,8 @@ -(NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableC
cell.textField.stringValue = @"";
}

//disable button delete button if rule is a default (system) rule
if(RULE_TYPE_DEFAULT == rule.type.intValue)
{
//disable
[(NSButton*)[cell viewWithTag:TABLE_ROW_DELETE_TAG] setEnabled:NO];
}

//otherwise
// enable delete button
else
{
//enable
[(NSButton*)[cell viewWithTag:TABLE_ROW_DELETE_TAG] setEnabled:YES];
}
//enable
[(NSButton*)[cell viewWithTag:TABLE_ROW_DELETE_TAG] setEnabled:YES];
}

bail:
Expand Down Expand Up @@ -967,14 +1018,17 @@ -(IBAction)deleteRule:(id)sender
uuid = rule.uuid;
}

//don't delete system rules
//default rule?
// show alert/warning
if(RULE_TYPE_DEFAULT == rule.type.intValue)
{
//dbg msg
os_log_debug(logHandle, "rule is default/system ...won't delete");

//bail
goto bail;
//show alert
// ...and bail if user cancels
if(NSModalResponseCancel == [self showDefaultRuleAlert:rule action:@"Deleting"])
{
//bail
goto bail;
}
}

//remove rule via XPC
Expand Down
2 changes: 1 addition & 1 deletion LuLu/App/patrons.txt
Expand Up @@ -2,4 +2,4 @@ Patrons (2^6+):
Jan Koum, Christian Blümlein, MikeyH

Friends of Objective-See:
1Password, SmugMug, Guardian Mobile Firewall, SecureMac, iVerify, Halo Privacy
1Password, SmugMug, Guardian Mobile Firewall, SecureMac, iVerify, Halo Privacy

0 comments on commit 4e2096b

Please sign in to comment.