@implementation AFSBackgrounderDelegate
#pragma mark NSApp Delegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- NSLog(@"Init the afs manager");
afsMngr = [[AFSPropertyManager alloc] initWithAfsPath:afsSysPath];
// allocate the lock for concurent afs check state
tokensLock = [[NSLock alloc] init];
// -------------------------------------------------------------------------------
- (void) readPreferenceFile:(NSNotification *)notification
{
- NSLog(@"Reading preference file");
if(afsSysPath) {
[afsSysPath release];
afsSysPath = nil;
// -------------------------------------------------------------------------------
/**/
- (void)chageMenuVisibility:(NSNotification *)notification {
- NSLog(@"chageMenuVisibility");
[self readPreferenceFile:nil];
- NSLog(@"showStatusMenu: %d", [showStatusMenu intValue]);
[self setStatusItem:[showStatusMenu boolValue]];
}
// -------------------------------------------------------------------------------
- (void)startStopAfs:(id)sender
{
- NSLog(@"startStopAfs: %s",[afsSysPath UTF8String]);
if(!afsSysPath) return;
OSStatus status = noErr;
if(afsdPath == nil) return;
currentAfsState = [afsMngr checkAfsStatus];
rootHelperApp = [[NSBundle mainBundle] pathForResource:@"afshlp" ofType:@""];
-
- //[startStopScript setString: resourcePath];
- //NSLog(@"LAunch repair HelperTool");
+
//Check helper app
[self repairHelperTool];
if(status == noErr){
if(currentAfsState){
//shutdown afs
- //NSLog(@"Shutting down afs");
NSMutableString *afsKextPath = [[NSMutableString alloc] initWithCapacity:256];
[afsKextPath setString:afsSysPath];
[afsKextPath appendString:@"/etc/afs.kext"];
- //NSLog(@"executeTaskWithAuth");
const char *stopAfsArgs[] = {"stop_afs", [afsKextPath UTF8String], [afsdPath UTF8String], 0L};
[[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
args:stopAfsArgs
output:nil];
} else {
- //NSLog(@"Starting up afs");
const char *startAfsArgs[] = {[[ [NSBundle mainBundle] pathForResource:@"start_afs" ofType:@"sh"] UTF8String], [afsSysPath UTF8String], [afsdPath UTF8String], 0L};
[[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
args:startAfsArgs
AFSPropertyManager *afsPropMngr = [[AFSPropertyManager alloc] initWithAfsPath:afsSysPath ];
[afsPropMngr loadConfiguration];
-
if([useAklogPrefValue boolValue]) {
- NSLog(@"Use Aklog");
[afsPropMngr getTokens:false
usr:nil
pwd:nil];
[self klogUserEven:nil];
} else {
- NSLog(@"Use Klog");
// register for user event
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(klogUserEven:)
{
struct stat st;
int fdTool;
- int status = 0;
- NSLog(@"repairHelperTool");
+ int status = 0;
NSString *afshlpPath = [[NSBundle mainBundle] pathForResource:@"afshlp" ofType:nil];
[[AuthUtil shared] deautorize];
}
} else NSLog(@"st_uid = 0");
-
-
-
close(fdTool);
-
NSLog(@"Self-repair done.");
}
viewRect = rect;
credentialWindow = nil;
afsPropMngr = [afsPropManager retain];
- NSLog(@"init AFSMenuCredentialContoller");
return [self init];
}
- (void)dealloc {
- NSLog(@"dealloc AFSMenuCredentialContoller");
if(credentialWindow) [credentialWindow release];
[super dealloc];
{
// calculate the point where show the window
NSPoint topLeft = {viewRect.origin.x-160,[[NSScreen mainScreen] frame].size.height-kMenuBarHeight};
- NSLog(@"viewRect.origin.x=%d, topLeft.x=%d", viewRect.origin.x, topLeft.x);
// load the bundle for
[NSBundle loadNibNamed:@"CredentialWindow.nib" owner:self];
- NSLog(@"prepare to open window CredentialWindow");
credentialWindow = [[NSWindow alloc] initWithContentRect:[((NSView*) credentialView) frame]
styleMask:NSTitledWindowMask /*| NSUtilityWindowMask*/
backing:NSBackingStoreBuffered
defer:YES screen:[NSScreen mainScreen]];
- NSLog(@"Finestra");
[credentialWindow setTitle:@"Klog"];
[credentialWindow setFrameTopLeftPoint:topLeft];
[credentialWindow setContentView:credentialView];
[credentialWindow makeKeyAndOrderFront:self];
- NSLog(@"creata");
-
}
-(void) closeWindow
{
- NSLog(@"closeWindow");
if([(CredentialWindowController*)credWinController takenToken] && afsPropMngr) {
[afsPropMngr getTokens:true
usr:[(CredentialWindowController*)credWinController uName]
afsSysPath = nil;
}
- afsSysPath = PREFERENCE_AFS_SYS_PAT_STATIC;/*(NSString*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_AFS_SYS_PAT,
- (CFStringRef)afsCommanderID,
- kCFPreferencesAnyUser,
- kCFPreferencesAnyHost);*/
- //NSLog(@"Path readed %s", (afsSysPath==nil?[afsSysPath UTF8String]:@" no path found "));
+ afsSysPath = PREFERENCE_AFS_SYS_PAT_STATIC;
// read the preference for aklog use
useAklogPrefValue = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_USE_AKLOG,
(CFStringRef)afsCommanderID,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
- //set the menu name
- //NSLog(@"Preference readed for useAklogPrefValue %d", [useAklogPrefValue intValue]);
-
[self updateAfsStatus:nil];
}
// -------------------------------------------------------------------------------
- (void)startStopAfs:(id)sender
{
- NSLog(@"startStopAfs: %s",[afsSysPath UTF8String]);
if(!afsSysPath) return;
OSStatus status = noErr;
[afsMngr release];
rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
-
- //[startStopScript setString: resourcePath];
- //NSLog(@"LAunch repair HelperTool");
+
//Check helper app
[self repairHelperTool];
// make the parameter to call the root helper app
- //NSLog(@"Path installazione afs: %s",[afsSysPath UTF8String]);
- //NSLog(@"Path installazione afsd: %s", [afsdPath UTF8String]);
status = [[AuthUtil shared] autorize];
if(status == noErr){
if(currentAfsState){
//shutdown afs
- //NSLog(@"Shutting down afs");
NSMutableString *afsKextPath = [[NSMutableString alloc] initWithCapacity:256];
[afsKextPath setString:afsSysPath];
[afsKextPath appendString:@"/etc/afs.kext"];
- //NSLog(@"executeTaskWithAuth");
const char *stopAfsArgs[] = {"stop_afs", [afsKextPath UTF8String], [afsdPath UTF8String], 0L};
[[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
args:stopAfsArgs
output:nil];
} else {
- //NSLog(@"Starting up afs");
const char *startAfsArgs[] = {[[[self bundle] pathForResource:@"start_afs" ofType:@"sh"] UTF8String], [afsSysPath UTF8String], [afsdPath UTF8String], 0L};
[[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
args:startAfsArgs
if([useAklogPrefValue intValue]==NSOnState ) {
- NSLog(@"Use Aklog");
[afsPropMngr getTokens:false
usr:nil
pwd:nil];
[self klogUserEven:nil];
} else {
- NSLog(@"Use Klog");
// register for user event
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
selector:@selector(klogUserEven:)
{
struct stat st;
int fdTool;
- int status = 0;
- NSLog(@"repairHelperTool");
+ int status = 0;
NSString *afshlpPath = [[self bundle] pathForResource:@"afshlp" ofType:nil];
close(fdTool);
-
NSLog(@"Self-repair done.");
}@end
// -------------------------------------------------------------------------------
- (void)awakeFromNib
{
- NSLog(@"awakeFromNib");
}
// -------------------------------------------------------------------------------
- (IBAction) closePanel:(id) sender
{
taken = NO;
- NSLog(@"closePanel");
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kLogWindowClosed];
}
[alert close];
switch (returnCode) {
case 1:
- NSLog(@"Yes");
if([[NSFileManager defaultManager] createDirectoryAtPath:[HOME_LAUNCHD_AGENT_FOLDER stringByExpandingTildeInPath]
attributes:nil]) {
}
break;
case 0:
- NSLog(@"No");
-
break;
}
}
// -------------------------------------------------------------------------------
- (void)willUnselect
{
- NSLog(@"willUnselect");
// remove self as datasource
[((NSTableView*)cellList) setDataSource:nil];
[((NSTableView*)tokensTable) setDataSource:nil];
- (IBAction) saveCacheManagerParam:(id) sender
{
@try{
- NSLog(@"Backing up the cache configuration file");
//Update the value form view to afs property manager class
[self updateCacheParamFromView];
[afsProperty saveCacheConfigurationFiles:YES];
- NSLog(@"Cache configuration file backuped");
[self showMessage:kSavedCacheConfiguration];
}@catch(NSException *e){
[self showMessage:[e reason]];
// -------------------------------------------------------------------------------
- (IBAction) refreshConfiguration:(id) sender
{
- NSLog(@"refreshConfiguration");
NSString *afsBasePath = PREFERENCE_AFS_SYS_PAT_STATIC;
-
@try{
// set the afs path
[afsProperty setPath:afsBasePath];
// -------------------------------------------------------------------------------
- (IBAction) info:(id) sender
{
- //NSLog(kDevelopInfo);
- //[self showMessage:kDevelopInfo];
[((InfoController*) infoController) showHtmlResource:[[self bundle] pathForResource:@"licenza" ofType:@"rtf"]];
[NSApp beginSheet: infoSheet
// check if the element can be get
if(doFilter) {
//Get the CellServDB array enumerator
- //NSLog(@"String for filtering: %s", [textToFilter UTF8String]);
NSRange rsltRng = [[[cellElement getCellName] lowercaseString] rangeOfString:textToFilter];
if(rsltRng.location != NSNotFound) {
//we can add this cell to filtered
- //NSLog(@"Element found during filter: %s", [[cellElement getCellName] UTF8String]);
[filteredCellDB addObject:[cellElement retain]];
}
} else {
-(void) setAfsStatus
{
BOOL afsIsUp = [afsProperty checkAfsStatus];
- NSLog(@"Afs is: %s", afsIsUp?"Up":"Down");
[((NSButton *)startStopButton) setTitle: (afsIsUp?kAfsButtonShutdown:kAfsButtonStartup)];
NSMutableAttributedString *colorTitle =[[NSMutableAttributedString alloc] initWithAttributedString:[((NSButton *)startStopButton) attributedTitle]];
//check to see if the cache param tab is the tab that will be selected
if([((NSString*)[tabViewItem identifier]) intValue] == TAB_LINK)
{
-
- // [groupsBox setHidden:YES];
- NSLog([tabViewItem label]);
[ViewUtility enbleDisableControlView:[tabViewItem view]
controlState:NO];
}
// -------------------------------------------------------------------------------
- (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- NSLog(@"didEndSheet");
[sheet orderOut:self];
//Filter the cellServDb and allocate filtered array
[self searchCellTextEvent:nil];
[((NSTableView*)cellList) reloadData];
- NSLog(@"Has saved %s:", ([((IpConfiguratorCommander*) ipConfControllerCommander) saved])?"YES":"NO");
}
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
- (void)didEndCredentialSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- NSLog(@"didEndCredentialSheet");
if([((TokenCredentialController*)credentialCommander) takenToken] == YES){
/*[AFSPropertyManager klog:[((TokenCredentialController*)credentialCommander) uName]
uPwd:[((TokenCredentialController*)credentialCommander) uPwd] ];*/
// -------------------------------------------------------------------------------
- (void)didEndInfoSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- NSLog(@"didEndInfoSheet");
[sheet orderOut:self];
}
// -------------------------------------------------------------------------------
- (void)didEndSymlinkSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
- NSLog(@"didEndSymlinkSheet");
[lyncCreationSheet orderOut:self];
}
@end
// -------------------------------------------------------------------------------
-(void) dealloc
{
- if(installationPath){ [installationPath release]; NSLog(@"Released installationPath"); }
- if(cellList) { NSLog(@"Released cellList");[cellList removeAllObjects];[cellList release];}
- if(cellName) { NSLog(@"Released cellName");[cellName release];}
+ if(installationPath){ [installationPath release];}
+ if(cellList) {[cellList removeAllObjects];[cellList release];}
+ if(cellName) {[cellName release];}
if(futil) {
[futil endAutorization];
[futil release];
// read thiscell config file
[filePath setString:installationPath];
[filePath appendString: @"/etc/ThisCell"];
- NSLog(@"Search for cell name.");
+
[self readCellInfo:filePath];
if(!cellName){
@throw [NSException exceptionWithName:@"readCellInfo"
reason:kThisCellFOError
userInfo:nil];
}
- NSLog(@"Cell found: %@", cellName);
-
//read TheseCell file
[filePath setString: installationPath];
[filePath appendString: @"/etc/TheseCells"];
userDefaultCellArray = [self readTheseCell:filePath];
//read cell serv db
- NSLog(@"Scan for cell db");
[filePath setString: installationPath];
[filePath appendString: @"/etc/CellServDB"];
[self readCellDB:filePath];
- NSLog(@"Server found: %d", [cellList count]);
-
-
//Read cacheinfo
- NSLog(@"Scan cacheinfo file");
[filePath setString: installationPath];
[filePath appendString: @"/etc/cacheinfo"];
[self readCacheInfo:filePath];
- NSLog(@"End scan cacheinfo file");
//Read config/afsd.options
[filePath setString: installationPath];
[filePath appendString: useAfsdConfVersion?AFSD_NEW_PREFERENCE_FILE:AFSD_OLD_PREFERENCE_FILE];
[self readAfsdOption:filePath];
-
} @catch(NSException * e){
@throw e;
} @finally {
do{
[afsdOptionS scanUpToCharactersFromSet:space intoString:&tmpString];
if(!tmpString) continue;
-
- NSLog(tmpString);
//check parameter type
if([tmpString isEqualToString:@AFSD_OPTION_DAEMONS_KEY])
{
//scann the line
- [lineScanner scanUpToString:@"\"" intoString:¶mValue]; NSLog(paramValue);[lineScanner scanUpToString:@"-" intoString:¶mValue];
- [lineScanner scanUpToString:@"\"" intoString:¶mValue]; NSLog(paramValue);
+ [lineScanner scanUpToString:@"\"" intoString:¶mValue];[lineScanner scanUpToString:@"-" intoString:¶mValue];
+ [lineScanner scanUpToString:@"\"" intoString:¶mValue];
// read the asfd option param line
[self readAFSDParamLineContent:paramValue];
{
NSString *tmpString = nil;
NSString *result = [TaskUtil executeTaskSearchingPath:@"fs" args:[NSArray arrayWithObjects:@"-version", nil]];
- if(result) NSLog(@"fs -version return: %@", result);
-
-
NSCharacterSet *endVersionCS = [NSCharacterSet characterSetWithCharactersInString:@"qwertyuiopasdfghjklzxcvbnmMNBVCXZLKJHGFDSAPOIUYTREWQ"];
-
NSCharacterSet *spaceCS = [NSCharacterSet characterSetWithCharactersInString:@" "];
NSScanner *versionS = [NSScanner scannerWithString:result];
//go to start of version
// readCellInfo:
// -------------------------------------------------------------------------------
-(void) readCellInfo:(NSString*) configFile {
-
-
NSError *error = nil;
NSString *tmpStr = nil;
- NSLog(@"Try to opening file: %@",configFile);
NSString * result = [NSString stringWithContentsOfFile:configFile
encoding:NSASCIIStringEncoding
error:&error];
userInfo:nil];
}
NSScanner *scanner = [NSScanner scannerWithString:result];
-
[scanner scanUpToString:@"\n"
intoString:&tmpStr];
if(line >= 2){
- NSLog(@"Token found %s", [tokenLine UTF8String]);
// add enteir row to result
[tokenList addObject:tokenLine];
// create the line scanner for all the row that contains token info
// -------------------------------------------------------------------------------
- (void)awakeFromNib
{
- NSLog(@"awakeFromNib");
htmlLicence = nil;
}
// -------------------------------------------------------------------------------
- (void)awakeFromNib
{
- NSLog(@"awakeFromNib");
[((NSTableView*)tableViewCellIP) setDelegate:self];
[((NSTableView*)tableViewCellIP) setDataSource:self];
}
//store the cell name
[cellElement setCellName:[((NSControl*) textFieldCellName) stringValue]];
[cellElement setCellComment:[((NSControl*) textFieldComment) stringValue]];
-
- NSLog(@"Deleting:\n%@",[bkIPArray description]);
[bkIPArray removeAllObjects];
- NSLog(@"deleted:\n");
- NSLog(@"Coping:\n%@",[workIPArray description]);
[bkIPArray setArray:workIPArray];
- NSLog(@"Copied:\n%@",[workIPArray description]);
- NSLog(@"Releasing:\n%@",[workIPArray description]);
[workIPArray release];
- NSLog(@"Released:\n%@",[workIPArray description]);
}
// -------------------------------------------------------------------------------
- (void)tableView:(NSTableView *)aTable setObjectValue:(id)aData
forTableColumn:(NSTableColumn *)aCol row:(int)aRow
{
- NSLog([aData description]);
CellIp *ipElement = (CellIp*)[workIPArray objectAtIndex:aRow];
switch([((NSNumber*)[aCol identifier]) intValue])
{
// executeTask:
// -------------------------------------------------------------------------------
+(NSString*) executeTask:(NSString*) taskName arguments:(NSArray *)args{
- NSLog(taskName);
NSString *result = nil;
int status = 0;
NSFileHandle *file = nil;
[taskToRun waitUntilExit];
status = [taskToRun terminationStatus];
if (status == 0){
- NSLog(@"Task succeeded.");
NSData *data = [file readDataToEndOfFile];
// remove the \n character from unix command
if([data length] > 0){
[taskToRun release];
result = [[NSString alloc] initWithData: realData
encoding: NSUTF8StringEncoding];
- NSLog(result);
}
} else {
NSLog(@"Task failed.");
// executeTask:
// -------------------------------------------------------------------------------
+(int) executeTaskWithAuth:(NSString*) taskName arguments:(NSArray *)args authExtForm:(NSData*)auth {
- NSLog(taskName);
NSString *result = nil;
int status = 0;
NSFileHandle *file = nil;
[taskToRun waitUntilExit];
status = [taskToRun terminationStatus];
if (status == 0){
- NSLog(@"Task succeeded.");
NSData *data = [file readDataToEndOfFile];
// remove the \n character from unix command
if([data length] > 0){
[taskToRun release];
result = [[NSString alloc] initWithData: realData
encoding: NSUTF8StringEncoding];
- NSLog(result);
[result release];
}
} else {
- NSLog(@"Task failed.");
}
return status;
// -------------------------------------------------------------------------------
- (void)awakeFromNib
{
- NSLog(@"awakeFromNib");
}