5 // Created by Claudio Bisegni on 10/05/07.
6 // Copyright (c) 2007 INFN - National Institute of Nuclear Physics. All rights reserved.
9 #import "AFSCommanderPref.h"
10 #import "IpConfiguratorCommander.h"
11 #import "TokenCredentialController.h"
12 #import "InfoController.h"
14 #import "PListManager.h"
15 #import "DialogUtility.h"
16 #import "NSString+search.h"
17 #include <sys/param.h>
20 #include <sys/types.h>
21 #include <sys/fcntl.h>
22 #include <sys/errno.h>
26 #import <CoreServices/CoreServices.h>
29 #define ADD_CELL_CONTROL_TAG 1
30 #define REMOVE_CELL_CONTROL_TAG 2
32 #define TABLE_TOKENS_LIST 1
33 #define TABLE_CELL_LIST 2
36 #define TAB_CELL_SERV_DB 2
41 #define CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN 0
42 #define CELLSRVDB_TABLE_DFLT_CHECK_COLUMN 1
43 #define CELLSRVDB_TABLE_NAME_COLUMN 2
44 #define CELLSRVDB_TABLE_DESCRIPTION_COLUMN 3
46 @implementation AFSCommanderPref
48 // -------------------------------------------------------------------------------
50 // -------------------------------------------------------------------------------
51 - (id)initWithBundle:(NSBundle *)bundle
53 if ( ( self = [super initWithBundle:bundle] ) != nil ) {
54 //appID = kAfsCommanderID;
60 // -------------------------------------------------------------------------------
62 // -------------------------------------------------------------------------------
63 - (NSView *) mainView {
64 if (prefStartUp == 1){
67 if (Gestalt(gestaltSystemVersionMajor, &osxMJVers) == noErr && Gestalt(gestaltSystemVersionMinor, &osxMnVers) == noErr) {
68 if (osxMJVers == 10 && osxMnVers>= 5) {
69 [afsCommanderView setFrameSize:NSMakeSize(668, [afsCommanderView frame].size.height)];
75 return afsCommanderView;
78 // -------------------------------------------------------------------------------
80 // -------------------------------------------------------------------------------
81 - (void) mainViewDidLoad
84 [((NSTableView*)cellList) setDelegate:self];
85 [((NSTableView*)cellList) setTarget:self];
86 [((NSTableView*)cellList) setDoubleAction:@selector(tableDoubleAction:)];
91 // -------------------------------------------------------------------------------
93 // -------------------------------------------------------------------------------
96 //try to install the launchd file for backgrounder
97 //Remove launchd ctrl file
99 [PListManager installBackgrounderLaunchdFile:YES
100 resourcePath:[[self bundle] resourcePath]];
102 @catch (NSException * e) {
103 NSDictionary *excecptDic = [e userInfo];
104 NSNumber *keyNum = [excecptDic objectForKey:@"agent_folder_error"];
105 if(keyNum && [keyNum boolValue]) {
106 // the dir HOME_LAUNCHD_AGENT_FOLDER (PListManager.h) must be created
107 NSBeginAlertSheet([[NSString stringWithString:kDoYouWantCreateTheDirectory] stringByAppendingString:HOME_LAUNCHD_AGENT_FOLDER],
108 @"Create", @"Cancel", nil,
109 [[self mainView] window], self, @selector(credentialAtLoginTimeEventCreationLaunchAgentDir:returnCode:contextInfo:), NULL,
118 // Set Developer info
119 [textFieldDevInfoLabel setStringValue:kDevelopInfo];
121 tokensLock = [[NSLock alloc] init];
123 //Initialization cellservdb and token list
124 filteredCellDB = nil;
127 [self readPreferenceFile];
129 // alloc the afs property mananger
130 afsProperty = [[AFSPropertyManager alloc] init];
132 // register preference pane to detect menuextra killed by user
133 /* [[NSDistributedNotificationCenter defaultCenter] addObserver:self
134 selector:@selector(mextraChangeActivation:)
136 object:kMExtraClosedNotification];*/
138 [[NSDistributedNotificationCenter defaultCenter] addObserver:self
139 selector:@selector(refreshGui:)
141 object:kMenuExtraEventOccured];
143 //Register for mount/unmount afs volume
144 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
145 selector:@selector(afsVolumeMountChange:)
146 name:NSWorkspaceDidMountNotification object:nil];
148 [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
149 selector:@selector(afsVolumeMountChange:)
150 name:NSWorkspaceDidUnmountNotification object:nil];
152 // set self as table data source
153 [((NSTableView*)cellList) setDataSource:self];
154 [((NSTableView*)tokensTable) setDataSource:self];
156 //check the afs state
159 // let show the configuration after prefpane is open
160 [self refreshConfiguration:nil];
162 // refresh the token list
163 //[self refreshTokens:nil];
165 //refresh table to reflect the NSSearchField contained text
166 [self searchCellTextEvent:nil];
169 // -------------------------------------------------------------------------------
170 // credentialAtLoginTimeEventCreationLaunchAgentDir:
171 // -------------------------------------------------------------------------------
172 - (void) credentialAtLoginTimeEventCreationLaunchAgentDir:(NSWindow*)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo {
174 switch (returnCode) {
176 if([[NSFileManager defaultManager] createDirectoryAtPath:[HOME_LAUNCHD_AGENT_FOLDER stringByExpandingTildeInPath]
180 [PListManager installBackgrounderLaunchdFile:YES
181 resourcePath:[[self bundle] resourcePath]];
182 [self showMessage:kDirectoryCreated];
184 [self showMessage:kErrorCreatingDirectory];
193 // -------------------------------------------------------------------------------
195 // -------------------------------------------------------------------------------
198 // remove self as datasource
199 [((NSTableView*)cellList) setDataSource:nil];
200 [((NSTableView*)tokensTable) setDataSource:nil];
202 //release the afs property manager
203 if(afsProperty) [afsProperty release];
204 //release tokens list
205 if(tokenList) [tokenList release];
206 //Remove the cell temp array
207 if(filteredCellDB) [filteredCellDB release];
209 [self writePreferenceFile];
211 // unregister preference pane to detect menuextra killed by user
212 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self
214 object:kMExtraClosedNotification];
215 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self
217 object:kMenuExtraEventOccured];
218 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self
219 name:NSWorkspaceDidMountNotification object:nil];
220 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self
221 name:NSWorkspaceDidUnmountNotification object:nil];
224 [tokensLock release];
228 // -------------------------------------------------------------------------------
230 // -------------------------------------------------------------------------------
232 //start the time for check tokens validity
233 if(timerForCheckTokensList) return;
234 timerForCheckTokensList = [NSTimer scheduledTimerWithTimeInterval:TOKENS_REFRESH_TIME_IN_SEC
236 selector:@selector(refreshTokens:)
239 [timerForCheckTokensList fire];
242 // -------------------------------------------------------------------------------
244 // -------------------------------------------------------------------------------
246 if(!timerForCheckTokensList) return;
247 [timerForCheckTokensList invalidate];
248 timerForCheckTokensList = nil;
252 // -------------------------------------------------------------------------------
253 // readPreferenceFile:
254 // -------------------------------------------------------------------------------
255 - (void) readPreferenceFile
258 // read the preference for aklog use
259 NSNumber *useAklogPrefValue = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_USE_AKLOG, (CFStringRef)kAfsCommanderID,
260 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
261 NSNumber *aklogTokenAtLogin = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN, (CFStringRef)kAfsCommanderID,
262 kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
263 [useAklogCheck setState:[useAklogPrefValue intValue]];
264 [aklogCredentialAtLoginTime setEnabled:useAklogPrefValue && [useAklogPrefValue boolValue]];
265 [aklogCredentialAtLoginTime setState:aklogTokenAtLogin && [aklogTokenAtLogin boolValue]];
267 //check krb5 at login time
268 [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
270 //check for AFS enable at startup
271 NSNumber *afsEnableStartupTime = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP,
272 (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
273 if(afsEnableStartupTime)
274 startAFSAtLogin = [afsEnableStartupTime boolValue];
276 startAFSAtLogin = false;
277 //set the check button state
278 [checkButtonAfsAtBootTime setState:startAFSAtLogin];
280 NSNumber *showStatusMenu = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU, (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
281 [(NSButton*)afsMenucheckBox setState: [showStatusMenu boolValue]];
284 [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
287 // -------------------------------------------------------------------------------
289 // -------------------------------------------------------------------------------
290 - (void) writePreferenceFile
292 //Set the preference for afs path
293 /*CFPreferencesSetValue((CFStringRef)PREFERENCE_AFS_SYS_PAT,
294 (CFStringRef)[((NSTextField*) installationPathTextField ) stringValue],
295 (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);*/
297 //Set the preference for aklog use
298 CFPreferencesSetValue((CFStringRef)PREFERENCE_USE_AKLOG,
299 (CFNumberRef)[NSNumber numberWithInt:[useAklogCheck state]],
300 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
302 //set AFS enable state at startup
303 CFPreferencesSetValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP,
304 (CFNumberRef)[NSNumber numberWithBool:startAFSAtLogin],
305 (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
308 CFPreferencesSetValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN,
309 (CFNumberRef)[NSNumber numberWithBool:[aklogCredentialAtLoginTime state]],
310 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
313 CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU,
314 (CFNumberRef)[NSNumber numberWithBool:[afsMenucheckBox state]],
315 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
317 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
318 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
320 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kPrefChangeNotification];
323 // -------------------------------------------------------------------------------
324 // saveConfiguration:
325 // -------------------------------------------------------------------------------
326 - (IBAction) saveConfiguration:(id) sender
330 //[afsProperty setCellName:[cellNameTextEdit stringValue]];
331 [afsProperty setCellName:[afsProperty getDefaultCellName]];
333 //save configurations
334 [afsProperty saveConfigurationFiles:YES];
337 //Reload all configuration
338 [self refreshConfiguration:nil];
340 //refresh table to reflect the NSSearchField contained text
341 [self searchCellTextEvent:nil];
343 //Show dialog for notifity al saving process ar gone ell
344 [self showMessage:kConfigurationSaved];
345 }@catch(NSException *e){
346 [self showMessage:[e reason]];
348 [((NSTableView*)cellList) reloadData];
353 // -------------------------------------------------------------------------------
354 // saveCacheManagerParam:
355 // -------------------------------------------------------------------------------
356 - (IBAction) saveCacheManagerParam:(id) sender
359 //Update the value form view to afs property manager class
360 [self updateCacheParamFromView];
361 [afsProperty saveCacheConfigurationFiles:YES];
362 [self showMessage:kSavedCacheConfiguration];
363 }@catch(NSException *e){
364 [self showMessage:[e reason]];
366 [((NSTableView*)cellList) reloadData];
370 // -------------------------------------------------------------------------------
371 // refreshConfiguration:
372 // -------------------------------------------------------------------------------
373 - (IBAction) refreshConfiguration:(id) sender
375 NSString *afsBasePath = PREFERENCE_AFS_SYS_PAT_STATIC;
378 [afsProperty setPath:afsBasePath];
380 // load configuration
381 [afsProperty loadConfiguration];
383 //set the afs version label
384 [afsVersionLabel setStringValue:[afsProperty getAfsVersion]];
386 //set the current default cell
387 [afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
390 [self fillCacheParamView];
392 //Filter the cellServDb and allocate filtered array
393 [self filterCellServDB:nil];
395 }@catch(NSException *e){
396 [self showMessage:[e reason]];
398 [((NSTableView*)cellList) reloadData];
402 // -------------------------------------------------------------------------------
403 // fillCacheParamView:
404 // -------------------------------------------------------------------------------
405 -(void) fillCacheParamView
407 [dynRoot setState:[afsProperty dynRoot]?NSOnState:NSOffState];
408 [afsDB setState:[afsProperty afsDB]?NSOnState:NSOffState];
409 [statCacheEntry setIntValue:[afsProperty statCacheEntry]];
410 [dCacheDim setIntValue:[afsProperty dCacheDim]];
411 [cacheDimension setIntValue:[afsProperty cacheDimension]];
412 [daemonNumber setIntValue:[afsProperty daemonNumber]];
413 [afsRootMountPoint setStringValue:[afsProperty afsRootMountPoint]];
414 [nVolEntry setIntValue:[afsProperty nVolEntry]];
416 //new version property
417 //[verbose setEnabled:[afsProperty useAfsdConfConfigFile]];
418 [verbose setState:[afsProperty verbose]?NSOnState:NSOffState];
422 // -------------------------------------------------------------------------------
423 // updateCacheParamFromView:
424 // -------------------------------------------------------------------------------
425 -(void) updateCacheParamFromView
427 NSString *tmpAfsPath = [afsRootMountPoint stringValue];
428 if(!tmpAfsPath || ([tmpAfsPath length] == 0) || ([tmpAfsPath characterAtIndex:0] != '/'))
429 @throw [NSException exceptionWithName:@"updateCacheParamFromView"
430 reason:kBadAfsRootMountPoint
434 [afsProperty setDynRoot:[dynRoot state]==NSOnState];
435 [afsProperty setAfsDB:[afsDB state]==NSOnState];
436 [afsProperty setStatCacheEntry:[statCacheEntry intValue]];
437 [afsProperty setDCacheDim:[dCacheDim intValue]];
438 [afsProperty setCacheDimension:[cacheDimension intValue]];
439 [afsProperty setDaemonNumber:[daemonNumber intValue]];
440 [afsProperty setAfsRootMountPoint:tmpAfsPath];
441 [afsProperty setNVolEntry:[nVolEntry intValue]];
442 [afsProperty setVerbose:[verbose state]==NSOnState];
446 // -------------------------------------------------------------------------------
448 // -------------------------------------------------------------------------------
449 - (IBAction) showCellIP:(id) sender
451 int rowSelected = [((NSTableView *) cellList) selectedRow];
452 [self modifyCellByIDX:rowSelected];
455 // -------------------------------------------------------------------------------
457 // -------------------------------------------------------------------------------
458 -(void) modifyCellByIDX:(int) idx
460 [self modifyCell:[self getCellByIDX:idx]];
463 // -------------------------------------------------------------------------------
465 // -------------------------------------------------------------------------------
466 -(void) modifyCell:(DBCellElement*) cellElement
468 [NSBundle loadNibNamed:@"IpPanel" owner:self];
469 [((IpConfiguratorCommander*) ipConfControllerCommander) setWorkCell:cellElement];
470 [NSApp beginSheet: ipConfigurationSheet
471 modalForWindow: [[self mainView] window]
473 didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
477 // -------------------------------------------------------------------------------
479 // -------------------------------------------------------------------------------
480 - (IBAction) addRemoveCell:(id) sender
482 switch([((NSControl*) sender) tag]){
483 case ADD_CELL_CONTROL_TAG:
485 DBCellElement *newCell = [[DBCellElement alloc] init];
488 [newCell setCellName:kNewCellName];
489 [newCell setCellComment:kNewCellComment];
491 [[afsProperty getCellList] addObject:newCell];
495 [self modifyCell:newCell];
499 case REMOVE_CELL_CONTROL_TAG:
502 NSIndexSet *selectedIndex = [(NSTableView*)cellList selectedRowIndexes];
503 if( [selectedIndex count] > 0) {
504 index = [selectedIndex firstIndex];
506 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:index];
507 [[afsProperty getCellList] removeObject:cellElement];
508 } while ((index = [selectedIndex indexGreaterThanIndex: index]) != NSNotFound);
513 //Filter the cellServDb and allocate filtered array
514 [self searchCellTextEvent:nil];
515 [(NSTableView*)cellList deselectAll:nil];
516 [(NSTableView*)cellList reloadData];
519 // -------------------------------------------------------------------------------
521 // -------------------------------------------------------------------------------
522 - (void) repairHelperTool
527 NSLog(@"repairHelperTool");
528 NSString *afshlpPath = [[self bundle] pathForResource:@"afshlp" ofType:nil];
532 // Open tool exclusively, so nobody can change it while we bless it.
533 fdTool = open([afshlpPath UTF8String], O_NONBLOCK | O_RDONLY | O_EXLOCK, 0);
537 NSLog(@"Exclusive open while repairing tool failed: %d.", errno);
541 if(fstat(fdTool, &st))
543 NSLog(@"fstat failed.");
549 status = [[AuthUtil shared] autorize];
551 fchown(fdTool, 0, st.st_gid);
553 // Disable group and world writability and make setuid root.
554 fchmod(fdTool, (st.st_mode & (~(S_IWGRP | S_IWOTH)))/* | S_ISUID*/);
555 const char *args[] = {"root", [afshlpPath UTF8String],0L};
556 [[AuthUtil shared] execUnixCommand:"/usr/sbin/chown"
559 [[AuthUtil shared] deautorize];
561 } else NSLog(@"st_uid = 0");
567 NSLog(@"Self-repair done.");
572 // -------------------------------------------------------------------------------
574 // -------------------------------------------------------------------------------
575 - (IBAction) startStopAfs:(id) sender
577 OSStatus status = noErr;
578 NSString *afsdPath = [TaskUtil searchExecutablePath:@"afsd"];
579 //NSString *startStopScript = nil;
580 NSString *rootHelperApp = nil;
581 BOOL currentAfsState = NO;
584 if(afsdPath == nil) return;
585 currentAfsState = [afsProperty checkAfsStatus];
586 rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
588 //[startStopScript setString: resourcePath];
589 NSLog(@"Launch repair HelperTool");
591 [self repairHelperTool];
593 // make the parameter to call the root helper app
594 status = [[AuthUtil shared] autorize];
598 NSLog(@"Shutting down afs");
599 NSMutableString *afsKextPath = [[NSMutableString alloc] initWithCapacity:256];
600 [afsKextPath setString:[afsProperty path]];
601 [afsKextPath appendString:@"/etc/afs.kext"];
603 //Make the array for arguments
604 NSLog(@"executeTaskWithAuth");
605 const char *stopAfsArgs[] = {"stop_afs", [afsKextPath UTF8String], [afsdPath UTF8String], 0L};
606 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
611 NSLog(@"Starting up afs");
612 const char *startAfsArgs[] = {[[[self bundle] pathForResource:@"start_afs" ofType:@"sh"] UTF8String], [[afsProperty path] UTF8String], [afsdPath UTF8String], 0L};
613 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
618 [self refreshGui:nil];
620 @catch (NSException * e) {
621 [self showMessage:[e reason]];
624 [[AuthUtil shared] deautorize];
628 // -------------------------------------------------------------------------------
630 // -------------------------------------------------------------------------------
631 - (void) refreshGui:(NSNotification *)notification{
632 BOOL afsIsUp = [afsProperty checkAfsStatus];
634 //[self refreshTokens:nil];
635 [tokensButton setEnabled:afsIsUp];
636 [unlogButton setEnabled:afsIsUp];
639 // -------------------------------------------------------------------------------
640 // afsVolumeMountChange: Track the afs volume state change
641 // -------------------------------------------------------------------------------
642 - (void) afsVolumeMountChange:(NSNotification *)notification{
643 // Cehck if is mounted or unmounted afs
644 if([[[notification userInfo] objectForKey:@"NSDevicePath"] isEqualToString:@"/afs"]){
646 [self refreshTokens:nil];
650 // -------------------------------------------------------------------------------
652 // -------------------------------------------------------------------------------
653 - (IBAction) info:(id) sender
655 [((InfoController*) infoController) showHtmlResource:[[self bundle] pathForResource:@"licenza" ofType:@"rtf"]];
657 [NSApp beginSheet: infoSheet
658 modalForWindow: [[self mainView] window]
660 didEndSelector: @selector(didEndInfoSheet:returnCode:contextInfo:)
664 // -------------------------------------------------------------------------------
665 // tableDoubleAction:
666 // -------------------------------------------------------------------------------
667 - (IBAction) tableDoubleAction:(id) sender
669 [self showCellIP:nil];
672 // -------------------------------------------------------------------------------
674 // -------------------------------------------------------------------------------
675 - (IBAction) getNewToken:(id) sender
677 BOOL useAklog = [useAklogCheck state] == NSOnState;
679 //[AFSPropertyManager aklog];
680 [afsProperty getTokens:false
683 [self refreshTokens:nil];
684 //Inform afs menuextra to updata afs status
685 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
688 [NSBundle loadNibNamed:@"CredentialPanel" owner:self];
689 [NSApp beginSheet: credentialSheet
690 modalForWindow: [[self mainView] window]
692 didEndSelector: @selector(didEndCredentialSheet:returnCode:contextInfo:)
698 // -------------------------------------------------------------------------------
699 // getCurrentCellInDB:
700 // -------------------------------------------------------------------------------
701 - (IBAction) unlog:(id) sender
704 NSIndexSet *selectedIndex = [(NSTableView*)tokensTable selectedRowIndexes];
705 if( [selectedIndex count] > 0) {
706 index = [selectedIndex firstIndex];
708 NSString *tokenDesc = [tokenList objectAtIndex:index];
709 NSString *cellToUnlog = [tokenDesc estractTokenByDelimiter:@"afs@"
711 [afsProperty unlog:cellToUnlog];
712 } while ((index = [selectedIndex indexGreaterThanIndex: index]) != NSNotFound);
714 [afsProperty unlog:nil];
716 [self refreshTokens:nil];
717 //Inform afs menuextra to updata afs status
718 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
723 // -------------------------------------------------------------------------------
725 // -------------------------------------------------------------------------------
726 - (IBAction) aklogSwitchEvent:(id) sender
728 //afs menu extra is loaded inform it to read preference
730 if(![useAklogCheck state]) {
731 //deselect the checkbox
732 [aklogCredentialAtLoginTime setState:NO];
735 [self writePreferenceFile];
737 //Enable disable aklog at login time checkbox according the useAklog checkbox
738 [aklogCredentialAtLoginTime setEnabled:[useAklogCheck state]];
741 @catch (NSException * e) {
742 [self showMessage:[e reason]];
748 // -------------------------------------------------------------------------------
749 // credentialAtLoginTimeEvent:
750 // -------------------------------------------------------------------------------
751 - (IBAction) credentialAtLoginTimeEvent:(id) sender {
752 [self writePreferenceFile];
755 // -------------------------------------------------------------------------------
756 // afsStartupSwitchEvent:
757 // -------------------------------------------------------------------------------
758 - (IBAction) afsStartupSwitchEvent:(id) sender {
759 NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
761 NSString *afsdPath = [TaskUtil searchExecutablePath:@"afsd"];
762 NSString *afsStartupScriptPath = [[self bundle] pathForResource:@"start_afs" ofType:@"sh"];
763 startAFSAtLogin = [checkButtonAfsAtBootTime state];
764 const char *startAfsArgs[] = {"load", "-w", [AFS_STARTUP_CONTROL_FILE UTF8String], 0L};
765 const char *stopAfsArgs[] = {"unload", "-w", [AFS_STARTUP_CONTROL_FILE UTF8String], 0L};
766 const char *launchctlExecutable = "/bin/launchctl";
767 /* [PListManager manageAfsStartupLaunchdFile:startAFSAtLogin
768 afsStartupScript:afsStartupScriptPath
769 afsBasePath:[afsProperty path] afsdPath:afsdPath];
771 const char *startupConfigureOption[] = {"start_afs_at_startup", [afsStartupScriptPath UTF8String], [afsdPath UTF8String], [[afsProperty path] UTF8String], 0L};
772 if([[AuthUtil shared] autorize] == noErr) {
773 if(startAFSAtLogin) {
774 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
775 args:startupConfigureOption
778 [[AuthUtil shared] execUnixCommand:launchctlExecutable
782 //now disable the launchd configuration
783 [[AuthUtil shared] execUnixCommand:launchctlExecutable
791 // -------------------------------------------------------------------------------
792 // afsMenuActivationEvent:
793 // -------------------------------------------------------------------------------
794 - (IBAction) krb5KredentialAtLoginTimeEvent:(id) sender {
796 NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
797 const char *args[] = {"enable_krb5_startup", [[installKRB5AuthAtLoginButton stringValue] UTF8String], "", 0L};
800 [self repairHelperTool];
801 if([[AuthUtil shared] autorize] == noErr) {
802 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
806 //check if all is gone well
807 [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
811 // -------------------------------------------------------------------------------
812 // afsMenuActivationEvent:
813 // -------------------------------------------------------------------------------
814 -(IBAction) afsMenuActivationEvent:(id) sender
816 CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU,
817 (CFNumberRef)[NSNumber numberWithBool:[afsMenucheckBox state]],
818 (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
820 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
821 CFPreferencesSynchronize((CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
823 //notify the backgrounder
824 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSMenuChangeState];
827 // -------------------------------------------------------------------------------
828 // searchCellTextEvent:
829 // Fileter the CellServDB list according to NSSearch content
830 // -------------------------------------------------------------------------------
831 - (IBAction) searchCellTextEvent:(id) sender
834 NSString *searchText = [[textSearchField stringValue] lowercaseString]; //filter string
835 [self filterCellServDB:searchText];
836 [((NSTableView*)cellList) reloadData];
839 // -------------------------------------------------------------------------------
840 // clearCellServDBFiltering:
841 // clear the NSSearchField and showw all CellServDB table
842 // -------------------------------------------------------------------------------
843 - (void) clearCellServDBFiltering {
844 //Clear the text search
845 [textSearchField setStringValue:@""];
846 //load the temp array with all cell servdb
847 [self searchCellTextEvent:nil];
849 // --------------------------------------o-----------------------------------------
851 // make the NSMutableArray with all cellservdb or filtered element
852 // -------------------------------------------------------------------------------
853 - (void) filterCellServDB:(NSString*)textToFilter {
854 DBCellElement *cellElement; //Filtered element
855 BOOL doFilter = !(textToFilter == nil || ([textToFilter length] == 0));
857 // We can do filtering and make the temp array
859 [filteredCellDB release];
861 filteredCellDB = [[NSMutableArray alloc] init];
862 NSEnumerator *e = [[afsProperty getCellList] objectEnumerator];
863 while(cellElement = (DBCellElement*)[e nextObject]) {
864 // check if the element can be get
866 //Get the CellServDB array enumerator
867 NSRange rsltRng = [[[cellElement getCellName] lowercaseString] rangeOfString:textToFilter];
868 if(rsltRng.location != NSNotFound) {
869 //we can add this cell to filtered
870 [filteredCellDB addObject:[cellElement retain]];
873 [filteredCellDB addObject:[cellElement retain]];
879 // -------------------------------------------------------------------------------
880 // getCurrentCellInDB:
881 // -------------------------------------------------------------------------------
882 - (DBCellElement*) getCurrentCellInDB
884 int rowSelected = [((NSTableView *) cellList) selectedRow];
885 return [self getCellByIDX:rowSelected];
888 // -------------------------------------------------------------------------------
889 // getCurrentCellInDB:
890 // -------------------------------------------------------------------------------
891 - (DBCellElement*) getCellByIDX:(int) idx
893 //NSMutableArray *cellArray = [afsProperty getCellList];
894 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:idx];
898 // -------------------------------------------------------------------------------
900 // -------------------------------------------------------------------------------
901 -(void) showMessage:(NSString*) message{
902 NSAlert *alert = [[NSAlert alloc] init];
904 [alert setMessageText:message];
905 [alert beginSheetModalForWindow:[[self mainView] window]
912 // -------------------------------------------------------------------------------
913 // manageButtonState:
914 // -------------------------------------------------------------------------------
915 -(void) manageButtonState:(int) rowSelected {
916 [((NSControl*) cellIpButton) setEnabled:rowSelected >= 0];
917 [((NSControl*) removeCellButton) setEnabled:rowSelected >= 0];
920 // -------------------------------------------------------------------------------
922 // -------------------------------------------------------------------------------
925 BOOL afsIsUp = [afsProperty checkAfsStatus];
926 [((NSButton *)startStopButton) setTitle: (afsIsUp?kAfsButtonShutdown:kAfsButtonStartup)];
928 NSMutableAttributedString *colorTitle =[[NSMutableAttributedString alloc] initWithAttributedString:[((NSButton *)startStopButton) attributedTitle]];
929 NSRange titleRange = NSMakeRange(0, [colorTitle length]);
931 [colorTitle addAttribute:NSForegroundColorAttributeName
932 value:(afsIsUp?[NSColor redColor]:[NSColor blackColor])
935 [((NSButton *)startStopButton) setAttributedTitle:colorTitle];
944 // -------------------------------------------------------------------------------
946 // -------------------------------------------------------------------------------
947 - (void) refreshTokens:(NSTimer*)theTimer;
949 if(![tokensLock tryLock]) return;
954 tokenList = [afsProperty getTokenList];
955 [((NSTableView*)tokensTable) reloadData];
959 // -------------------------------------------------------------------------------
961 // -------------------------------------------------------------------------------
962 - (IBAction) addLink:(id) sender {
963 [NSBundle loadNibNamed:@"SymLinkEdit" owner:self];
965 [NSApp beginSheet: lyncCreationSheet
966 modalForWindow: [[self mainView] window]
968 didEndSelector: @selector(didEndSymlinkSheet:returnCode:contextInfo:)
973 // -------------------------------------------------------------------------------
975 // -------------------------------------------------------------------------------
976 - (IBAction) removeLink:(id) sender {
980 // -------------------------------------------------------------------------------
982 // -------------------------------------------------------------------------------
983 - (IBAction) enableLink:(id) sender {
987 // -------------------------------------------------------------------------------
989 // -------------------------------------------------------------------------------
990 - (IBAction) manageBackgrounderActivation:(id)sender {
991 [PListManager launchctlCommand:[(NSButton*)sender state]
993 option:[NSArray arrayWithObjects:@"-S", @"Aqua", nil]
994 plistName:[NSString stringWithFormat:@"%@.plist", BACKGROUNDER_P_FILE]];
995 //re ad the status to check taht all is gone well
996 [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
1000 // -------------------------------------------------------------------------------
1001 // - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem
1002 // -------------------------------------------------------------------------------
1003 - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem
1005 //check to see if the cache param tab is the tab that will be selected
1006 if([((NSString*)[tabViewItem identifier]) intValue] == TAB_LINK)
1008 [ViewUtility enbleDisableControlView:[tabViewItem view]
1015 @implementation AFSCommanderPref (NSTableDataSource)
1018 // -------------------------------------------------------------------------------
1020 // Manage the checkbox of CellServDB Table
1022 // -------------------------------------------------------------------------------
1023 - (void)tableView:(NSTableView *)table
1024 setObjectValue:(id)data
1025 forTableColumn:(NSTableColumn *)col
1028 NSString *identifier = (NSString*)[col identifier];
1029 switch([table tag]){
1030 case TABLE_TOKENS_LIST:
1033 case TABLE_CELL_LIST:
1034 // we are editing checkbox for cellservdb table
1035 if([identifier intValue] == CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN) {
1036 // set the user default cell
1037 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1038 [afsProperty setDefaultCellByName:[cellElement getCellName]];
1039 //[afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
1040 [((NSTableView*)cellList) reloadData];
1041 } else if([identifier intValue] == CELLSRVDB_TABLE_DFLT_CHECK_COLUMN) {
1042 // set the cell for wich the user want to get token
1043 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1044 [cellElement setUserDefaultForToken:![cellElement userDefaultForToken]];
1052 // -------------------------------------------------------------------------------
1054 // refresh delegate method for two AFSCommander table
1055 // -------------------------------------------------------------------------------
1056 - (id) tableView:(NSTableView *) aTableView
1057 objectValueForTableColumn:(NSTableColumn *) aTableColumn
1062 NSString *identifier = (NSString*)[aTableColumn identifier];
1063 switch([aTableView tag]){
1064 case TABLE_TOKENS_LIST:
1065 //We are refreshing tokens table
1066 result = [self getTableTokensListValue:[identifier intValue] row:rowIndex];
1069 case TABLE_CELL_LIST:
1070 //We are refreshing cell db table
1071 result = [self getTableCelListValue:[identifier intValue] row:rowIndex];
1079 // -------------------------------------------------------------------------------
1080 // getTableCelListValue:
1081 // -------------------------------------------------------------------------------
1082 - (id)getTableTokensListValue:(int) colId row:(int)row
1085 if(!tokenList) return nil;
1088 result = (NSString*)[tokenList objectAtIndex:row];
1095 // -------------------------------------------------------------------------------
1096 // getTableCelListValue:
1097 // -------------------------------------------------------------------------------
1098 - (id)getTableCelListValue:(int) colId row:(int)row
1101 //NSMutableArray *cellArray = [afsProperty getCellList];
1102 DBCellElement *cellElement = (DBCellElement*)[filteredCellDB objectAtIndex:row];
1104 case CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN:
1105 result = [NSNumber numberWithInt:[cellElement userDefaultForCell]];
1108 case CELLSRVDB_TABLE_DFLT_CHECK_COLUMN:
1109 result = [NSNumber numberWithInt:[cellElement userDefaultForToken]];
1111 case CELLSRVDB_TABLE_NAME_COLUMN:
1112 result = [cellElement getCellName];
1115 case CELLSRVDB_TABLE_DESCRIPTION_COLUMN:
1116 result = [cellElement getCellComment];
1122 // -------------------------------------------------------------------------------
1123 // numberOfRowsInTableView:
1124 // -------------------------------------------------------------------------------
1125 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1128 //NSMutableArray *cellArray = nil;
1129 switch([aTableView tag]){
1130 case TABLE_TOKENS_LIST:
1131 if(tokenList) rowCount = [tokenList count];
1134 case TABLE_CELL_LIST:
1135 //cellArray = [afsProperty getCellList];
1136 if(filteredCellDB) rowCount = [filteredCellDB count];
1145 @implementation AFSCommanderPref (TableDelegate)
1146 // -------------------------------------------------------------------------------
1147 // selectionShouldChangeInTableView:
1148 // -------------------------------------------------------------------------------
1149 - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTable
1151 [self manageButtonState:[aTable selectedRow]];
1155 // -------------------------------------------------------------------------------
1157 // -------------------------------------------------------------------------------
1158 - (BOOL)tableView:(NSTableView *)aTable shouldSelectRow:(int)aRow
1160 [self manageButtonState:aRow];
1167 @implementation AFSCommanderPref (ModalDelegate)
1168 // -------------------------------------------------------------------------------
1170 // -------------------------------------------------------------------------------
1171 - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1173 [sheet orderOut:self];
1174 //Filter the cellServDb and allocate filtered array
1175 [self searchCellTextEvent:nil];
1176 [((NSTableView*)cellList) reloadData];
1179 // -------------------------------------------------------------------------------
1180 // Klog credential request
1181 // -------------------------------------------------------------------------------
1182 - (void)didEndCredentialSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1184 if([((TokenCredentialController*)credentialCommander) takenToken] == YES){
1185 /*[AFSPropertyManager klog:[((TokenCredentialController*)credentialCommander) uName]
1186 uPwd:[((TokenCredentialController*)credentialCommander) uPwd] ];*/
1187 [afsProperty getTokens:true
1188 usr:[((TokenCredentialController*)credentialCommander) uName]
1189 pwd:[((TokenCredentialController*)credentialCommander) uPwd]];
1191 [sheet orderOut:self];
1192 [self refreshTokens:nil];
1193 //Inform afs menuextra to updata afs status
1194 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
1198 // -------------------------------------------------------------------------------
1199 // Klog credential request
1200 // -------------------------------------------------------------------------------
1201 - (void)didEndInfoSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1203 [sheet orderOut:self];
1206 // -------------------------------------------------------------------------------
1208 // -------------------------------------------------------------------------------
1209 - (void)didEndSymlinkSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1211 [lyncCreationSheet orderOut:self];