예제 #1
0
def read_transceiver(formfactor, transceiver_pwd):
    codes = {}
    if (formfactor == 'SFP'):
        SFP_pages = ['A0L', 'A0U', 'A2U', 'A2L', 'A2U00', 'A2U01', 'A2U02']

        default_page = command_parse.exec_cmd('A2,0x7F??1')
        if ('True' not in command_parse.exec_cmd('A2,0x7F=00?!')):
            SFP_pages.remove('A2U00')
        if ('True' not in command_parse.exec_cmd('A2,0x7F=01?!')):
            SFP_pages.remove('A2U01')
        if ('True' not in command_parse.exec_cmd('A2,0x7F=02?!')):
            SFP_pages.remove('A2U02')
        for page in SFP_pages:
            codes[page] = read_page(page, default_page)
    elif (formfactor == 'QSFP' or formfactor == 'XFP'):
        XFP_pages = ['A0L', 'T00', 'T01', 'T02']

        default_page = command_parse.exec_cmd('A0,0x7F??1')
        if ('True' not in command_parse.exec_cmd('A0,0x7F=00?!')):
            SFP_pages.remove('T00')
        if ('True' not in command_parse.exec_cmd('A0,0x7F=01?!')):
            SFP_pages.remove('T01')
        if ('True' not in command_parse.exec_cmd('A0,0x7F=02?!')):
            SFP_pages.remove('T02')

        for page in XFP_pages:
            codes[page] = read_page(page, default_page)

    return codes, default_page
예제 #2
0
def check_connection():

    email = request.form.get('email')
    output_content = ""
    string = ""
    filename = "database.db"
    upload_user = 0
    if (email == '*****@*****.**'):
        upload_user = 1
    else:
        output_content = (request.cookies.get("output_content") if
                          (request.cookies.get("output_content")) else "")
        try:
            byte = command_parse.exec_cmd('A0,0x00??')
            output_content += "Connection Open...\n"
            sDatabase_File = '/home/pi/web_app/useruploads/{}'.format(filename)
            conn = sqlite3.connect(sDatabase_File)
            c = conn.cursor()
            c.execute('SELECT firstbyte from Configuration')
            c.execute(
                "SELECT options from Configuration WHERE firstbyte = '{}'".
                format(byte))
            lst = c.fetchall()
            string = ""
            for i in lst:
                string += i[0] + "\n"
        except Exception, e:
            output_content += "Connection Failed...\n"
예제 #3
0
def pi_bulk_input():
    command = request.form.get('command_select')
    commands = request.form.get('commands')
    return_lst = []
    output_content = (request.cookies.get("output_content") if
                      (request.cookies.get("output_content")) else "")
    if (len(commands) > 0):
        if ('\r' in commands):
            cmds = commands.split('\r')
        else:
            cmds = commands.split('\n')
        for cmd in cmds:
            output = command_parse.exec_cmd(cmd)
            return_lst.append([cmd, output])

        output_content += get_list_string(return_lst)

    else:
        if (command == 'SFP/SFP+/SFP28'):
            read_codes, default_page = read_code('SFP')
            SFP_pages = ['A0L', 'A0U', 'A2L', 'A2U', 'A2U00', 'A2U01', 'A2U02']
            for key in SFP_pages:
                if (key in read_codes.keys()):
                    if (key == 'A0L'):
                        main_page = True
                    else:
                        main_page = False
                    with open('/home/pi/web_app/tmp1.out', 'a') as f:
                        f.write('\n' + key + '\n')
                    run_P17_011R2('/home/pi/web_app/tmp1.out', read_codes[key],
                                  main_page)
            command_parse.exec_cmd('A2,0x7F=' + default_page)
            output_content += get_printable_dict(read_codes)
        elif ('QSFP' in command or 'XFP' in command):
            #QSFP and XFP have the same read pattern
            read_codes = read_code('XFP')
            XFP_pages = ['A0L', 'T00', 'T01', 'T02']
            for key in XFP_pages:
                if (key in read_codes.keys()):
                    if (command == 'QSFP' and key == 'T00'):
                        main_page = True
                    elif (command == 'XFP' and key == 'T01'):
                        main_page = True
                    else:
                        main_page = False
                    with open('/home/pi/web_app/tmp1.out', 'a') as f:
                        f.write('\n' + key + '\n')
                    run_P17_011R2('/home/pi/web_app/tmp1.out', read_codes[key],
                                  main_page)
            command_parse.exec_cmd('A2,0x7F=' + default_page)
            output_content += get_printable_dict(read_codes)
        elif ('T00' in command or 'T01' in command or 'T02' in command):
            default_page = command_parse.exec_cmd('A0,0x7F??')
            if ('T00' in command):
                command_parse.exec_cmd('A0,0x7F=00')
                output = command_parse.exec_cmd('A0,0x80??128')
                return_lst.append([
                    'T00',
                ])
                with open('/home/pi/web_app/tmp1.out', 'a') as f:
                    f.write('\n' + 'T00' + '\n')
                run_P17_011R2('/home/pi/web_app/tmp1.out', output, True)
            elif ('T01' in command):
                command_parse.exec_cmd('A0,0x7F=01')
                return_lst.append(
                    ['T01', command_parse.exec_cmd('A0,0x80??128')])
            elif ('T02' in command):
                command_parse.exec_cmd('A0,0x7F=02')
                return_lst.append(
                    ['T02', command_parse.exec_cmd('A0,0x80??128')])
            output_content += get_list_string(return_lst)
            command_parse.exec_cmd('A0,0x7F=' + default_page)
        else:
            cmd = get_cmd(command)
            output = command_parse.exec_cmd(cmd)
            return_lst.append([cmd, output])
            with open('/home/pi/web_app/tmp1.out', 'a') as f:
                f.write('\n' + command + '\n')
            if ('=' not in cmd and '?' in cmd):                \
                                run_P17_011R2('/home/pi/web_app/tmp1.out', output, command=='A0L')
            output_content += get_list_string(return_lst)
    resp = redirect(
        url_for('pi_blueprint.pro_reader', output_content=output_content))
    resp.set_cookie("Output Content", output_content)
    return resp
