-2

I'm making an application for someone, and theres some things I'd like to monitor. I have NSLogs all set in place for each action, but I want to be able to send those to a console or something. Is there anyway of doing this? Also I don't want the user to know about it, I'm monitoring this because I gave the user a password for an account he has to manage, and I want to see what he's doing to make sure he's not breaking any rules.

Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175

1 Answers1

2

I don't quite get what you want here; NSLog() is the standard function to output to the console - at least in debug mode, generally NSLog()'s are removed from release code. (a big generalisation I know, but generally correct)

Is the user on your machine? Are you connected over a network.. etc There's a few questions you've left out.

Furthermore, why are you giving the user the options to do stuff which break the rules? I think this should be the biggest point from your post. The user obviously has the functionality to break the rules; how about changing that functionality instead of spying on them?

If I thought software I was using was being "logged" so the developer could see what I was doing, I would immediately begin looking at alternatives.


Edit: This is what I am trying to explain in the comments of this answer. I'm not claiming this code to be compile-able, I'm merely trying to explain how such a solution should work. It may not be the best, nor the quickest - it will however get the job done. I still personally believe the user shouldn't have that kind of functionality if he has no reason for it, and seeing as you have the source code to the application it should be trivial to remove that functionality - even temporarily.

PHP Script - This will mail you the error;

<?php
/* Get the specified incident */
$incident = $_GET['incident'];
$app = $_GET['app'];
$email = ''; //Your email address

/* send it to $email, with a subject of $app,
** and the "incident as a message" */
if( mail($email, $app, $incident) ){
    echo "SUCCESS";
}
?>

Then, to call it in Objective-C - implement a quick wrapper function to use the functionality of NSString's stringWithContentsOfURL method. Like this..

-(BOOL) userRuleBreak:(NSString *)incident{

/* We need to generate a URL of http://xxxxxx/perm.php?incident=???&app=???? */

NSUrl *alert = [NSUrl initWithString:[NSString
                initWithFormat:@"http://www.xxxxxx.xxx/perm.php?incident=%s&app=%s",
                    incident, @"APPNAME"];

NSString *status = [NSString stringWithContentsOfURL:alert,
                            encoding:NSASCIIStringEncoding];

if( status != nil ){
    return YES; 
} else {
    return NO;
}

}

Obviously, replacing the if statement at the end for something that will actually check the contents of the NSString. This code may, or may not compile - I haven't tried, but even if it does I advise you to code your own solution as that was written up quickly after a long couple of days with little sleep!

Look, The real issue with this application isn't the fact you're waiting for the user to do something he shouldn't - it's the fact that you're giving that user the ability to do something he shouldn't. If you don't want a user doing something - then don't give them the functionality. It's a poor idea to wait for an email after the user has already done something - by then, its too late. Stop it before it happens - don't give them the option to do it. Be pro-active and not reactionary, because if the user does something he shouldn't; its all fine and well saying "But I told you not to do that! You're not allowed" - but you'll be the one trying to undo the damage he's done.

EnOpenUK
  • 391
  • 1
  • 5
  • This person is doing a job for me, but has the accessibility to change passwords, and publish things that SHOULD NOT BE PUBLISHED. This is why I would like to monitor his actions. He would be on a computer nowhere near me. – Daniel Ricany Jul 18 '10 at 15:23
  • Does he require the functionality then? If he has access to those then I can see your concern - that's a giant security problem. I may be wrong, but I'd create a simple PHP script to send an email. Pass it a string(s) in the URL, (script.php?event="password-change" etc) then have the PHP Script called by [NSString setStringWithContentsOfURL] - with the URL as an argument, then just check the NSString to ensure it went correctly. You could even make a wrapper function for it. There maybe nicer options, but IMO this will get the job done. Of course, the functionality shouldn't even be there. – EnOpenUK Jul 18 '10 at 20:58
  • But its not on my website, its on another company's website. – Daniel Ricany Jul 19 '10 at 01:55
  • Edited to explain solution; note; the PHP script can be on anyone's server - as long as its accessible. – EnOpenUK Jul 19 '10 at 15:57
  • 1
    Ah, this is why I love knowing Objective-C *and* web-programming languages. :) Thanks for this! – esqew Jul 19 '10 at 16:14
  • I'm confused. And its resulting in many errors. What is supposed to be where "http://www.xxxxxx.xxx/perm.php?incident=%s&app=%s" is? Also, what do I put for "incident", and what is "encoding:" supposed to mean? Xcode thinks its not part of the method and is telling me its not declared. – Daniel Ricany Jul 19 '10 at 17:26
  • Let me just check this - you developed this application yourself? I did say I hadn't tested that code and it was just an explanation for how such a solution could be implemented. That code is a PHP script you would place on your own server. The Objective-C method would take an NSString as an argument, this is what you'd want emailed to you. The Objective-C method then loads the PHP script (located where I have put "xxxxxxxx") - which will email you. Encoding is an argument of "stringWithContentsOfURL" method of NSString. – EnOpenUK Jul 19 '10 at 17:40
  • I made the application for another site, I did not create the site. I have no control of what he does once he has the password, but he needs the password for the job. Understand now? – Daniel Ricany Jul 19 '10 at 18:52
  • It still isn't working...I can't figure out what's going wrong. I've made a new webpage, I edited the .html file so that its just the PHP script, and I just can't figure out whats going wrong. Can you tell me if I'm doing this right, and be detailed when explaining? Thank you. – Daniel Ricany Jul 19 '10 at 19:11
  • -(BOOL) userRuleBreak:(NSString *)incident{ NSURL *alert = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.applehack23.com/AppleHack23/Server.html/perm.php?incident=%s&app=%s", incident, @"APPNAME"]]; NSString *status = [NSString stringWithContentsOfURL:[alert encoding:NSASCIIStringEncoding]]; if( [[SpecialCodeTextField stringValue] isEqualToString:@"abc"] ){ return YES; } else { return NO; } } – Daniel Ricany Jul 19 '10 at 19:12