Esempio n. 1
0
def connect_ssh():
    global shell, ssh
    if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists(
            '/root/.ssh/id_rsa') or not os.path.exists(
                '/root/.ssh/id_rsa.pub'):
        create_rsa()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect('127.0.0.1', public.GetSSHPort())
    except:
        if public.GetSSHStatus():
            try:
                ssh.connect('localhost', public.GetSSHPort())
            except:
                create_rsa()
                return False
        import firewalls
        fw = firewalls.firewalls()
        get = common.dict_obj()
        get.status = '0'
        fw.SetSshStatus(get)
        ssh.connect('127.0.0.1', public.GetSSHPort())
        get.status = '1'
        fw.SetSshStatus(get)
    shell = ssh.invoke_shell(term='xterm', width=100, height=29)
    shell.setblocking(0)
    return True
Esempio n. 2
0
def get_input():
    data = common.dict_obj()
    post = request.form.to_dict()
    get = request.args.to_dict()
    data.args = get
    for key in get.keys():
        data[key] = str(get[key])
    for key in post.keys():
        data[key] = str(post[key])

    if not hasattr(data, 'data'): data.data = []
    return data
Esempio n. 3
0
def connect_ssh(user=None, passwd=None):
    global shell, ssh
    pkey = '/root/.ssh/id_rsa_bt'
    if not os.path.exists('/root/.ssh/authorized_keys') or not os.path.exists(
            pkey):
        create_rsa()
    try:
        if not user:
            key = paramiko.RSAKey.from_private_key_file(pkey)
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        try:
            if not user:
                ssh.connect('127.0.0.1', public.GetSSHPort(), pkey=key)
            else:
                ssh.connect('127.0.0.1',
                            public.GetSSHPort(),
                            username=user,
                            password=passwd)
        except:
            if public.GetSSHStatus():
                try:
                    if not user:
                        ssh.connect('localhost', public.GetSSHPort(), pkey=key)
                    else:
                        ssh.connect('localhost',
                                    public.GetSSHPort(),
                                    username=user,
                                    password=passwd)
                except:
                    create_rsa()
                    return False
            import firewalls
            fw = firewalls.firewalls()
            get = common.dict_obj()
            get.status = '0'
            fw.SetSshStatus(get)
            if not user:
                ssh.connect('127.0.0.1', public.GetSSHPort(), pkey=key)
            else:
                ssh.connect('127.0.0.1',
                            public.GetSSHPort(),
                            username=user,
                            password=passwd)
            get.status = '1'
            fw.SetSshStatus(get)
        shell = ssh.invoke_shell(term='xterm', width=100, height=29)
        shell.setblocking(0)
        return True
    except:
        shell = None
        return False
Esempio n. 4
0
def site_end_task():
    global oldEdate
    if not oldEdate: oldEdate = public.readFile('data/edate.pl')
    if not oldEdate: oldEdate = '0000-00-00'
    mEdate = time.strftime('%Y-%m-%d',time.localtime())
    if oldEdate == mEdate: return False
    edateSites = public.M('sites').where('edate>? AND edate<? AND (status=? OR status=?)',('0000-00-00',mEdate,1,u'正在运行')).field('id,name').select()
    import panelSite,common
    siteObject = panelSite.panelSite()
    for site in edateSites:
        get = common.dict_obj()
        get.id = site['id']
        get.name = site['name']
        siteObject.SiteStop(get)
    oldEdate = mEdate
    public.writeFile('data/edate.pl',mEdate)
Esempio n. 5
0
def get_input():
    data = common.dict_obj()
    exludes = ['blob']
    for key in request.args.keys():
        data[key] = str(request.args.get(key,''))
    try:
        for key in request.form.keys():
            if key in exludes: continue
            data[key] = str(request.form.get(key,''))
    except:
        try:
            post = request.form.to_dict()
            for key in post.keys():
                if key in exludes: continue
                data[key] = str(post[key])
        except:
            pass

    if not hasattr(data,'data'): data.data = []
    return data
Esempio n. 6
0
def connect_ssh():
    global shell, ssh
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect('127.0.0.1', public.GetSSHPort())
    except:
        if public.GetSSHStatus():
            try:
                ssh.connect('localhost', public.GetSSHPort())
            except:
                return False
        import firewalls
        fw = firewalls.firewalls()
        get = common.dict_obj()
        get.status = '0'
        fw.SetSshStatus(get)
        ssh.connect('127.0.0.1', public.GetSSHPort())
        get.status = '1'
        fw.SetSshStatus(get)
    shell = ssh.invoke_shell(term='xterm', width=100, height=29)
    shell.setblocking(0)
    return True
Esempio n. 7
0
 def connect_ssh(self):
     import paramiko
     self.ssh = paramiko.SSHClient()
     self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
     try:
         self.ssh.connect('127.0.0.1', public.GetSSHPort())
     except:
         if public.GetSSHStatus():
             try:
                 self.ssh.connect('localhost', public.GetSSHPort())
             except:
                 return False;
         import firewalls,common
         fw = firewalls.firewalls()
         get = common.dict_obj()
         get.status = '0';
         fw.SetSshStatus(get)
         self.ssh.connect('127.0.0.1', public.GetSSHPort())
         get.status = '1';
         fw.SetSshStatus(get);
     self.shell = self.ssh.invoke_shell(term='xterm', width=100, height=29)
     self.shell.setblocking(0)
     return True
Esempio n. 8
0
def get_input_data(data):
    pdata = common.dict_obj()
    for key in data.keys():
        pdata[key] = str(data[key])
    return pdata