Exemplo n.º 1
0
def main():
    from gate import create_default_gate
    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    session = requests.Session()
    session.headers.update({'USER-AGENT': opts.user_agent})

    o = session.post(opts.smoonURL + '', timeout=opts.timeout)

    exceptions = (requests.exceptions.HTTPError,
                  requests.exceptions.URLRequired,
                  requests.exceptions.Timeout,
                  requests.exceptions.ConnectionError,
                  requests.exceptions.InvalidURL)

    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = opts.smoonURL + 'client/pub_uuid?uuid=%s' % profile.host.UUID
        pub_uuid_fli = session.get(pub_uuid_fli, timeout=opts.timeout)
    except exceptions as e:
        error(_('Error contacting Server: %s') % e)
        return 1
    try:
        pub_uuid_obj = pub_uuid_fli.json()
        try:
            print(_('To view your profile visit: %s') % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"]))
        except ValueError as e:
            error(_('Something went wrong fetching the public UUID'))
    finally:
        session.close()
Exemplo n.º 2
0
def main():
    profile = smolt.get_profile()
    #first find out the server desired protocol
    try:
        #fli is a file like item
        req = Request('/client/pub_uuid?uuid=%s' % profile.host.UUID)
        pub_uuid_fli.open()
    except urllib2.URLError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
Exemplo n.º 3
0
def main():
    profile = smolt.get_profile()
    #first find out the server desired protocol
    try:
        #fli is a file like item
        req = Request('/client/pub_uuid?uuid=%s' % profile.host.UUID)
        pub_uuid_fli.open()
    except urllib2.URLError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
Exemplo n.º 4
0
def main():
    profile = smolt.get_profile()
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(urljoin(opts.smoonURL + "/", '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
Exemplo n.º 5
0
def main():
    from gate import create_default_gate
    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(urljoin(opts.smoonURL + "/", '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
Exemplo n.º 6
0
def main_request_new_public_uuid(uuiddb, uuid, profile, opts):
    ensure_code_reachability()
    from i18n import _
    from smolt import error, ServerError

    try:
        pub_uuid = profile.regenerate_pub_uuid(uuiddb, uuid, user_agent=opts.user_agent,
                            smoonURL=opts.smoonURL,
                            timeout=opts.timeout)
    except ServerError, e:
        error(_('Error contacting server: %s') % str(e))
        sys.exit(1)
Exemplo n.º 7
0
def present_and_require_confirmation(profile):
    import subprocess
    from tempfile import NamedTemporaryFile

    ensure_code_reachability()
    from i18n import _
    from smolt import error

    excerpts = make_display_excerpts(profile)

    submit = False
    while not submit:
        dump_excerpts(excerpts)

        try:
            choice = raw_input(_('Your choice (s)end (v)iew (q)uit: ')).strip()
        except KeyboardInterrupt:
            error(_('Exiting...'))
            sys.exit(4)
        if choice in (_('s|y|yes')).split('|'):
            submit = True
            print '\n\n'
        elif choice in (_('q|n|no')).split('|'):
            sys.exit(0)
        elif choice in (_('v')).split('|'):
            f = NamedTemporaryFile()
            for line in profile.getProfile():
                try:
                    f.write(line + '\n')
                except UnicodeEncodeError:
                    pass
            f.flush()
            os.chmod(f.name, 0400)
            try:
                pager_command = os.environ['PAGER']
            except KeyError:
                if os.path.exists('/usr/bin/less'):
                    pager_command = '/usr/bin/less'
                elif os.path.exists('/bin/less'):
                    pager_command = '/bin/less'
                else:
                    #fallback to more  , could use /bin/more but might as well let the path sort it out.
                    pager_command = 'more'
            try:
                subprocess.call([pager_command, f.name])
            except NameError:
                os.system(' '.join([pager_command, f.name]))
            f.close()
            print '\n\n'
        else:
            error(_('Exiting...'))
            sys.exit(4)
Exemplo n.º 8
0
def present_and_require_confirmation(profile):
    import subprocess
    from tempfile import NamedTemporaryFile

    ensure_code_reachability()
    from i18n import _
    from smolt import error

    excerpts = make_display_excerpts(profile)

    submit = False
    while not submit:
        dump_excerpts(excerpts)

        try:
            choice = raw_input(_('Your choice (s)end (v)iew (q)uit: ')).strip()
        except KeyboardInterrupt:
            error(_('Exiting...'))
            sys.exit(4)
        if choice in (_('s|y|yes')).split('|'):
            submit = True
            print '\n\n'
        elif choice in (_('q|n|no')).split('|'):
            sys.exit(0)
        elif choice in (_('v')).split('|'):
            f = NamedTemporaryFile()
            for line in profile.getProfile():
                try:
                    f.write(line + '\n')
                except UnicodeEncodeError:
                    pass
            f.flush()
            os.chmod(f.name, 0400)
            try:
                pager_command = os.environ['PAGER']
            except KeyError:
                if os.path.exists('/usr/bin/less'):
                    pager_command = '/usr/bin/less'
                elif os.path.exists('/bin/less'):
                    pager_command = '/bin/less'
                else:
                    #fallback to more  , could use /bin/more but might as well let the path sort it out.
                    pager_command = 'more'
            try:
                subprocess.call([pager_command, f.name])
            except NameError:
                os.system(' '.join([pager_command, f.name]))
            f.close()
            print '\n\n'
        else:
            error(_('Exiting...'))
            sys.exit(4)
Exemplo n.º 9
0
def main():
    from gate import create_default_gate

    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    # first find out the server desired protocol
    try:
        # fli is a file like item
        pub_uuid_fli = grabber.urlopen(
            urljoin(opts.smoonURL + "/", "/client/pub_uuid?uuid=%s" % profile.host.UUID, False)
        )
    except urlgrabber.grabber.URLGrabError, e:
        error(_("Error contacting Server: %s") % e)
        return 1
Exemplo n.º 10
0
def main_request_new_public_uuid(uuiddb, uuid, profile, opts):
    ensure_code_reachability()
    from i18n import _
    from smolt import error, ServerError

    try:
        pub_uuid = profile.regenerate_pub_uuid(uuiddb,
                                               uuid,
                                               user_agent=opts.user_agent,
                                               smoonURL=opts.smoonURL,
                                               timeout=opts.timeout)
    except ServerError, e:
        error(_('Error contacting server: %s') % str(e))
        sys.exit(1)
Exemplo n.º 11
0
def send_profile(uuiddb, uuid, profile, opts, proxies):
    ensure_code_reachability()
    from i18n import _
    from smolt import error

    if opts.retry:
        while 1:
            (error_code, pub_uuid, admin) = do_send_profile(uuiddb, uuid, profile, opts, proxies)
            if not error_code:
                break
            error(_('Retry Enabled - Retrying'))
            time.sleep(30)
    else:
        (error_code, pub_uuid, admin) = do_send_profile(uuiddb, uuid, profile, opts, proxies)
        if error_code:
            print _('Could not send - Exiting')
            sys.exit(1)

    return (error_code, pub_uuid, admin)
Exemplo n.º 12
0
def send_profile(uuiddb, uuid, profile, opts, proxies):
    ensure_code_reachability()
    from i18n import _
    from smolt import error

    if opts.retry:
        while 1:
            (error_code, pub_uuid,
             admin) = do_send_profile(uuiddb, uuid, profile, opts, proxies)
            if not error_code:
                break
            error(_('Retry Enabled - Retrying'))
            time.sleep(30)
    else:
        (error_code, pub_uuid,
         admin) = do_send_profile(uuiddb, uuid, profile, opts, proxies)
        if error_code:
            print _('Could not send - Exiting')
            sys.exit(1)

    return (error_code, pub_uuid, admin)
Exemplo n.º 13
0
if opts.checkin:
    # Smolt is set to run
    opts.autoSend = True

# read the profile
try:
    profile = smolt.get_profile()
except smolt.UUIDError, e:
    sys.stderr.write(_('%s\n' % e))
    sys.exit(9)

if opts.new_pub:
    try:
        pub_uuid = profile.regenerate_pub_uuid(smoonURL=opts.smoonURL)
    except ServerError, e:
        error(_('Error contacting server: %s') % str(e))
        sys.exit(1)

    print _('Success!  Your new public UUID is: %s' % pub_uuid)
    sys.exit(0)

if opts.scanOnly:
    scan(profile, opts.smoonURL)
    rating(profile, opts.smoonURL)
    sys.exit(0)

if not opts.autoSend:
    if opts.printOnly:
        for line in profile.getProfile():
            if not line.startswith('#'):
                print line.encode('utf-8')
Exemplo n.º 14
0
                  help = _('specify HTTP timeout in seconds (default %default seconds)'))
parser.add_option('--uuidFile',
                  dest = 'uuidFile',
                  default = smolt.hw_uuid_file,
                  help = _('specify which uuid to use, useful for debugging and testing mostly.'))

(opts, args) = parser.parse_args()

def main():
    profile = smolt.get_profile()
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(urljoin(opts.smoonURL + "/", '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
    pub_uuid_str = pub_uuid_fli.read()
    try:
        try:
            pub_uuid_obj = simplejson.loads(pub_uuid_str)
            print _('To view your profile visit: %s') % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"])
        except ValueError, e:
            error(_('Something went wrong fetching the public UUID'))
    finally:
        pub_uuid_fli.close()
        
if __name__ == '__main__':
    main() 
Exemplo n.º 15
0

def main():
    from gate import create_default_gate
    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent,
                                            timeout=opts.timeout)
    #first find out the server desired protocol
    try:
        #fli is a file like item
        pub_uuid_fli = grabber.urlopen(
            urljoin(opts.smoonURL + "/",
                    '/client/pub_uuid?uuid=%s' % profile.host.UUID, False))
    except urlgrabber.grabber.URLGrabError, e:
        error(_('Error contacting Server: %s') % e)
        return 1
    pub_uuid_str = pub_uuid_fli.read()
    try:
        try:
            pub_uuid_obj = json.loads(pub_uuid_str)
            print _('To view your profile visit: %s') % smolt.get_profile_link(
                opts.smoonURL, pub_uuid_obj["pub_uuid"])
        except ValueError, e:
            error(_('Something went wrong fetching the public UUID'))
    finally:
        pub_uuid_fli.close()


if __name__ == '__main__':
    main()
Exemplo n.º 16
0
def serverMessage(page):
    for line in page.split("\n"):
        if 'ServerMessage:' in line:
            error(_('Server Message: "%s"') % line.split('ServerMessage: ')[1])
            if 'Critical' in line:
                sys.exit(3)
Exemplo n.º 17
0
 def serverMessage(page):
     for line in page.split("\n"):
         if 'ServerMessage:' in line:
             error(_('Server Message: "%s"') % line.split('ServerMessage: ')[1])
             if 'Critical' in line:
                 sys.exit(3)
Exemplo n.º 18
0
for line in profile.getProfile():
    try:
        print line
    except UnicodeEncodeError:
        pass

if not opts.autoSend:
    if opts.printOnly:
        sys.exit(0)
    else:
        try:
            send = raw_input('\n' +
                             _('Send this information to the Smolt server? (y/n)') + ' ')
            if send[:1].lower() != _('y'):
                error(_('Exiting...'))
                sys.exit(4)
        except KeyboardInterrupt:
            error(_('Exiting...'))
            sys.exit(4)

if opts.retry:
    while 1:
        result, pub_uuid, admin = profile.send(user_agent=opts.user_agent,
                              smoonURL=opts.smoonURL,
                              timeout=opts.timeout,
                              proxies=proxies)
        if not result:
            sys.exit(0)
        error(_('Retry Enabled - Retrying'))
        time.sleep(30)
Exemplo n.º 19
0
    opts.autoSend = True

# read the profile
try:
    profile = smolt.get_profile()
except smolt.UUIDError, e:
    sys.stderr.write(_('%s\n' % e))
    sys.exit(9)

if opts.new_pub:
    try:
        pub_uuid = profile.regenerate_pub_uuid(user_agent=opts.user_agent,
                                               smoonURL=opts.smoonURL,
                                               timeout=opts.timeout)
    except ServerError, e:
        error(_('Error contacting server: %s') % str(e))
        sys.exit(1)

    print _('Success!  Your new public UUID is: %s' % pub_uuid)
    sys.exit(0)

if opts.scanOnly:
    scan(profile, opts.smoonURL)
    rating(profile, opts.smoonURL)
    sys.exit(0)

if not opts.autoSend:
    if opts.printOnly:
        for line in profile.getProfile():
            if not line.startswith('#'):
                print line.encode('utf-8')
Exemplo n.º 20
0
(opts, args) = parser.parse_args()


def main():
    from gate import create_default_gate

    profile = smolt.create_profile(create_default_gate(), smolt.read_uuid())
    grabber = urlgrabber.grabber.URLGrabber(user_agent=opts.user_agent, timeout=opts.timeout)
    # first find out the server desired protocol
    try:
        # fli is a file like item
        pub_uuid_fli = grabber.urlopen(
            urljoin(opts.smoonURL + "/", "/client/pub_uuid?uuid=%s" % profile.host.UUID, False)
        )
    except urlgrabber.grabber.URLGrabError, e:
        error(_("Error contacting Server: %s") % e)
        return 1
    pub_uuid_str = pub_uuid_fli.read()
    try:
        try:
            pub_uuid_obj = simplejson.loads(pub_uuid_str)
            print _("To view your profile visit: %s") % smolt.get_profile_link(opts.smoonURL, pub_uuid_obj["pub_uuid"])
        except ValueError, e:
            error(_("Something went wrong fetching the public UUID"))
    finally:
        pub_uuid_fli.close()


if __name__ == "__main__":
    main()