NSLog(@"Starting"); /* Create the Preferences Table, it holds all the controls on the preferences page */ pref = [[UIPreferencesTable alloc] initWithFrame: CGRectMake(0.0f, 48.0f, 320.0f, 480.0f-48.0f)]; /* Tell the preferences table to get its data from this class */ [pref setDataSource: self]; /* Tell the preferences table to send events to this class */ [pref setDelegate: self]; /* Necessary variables for setting up preferences table */ CGRect controlPos = CGRectMake(0.0f, 0.0f, 320.0f, 45.0f); NSFileManager *fileManager = [NSFileManager defaultManager]; /* Create header cell*/ netServicesHeader = [[UIPreferencesTableCell alloc] init]; [netServicesHeader _setDrawAsLabel: YES]; [netServicesHeader setDrawsBackground: YES]; [netServicesHeader setTitle:@"Tap Label to Change Set Visibility"]; [netServicesHeader setShowSelection: NO]; /* Holds the services that are listed under the Network Services group */ netServices2 = [[[NSMutableArray alloc] init] retain]; ServiceTableCell2 *cell; /* Initialize the Edge Service Control */ cell = [[EDGEServiceTableCell2 alloc] initWithFrame: controlPos]; /* Add this to the array of services */ [netServices2 addObject:cell]; /* Initialize the Bluetooth Control */ cell = [[BluetoothServiceTableCell2 alloc] initWithFrame: controlPos]; /* Add this to the array of services */ [netServices2 addObject:cell]; /* Initialize the Wifi Control */ cell = [[WifiServiceTableCell2 alloc] initWithFrame: controlPos]; /* Add this to the array of services */ [netServices2 addObject:cell]; /* Initialize the Airport Control */ cell = [[PhoneServiceTableCell2 alloc] initWithFrame: controlPos]; /* Add this to the array of services */ [netServices2 addObject:cell]; /* Initialize the OpenSSH Control */ /* Add this to the array of services, only if the opensshd daemon exists */ if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.openssh.sshd.plist"]) { cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Dropbear SSH Control */ cell = nil; NSString *dropbear = @"/System/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist"; if ([fileManager fileExistsAtPath:dropbear]) { cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos]; } else if ([fileManager fileExistsAtPath:(dropbear = @"/Library/LaunchDaemons/au.asn.ucc.matt.dropbear.plist")]) { cell = [[SSHServiceTableCell2 alloc] initWithFrame: controlPos]; } /* Add this to the array of services, only if the sshd daemon exists */ if (cell != nil) { [netServices2 addObject:cell]; } /* Initialize the AFP Control */ /* Add this to the array of services, only if the AFP daemon exists */ if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.core.afp.plist"]) { cell = [[AFPServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Samba Control */ /* Add this to the array of services, only if the Samba daemon exists */ if ([fileManager fileExistsAtPath:@"/usr/local/samba/smbd"]) { cell = [[SambaServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the FireFly Control */ /* Add this to the array of services, only if the Firefly daemon exists */ if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/org.fireflymediaserver.mt-daapd.plist"]) { cell = [[FireflyServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Apache Control */ /* Add this to the array of services, only if the Apache daemon exists */ if ([fileManager fileExistsAtPath:@"/System/Library/LaunchDaemons/org.apache.httpd.plist"]) { cell = [[ApacheServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Lighttpd Control */ /* Add this to the array of services, only if the Lighttpd daemon exists */ if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/com.amcgregor.lighttpd.plist"]) { cell = [[LighttpdServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Socks Server Control */ /* Add this to the array of services, only if the Socks Server daemon exists */ if ([fileManager fileExistsAtPath:@"/Library/LaunchDaemons/net.sourceforge.socks-relay.srelay.plist"]) { cell = [[SocksServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; } /* Initialize the Tinyproxy Control */ /* Add this to the array of services, only if the Tinyproxy daemon exists */ cell = nil; NSString *tinyproxy = @"/System/Library/LaunchDaemons/com.wickedpsyched.iphone.tinyproxy.plist"; if ([fileManager fileExistsAtPath:tinyproxy]) { cell = [[TinyproxyServiceTableCell2 alloc] initWithFrame: controlPos]; } else if ([fileManager fileExistsAtPath:@"/System/Library/LaunchDaemonscom.wickedpsyched.iphone.tinyproxy.plist"]) { cell = [[TinyproxyServiceTableCell2 alloc] initWithFrame: controlPos]; } if (cell != nil) { [netServices2 addObject:cell]; } /* Initialize the IP Control Add this to the array of services */ cell = [[IPTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; /* Initialize the Autolock Control Add this to the array of services */ cell = [[AutolockServiceTableCell2 alloc] initWithFrame: controlPos]; [netServices2 addObject:cell]; topBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)]; [topBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle: @"NetServices"]]; [topBar showButtonsWithLeftTitle:@"Main" rightTitle:nil leftBack:YES]; [topBar enableAnimation]; [topBar setDelegate:self]; /* Create the cells for the about information */ aboutVersion = [[UIPreferencesTableCell alloc] init]; [aboutVersion setTitle:[[NSString alloc] initWithFormat:@"Version %@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]]; [aboutVersion _setDrawAsLabel: YES]; [aboutVersion setDrawsBackground: NO]; aboutCopyright = [[UIPreferencesTableCell alloc] init]; [aboutCopyright setTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleCopyright"]]; [aboutCopyright _setDrawAsLabel: YES]; [aboutCopyright setDrawsBackground: NO]; /* Populate the Preference table */ [pref reloadData]; [self addSubview:topBar]; [self addSubview:pref]; return self; } - (void)reloadData { [pref reloadData]; } - (void)changeLabel:(NSString *)newLabel { NSDictionary *labelDictionary = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/NetServices.app/ProgramFiles/plists/settings.plist"]; NSLog(@"got dict"); NSString *fullLabel = [NSString stringWithFormat:@"Label-%@", newLabel]; NSString *changeButtonLabel = [labelDictionary objectForKey:fullLabel]; NSLog(@"buttonLabel in plist %@", changeButtonLabel); system([[NSString stringWithFormat:@"/Applications/NetServices.app/ProgramFiles/bin/alert -t 'Switch Label Change' -b \"Change the Label for %@\" -o -F \"%@\" > /Applications/NetServices.app/file", newLabel, changeButtonLabel] UTF8String]); NSData *labelData = [NSData dataWithContentsOfFile: @"/Applications/NetServices.app/file"]; NSString *changedLabel = [[NSString alloc] initWithData: labelData encoding: NSUTF8StringEncoding]; NSLog (@"got\n%@", changedLabel); changedLabel = [changedLabel stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n"]]; system([[NSString stringWithFormat:@"/Applications/NetServices.app/ProgramFiles/bin/plutil -s \"%@\" -v \"%@\" /Applications/NetServices.app/ProgramFiles/plists/settings.plist", fullLabel, changedLabel] UTF8String]); [self reloadData]; } - (void)tableRowSelected:(NSNotification *)notification { int rowIndex = [pref selectedRow]; NSLog(@"table=%@", pref); NSLog(@"selected row %d", rowIndex); NSString *rowValue = [NSString stringWithFormat:@"%@", [pref cellAtRow:rowIndex column:0]]; NSLog(@"rowValue %@", rowValue); NSString *serviceStringShort = [rowValue substringWithRange:NSMakeRange(1, 4)]; NSLog(@"substring %@", serviceStringShort); if ([serviceStringShort isEqual:@"AFPS"]){ [self changeLabel:@"AFP"]; } if ([serviceStringShort isEqual:@"Apac"]){ [self changeLabel:@"Apache"]; } if ([serviceStringShort isEqual:@"Auto"]){ [self changeLabel:@"Autolock"]; } if ([serviceStringShort isEqual:@"Blue"]){ [self changeLabel:@"Bluetooth"]; } if ([serviceStringShort isEqual:@"Drop"]){ [self changeLabel:@"Dropbear"]; } if ([serviceStringShort isEqual:@"EDGE"]){ [self changeLabel:@"EDGE"]; } if ([serviceStringShort isEqual:@"File"]){ [self changeLabel:@"Fileshare"]; } if ([serviceStringShort isEqual:@"Fire"]){ [self changeLabel:@"Firefly"]; } if ([serviceStringShort isEqual:@"IPTa"]){ [self changeLabel:@"IP"]; } if ([serviceStringShort isEqual:@"Ligh"]){ [self changeLabel:@"Lighttpd"]; } if ([serviceStringShort isEqual:@"Phon"]){ [self changeLabel:@"Airplane"]; } if ([serviceStringShort isEqual:@"SSHS"]){ [self changeLabel:@"SSH"]; } if ([serviceStringShort isEqual:@"Samb"]){ [self changeLabel:@"Samba"]; } if ([serviceStringShort isEqual:@"Sock"]){ [self changeLabel:@"Socks"]; } if ([serviceStringShort isEqual:@"Tiny"]){ [self changeLabel:@"Tiny"]; } if ([serviceStringShort isEqual:@"Wifi"]){ [self changeLabel:@"Wifi"]; } }