Commit 6049543f authored by David Smith's avatar David Smith Committed by david

Lots of Mac changes: new prefpane UI, uses a helper tool instead of shell...

Lots of Mac changes: new prefpane UI, uses a helper tool instead of shell scripts, closer to 10.5 compatibility

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6465 b35dd754-fafc-0310-a699-88a17e54d16e
parent 684c6966
......@@ -2,14 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>WILDFIRE_HOME</key>
<string>/usr/local/wildfire/</string>
</dict>
<key>Label</key>
<string>org.jivesoftware.wildfire</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/wildfire/bin/extra/wildfire-launchd-wrapper.sh</string>
</array>
<key>Program</key>
<string>/usr/local/wildfire/bin/extra/wildfire-launchd-wrapper.sh</string>
<key>RunAtLoad</key>
<false/>
<key>ServiceDescription</key>
......
#!/bin/bash
#determine safe uid/gid
WILDFIRE_USER=`nireport / /users name | grep "wildfire"`
WILDFIRE_GID=`nireport / /users gid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER] ; then
WILDFIRE_UID=`nireport / /users uid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
niutil -create . /users/wildfire
#set properties
niutil -createprop . /users/wildfire gid $WILDFIRE_GID
niutil -createprop . /users/wildfire uid $WILDFIRE_UID
niutil -createprop . /users/wildfire shell /usr/bin/false
niutil -createprop . /users/wildfire home /usr/local/wildfire/
niutil -createprop . /users/wildfire realname "Jive Wildfire"
niutil -createprop . /users/wildfire passwd '*'
fi
\ No newline at end of file
NIUTIL_PRESENT=`which niutil`
if [ -z $NIUTIL_PRESENT] ; then
echo "No niutil"
WILDFIRE_USER=`dscl . -search /Users name wildfire | awk '{print $1}'`
WILDFIRE_GID=`dscl . -readall /Users PrimaryGroupID | awk '/PrimaryGroupID/{print $2}' | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER ] ; then
WILDFIRE_UID=`dscl . -readall /Users UniqueID | awk '/UniqueID/{print $2}' | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
dscl . -create /Users/wildfire
#set properties
dscl . -create /Users/wildfire PrimaryGroupID $WILDFIRE_GID
dscl . -create /Users/wildfire UniqueID $WILDFIRE_UID
dscl . -create /Users/wildfire UserShell /usr/bin/false
dscl . -create /Users/wildfire NFSHomeDirectory /usr/local/wildfire/
dscl . -create /Users/wildfire RealName "Jive Wildfire"
dscl . -passwd /Users/wildfire '*'
fi
else
WILDFIRE_USER=`nireport / /users name | grep "wildfire"`
WILDFIRE_GID=`nireport / /users gid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_GID=$WILDFIRE_GID+1"
echo $WILDFIRE_GID > /private/tmp/wildfiregid
if [ -z $WILDFIRE_USER] ; then
WILDFIRE_UID=`nireport / /users uid | sort -n | egrep -v "\b[5-9][0-9]{2,5}\b" | tail -n 1`
let "WILDFIRE_UID=$WILDFIRE_UID+1"
echo $WILDFIRE_UID
#create user
niutil -create . /users/wildfire
#set properties
niutil -createprop . /users/wildfire gid $WILDFIRE_GID
niutil -createprop . /users/wildfire uid $WILDFIRE_UID
niutil -createprop . /users/wildfire shell /usr/bin/false
niutil -createprop . /users/wildfire home /usr/local/wildfire/
niutil -createprop . /users/wildfire realname "Jive Wildfire"
niutil -createprop . /users/wildfire passwd '*'
fi
fi
{
IBClasses = (
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
{CLASS = NSObject; LANGUAGE = ObjC; },
{
CLASS = NSPreferencePane;
LANGUAGE = ObjC;
......@@ -12,24 +13,20 @@
};
SUPERCLASS = NSObject;
},
{CLASS = SFAuthorizationView; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = WilfireStartStop; LANGUAGE = ObjC; SUPERCLASS = NSButton; },
{
ACTIONS = {
openAdminInterface = id;
openAdminInterfaceSSL = id;
toggleAutoStart = id;
toggleServer = id;
};
ACTIONS = {openAdminInterface = id; toggleAutoStart = id; toggleServer = id; };
CLASS = wildfirePrefPane;
LANGUAGE = ObjC;
OUTLETS = {
authView = SFAuthorizationView;
autoStartCheckbox = NSButton;
startButton = NSButton;
statusDescription = NSTextField;
statusMessage = NSTextField;
statusProgress = NSProgressIndicator;
viewAdminButton = NSButton;
viewAdminButtonSSL = NSButton;
};
SUPERCLASS = NSPreferencePane;
}
......
......@@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>1155 145 481 349 0 0 1680 1028 </string>
<string>35 145 481 349 0 0 1280 778 </string>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOpenObjects</key>
......
#include <unistd.h>
#include <stdbool.h>
#include <CoreFoundation/CoreFoundation.h>
static void CFQRelease(CFTypeRef cf)
// A version of CFRelease that's tolerant of NULL.
{
if (cf != NULL) {
CFRelease(cf);
}
}
static int GetPathToSelf(char **pathToSelfPtr)
// A drop-in replacement for GetPathToSelf() from MoreAuthSample's MoreSecurity.c,
// implemented using CoreFoundation. From CocoaDev.com
{
int err = 0;
assert( pathToSelfPtr != NULL);
assert(*pathToSelfPtr == NULL);
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef executableURL = NULL;
CFStringRef pathStringRef = NULL;
char *path = NULL;
if (mainBundle != NULL) {
executableURL = CFBundleCopyExecutableURL(mainBundle);
if (executableURL != NULL) {
pathStringRef = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle);
if (pathStringRef != NULL) {
CFIndex pathSize = CFStringGetLength(pathStringRef) + 1;
path = (char *)calloc(pathSize,1);
if (path != NULL) {
Boolean gotCString = CFStringGetCString(pathStringRef, path, pathSize, kCFStringEncodingUTF8);
if (!gotCString) {
free(path);
path = NULL;
}
}
}
}
}
*pathToSelfPtr = path;
// Do the CF memory management.
CFQRelease(executableURL);
CFQRelease(pathStringRef);
assert(*pathToSelfPtr != NULL);
if (*pathToSelfPtr == NULL)
{
err = -1;
}
return err;
}
static bool wildfireIsRunning()
{
FILE *ps;
char buff[1024];
if((ps=popen("/bin/ps auxww | fgrep -v 'fgrep' | fgrep wildfire/lib/startup.jar", "r")) == NULL)
{
return false;
}
else
{
bool running = false;
if(fgets(buff, 1024, ps)) {
running = true;
}
pclose(ps);
return running;
}
}
static void toggleStartWildfireAtBoot()
{
CFURLRef propFile = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
CFSTR("/Library/LaunchDaemons/org.jivesoftware.wildfire.plist"),
kCFURLPOSIXPathStyle,
false);
CFDataRef xmlData;
CFURLCreateDataAndPropertiesFromResource (kCFAllocatorDefault,
propFile,
&xmlData,
NULL,
NULL,
NULL);
CFPropertyListRef props = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
xmlData,
kCFPropertyListMutableContainersAndLeaves,
NULL);
if(CFGetTypeID(props) == CFDictionaryGetTypeID()) {
CFMutableDictionaryRef propsDict = (CFMutableDictionaryRef)props;
CFBooleanRef currentValue = CFDictionaryGetValue(propsDict,CFSTR("RunAtLoad"));
CFDictionaryReplaceValue(propsDict, CFSTR("RunAtLoad"), ((currentValue == kCFBooleanTrue) ? kCFBooleanFalse : kCFBooleanTrue));
CFQRelease(xmlData);
xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault,(CFPropertyListRef)propsDict);
CFURLWriteDataAndPropertiesToResource(propFile,xmlData,NULL,NULL);
}
CFQRelease(props);
CFQRelease(xmlData);
CFQRelease(propFile);
}
static void toggleWildfire()
{
char *args[4];
args[0] = "launchctl";
if(wildfireIsRunning())
args[1] = "unload";
else
args[1] = "load";
args[2] = "/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
args[3] = NULL;
execv("/bin/launchctl", args);
}
int main(int inArgsCount, char * const inArgs[])
{
char* selfPath = NULL;
int err = GetPathToSelf(&selfPath);
const char* correctPath = "/Library/PreferencePanes/Wildfire.prefPane/Contents/MacOS/HelperTool";
if(err == 0 && strncmp(correctPath, selfPath, strlen(correctPath)) == 0) {
setuid(0);
if(inArgs[1] && strlen(inArgs[1]) == strlen("boot") && strncmp("boot", inArgs[1], strlen("boot")) == 0) {
toggleStartWildfireAtBoot();
} else {
toggleWildfire();
}
}
return 1;
}
\ No newline at end of file
#!/bin/bash
CURRENT_FLAG=`sudo awk '/RunAtLoad/{getline; print}' /Library/LaunchDaemons/org.jivesoftware.wildfire.plist | tr -d '\n' | grep true`
echo "Current flag is $CURRENT_FLAG"
if [ -z "$CURRENT_FLAG" ] ; then
CURRENT_FLAG="false"
NEW_FLAG="true"
else
CURRENT_FLAG="true"
NEW_FLAG="false"
fi
sudo sed -i "" -e "/RunAtLoad/ {
n
s/$CURRENT_FLAG/$NEW_FLAG/
}" /Library/LaunchDaemons/org.jivesoftware.wildfire.plist
......@@ -9,8 +9,8 @@
//
#import <PreferencePanes/PreferencePanes.h>
#import <Security/Authorization.h>
#import <Security/AuthorizationTags.h>
#import <Security/Security.h>
#import <SecurityInterface/SFAuthorizationView.h>
#include <unistd.h>
// 'ps' command to use to check for running wildfire daemon
......@@ -25,16 +25,10 @@ NSString *plistPath = @"/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
IBOutlet NSButton *startButton;
IBOutlet NSButton *autoStartCheckbox;
IBOutlet NSButton *viewAdminButton;
IBOutlet NSButton *viewAdminButtonSSL;
IBOutlet NSTextField *statusMessage;
IBOutlet NSTextField *statusDescription;
IBOutlet NSProgressIndicator *statusProgress;
AuthorizationRef authorizationRef;
AuthorizationRights authRights;
AuthorizationRights *authorizedRights;
AuthorizationFlags authFlags;
OSStatus ourStatus;
IBOutlet SFAuthorizationView *authView;
NSTimer *statusTimer;
}
......@@ -42,7 +36,6 @@ NSString *plistPath = @"/Library/LaunchDaemons/org.jivesoftware.wildfire.plist";
- (IBAction)toggleServer:(id)sender;
- (IBAction)toggleAutoStart:(id)sender;
- (IBAction)openAdminInterface:(id)sender;
- (IBAction)openAdminInterfaceSSL:(id)sender;
- (void)mainViewDidLoad;
- (void)updateStatus;
- (void)startServer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment