Beispiel #1
0
def find_profiles(user=None):
    if user and user != "root":
        paths = run_cmd("find /Users/%s/Library/Application\ Support/Skype -name 'main.db'" % user)
    else:
        paths = run_cmd("find /*/*/Users/*/Library/Application\ Support/Skype -name 'main.db'")
        root_skypes = run_cmd("find /var/root/Library/Application\ Support/Skype -name 'main.db'")
        paths.extend([path for path in root_skypes if path])
    return paths
Beispiel #2
0
def get_main_user():
    """guess the primary user of the computer who is currently logged in"""
    # Guess main user by seeing who is currently running Finder.app
    main_user = run_cmd("ps aux | grep CoreServices/Finder.app | head -1 | awk '{print $1}'")[0]

    if not main_user or main_user == 'root':
        # fallback to guess main user by seeing who owns the console file
        main_user = run_cmd("stat -f '%Su' /dev/console")[0]

    return main_user
Beispiel #3
0
def get_main_user():
    """guess the primary user of the computer who is currently logged in"""
    # Guess main user by seeing who is currently running Finder.app
    main_user = run_cmd("ps aux | grep CoreServices/Finder.app | head -1 | awk '{print $1}'")[0]

    if not main_user or main_user == 'root':
        # fallback to guess main user by seeing who owns the console file
        main_user = run_cmd("stat -f '%Su' /dev/console")[0]

    return main_user
Beispiel #4
0
def email(to='*****@*****.**',
          _from=default_from,
          subject='BOT MSG',
          message="Info email",
          attachments=None):
    """function to send mail to a specified address with the given attachments"""
    for attachment in attachments or []:
        filename = attachment.strip()
        try:
            result = run_cmd('uuencode %s %s | mailx -s "%s" %s' %
                             (filename, filename, subject, to))[0]
            return "Sending email From: %s; To: %s; Subject: %s; Attachment: %s (%s)" % (
                _from, to, subject, filename, result or 'Succeded')
        except Exception as error:
            return str(error)

    if not attachments:
        p = os.popen("/usr/sbin/sendmail -t", "w")
        p.write("From: %s\n" % _from)
        p.write("To: %s\n" % to)
        p.write("Subject: %s\n" % subject)
        p.write("\n")  # blank line separating headers from body
        p.write('%s\n' % message)
        result = p.close()

    if not result:
        return "Sent email From: %s; To: %s; Subject: %s; Attachments: %s)" % (
            _from, to, subject, ','.join(attachments or []))
    else:
        return "Error: %s. Please fix Postfix:\n %s" % (result, help_str)
def email(to='*****@*****.**', _from=default_from, subject='BOT MSG', message="Info email", attachments=None):
    """function to send mail to a specified address with the given attachments"""
    for attachment in attachments or []:
        filename = attachment.strip()
        try:
            result = run_cmd('uuencode %s %s | mailx -s "%s" %s' % (filename, filename, subject, to))[0]
            return "Sending email From: %s; To: %s; Subject: %s; Attachment: %s (%s)" % (_from, to, subject, filename, result or 'Succeded')
        except Exception as error:
            return str(error)

    if not attachments:
        p = os.popen("/usr/sbin/sendmail -t", "w")
        p.write("From: %s\n" % _from)
        p.write("To: %s\n" % to)
        p.write("Subject: %s\n" % subject)
        p.write("\n")   # blank line separating headers from body
        p.write('%s\n' % message)
        result = p.close()

    if not result:
        return "Sent email From: %s; To: %s; Subject: %s; Attachments: %s)" % (_from, to, subject, ','.join(attachments or []))
    else:
        return "Error: %s. Please fix Postfix:\n %s" % (result, help_str)
Beispiel #6
0
def get_uptime():
    return run_cmd('uptime')[0]
Beispiel #7
0
def get_power():
    """detect whether computer is plugged in"""
    return run_cmd(
        "system_profiler SPPowerDataType | grep -q Connected && echo 'Connected' || echo 'Disconnected'"
    )[0]
Beispiel #8
0
def get_hardware():
    """detailed hardware overview from system profiler"""
    return run_cmd('system_profiler SPHardwareDataType', verbose=False)[1:]
Beispiel #9
0
def get_full_username(user):
    """sarah -> Sarah J. Connor"""
    full_name = run_cmd(
        "finger %s | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //'" %
        user)[0]
    return full_name or user
Beispiel #10
0
def lock_screen():
    return run_cmd('/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend')
Beispiel #11
0
def screensaver():
    return run_cmd('open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app')
Beispiel #12
0
def get_local_ips():
    """parse ifconfig for all the computer's local IP addresses"""
    local_ips = run_cmd(
        r"ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'")
    local_ips.remove('127.0.0.1')
    return local_ips
Beispiel #13
0
def get_full_username(user):
    """sarah -> Sarah J. Connor"""
    full_name = run_cmd("finger %s | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //'" % user)[0]
    return full_name or user
Beispiel #14
0
def get_public_ip():
    """get the computer's current public IP by querying the opendns public ip resolver"""
    return run_cmd('dig +short myip.opendns.com @resolver1.opendns.com')[0]
Beispiel #15
0
def get_local_ips():
    """parse ifconfig for all the computer's local IP addresses"""
    local_ips = run_cmd(r"ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'")
    local_ips.remove('127.0.0.1')
    return local_ips
Beispiel #16
0
def get_uptime():
    return run_cmd('uptime')[0]
Beispiel #17
0
def get_power():
    """detect whether computer is plugged in"""
    return run_cmd("system_profiler SPPowerDataType | grep -q Connected && echo 'Connected' || echo 'Disconnected'")[0]
Beispiel #18
0
def get_hardware():
    """detailed hardware overview from system profiler"""
    return run_cmd('system_profiler SPHardwareDataType', verbose=False)[1:]
Beispiel #19
0
def get_public_ip():
    """get the computer's current public IP by querying the opendns public ip resolver"""
    return run_cmd('dig +short myip.opendns.com @resolver1.opendns.com')[0]
Beispiel #20
0
def add_gatekeeper_exception(app_path):
    """WARNING: big scary password prompt is shown to the current active user"""
    return run_cmd('spctl --add "%s"' % app_path)