예제 #4
0
def write_to_pi(new_codes_hex=None, default_page=None, form_factor=None):

    command_parse.exec_cmd('A2,0x7F=' + default_page)
    write_response = True
    return_dict = {}
    for new_code in new_codes_hex.keys():
        if (new_code == "A0L"):
            output = command_parse.exec_cmd("A0,0x00=#" +
                                            new_codes_hex["A0L"].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A0U"):
            output = command_parse.exec_cmd("A0,0x80=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A2L"):
            output = command_parse.exec_cmd("A2,0x00=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A2U"):
            output = command_parse.exec_cmd("A2,0x80=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A2U00" and "00" not in default_page):
            command_parse.exec_cmd('A2,0x7F=00')
            output = command_parse.exec_cmd("A2,0x80=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A2U01" and "01" not in default_page):
            command_parse.exec_cmd('A2,0x7F=01')
            output = command_parse.exec_cmd("A2,0x80=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")
        elif (new_code == "A2U02" and "02" not in default_page):
            command_parse.exec_cmd('A2,0x7F=02')
            output = command_parse.exec_cmd("A2,0x80=#" +
                                            new_codes_hex[new_code].upper())
            if ('False' in output):
                write_response = False
            return_dict[new_code] = output.replace('False',
                                                   "").replace('True', "")

        return write_response, return_dict
예제 #5
0
def read_page(page, default_page):
    #commands = {'A0L' : 'A0,0x00??128', 'A0U' : 'A0,0x80??128'
    #, 'A2L', 'A2U00', 'A2U01', 'A2U02', 'T00', 'T01', 'T02'}

    if page == 'A0L':
        return command_parse.exec_cmd('A0,0x00??128')
        #return client.send_cmd(ssh, 'A0,0x00??128')
    elif page == 'A0U':
        return command_parse.exec_cmd('A0,0x80??128')
        #return client.send_cmd(ssh, 'A0,0x80??128')
    elif page == 'A2L':
        return command_parse.exec_cmd('A2,0x00??128')
        #return client.send_cmd(ssh, 'A2,0x00??128')
    elif page == 'A2U00':
        command_parse.exec_cmd('A2,0x7F=00')
        return command_parse.exec_cmd('A2,0x80??128')
    elif page == 'A2U01':
        command_parse.exec_cmd('A2,0x7F=01')
        return command_parse.exec_cmd('A2,0x80??128')
    elif page == 'A2U02':
        command_parse.exec_cmd('A2,0x7F=02')
        return command_parse.exec_cmd('A2,0x80??128')
    elif page == 'A2U':
        command_parse.exec_cmd('A2,0x7F=' + default_page)
        return command_parse.exec_cmd('A2,0x80??128')
    elif page == 'T00':
        command_parse.exec_cmd('A0,0x7F=00')
        return command_parse.exec_cmd('A0,0x80??128')
    elif page == 'T01':
        command_parse.exec_cmd('A0,0x7F=01')
        return command_parse.exec_cmd('A0,0x80??128')
    elif page == 'T02':
        command_parse.exec_cmd('A0,0x7F=02')
        return command_parse.exec_cmd('A0,0x80??128')
    else:
        return "Unfound page error"