Beispiel #1
0
def client_del_sid(client):
    """ delete this session """
    sid = get_sid(client.SID_FILE)
    try:
        s = client.service.del_sid(sid)

        if s[0][0] == "-1":
            print _("No access to the file!")
            return -1
        if s[0][0] == "1":
            print _("Failed to obtain certificate data!")
            return -2
        if s[0][0] == "Permission denied":
            _print (_("%s: permission denied") % s[1][1])
            return -3

        if s[0][0] == '0':
            fi = open(client.SID_FILE, 'w')
            fi.write('0')
            fi.close()
            print _("SID deleted!")
    except:
        print _("SID deletion error on the server")
        return 1
    return 0
def client_pid_info(client):
    """ get information about selected process (or about all) """
#    try:
    sid = get_sid(client.SID_FILE)
    pid_ls = gen_pid_ls(client)
    if pid_ls:
        pid_inf(client, sid, pid_ls)
Beispiel #3
0
def client_post_auth(client):
    """ authorization client or post request """
    sid = get_sid(client.SID_FILE)
    client.sid = int(sid)
    try:
        if os.path.exists(client.CERT_FILE):
            pass#client_post_cert(client)
        else:
            #client_post_request(client)
            print _("You do not have a certificate. Use option --gen-cert-by HOST to generate a new request or --get-cert-from HOST to get a new certificate from the server.")
            raise Exception(1)
#        print client.service.versions(sid, VERSION)
    except VerifyError, e:
        print e.value
        raise Exception(1)
def gen_pid_ls(client, pid_ls):
    """ generation list with pid for this session """
    sid = get_sid(client.SID_FILE)

    try:
        list_pid = client.service.list_pid(sid = sid)
        if list_pid[0][0] == 0:
            print _("PIDs not found for this session!")
            return 0
        else:
            for i in list_pid[0]:
                pid_ls.append(i)
    except:
        print _("Failed to get PIDs from the server")
        return 0
    return pid_ls
def client_list_pid(client):
    """ get all process id for this session """
    sid = get_sid(client.SID_FILE)

    try:
        list_pid = client.service.list_pid(sid = sid)
        if list_pid[0][0] == 0:
            print _("PIDs not found for this session!")
            return 0
        else:
            for i in list_pid[0]:
                print "pid - %d" %i
    except:
        print _("Failed to get PIDs from the server")
        return 1
    return len(list_pid[0])
def gen_pid_ls(client):
    """ generation list with pid for this session """
    sid = get_sid(client.SID_FILE)
    pid_ls = []
    try:
        list_pid = client.service.list_pid(sid = sid)
        if list_pid[0][0] == 0:
            print _("PIDs not found for this session!")
            return 0
        else:
            for i in list_pid[0]:
                pid_ls.append(i)
    except:
        print _("Error fetching the PID list from the server")
        return 0
    return pid_ls
Beispiel #7
0
def client_post_auth(client):
    """ authorization client or post request """
    sid = get_sid(client.SID_FILE)
    try:
        if os.path.exists(client.CERT_FILE):
            pass#client_post_cert(client)
        else:
            #client_post_request(client)
            print _('You do not have a certificate. Use option '
                    '--gen-cert-by HOST to generate a new certificate '
                    'or --get-cert-from HOST to get the certificate '
                    'from the server.')
            sys.exit()
        print client.service.versions(sid, VERSION)
    except VerifyError, e:
        print e.value
        sys.exit()
def client_pid_kill(client, pid):
    sid = get_sid(client.SID_FILE)

    result = client.service.pid_kill(pid, sid)
    if result == 0:
        print _("Process completed")
    elif result == 2:
        print _("Process killed")
    elif result == 3:
        print _("Process not found")
    elif result == -1:
        print _("Certificate not found on the server")
    elif result == -2:
        print _("Session not matching your certificate")
    elif result == 1:
        print _("Failed to terminate the process")
    return 0
