Example #1
0
    def mvFiles(self, ssh_name, ssh_passwd, confirm):
        localpath = [license_path, licenseLib_path]
        remotepath = '/home/%s/' % ssh_name
        if ssh_name == 'root':
            remotepath = '/root/'
        try:
            ssh = SSHConnection(parse_ip(self.input_ip), 22, ssh_name, ssh_passwd)
        except:
            logger.error('未知错误')
            logger.info('ssh_name:' + ssh_name)
            logger.info('ssh_passwd:' + ssh_passwd)
            logger.info('host:' +parse_ip(self.input_ip))
            sys.exit(1)
        for i in localpath:
            logger.info("-----正在上传【%s】至Flexsafe....-----" % i)
            logger.debug('remotepath:' + remotepath + str(i).split('/')[-1])
            ssh.put(i, remotepath + str(i).split('/')[-1])
        ssh.exec_command('cd /home/%s/;sudo mv license libLicenseConfig.so /usr/lib/jni/' % ssh_name, ssh_passwd)

        if confirm == '0' or confirm == '':
            if ssh_name != 'root':
                ls = 'sudo ls /etc/init.d/ | grep jetty'
                jetty_v = ssh.exec_command(ls, ssh_passwd).decode('utf-8').split('\r\n')[2]
                logger.info("-----正在重启Jetty....-----")
                logger.debug('jetty_v:' + jetty_v)
                ssh.exec_command('sudo service %s restart' % jetty_v, ssh_passwd)
            else:
                try:
                    ssh.exec_command('service jettydr restart', ssh_passwd)
                    ssh.exec_command('service jettyd restart', ssh_passwd)
                except:
                    logger.error('重启Jetty失败,请手动重启!')
                    os._exit(0)
        if confirm == '1':
            ssh.exec_command('sudo reboot', ssh_passwd)

        # 检查Jetty状态
        http_url = 'http://' + parse_ip(self.input_ip)
        if ':' not in self.input_ip:
            http_url = 'http://' + parse_ip(self.input_ip) + ':8080'
        check_jetty(http_url, 200)
Example #2
0
legal_user = []
print('''
注意:

    1.尽量避免多个用户同时使用本程序,否则可能会导致创建用户失败或其他错误!
    2.建议一次性创建完所有用户,然后根据用户序号分配给相关测试人员。
    3.用户创建完成后,会自动登录,以产生【个人文件夹】,所以可以直接登录Windows Client。
    4.注意输出日志,若有错误,及时反馈。
    5.默认创建用户的密码为【123qwe】,空间大小为2GB。
    6.【Ctrl+u】撤销输入,而不必【Ctrl+c】中断程序。
    7.输入FlexSafe Server后两段IP地址,按回车继续^_^


''')
input_ip = input('请输入FlexSafe Server IP:172.16.')
host = parse_ip(input_ip)
logger.info("服务器IP:【%s】" % host)

flexsafe_version = get_flexsafe_version(host)
authorization = flexsafe_login(host)[0]
if authorization == None:
    logger.error("获取认证失败,请检查Flexsafe服务是否正常!")
    sys.exit(1)
s = session()
header = {
    "Connection": "keep-alive",
    "Accept": "application/json, text/plain, */*",
    "Authorization": '',
    "User-Agent":
    "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25",
    "Content-Type": "application/json;charset=UTF-8",
Example #3
0
 def __init__(self):
     self.input_ip = input("请输入Flexsafe Server IP:172.16.")
     self.base_url = ' http://' + parse_ip(self.input_ip)
     self.apply_timestamp = None
     self.keygen = None
     self.files = None
Example #4
0
if __name__ == '__main__':
    logger.remove()
    logger.add(sys.stdout, level="INFO")
    print('''
    执行步骤:

        1.使用默认的SSH账号【cfservice】和密码【cfzoom2016】尝试连接FlexServer,若失败,提示用户进行输入;
        2.下载FlexServer的KeyGen文件;
        3.通过KeyGen查找License Server上MySQL的license记录,若存在,则进行删除;
        4.读取License配置文件【conf.cfg】,请求License Server将license文件发送至邮箱【[email protected]】;
        5.读取LibLicense配置文件【conf.cfg】,请求并获取到【libLicenseConfig.so】文件;
        6.模拟登陆邮箱【[email protected]】,或取到附件【license】;
        7.SSH登陆FlexServer,将license、libLicenseConfig.so移动至路径【/usr/lib/jni】;
        8.提供后续操作选项:重启Jetty、重启服务器;


    ''')
    f = FlexSafe()
    confirm = input('''请输入操作选项(默认为0):
    0---->重启Jetty;
    1---->重启服务器;
    ''')
    ssh_account = ssh_login(parse_ip(f.input_ip))
    f.get_keygen_text()
    f.getLibLicense()
    f.clear_license()
    f.applyLicense()
    f.downloadLicenseFromMail()
    f.mvFiles(ssh_account[0], ssh_account[1], confirm)