From 9aa4c2b4ae5d5bfb29735d96c638f68a59634e3c Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 4 Jun 2008 03:50:10 +0000 Subject: [PATCH] add rpc access control table to prefs --- macosx/Controller.m | 2 +- macosx/Defaults.plist | 8 +- macosx/English.lproj/MainMenu.xib | 2 + macosx/English.lproj/PrefsWindow.xib | 402 +++++++++++++++++++++++++-- macosx/PrefsController.h | 3 + macosx/PrefsController.m | 103 +++++++ 6 files changed, 499 insertions(+), 21 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 1034ed9b4..a181396ba 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -219,7 +219,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy TR_DEFAULT_PEER_SOCKET_TOS, [fDefaults boolForKey: @"RPC"], [fDefaults integerForKey: @"RPCPort"], - TR_DEFAULT_RPC_ACL); + /*TR_DEFAULT_RPC_ACL*/""); [NSApp setDelegate: self]; diff --git a/macosx/Defaults.plist b/macosx/Defaults.plist index 2a67c7995..e028ec6cf 100644 --- a/macosx/Defaults.plist +++ b/macosx/Defaults.plist @@ -84,10 +84,6 @@ Constant NatTraversal - RPC - - RPCPort - 9091 PEXGlobal PeersTorrent @@ -114,6 +110,10 @@ RatioLimit 2 + RPC + + RPCPort + 9091 SeedingSound Submarine ShowInspector diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index e8a8ad1ae..0e29a56b7 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -9,6 +9,7 @@ YES + YES @@ -2214,6 +2215,7 @@ zJLMsszTzPPNFM00zVXNdc2GzabNx83nzgjOKM5JzmnOis6qzrrO2877zxzPPM9dz33Pns++z9/P79AA 2147483647 + 501 diff --git a/macosx/English.lproj/PrefsWindow.xib b/macosx/English.lproj/PrefsWindow.xib index 0ae789015..ce9823e58 100644 --- a/macosx/English.lproj/PrefsWindow.xib +++ b/macosx/English.lproj/PrefsWindow.xib @@ -8,9 +8,7 @@ 352.00 YES - - YES @@ -929,7 +927,7 @@ 6 System textBackgroundColor - + 3 MQA @@ -1519,7 +1517,7 @@ NSResponder - + 256 YES @@ -2114,7 +2112,6 @@ AAABAAAAAQ {535, 226} - NSView NSResponder @@ -2536,7 +2533,7 @@ AAABAAAAAQ NSResponder - + 256 YES @@ -2796,7 +2793,6 @@ AAABAAAAAQ {535, 153} - NSView NSResponder @@ -2808,7 +2804,7 @@ AAABAAAAAQ 256 - {{103, 48}, {96, 17}} + {{102, 210}, {96, 17}} YES @@ -2824,7 +2820,7 @@ AAABAAAAAQ 256 - {{204, 46}, {50, 22}} + {{204, 208}, {50, 22}} YES @@ -2890,7 +2886,7 @@ AAABAAAAAQ 256 - {{84, 72}, {367, 18}} + {{84, 234}, {367, 18}} YES @@ -2912,7 +2908,7 @@ AAABAAAAAQ 256 - {{104, 21}, {139, 18}} + {{103, 183}, {139, 18}} YES @@ -2934,7 +2930,7 @@ AAABAAAAAQ 256 - {{249, 20}, {152, 22}} + {{248, 182}, {152, 22}} YES @@ -2952,8 +2948,229 @@ AAABAAAAAQ + + + 256 + {{102, 161}, {123, 17}} + + YES + + 67239424 + 71303168 + Access control list: + + + + + + + + + 268 + + YES + + + 2304 + + YES + + + 256 + {327, 117} + + YES + + + 256 + {327, 17} + + + + + + 256 + {{328, 0}, {16, 17}} + + + + YES + + IP + 2.570000e+02 + 4.000000e+01 + 1.000000e+03 + + 75628032 + 0 + IP Address + + + 3 + MC4zMzMzMzI5OQA + + + 6 + System + headerTextColor + + + + + 337772096 + 2048 + Text Cell + + + + + + 3 + YES + YES + + + + Permission + 6.400000e+01 + 4.000000e+01 + 1.000000e+03 + + 75628032 + 0 + Permission + + + + + + -2076049856 + 133120 + + + 100679935 + 129 + + + 400 + 75 + + + Allow + + 1048576 + 2147483647 + 1 + + + _popUpItemAction: + + + YES + + OtherViews + + YES + + + + Block + + 2147483647 + + + _popUpItemAction: + + + + + 3 + YES + YES + 1 + + 3 + YES + YES + + + + 3.000000e+00 + 2.000000e+00 + + + 6 + System + gridColor + + 3 + MC41AA + + + 1.700000e+01 + -557842432 + 4 + 15 + 0 + YES + + + {{1, 17}, {327, 117}} + + + + + 4 + + + + 256 + {{328, 17}, {15, 117}} + + + _doScroller: + 3.700000e+01 + 1.947368e-01 + + + + 256 + {{-100, -100}, {327, 15}} + + 1 + + _doScroller: + 9.971265e-01 + + + + 2304 + + YES + + + {{1, 0}, {327, 17}} + + + + + 4 + + + + {{105, 18}, {344, 135}} + + + 18 + + + + + + QSAAAEEgAABBmAAAQZgAAA + - {535, 108} + {535, 270} NSView NSResponder @@ -4688,6 +4905,22 @@ AAABAAAAAQ 1515 + + + dataSource + + + + 1532 + + + + fRPCAccessTable + + + + 1533 + @@ -6487,11 +6720,13 @@ AAABAAAAAQ YES - + + + Remote @@ -6575,6 +6810,109 @@ AAABAAAAAQ + + 1516 + + + YES + + + + + + 1517 + + + + + 1518 + + + YES + + + + + + + + + 1519 + + + + + 1520 + + + + + 1521 + + + YES + + + + + + + 1522 + + + + + 1523 + + + YES + + + + + + 1524 + + + YES + + + + + + 1526 + + + + + 1528 + + + YES + + + + + + 1529 + + + YES + + + + + + + 1530 + + + + + 1531 + + + @@ -6679,10 +7017,25 @@ AAABAAAAAQ 1504.ImportedFromIB2 1509.IBPluginDependency 1510.IBPluginDependency + 1516.IBPluginDependency + 1516.ImportedFromIB2 + 1518.IBPluginDependency + 1519.IBPluginDependency + 1520.IBPluginDependency + 1521.IBPluginDependency + 1522.IBPluginDependency + 1523.IBPluginDependency + 1524.IBPluginDependency + 1526.IBPluginDependency + 1528.IBPluginDependency + 1529.IBEditorWindowLastContentRect + 1529.IBPluginDependency 153.IBEditorWindowLastContentRect 153.IBPluginDependency 153.ImportedFromIB2 153.editorWindowContentRectSynchronizationRect + 1530.IBPluginDependency + 1531.IBPluginDependency 154.IBPluginDependency 154.ImportedFromIB2 155.IBPluginDependency @@ -6978,7 +7331,7 @@ AAABAAAAAQ com.apple.InterfaceBuilder.CocoaPlugin - {{472, 699}, {535, 108}} + {{404, 377}, {535, 270}} com.apple.InterfaceBuilder.CocoaPlugin {{281, 577}, {539, 315}} @@ -6994,11 +7347,26 @@ AAABAAAAAQ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{499, 476}, {327, 37}} + com.apple.InterfaceBuilder.CocoaPlugin {{289, 658}, {535, 226}} com.apple.InterfaceBuilder.CocoaPlugin {{149, 524}, {539, 226}} com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7237,7 +7605,7 @@ AAABAAAAAQ - 1515 + 1533 @@ -7415,6 +7783,7 @@ AAABAAAAAQ fPortStatusProgress fQueueDownloadField fQueueSeedField + fRPCAccessTable fRPCPortField fRatioStopField fRemoteView @@ -7445,6 +7814,7 @@ AAABAAAAAQ NSProgressIndicator NSTextField NSTextField + NSTableView NSTextField NSTextField NSView diff --git a/macosx/PrefsController.h b/macosx/PrefsController.h index 12778f2d0..3d544a336 100644 --- a/macosx/PrefsController.h +++ b/macosx/PrefsController.h @@ -58,6 +58,8 @@ int fPeerPort, fNatStatus; IBOutlet NSTextField * fRPCPortField; + IBOutlet NSTableView * fRPCAccessTable; + NSMutableArray * fRPCAccessArray; } - (id) initWithHandle: (tr_handle *) handle; @@ -120,6 +122,7 @@ - (void) setRPCEnabled: (id) sender; - (void) setRPCPort: (id) sender; +- (void) updateRPCAccessList; - (void) rpcUpdatePrefs; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 3af70cf10..9846cc106 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -31,6 +31,9 @@ #define DOWNLOAD_FOLDER 0 #define DOWNLOAD_TORRENT 2 +#define RPC_ACCESS_ALLOW 0 +#define RPC_ACCESS_BLOCK 1 + #define UPDATE_SECONDS 86400 #define TOOLBAR_GENERAL @"TOOLBAR_GENERAL" @@ -94,6 +97,13 @@ //actually set bandwidth limits [self applySpeedSettings: nil]; + + //update rpc access list + fRPCAccessArray = [[fDefaults arrayForKey: @"RPCAccessList"] mutableCopy]; + if (!fRPCAccessArray) + fRPCAccessArray = [[NSMutableArray arrayWithObject: [NSDictionary dictionaryWithObjectsAndKeys: @"127.0.0.1", @"IP", + [NSNumber numberWithBool: YES], @"Allow", nil]] retain]; + [self updateRPCAccessList]; } return self; @@ -114,6 +124,8 @@ [fPortChecker release]; } + [fRPCAccessArray release]; + [super dealloc]; } @@ -637,6 +649,97 @@ tr_sessionSetRPCPort(fHandle, port); } +- (void) updateRPCAccessList +{ + NSMutableString * string = [NSMutableString stringWithCapacity: 17 * [fRPCAccessArray count]]; + + NSEnumerator * enumerator = [fRPCAccessArray objectEnumerator]; + NSDictionary * dict; + while ((dict = [enumerator nextObject])) + { + [string appendFormat: @"%c%@,", [[dict objectForKey: @"Allow"] boolValue] ? '+' : '-', [dict objectForKey: @"IP"]]; + } + + //remove last comma + NSUInteger length = [string length]; + if (length > 0) + [string deleteCharactersInRange: NSMakeRange(length-1, 1)]; + + #warning check for an error! + tr_sessionSetRPCACL(fHandle, [string UTF8String], NULL); +} + +- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView +{ + return [fRPCAccessArray count]; +} + +- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row +{ + NSDictionary * dict = [fRPCAccessArray objectAtIndex: row]; + + NSString * ident = [tableColumn identifier]; + if ([ident isEqualToString: @"Permission"]) + { + int allow = [[dict objectForKey: @"Allow"] boolValue] ? RPC_ACCESS_ALLOW : RPC_ACCESS_BLOCK; + return [NSNumber numberWithInt: allow]; + } + else + return [dict objectForKey: @"IP"]; +} + +- (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn + row: (NSInteger) row +{ + NSDictionary * oldDict = [fRPCAccessArray objectAtIndex: row], * newDict; + + NSString * ident = [tableColumn identifier]; + if ([ident isEqualToString: @"Permission"]) + { + NSNumber * allow = [NSNumber numberWithBool: [object intValue] == RPC_ACCESS_ALLOW]; + newDict = [NSDictionary dictionaryWithObjectsAndKeys: [oldDict objectForKey: @"IP"], @"IP", allow, @"Allow", nil]; + } + else + { + //verify ip + NSArray * components = [object componentsSeparatedByString: @"."]; + if ([components count] != 4) + { + NSBeep(); + return; + } + + NSMutableArray * newComponents = [NSMutableArray arrayWithCapacity: 4]; + + NSEnumerator * enumerator = [components objectEnumerator]; + NSString * component; + while ((component = [enumerator nextObject])) + { + if ([component isEqualToString: @"*"]) + [newComponents addObject: component]; + else + { + int value = [component intValue]; + if (value >= 0 && value < 256) + [newComponents addObject: [[NSNumber numberWithInt: value] stringValue]]; + else + { + NSBeep(); + return; + } + } + } + + newDict = [NSDictionary dictionaryWithObjectsAndKeys: [newComponents componentsJoinedByString: @"."], @"IP", + [oldDict objectForKey: @"Allow"], @"Allow", nil];NSLog([newDict description]); + } + + [fRPCAccessArray replaceObjectAtIndex: row withObject: newDict]; + + [fDefaults setObject: fRPCAccessArray forKey: @"RPCAccessList"]; + [self updateRPCAccessList]; +} + - (void) helpForPeers: (id) sender { [[NSHelpManager sharedHelpManager] openHelpAnchor: @"PeersPrefs"