Beispiel #9
0
def client_post_cert (client, clVars, show_info = False):
    """ send a certificate server for check """
    sid = get_sid(client.SID_FILE)
    
    lang = os.environ['LANG'][:2]
    _result_post_cert, _result_sid = client.service.init_session(sid, lang)
    result_post_cert = _result_post_cert[1].integer
    result_sid = _result_sid[1].integer

    print _("the client uses certificate %s") %client.CERT_FILE
    print  result_post_cert[0]
    if result_post_cert[0] == -4:
        print _("Certificate not found on the server")
        print _("the client uses certificate %s") %client.CERT_FILE
        print _('You can generate a new certificate using options --gen-cert-by and '\
                '--get-cert-from')
        raise Exception(3)

#    client_sid(sid, client, cert_id = results[0][0], clVars = clVars)
    if result_post_cert[0] == -3:
        print _("Certificate not sent!")
    elif result_post_cert[0] == -2:
        print _("Using the upstream certificate")
    else:
        if show_info:
            print _(" Your certifitate ID = %d") %(result_post_cert[0])
        try:
            if result_post_cert[1] == -2:
                print _("The certificate has expired")
            elif result_post_cert[1] > 0:
                if show_info:
                    print _("The certificate expires after %d days") \
                                                    %(result_post_cert[1])
        except:
            pass

    # work with sid
    fi = open(client.SID_FILE, 'w')
    sid = str(result_sid[0])
    fi.write(sid)
    fi.close()
    if show_info:
        if result_sid[1] == 1:
            print _(" New Session")
        else: print _(" Old Session")
        print _(" Your session ID = %s") %sid
def client_list_pid(client):
    """ get all process id for this session """
    sid = get_sid(client.SID_FILE)

    red = '\033[31m * \033[0m'
    green = '\033[32m * \033[0m'
    try:
        list_pid = client.service.list_pid(sid = sid)
        if list_pid[0][0] == 0:
            print red + _("PIDs not found for this session!")
            return 0
        else:
            for i in list_pid[0]:
                print green + "pid - %d" %i
    except:
        print red + _("Error fetching the PID list from the server")
        return 1
    return len(list_pid[0])
Beispiel #11
0
def client_post_cert (client):
    """ send a certificate server for check """
    sid = get_sid(client.SID_FILE)
    results = client.service.post_cert()
    
    if results[0][0] == -4:
        print _("Certificate not found in the server database!")
        sys.exit(1)
    client_sid(sid, client, cert_id = results[0][0])
    if results[0][0] == -3:
        print _("Certificate not sent!")
    else:
        print _(" Your certifitate ID = %d") %(results[0][0])
        try:
            if results[0][1] == -2:
                print _("Certificate expired")
            elif results[0][1] > 0:
                print _("The certificate expires after %d days")%(results[0][1])
        except:
            pass
Beispiel #12
0
def client_view_cert_right(client):
    cert_id = raw_input (_("Certificate ID: "))
    try:
        cert_id = int (cert_id)
    except:
        print _("Invalid certificate ID")
        return 1
    try:
        sid = get_sid(client.SID_FILE)
        if cert_id > 0:
            cert_right_inf(client, sid, cert_id)
        else:
            print _("Please enter a valid certificate ID!")
    except Exception, e:
        if e[0][0] == 403:
            print _('Permission denied')
        else: 
            print e
        #print _("Failed to get data")
        return 1
def client_pid_info(client):
    """ get information about selected process (or about all) """
    pid = raw_input ("PID: ")
    try:
        pid = int (pid)
    except:
        print _("PID error")
        return 1
    try:
        pid_ls = []
        pid_get = []
        pid_get.append(pid)
        sid = get_sid(client.SID_FILE)
        if pid > 0:
            pid_inf(client, sid, pid_get)
        elif pid == 0:
            if gen_pid_ls(client, pid_ls):
                pid_inf(client, sid, pid_ls)
    except:
        print _("Failed to get data")
        return 1
    return 0
def client_pid_kill(client):
    """ kill process on server """
    pid = raw_input (_("PID to be killed: "))
    try:
        pid = int (pid)
    except:
        print _("PID error")
        return 1        

    sid = get_sid(client.SID_FILE)

    result = client.service.pid_kill(pid, sid)
    if result == 0:
        print _(" Killed successfully!")
    elif result == 2:
        print _(" Process completed!")
    elif result == -1:
        print _(" Certificate not found in the server database!")
    elif result == -2:
        print _(" Session not matching your certificate!")
    elif result == 1:
        print _(" Failed to terminate the process!")