Пример #1
0
    def _kinit(self, user_principal, password):
        cc_armor_name = "k5_armor_%s" % (user_principal.principal,)
        cc_armor_path = os.path.join(tempfile.gettempdir(), cc_armor_name)

        # get an armor ccache
        exec_cmd([self.paths.kinit, '-kt', self.server_principal.keytab, self.server_principal.principal], environment={'KRB5CCNAME': cc_armor_path})

        if user_principal.ccache is None:
            cc_user_name = "k5_user_%s" % (user_principal.principal,)
            cc_user_path = os.path.join(tempfile.gettempdir(), cc_user_name)
            user_principal.ccache = cc_user_path

        (stdout, stderr, returncode) = exec_cmd(
            [self.paths.kinit, user_principal.principal, '-T', cc_armor_path],
            environment={'KRB5CCNAME': user_principal.ccache, 'LC_ALL': 'C'},
            stdin=password, raiseonerr=False
        )

        exec_cmd([self.paths.kdestroy, '-A', '-c', cc_armor_path], environment={'KRB5CCNAME': cc_armor_path}, raiseonerr=False)

        if returncode != 0:
            se = stderr.strip()
            if se == 'kinit: Password incorrect while getting initial credentials':
                raise PasswordInvalidException()
            elif se == 'kinit: Cannot read password while getting initial credentials':
                raise PasswordExpiredException()
            elif se == 'kinit: Clients credentials have been revoked while getting initial credentials':
                raise AccountLockedException()
            raise LoginException("Unable to login - got '{}' from kinit".format(se))

        return user_principal
Пример #2
0
def delete_ftp(name):
  r = mysql.delete_mysql_ftpuser(name)
  if r:
    filename = '/etc/lamp/ftp_users/%s' % r.username

    utils.exec_cmd('rm -rf %s' % filename)
    utils.exec_cmd('service vsftpd reload')
Пример #3
0
def disable_site(domain):
	filename = utils.get_account_name(domain)
	file1 = '%s/sites-available/%s' % (config['apache_etc'], filename)
	file2 = '%s/sites-enabled/%s' % (config['apache_etc'], filename)

	if not os.path.isfile(file1):
		logging.info('apache conf file: %s no exists!')
		return

	if not os.path.isfile(file2):
		logging.info('this site is not enabled!')
		return

	utils.exec_cmd('rm -rf %s' % (file2))
	utils.exec_cmd('service %s reload' % config['apache'])
Пример #4
0
def _xml_exec(cmd):
    cmd += ["--xml"]
    rc, out, err = exec_cmd(cmd)
    if rc == 0:
        return out
    else:
        raise GlusterVolumeInfoFailed(err)
Пример #5
0
def stat_version(**kwargs):
    versions = {}

    for k, v in kwargs.items():
        t, args = v['type'], v['args']
        if t == "file":
            if osp.exists(args):
                versions[k] = open(args).read().strip()
            else:
                versions[k] = "null"
        elif t == 'git':
            versions[k]= gitversion(args,
                                    local=v.get('local', 'HEAD'),
                                    remote=v.get('remote', None))
        elif t in ("dpkg", "exec", "svn"):
            if t == "exec":
                cmd = args
            elif t == "svn":
                cmd = ("svnversion", "-c", args)
            elif t == "dpkg":
                cmd = ("dpkg-query", "-W", "-f=${Version}", args)
            ret, out = exec_cmd(cmd)
            versions[k] = out.strip()
        else:
            versions[k] = "TYPE `%s' UNKNOWN" % t

    return versions
Пример #6
0
def main():
	logging.basicConfig(filename='/tmp/lampsetup.log', level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', filemode='w+')
	console = logging.StreamHandler()
	console.setLevel(logging.INFO)
	#console.setLevel(logging.DEBUG)
	console.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
	logging.getLogger('').addHandler(console)
	logging.info('LAMP Setup script started!\nIf an error has occurred, Please seed log file /tmp/lampsetup.log to me.\n')

	#start check
	if os.geteuid() != 0:
		logging.info('This program must be run as root, Exiting...')
		exit()
	if utils.exec_cmd('ping github.com -c 2') == 2:
		logging.info('DNS Error Has Occured, Exiting...')
		exit()


	current_os = platform.dist()[0]

	if current_os.find('Ubuntu') != -1 or current_os.find('Debian') != -1:
		go_debian()
	elif current_os.find('centos') != -1:
		go_centos()
	else:
		logging.info('System is unknown, Exiting...')
		exit()

	logging.info('LAMP Setup script finished!')
Пример #7
0
def save_alias(site, alias):
	filename = utils.get_account_name(site.domain)

	conf_alias = 'ServerAlias %s#Alias'
	for a in alias:
		conf_alias = conf_alias % (a + ' %s')

	conf_alias = conf_alias % ''

	utils.change_conf('%s/sites-available/%s' % (config['apache_etc'], filename),
		[
			{'flags':'re.M','old':r"ServerAlias.*?$",'new':conf_alias}
		])

	utils.exec_cmd('service %s reload' % config['apache'])

	mysql.update_site_alias(site.id, alias)
Пример #8
0
def delete_site(args):
	site_root = '%s/%s' % (config['wwwroot'], args['username'])

	logging.debug('delete site, args: %s', args['domain'])
	site = mysql.delete_site(args['domain'])

	if site != -1:
		if utils.get_yseorno('Do you want backup site files?'):
			import datetime
			dt = datetime.datetime.now()
			# backup all site files to root dir
			utils.exec_cmd('tar czf /root/lamp_bak/%s-%s.tar.gz -C %s %s' %(args['domain'], dt.strftime('%Y-%m-%d_%H:%M'), config['wwwroot'], args['username']))

		utils.exec_cmd('rm -rf %s' % site_root)
		mysql.delete_mysql_bysite(site.id)

		import ftp
		ftp.delete_ftp_bysite(site.id)
def get_network_info():
    network = {}
    cmd = ifconfig_path
    #output = exec_cmd(IFCONFIG_PATH)
    #return ifconfig_parser(output)
    ifcfg = ifconfig_parser(exec_cmd(ifconfig_path))
    for i in ifcfg:
        network[i.pop('name')] = i

    return network
Пример #10
0
def gitversion(git_dir=None, local='HEAD', remote=None):
    git_option = ''
    if git_dir:
        git_option = "--git-dir={0}/.git --work-tree={0}".format(git_dir)

    outa = []

    cmd = shlex.split("git {0} rev-parse --short HEAD".format(git_option))
    ret, out =  exec_cmd(cmd)
    if ret != 0:
        return ret, ' '.join(outa)
    outa.append(out.strip())

    if not remote:
        get_head_name_cmd = shlex.split("git {0} rev-parse --abbrev-ref HEAD"
                                        .format(git_option))
        head_name = exec_cmd(get_head_name_cmd)[1].strip()
        # if head_name is HEAD, it's in detached HEAD state
        # do not check if in this state
        if head_name != 'HEAD':
            remote = "origin/{0}".format(head_name)
    if remote:
        cmd = shlex.split("git {0} rev-list --left-right --count {1}...{2}"
                          .format(git_option, remote, local))
        ret, out =  exec_cmd(cmd)
        if ret != 0:
            return ret, ' '.join(outa)
        behind, ahead = [int(h) for h in out.strip().split('\t')]
        if ahead:
            outa.append('a{0}'.format(ahead))
        if behind:
            outa.append('b{0}'.format(behind))

    cmd = shlex.split('git {0} status --porcelain'.format(git_option))
    ret, out =  exec_cmd(cmd)
    if ret != 0:
        return ret, ' '.join(outa)
    if out: outa.append('*')

    return '-'.join(outa)
Пример #11
0
def finish_install(mysql_root_pass, ftp_pass, cmd=''):


	if cmd != '':
		utils.exec_cmd('screen -dmS sys-update %s' % (cmd))

	finish_text = '''
-------------------------------------------------------------------------------------------------------------------
 __   __ ___ _______ _______ ___ _______ __    _   _______ _______ __   __ _______ ___     _______ _______ _______
|  |_|  |   |       |       |   |       |  |  | | |       |       |  |_|  |       |   |   |       |       |       |
|       |   |  _____|  _____|   |   _   |   |_| | |       |   _   |       |    _  |   |   |    ___|_     _|    ___|
|       |   | |_____| |_____|   |  | |  |       | |       |  | |  |       |   |_| |   |   |   |___  |   | |   |___
|       |   |_____  |_____  |   |  |_|  |  _    | |      _|  |_|  |       |    ___|   |___|    ___| |   | |    ___|
| ||_|| |   |_____| |_____| |   |       | | |   | |     |_|       | ||_|| |   |   |       |   |___  |   | |   |___
|_|   |_|___|_______|_______|___|_______|_|  |__| |_______|_______|_|   |_|___|   |_______|_______| |___| |_______|

-------------------------------------------------------------------------------------------------------------------

Important!!!
By default system will run update progress, Please don't reboot or shutdown this server in 30 minutes.


Server information

WEB&FTP root: /var/www (Make sure upload you site files to your /public_html directory)
MySQL root pass: %s
Main FTP username: ftpuser, pass: %s
phpMyAdmin url: http://domain/phpmyadmin


More information: https://github.com/Abriko/pyLAMP

Now you can press key "q" exit the installation.
	''' % (mysql_root_pass, ftp_pass)

	f = open('/tmp/lamp/finish_msg', 'w+')
	f.write(finish_text)
	f.close()
	os.system('cat /tmp/lamp/finish_msg | less')
	utils.exec_cmd('rm -rf /tmp/lamp')
Пример #12
0
    def _do_exec(self, args=None):
        # Setup extra env
        self._setup_extra_env()
        cmd_args = []

        # jobs argument
        cmd_args.append(dragon.OPTIONS.jobs.make_arg)

        # Verbose
        if dragon.OPTIONS.verbose:
            cmd_args.append("V=1")

        # Get arguments from task if none provided
        if not args and self.defargs:
            cmd_args.extend(self.defargs)

        # Add given arguments
        if args:
            cmd_args.extend(args)

        # Execute command
        utils.exec_cmd("%s/scripts/alchemake %s" %
                (dragon.ALCHEMY_HOME, " ".join(cmd_args)),
                extra_env=self.extra_env)
Пример #13
0
def stat_varnish(**kwargs):
    ret, vstat = exec_cmd(VARNISHSTAT)
    vstats = json.loads(vstat)
    for k, v in vstats.items():
        if k == 'timestamp':
            vstats.pop(k)
        else:
            if isinstance(v, dict):
                value = v.get('value')
            if value is not None:
                vstats[k] = value
    if 'n_wrk' in vstats and 'n_sess' in vstats:
        vstats['n_wrk_idle'] = vstats['n_wrk'] - vstats['n_sess']
        vstats.pop('n_sess')

    return vstats
Пример #14
0
def init_db(mysql_root_pass):
	import db
	import platform

	logging.info('download phpmyadmin and config')
	utils.exec_cmd('axel -q -n 10 -o /tmp/lamp/phpmyadmin.tar.xz http://softlayer-ams.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.1.8/phpMyAdmin-4.1.8-all-languages.tar.xz')
	utils.exec_cmd('tar xf /tmp/lamp/phpmyadmin.tar.xz -C /var/www')
	utils.exec_cmd('mv /var/www/phpMyAdmin* /var/www/phpmyadmin')


	data = db.Connection(host='localhost',database='mysql',user='******',password=mysql_root_pass)

	# Support centos change all root pass
	data.execute("SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('%s');" % (mysql_root_pass))
	data.execute("SET PASSWORD FOR 'root'@'%s' = PASSWORD('%s');" % (platform.uname()[1], mysql_root_pass))

	# Create lamp&phpmyadmin control user
	lamp_controluser_pass = utils.gen_random_str()
	logging.debug('generate control user password : %s', lamp_controluser_pass)
	data.execute('CREATE USER "lamp"@"localhost" IDENTIFIED BY \"%s\";CREATE DATABASE IF NOT EXISTS `lamp`;GRANT ALL PRIVILEGES ON *.* TO "lamp"@"localhost" WITH GRANT OPTION;' % (lamp_controluser_pass))


	# Clean up default users
	data.execute('delete from mysql.user where user="";')
	data.execute("DROP USER ''@'%%';")

	#data.execute('delete from mysql.user where user = "******" and host != "localhost";flush privileges')
	data.execute("flush privileges;")
	del data

	utils.exec_cmd('mysql -uroot -p%s < %s/files/create_tables.sql' % (mysql_root_pass, os.path.dirname(os.path.abspath(__file__))))
	utils.cp('<APPROOT>/files/phpmyadmin_config.inc.php', '/var/www/phpmyadmin/config.inc.php')

	utils.change_conf('/var/www/phpmyadmin/config.inc.php',
		[
			{'old':'lamp_pass_value','new':lamp_controluser_pass},
			{'old':'blowfish_secret_value','new':utils.gen_random_str(20)}
		]
	)
	return lamp_controluser_pass
Пример #15
0
def create_ftp(args):
  config = utils.load_config()
  # using user name as ftp path or custom ftp path
  if not args.get('path') or args.get('path') == 'username':
    args['path'] = '%s/%s' % (config['ftproot'], args['username'])
  else:
    if not utils.chekc_path(args['path']):
      logging.info('exiting...')
      return

  # add ftp user mysql record
  ftp_pass = mysql.create_mysql_ftpuser(args)
  if ftp_pass == None:
    logging.info('create ftp account failed. exiting...')
    return

  utils.change_conf('<APPROOT>/files/vsftpd_user_template', [{'old':'<path>','new':args['path']}], '/etc/lamp/ftp_users/%s' % (args['username']))

  utils.exec_cmd('mkdir -p %s' % (args['path']))
  utils.exec_cmd('chown %s -R %s' % (config['root_own'], args['path']))

  utils.exec_cmd('service vsftpd reload')
  return ftp_pass
Пример #16
0
 def install(self):
     cmd = 'apt install -y targetcli-fb'
     utils.exec_cmd(cmd, self.conn)
Пример #17
0
 def set_auto_enable_tpgt(self):
     cmd = "targetcli set global auto_enable_tpgt=true"
     utils.exec_cmd(cmd, self.conn)
Пример #18
0
def main():

     progname = 'plot_shapiro_resids.py'
     args = get_opt(progname)


     # First, read in par file:
     f_par = open(args.parfile, 'r')
     par_data = [par_line.split() for par_line in f_par.readlines()]
     f_par.close()


     if(args.tempo2):
          resid_file = tempo2_resid_file
          infofile = None
     else:
          resid_file = tempo_resid_file
          infofile = tempo_info_file

     # Will run tempo/tempo2 3 times on best fit profile:
     
     # (1) Full solution with par file as is:
     if(args.tempo2):
          print 'par file = ', args.parfile
          tempo_command = 'tempo2 -output print_resids -f '+args.parfile+' '+\
                          args.timfile+' -file resid_output_format.dat '+ \
                          '-outfile '+tempo2_resid_file
          print 'tempo_command: ', tempo_command
          cmd_out = exec_cmd(tempo_command)
          print cmd_out
     else:
          tempo_command = 'tempo -f '+args.parfile+' '+args.timfile
          cmd_out = exec_cmd(tempo_command)
          exec_cmd('extract')
     # Read in residuals
     resid_data_allfit = read_resid(resid_file, 
                                    tempo2=args.tempo2, 
                                    info_file=infofile, 
                                    info_flag=args.infoflag)
     if(args.tempo2):
          if(args.info==None):
               resid_data_allfit['info']=None
               resid_data_allfit['info_val']=None
               resid_data_allfit['info_instr']=None
          elif(args.info==[]): # gave flag but no arguments
               args.info = resid_data_allfit['info_val']


     # (2) Get rid of SINI and M2 lines and fit everything else
     # Check as we go that SINI and M2 are in file
     temp_par_file = 'temp.par'
     f_temp_par = open(temp_par_file, 'w')
     for par_line in par_data:
          if((par_line[0] != 'SINI') & (par_line[0] != 'M2')):
               f_temp_par.write(' '.join(par_line)+'\n')
     f_temp_par.close()

     if(args.tempo2):
          tempo_command = 'tempo2 -output print_resids -f '+temp_par_file+' '+\
                          args.timfile+' -file resid_output_format.dat '+ \
                          '-outfile '+tempo2_resid_file
          cmd_out = exec_cmd(tempo_command)
     else:
          tempo_command = 'tempo -f '+temp_par_file+' '+args.timfile
          cmd_out = exec_cmd(tempo_command)
          exec_cmd('extract')
     # Read in residuals
     resid_data_orbfit = read_resid(resid_file, 
                                    tempo2=args.tempo2, 
                                    info_file=infofile, 
                                    info_flag=args.infoflag)
     if(args.tempo2):
          if(args.info==None):
               resid_data_orbfit['info']=None
               resid_data_orbfit['info_val']=None
               resid_data_orbfit['info_instr']=None
          elif(args.info==[]): # gave flag but no arguments
               args.info = resid_data_orbfit['info_val']
   

     # (3) Sam as (2), but turn off all fitting
     f_temp_par = open(temp_par_file, 'w')
     for par_line in par_data:
          if(len(par_line) > 2):
               if(par_line[2]=='1'):
                    par_line[2]='0'               
               if(par_line[0]=='JUMP'):
                    if(par_line[4]=='1'):
                         par_line[4]='0'
          if((par_line[0] != 'SINI') & (par_line[0] != 'M2')):
               f_temp_par.write(' '.join(par_line)+'\n')
     f_temp_par.close()
    
     if(args.tempo2):
          tempo_command = 'tempo2 -output print_resids -f '+temp_par_file+' '+ \
                          args.timfile+' -file resid_output_format.dat '+ \
                          '-outfile '+tempo2_resid_file
          exec_cmd(tempo_command)
     else:
          tempo_command = 'tempo -f '+temp_par_file+' '+args.timfile
          cmd_out = exec_cmd(tempo_command)
          exec_cmd('extract')
     # Read in residuals
     resid_data_nofit = read_resid(resid_file, 
                                   tempo2=args.tempo2, 
                                   info_file=infofile, 
                                   info_flag=args.infoflag)
     if(args.tempo2):
          if(args.info==None):
               resid_data_nofit['info']=None
               resid_data_nofit['info_val']=None
               resid_data_nofit['info_instr']=None
          elif(args.info==[]): # gave flag but no arguments
               args.info = resid_data_nofit['info_val']
     

     


# First, read in residuals data file, and assign each column to a separate
# numpy array     
#     print res_data['mjd']

#     if (len(argv) > 2):   # meaning 2nd argument is the desired output plot file name
#          plot_file = argv[2]
#     else:

     print "OUTFILE = ", args.outfile
     if(args.outfile == None):
          fig_size = (16, 18)
     else:
          fig_size = (14, 15)
          plot_file = args.outfile


               
     resid_data_list = [resid_data_allfit, resid_data_orbfit, resid_data_nofit]
     # resid_data_list = resid_data_allfit

     print 'xlim = ', args.xlim
     print 'ylim = ', args.ylim
     plot_resid(resid_data_list, info_plot=args.info, binsize=args.binsize,
                canvassize=fig_size, symsize=2.0,
                xunits='orbphase', yunits=args.yunits, 
                xticks=[True, False, False],
                xlabel=[True, False, False],
                ylabel=[False, True, False],
                xlim=args.xlim, ylim=args.ylim, gridlines=[0.],
                axislabelsize=32, ticklabelsize=32)

     if(args.outfile):
          plt.savefig(plot_file)
     else:
          plt.show()
Пример #19
0
def gen_report(addhtml=True, addtxt=False, compress=False):
    # Process step
    logging.info("Police: process")
    utils.exec_cmd("%s --infile %s --outfile %s %s" % (
            os.path.join(dragon.POLICE_HOME, "police-process.py"),
            dragon.POLICE_SPY_LOG,
            dragon.POLICE_PROCESS_LOG,
            "-v" if dragon.OPTIONS.verbose else ""))

    # Report step
    logging.info("Police: report")
    utils.exec_cmd("%s --infile %s --outdir %s --rootdir %s --builddir %s "
            "--finaldir %s --md5 --cmakepatch %s %s" % (
            os.path.join(dragon.POLICE_HOME, "police-report.py"),
            dragon.POLICE_PROCESS_LOG,
            dragon.POLICE_OUT_DIR,
            dragon.WORKSPACE_DIR,
            dragon.OUT_DIR,
            dragon.FINAL_DIR,
            "-v" if dragon.OPTIONS.verbose else "",
            " ".join([("--xml-license %s" % xml) for xml in dragon.POLICE_XML_LICENSES])))

    # Remove existing police files
    police_final_dir = os.path.join(dragon.FINAL_DIR, dragon.DEPLOY_DIR, "share", "police")
    utils.exec_cmd("rm -rf %s" % police_final_dir)
    utils.makedirs(police_final_dir)

    # Add files
    if addhtml:
        utils.exec_cmd("cp -af %s %s" % (
                os.path.join(dragon.POLICE_OUT_DIR, "police-notice.html"),
                police_final_dir))
        if compress:
            utils.exec_cmd("gzip %s" %
                    os.path.join(police_final_dir, "police-notice.html"))
    if addtxt:
        utils.exec_cmd("cp -af %s %s" % (
                os.path.join(dragon.POLICE_OUT_DIR, "police-notice.txt"),
                police_final_dir))
        if compress:
            utils.exec_cmd("gzip %s" %
                    os.path.join(police_final_dir, "police-notice.txt"))
Пример #20
0
    }

    try:
        raid_info = []
        raid_status = []
        try:
            k_dev = None
            opts, args = getopt.getopt(sys.argv[1:], 'd:')
            for opt, arg in opts:
                if opt in ('-d'):
                    if not dev_dict.get(arg):
                        raise Exception('Unsupported device {0}'.format(arg))
                    k_dev = arg
            for v in dev_dict[k_dev]:
                cmd = v['cmd']
                ret, output = exec_cmd(cmd)
                raid_info.append(output)
                result = {v['ok']: re.findall(v['rule'], output, re.I)}
                raid_status.append(result)

        except getopt.error, e:
            raid_info.append(traceback.format_exc())
        except:
            raid_info.append(traceback.format_exc())

        raid_ok = False
        if raid_status:
            raid_ok = True
            for d in raid_status:
                for k, v in d.items():
                    if not (d and all(i == k for i in v)):
Пример #21
0
 def set_ip(self, device, ip, gateway, netmask=24):
     connection_name = 'vtel_' + device
     cmd = f"nmcli connection add con-name {connection_name} type ethernet ifname {device} ipv4.addresses {ip}/{netmask} ipv4.gateway {gateway} ipv4.method manual"
     utils.exec_cmd(cmd, self.conn)
Пример #22
0
 def restart_corosync(self):
     cmd = 'systemctl restart corosync'
     utils.exec_cmd(cmd, self.conn)
Пример #23
0
    def check_scp_sftp(self):
        """ This method checks if the user is trying to SCP a file onto the    \
        server. If this is the case, it checks if the user is allowed to use   \
        SCP or not, and    acts as requested. : )
        """
        if self.conf.has_key('ssh'):
            if os.environ.has_key('SSH_CLIENT')                                \
                                        and not os.environ.has_key('SSH_TTY'):

                # check if sftp is requested and allowed
                if 'sftp-server' in self.conf['ssh']:
                    if self.conf['sftp'] is 1:
                        self.log.error('SFTP connect')
                        exec_cmd(self.conf['ssh'])
                        self.log.error('SFTP disconnect')
                        sys.exit(0)
                    else:
                        self.log.error('*** forbidden SFTP connection')
                        sys.exit(0)

                # initialise cli session
                from lshell.shellcmd import ShellCmd
                cli = ShellCmd(self.conf, None, None, None, None,              \
                                                            self.conf['ssh'])
                if cli.check_path(self.conf['ssh'], None, ssh=1) == 1:
                    self.ssh_warn('path over SSH', self.conf['ssh'])

                # check if scp is requested and allowed
                if self.conf['ssh'].startswith('scp '):
                    if self.conf['scp'] is 1 or 'scp' in self.conf['overssh']: 
                        if ' -f ' in self.conf['ssh']:
                            # case scp download is allowed
                            if self.conf['scp_download']:
                                self.log.error('SCP: GET "%s"' \
                                                            % self.conf['ssh'])
                            # case scp download is forbidden
                            else:
                                self.log.error('SCP: download forbidden: "%s"' \
                                                            % self.conf['ssh'])
                                sys.exit(0)
                        elif ' -t ' in self.conf['ssh']:
                            # case scp upload is allowed
                            if self.conf['scp_upload']:
                                if self.conf.has_key('scpforce'):
                                    cmdsplit = self.conf['ssh'].split(' ')
                                    scppath = os.path.realpath(cmdsplit[-1])
                                    forcedpath = os.path.realpath(self.conf
                                                                   ['scpforce'])
                                    if scppath != forcedpath:
                                        self.log.error('SCP: forced SCP '      \
                                                       + 'directory: %s'       \
                                                                    %scppath)
                                        cmdsplit.pop(-1)
                                        cmdsplit.append(forcedpath)
                                        self.conf['ssh'] = string.join(cmdsplit)
                                self.log.error('SCP: PUT "%s"'                 \
                                                        %self.conf['ssh'])
                            # case scp upload is forbidden
                            else:
                                self.log.error('SCP: upload forbidden: "%s"'   \
                                                            % self.conf['ssh']) 
                                sys.exit(0)
                        exec_cmd(self.conf['ssh'])
                        self.log.error('SCP disconnect')
                        sys.exit(0)
                    else:
                        self.ssh_warn('SCP connection', self.conf['ssh'], 'scp')

                # check if command is in allowed overssh commands
                elif self.conf['ssh']:
                    # replace aliases
                    self.conf['ssh'] = get_aliases(self.conf['ssh'],           \
                                                         self.conf['aliases'])
                    # if command is not "secure", exit
                    if cli.check_secure(self.conf['ssh'], strict=1, ssh=1):
                        self.ssh_warn('char/command over SSH', self.conf['ssh'])
                    # else
                    self.log.error('Over SSH: "%s"' %self.conf['ssh'])
                    # if command is "help"
                    if self.conf['ssh'] == "help":
                        cli.do_help(None)
                    else:
                        exec_cmd(self.conf['ssh'])
                    self.log.error('Exited')
                    sys.exit(0)

                # else warn and log
                else:
                    self.ssh_warn('command over SSH', self.conf['ssh'])

            else :
                # case of shell escapes
                self.ssh_warn('shell escape', self.conf['ssh'])
Пример #24
0
 def sync_time(self):
     cmd = 'ntpdate -u ntp.api.bz'
     utils.exec_cmd(cmd, self.conn)
     time.sleep(0)
Пример #25
0
 def _klist(self, user_principal):
     exec_cmd([self.paths.klist, '-c', user_principal.ccache], environment={'KRB5CCNAME': user_principal.ccache})
Пример #26
0
 def _kdestroy(self, user_principal):
     exec_cmd([self.paths.kdestroy, '-A', '-q', '-c', user_principal.ccache], environment={'KRB5CCNAME': user_principal.ccache})
Пример #27
0
 def _check_authorized_keys(self, cluster_hosts):
     authorized_keys = utils.exec_cmd('cat /root/.ssh/authorized_keys')
     time.sleep(0)
     hosts = re.findall('ssh-rsa\s[\s\S]*?\sroot@(.*)', authorized_keys)
     if set(cluster_hosts) <= set(hosts):
         return True
Пример #28
0
def restart_service(proc_name):
    cmd = ['service', proc_name, 'restart']
    exec_cmd(cmd)
Пример #29
0
 def get_version(self):
     cmd = 'corosync -v'
     result = utils.exec_cmd(cmd, self.conn)
     version = re.findall('version\s\'(.*)\'', result)
     if version:
         return version[0]
Пример #30
0
 def modify_hostsfile(self, ip, hostname):
     cmd = f"sed -i 's/{ip}.*/{ip}\t{hostname}/g' /etc/hosts"
     utils.exec_cmd(cmd, self.conn)
Пример #31
0
 def recover_conf(self):
     editor = utils.FileEdit(read_data)  # 恢复原始配置文件,需要read_data存在
     utils.exec_cmd(f'echo "{editor.data}" > {corosync_conf_path}',
                    self.conn)
Пример #32
0
def backup_database(name, config):
	import datetime
	dt = datetime.datetime.now()
	name = '/root/lamp_bak/%s-%s.sql.gz' % (name, dt.strftime('%Y-%m-%d_%H:%M'))
	utils.exec_cmd('mysqldump -u%s -p%s lamp  | gzip > %s' % (config['lampuser'], config['lamppass'], name))
	return name
Пример #33
0
 def uninstall(self):
     cmd = 'apt purge -y corosync'
     utils.exec_cmd(cmd, self.conn)
Пример #34
0
    def __getattr__(self, attr):
        """ This method actually takes care of all the called method that are
        not resolved (i.e not existing methods). It actually will simulate
        the existance of any method    entered in the 'allowed' variable list.

        e.g. You just have to add 'uname' in list of allowed commands in
        the 'allowed' variable, and lshell will react as if you had
        added a do_uname in the ShellCmd class!
        """

        # expand environment variables in command line
        self.g_cmd  = os.path.expandvars(self.g_cmd)
        self.g_line = os.path.expandvars(self.g_line)
        self.g_arg  = os.path.expandvars(self.g_arg)

        # in case the configuration file has been modified, reload it
        if self.conf['config_mtime'] != os.path.getmtime(self.conf['configfile']):
            from lshell.checkconfig import CheckConfig
            self.conf = CheckConfig(['--config', \
                                     self.conf['configfile']]).returnconf()
            self.prompt = '%s:~$ ' % self.setprompt(self.conf)
            self.log = self.conf['logpath']

        if self.g_cmd in ['quit', 'exit', 'EOF']:
            self.log.error('Exited')
            if self.g_cmd == 'EOF':
                self.stdout.write('\n')
            sys.exit(0)
        if self.check_secure(self.g_line, self.conf['strict']) == 1:
            # see http://tldp.org/LDP/abs/html/exitcodes.html
            self.retcode = 126
            return object.__getattribute__(self, attr)
        if self.check_path(self.g_line, strict = self.conf['strict']) == 1:
            # see http://tldp.org/LDP/abs/html/exitcodes.html
            self.retcode = 126
            return object.__getattribute__(self, attr)
        if self.g_cmd in self.conf['allowed']:
            if self.conf['timer'] > 0:
                self.mytimer(0)
            self.g_arg = re.sub('^~$|^~/', '%s/' %self.conf['home_path'],      \
                                                                   self.g_arg)
            self.g_arg = re.sub(' ~/', ' %s/'  %self.conf['home_path'],        \
                                                                   self.g_arg)
            # replace previous command exit code
            # in case multiple commands (using separators), only replace first command
            # regex replaces all occureces of $?, before ;,&,|
            if re.search('[;&\|]', self.g_line):
              p = re.compile("(\s|^)(\$\?)([\s|$]?[;&|].*)")
            else:
              p = re.compile("(\s|^)(\$\?)(\s|$)")
            self.g_line = p.sub(r' %s \3' % self.retcode, self.g_line)

            if type(self.conf['aliases']) == dict:
                self.g_line = get_aliases(self.g_line, self.conf['aliases'])

            self.log.info('CMD: "%s"' %self.g_line)

            if self.g_cmd == 'cd':
              if re.search('[;&\|]', self.g_line):
                # ignore internal cd function in case more than one command
                self.retcode = exec_cmd(self.g_line)
              else:
                # builtin cd function
                self.retcode = self.cd()
            # builtin lpath function: list all allowed path
            elif self.g_cmd == 'lpath':
                self.retcode = self.lpath()
            # builtin lsudo function: list all allowed sudo commands
            elif self.g_cmd == 'lsudo':
                self.retcode = self.lsudo()
            # builtin history function: print command history
            elif self.g_cmd == 'history':
                self.retcode = self.history()
            # builtin export function
            elif self.g_cmd == 'export':
                self.retcode = self.export()
            # case 'cd' is in an alias e.g. {'toto':'cd /var/tmp'}
            elif self.g_line[0:2] == 'cd':
                self.g_cmd = self.g_line.split()[0]
                self.g_arg = ' '.join(self.g_line.split()[1:])
                self.retcode = self.cd()
            else:
                self.retcode = exec_cmd(self.g_line)

        elif self.g_cmd not in ['', '?', 'help', None]: 
            self.log.warn('INFO: unknown syntax -> "%s"' %self.g_line)
            self.stderr.write('*** unknown syntax: %s\n' %self.g_cmd)
        self.g_cmd, self.g_arg, self.g_line = ['', '', '']
        if self.conf['timer'] > 0:
            self.mytimer(self.conf['timer'])
        return object.__getattribute__(self, attr)
Пример #35
0
 def modify_cluster_name(self, cluster_name):
     cmd = f"crm config property cluster-name={cluster_name}"
     utils.exec_cmd(cmd, self.conn)
Пример #36
0
 def set_auto_add_mapped_luns(self):
     cmd = "targetcli set global auto_add_mapped_luns=false"
     utils.exec_cmd(cmd, self.conn)
Пример #37
0
 def modify_policy(self):
     cmd = "crm config property no-quorum-policy=ignore"
     utils.exec_cmd(cmd, self.conn)
Пример #38
0
 def get_networkcard_data(self):
     cmd_result = utils.exec_cmd('ip a', self.conn)
Пример #39
0
 def modify_stonith_enabled(self):
     cmd = "crm config property stonith-enabled=false"
     utils.exec_cmd(cmd, self.conn)
Пример #40
0
 def get_version(self):
     cmd = 'targetcli --version'
     result = utils.exec_cmd(cmd, self.conn)
     version = re.findall('version\s*(.*)', result)
     if version:
         return version[0]
Пример #41
0
 def modify_stickiness(self):
     cmd = "crm config rsc_defaults resource-stickiness=1000"
     utils.exec_cmd(cmd, self.conn)
Пример #42
0
    def __getattr__(self, attr):
        """ This method actually takes care of all the called method that are
        not resolved (i.e not existing methods). It actually will simulate
        the existance of any method    entered in the 'allowed' variable list.

        e.g. You just have to add 'uname' in list of allowed commands in
        the 'allowed' variable, and lshell will react as if you had
        added a do_uname in the ShellCmd class!
        """

        # expand environment variables in command line
        self.g_cmd = os.path.expandvars(self.g_cmd)
        self.g_line = os.path.expandvars(self.g_line)
        self.g_arg = os.path.expandvars(self.g_arg)

        # in case the configuration file has been modified, reload it
        if self.conf["config_mtime"] != os.path.getmtime(self.conf["configfile"]):
            from lshell.checkconfig import CheckConfig

            self.conf = CheckConfig(["--config", self.conf["configfile"]]).returnconf()
            self.prompt = "%s:~$ " % self.setprompt(self.conf)
            self.log = self.conf["logpath"]

        if self.g_cmd in ["quit", "exit", "EOF"]:
            self.log.error("Exited")
            if self.g_cmd == "EOF":
                self.stdout.write("\n")
            sys.exit(0)
        if self.check_secure(self.g_line, self.conf["strict"]) == 1:
            return object.__getattribute__(self, attr)
        if self.check_path(self.g_line, strict=self.conf["strict"]) == 1:
            return object.__getattribute__(self, attr)
        if self.g_cmd in self.conf["allowed"]:
            if self.conf["timer"] > 0:
                self.mytimer(0)
            self.g_arg = re.sub("^~$|^~/", "%s/" % self.conf["home_path"], self.g_arg)
            self.g_arg = re.sub(" ~/", " %s/" % self.conf["home_path"], self.g_arg)
            # replace previous command exit code
            # in case multiple commands (using separators), only replace first command
            # regex replaces all occureces of $?, before ;,&,|
            if re.search("[;&\|]", self.g_line):
                p = re.compile("(\s|^)(\$\?)([\s|$]?[;&|].*)")
            else:
                p = re.compile("(\s|^)(\$\?)(\s|$)")
            self.g_line = p.sub(r" %s \3" % self.retcode, self.g_line)

            if type(self.conf["aliases"]) == dict:
                self.g_line = get_aliases(self.g_line, self.conf["aliases"])

            self.log.info('CMD: "%s"' % self.g_line)

            if self.g_cmd == "cd":
                if re.search("[;&\|]", self.g_line):
                    # ignore internal cd function in case more than one command
                    self.retcode = exec_cmd(self.g_line)
                else:
                    # builtin cd function
                    self.retcode = self.cd()
            # builtin lpath function: list all allowed path
            elif self.g_cmd == "lpath":
                self.retcode = self.lpath()
            # builtin lsudo function: list all allowed sudo commands
            elif self.g_cmd == "lsudo":
                self.retcode = self.lsudo()
            # builtin history function: print command history
            elif self.g_cmd == "history":
                self.retcode = self.history()
            # builtin export function
            elif self.g_cmd == "export":
                self.retcode = self.export()
            # case 'cd' is in an alias e.g. {'toto':'cd /var/tmp'}
            elif self.g_line[0:2] == "cd":
                self.g_cmd = self.g_line.split()[0]
                self.g_arg = " ".join(self.g_line.split()[1:])
                self.retcode = self.cd()
            else:
                self.retcode = exec_cmd(self.g_line)

        elif self.g_cmd not in ["", "?", "help", None]:
            self.log.warn('INFO: unknown syntax -> "%s"' % self.g_line)
            self.stderr.write("*** unknown syntax: %s\n" % self.g_cmd)
        self.g_cmd, self.g_arg, self.g_line = ["", "", ""]
        if self.conf["timer"] > 0:
            self.mytimer(self.conf["timer"])
        return object.__getattribute__(self, attr)
Пример #43
0
 def up_ip_service(self, device):
     connection_name = 'vtel_' + device
     cmd = f"nmcli connection up id {connection_name}"
     utils.exec_cmd(cmd, self.conn)
def get_os_info():
    cmd = 'uname -sr'
    return exec_cmd(cmd).strip()    
Пример #45
0
 def restart(self):
     cmd = "systemctl restart pacemaker"
     utils.exec_cmd(cmd, self.conn)
Пример #46
0
 def check_hostname(self, hostname):
     lc_hostname = utils.exec_cmd('hostname', self.conn)
     if lc_hostname == hostname:
         return True
Пример #47
0
def go_centos():
	raw_input("LAMP Setup script is ready install it\nPress Enter key to continue, Press Ctrl+D to cancel progress\n")

	#generate config file
	os.mkdir('/tmp/lamp')
	os.mkdir('/etc/lamp')
	os.mkdir('/root/lamp_bak')
  	os.mkdir('/etc/lamp/ftp_users')
	config = {}
	global version
	config['version'] = version
	config['system'] = 'c'
	config['wwwroot'] = '/var/www'
	config['apache_etc'] = '/etc/httpd'
	config['apache'] = 'httpd'
	config['ftproot'] = '/var/www'
	config['vsftpd_conf_path'] = '/etc/vsftpd/vsftpd.conf'
	config['root_own'] = 'apache:apache'


	#setting mysql passwotrd
	mysql_root_pass = utils.gen_random_str()
	config['mysqlrootpass'] = mysql_root_pass
	utils.save_config(config)

	logging.debug('generate mysql root password : %s', mysql_root_pass)


	logging.info('load yum repo...')
	utils.exec_cmd('yum install yum-priorities -y')
	utils.exec_cmd('wget http://s1b-static.yuki.ws/files/lamp/files.tar.xz -O /tmp/lamp/files.tar.xz')
	utils.exec_cmd('tar xvf /tmp/lamp/files.tar.xz -C /tmp/lamp')

	# Get system detail info
	machine = platform.machine()
	if machine == 'i686':
		machine = 'i386'
	ver = platform.dist()[1]
	if ver >= 6:
		ver = 6
		utils.exec_cmd('wget http://ftp.riken.jp/Linux/fedora/epel/6/%s/epel-release-6-8.noarch.rpm -O /tmp/lamp/epel-release.rpm' % (machine))
		utils.exec_cmd('wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.%s.rpm -O /tmp/lamp/rpmforge-release.rpm' % (platform.machine()))
		#download vsftpd
		utils.exec_cmd('wget http://centos.alt.ru/repository/centos/6/%s/vsftpd-3.0.2-2.el6.%s.rpm -O /tmp/lamp/vsftpd.rpm' %(machine, platform.machine()))
	else:
		ver = 5
		utils.exec_cmd('wget http://ftp.riken.jp/Linux/fedora/epel/5/%s/epel-release-5-4.noarch.rpm -O /tmp/lamp/epel-release.rpm' % (machine))
		utils.exec_cmd('wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.%s.rpm -O /tmp/lamp/rpmforge-release.rpm' % (machine))
		utils.exec_cmd('wget http://centos.alt.ru/repository/centos/5/%s/vsftpd-3.0.2-1.el5.%s.rpm -O /tmp/lamp/vsftpd.rpm' %(platform.machine(), platform.machine()))

	utils.exec_cmd('yum localinstall /tmp/lamp/*-release.rpm -y')

	# Change yum priority
	utils.change_conf('/etc/yum.repos.d/CentOS-Base.repo', [{'old':'gpgcheck=1','new':'priority=1\ngpgcheck=1'}])
	utils.change_conf('/etc/yum.repos.d/rpmforge.repo', [{'old':'enabled =','new':'priority = 10\nenabled ='}])
	utils.change_conf('/etc/yum.repos.d/epel.repo', [{'old':'enabled=','new':'priority=11\nenabled='}])

	logging.info('update system, please wait...')
	utils.exec_cmd('yum makecache')
	#utils.exec_cmd('yum update -y')

	logging.info('install and config packages, please wait...')
	utils.exec_cmd('yum install axel screen MySQL-python vim pam_mysql httpd mysql-server php php-mysql php-pdo php-mcrypt php-mbstring php-gd php-pecl-imagick php-pecl-memcached php-xcache -y')


	logging.info('setting up web-server...')
	utils.change_conf('/etc/httpd/conf/httpd.conf',
		[
			{'old':'ple.com:80','new':'ple.com:80\nServerName %s' % (platform.uname()[1])},
			{'old':'Timeout 60','new':'Timeout 45'},
			{'old':'MaxKeepAliveRequests 100','new':'MaxKeepAliveRequests 200'},
			{'old':'ServerTokens OS','new':'ServerTokens Prod'},
			{'old':'ServerSignature On','new':'ServerSignature Off'},
			{'old':'/var/www/html','new':'/var/www/public_html'},
			{'old':'#NameVirtualHost \*:80','new':'NameVirtualHost *:80'},
			{'old':'#</VirtualHost>','new':'#</VirtualHost>\nInclude sites-enabled/'}
		]
	)

	# Set apache php.ini
	logging.debug('Setting php.ini')
	utils.change_conf('/etc/php.ini',
		[
			{'old':'post_max_size = 8M','new':'post_max_size = 50M'},
			{'old':'upload_max_filesize = 2M','new':'upload_max_filesize = 50M'},
			{'old':'expose_php = On','new':'expose_php = Off'},
			{'old':';date.timezone =','new':'date.timezone = Asia/Chongqing'},
			{'old':'request_order = "GP"','new':'request_order = "CGP"'}
		]
	)

	# Fix mcrypt.ini error
	utils.change_conf('/etc/php.d/mcrypt.ini',
		[
			{'old':'module.so','new':'mcrypt.so'}
		]
	)

	os.mkdir('/etc/httpd/sites-available')
	os.mkdir('/etc/httpd/sites-enabled')
	utils.exec_cmd('mv /var/www/html /var/www/public_html')

	# Create a default site
	os.mkdir('/var/www/logs')
	utils.change_conf('<APPROOT>/files/vhost_template',
		[
			{'old':'ServerName <ServerName>','new':''},
			{'old':'<ServerName>','new':'default'},
			{'old':'<siteroot>','new':'/var/www'}
		],
	'/etc/httpd/sites-enabled/default')



	# Init phpmyadmin and lamp user pass
	utils.exec_cmd('service mysqld restart')

	utils.exec_cmd('mysqladmin -u root password \'%s\'' % (mysql_root_pass))
	utils.cp('<APPROOT>/files/phpmyadmin_host', '/etc/httpd/conf.d/phpmyadmin.conf')
	lamp_controluser_pass = mysql.init_db(mysql_root_pass)

	config['lampuser'] = '******'
	config['lamppass'] = lamp_controluser_pass
	utils.save_config(config)

	
	utils.exec_cmd(r'echo "<?php phpinfo() ?>" > /var/www/public_html/test.php')

	# Change wwwroot permissions
	utils.exec_cmd('chown -R apache:apache /var/www')
	utils.exec_cmd('chmod -R go-rwx /var/www')
	utils.exec_cmd('chmod -R g+rw /var/www')
	utils.exec_cmd('chmod -R o+r /var/www')

	utils.exec_cmd('service httpd restart')

	logging.info('setting up ftp-server...')


	# Init ftp and create main account
	utils.exec_cmd('yum localinstall /tmp/lamp/vsftpd.rpm -y')
	utils.exec_cmd('mkdir -p /var/run/vsftpd')

	utils.change_conf('<APPROOT>/files/vsftpd_conf', [
		{'old':'<ftpuser>','new':'ftp'},
		{'old':'<guestuser>','new':'apache'}
	], '/etc/vsftpd/vsftpd.conf')

	utils.change_conf('<APPROOT>/files/vsftpd_mysql', [{'old':'<passwd>','new':lamp_controluser_pass}], '/etc/pam.d/vsftpd-mysql')

	args = {}
	args['username'] = '******'
	args['path'] = '/var/www'
	args['site_id'] = 1

	ftp_pass = ftp.create_ftp(args)
	utils.exec_cmd('service vsftpd restart')


	logging.info('setting up system...')
	# Set iptables
	utils.cp('<APPROOT>/files/iptables_rules', '/etc/sysconfig/iptables')
	utils.exec_cmd('service iptables restart')

	#load kernel ip_nat_ftp
	utils.exec_cmd('modprobe nf_nat_ftp')
	utils.exec_cmd('echo "modprobe nf_nat_ftp" >> /etc/sysconfig/modules/nf_nat_ftp.modules')
	utils.exec_cmd('chmod +x /etc/sysconfig/modules/nf_nat_ftp.modules')

	# Add auto start at boot
	utils.exec_cmd('chkconfig httpd on')
	utils.exec_cmd('chkconfig mysqld on')
	utils.exec_cmd('chkconfig vsftpd on')

	finish_install(mysql_root_pass, ftp_pass, 'yum update -y')
Пример #48
0
 def check_ra_target(self):
     cmd = f'grep -rs "#{self.ra_target}" {self.heartbeat_path}/iSCSITarget'
     result = utils.exec_cmd(cmd, self.conn)
     if result:
         return True
Пример #49
0
 def config_drbd_attr(self):
     cmd1 = 'crm config primitive drbd-attr ocf:linbit:drbd-attr'
     cmd2 = 'crm config clone drbd-attr-clone drbd-attr'
     utils.exec_cmd(cmd1, self.conn)
     utils.exec_cmd(cmd2, self.conn)
Пример #50
0
 def check_ra_logicalunit(self):
     cmd = f'grep -rs "#{self.ra_logicalunit}" {self.heartbeat_path}/iSCSILogicalUnit'
     result = utils.exec_cmd(cmd, self.conn)
     if result:
         return True
Пример #51
0
 def clear_crm_res(self):
     utils.exec_cmd(
         "crm res stop g_linstor p_fs_linstordb p_linstor-controller",
         self.conn)
     utils.exec_cmd("crm res stop ms_drbd_linstordb p_drbd_linstordb",
                    self.conn)
     utils.exec_cmd("crm res stop drbd-attr", self.conn)
     time.sleep(2)
     utils.exec_cmd(
         "crm conf del g_linstor p_fs_linstordb p_linstor-controller",
         self.conn)
     utils.exec_cmd(
         "crm conf del g_linstor ms_drbd_linstordb p_drbd_linstordb",
         self.conn)
     utils.exec_cmd("crm conf del drbd-attr", self.conn)
Пример #52
0
def go_debian():
	raw_input("LAMP Setup script is ready install it\nPress Enter key to continue, Press Ctrl+D to cancel the installation\n")

	#generate config file
	os.mkdir('/tmp/lamp')
	os.mkdir('/etc/lamp')
	os.mkdir('/root/lamp_bak')
  	os.mkdir('/etc/lamp/ftp_users')
	config = {}
	global version
	config['version'] = version
	config['system'] = 'u'
	config['wwwroot'] = '/var/www'
	config['apache_etc'] = '/etc/apache2'
	config['apache'] = 'apache2'
	config['ftproot'] = '/var/www'
	config['vsftpd_conf_path'] = '/etc/vsftpd.conf'
	config['root_own'] = 'www-data:www-data'

	'''
	logging.info('download files ...')
	utils.exec_cmd('wget http://s1b-static.yuki.ws/files/lamp/files.tar.xz -O /tmp/lamp/files.tar.xz')
	utils.exec_cmd('tar xvf /tmp/lamp/files.tar.xz -C /tmp/lamp')
	'''

	#setting mysql passwotrd
	mysql_root_pass = utils.gen_random_str()
	config['mysqlrootpass'] = mysql_root_pass
	utils.save_config(config)

	logging.debug('generate mysql root password : %s', mysql_root_pass)
	debconf_tmp = open('/tmp/lamp/debconf.tmp', 'w+')
	debconf_tmp.write('mysql-server mysql-server/root_password password %s\nmysql-server mysql-server/root_password_again password %s\n' % (mysql_root_pass, mysql_root_pass))
	debconf_tmp.write('iptables-persistent iptables-persistent/autosave_v4 boolean true\niptables-persistent iptables-persistent/autosave_v6 boolean true\n')
	debconf_tmp.close()
	utils.exec_cmd('debconf-set-selections /tmp/lamp/debconf.tmp')
	os.remove('/tmp/lamp/debconf.tmp')
	del debconf_tmp

	logging.info('update data packages info...')
	utils.exec_cmd('apt-get update')

	logging.info('update system, please wait...')
	#utils.exec_cmd('apt-get upgrade -y')

	logging.info('install and config packages, please wait...')
	utils.exec_cmd('apt-get install -y vim axel curl unzip build-essential python-mysqldb python-software-properties php5 apache2 libapache2-mod-php5 mysql-server php5-mysql php5-curl php5-gd php5-mcrypt php5-imagick php5-memcached php5-sqlite php5-xcache iptables-persistent libpam-mysql')


	logging.info('setting up web-server...')

	logging.debug('setting apache conf')
	httpd_conf = open('/etc/apache2/httpd.conf', 'w')
	httpd_conf.write('ServerName %s\n' % (platform.uname()[1]))
	httpd_conf.close()
	del httpd_conf

	utils.change_conf('/etc/apache2/apache2.conf',
		[
			{'old':'Timeout 300','new':'Timeout 45'},
			{'old':'MaxKeepAliveRequests 100','new':'MaxKeepAliveRequests 200'}
		]
	)

	utils.change_conf('/etc/apache2/conf.d/security',
		[
			{'old':'ServerTokens OS','new':'ServerTokens Prod'},
			{'old':'ServerSignature On','new':'ServerSignature Off'}
		]
	)

	# Enable mod-rewrite
	utils.exec_cmd('a2enmod rewrite')

	# Set apache php.ini
	logging.debug('Setting php.ini')
	utils.change_conf('/etc/php5/apache2/php.ini',
		[
			{'old':'post_max_size = 8M','new':'post_max_size = 50M'},
			{'old':'upload_max_filesize = 2M','new':'upload_max_filesize = 50M'},
			{'old':'expose_php = On','new':'expose_php = Off'},
			{'old':'display_errors = Off','new':'display_errors = On'},
			{'old':';date.timezone =','new':'date.timezone = Asia/Chongqing'},
			{'old':'request_order = "GP"','new':'request_order = "CGP"'}
		]
	)


	# Change default www dir
	utils.exec_cmd('mkdir -p /var/www/public_html')
	utils.exec_cmd('mv /var/www/index.html /var/www/public_html/')
	utils.change_conf('/etc/apache2/sites-enabled/000-default', [{'old':'/var/www','new':'/var/www/public_html'}])

	# Init phpmyadmin and lamp user pass
	utils.exec_cmd('service mysql restart')
	lamp_controluser_pass = mysql.init_db(mysql_root_pass)

	utils.cp('<APPROOT>/files/phpmyadmin_host', '/etc/apache2/mods-available/phpmyadmin.conf')
	utils.exec_cmd('ln -s /etc/apache2/mods-available/phpmyadmin.conf /etc/apache2/mods-enabled/phpmyadmin.conf')

	config['lampuser'] = '******'
	config['lamppass'] = lamp_controluser_pass
	utils.save_config(config)

	# create test php script
	utils.exec_cmd(r'echo "<?php phpinfo() ?>" > /var/www/public_html/test.php')

	# Change wwwroot permissions
	utils.exec_cmd('chown -R www-data:www-data /var/www')
	utils.exec_cmd('chmod -R go-rwx /var/www')
	utils.exec_cmd('chmod -R g+rw /var/www')
	utils.exec_cmd('chmod -R o+r /var/www')

	utils.exec_cmd('service apache2 restart')

	logging.info('setting up ftp-server...')

	# Init ftp and create main account
	#ftp_pass = ftp.init_ftp()
	if platform.machine() == 'x86_64':
		utils.exec_cmd('axel -q -n 3 -o /tmp/lamp/vsftpd.deb http://ftp.jaist.ac.jp/pub/Linux/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.2-1ubuntu1_amd64.deb')
		#add fix 12.04 pam.d-mysql bugs "libgcc_s.so.1 must be installed for pthread_cancel to work"
		utils.exec_cmd('DEBIAN_FRONTEND=noninteractive apt-get install -qq libpam-ldap')
	else:
		utils.exec_cmd('axel -q -n 3 -o /tmp/lamp/vsftpd.deb http://ftp.jaist.ac.jp/pub/Linux/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.2-1ubuntu1_i386.deb')

	returncode = utils.exec_cmd('dpkg -i /tmp/lamp/vsftpd.deb')
	if returncode == 2:
		logging.debug('install vsftpd failed!')

	utils.change_conf('<APPROOT>/files/vsftpd_conf', [
		{'old':'<ftpuser>','new':'ftp'},
		{'old':'<guestuser>','new':'www-data'}
	], '/etc/vsftpd.conf')


	#add fix 500 OOPS: priv_sock_get_cmd
	if platform.machine() == 'x86_64':
		utils.change_conf('/etc/vsftpd.conf', [{'old':'ftp_users','new':'ftp_users\nseccomp_sandbox=NO'}])

	utils.change_conf('<APPROOT>/files/vsftpd_mysql', [{'old':'<passwd>','new':lamp_controluser_pass}], '/etc/pam.d/vsftpd-mysql')

	#set master ftp account
	args = {}
	args['username'] = '******'
	args['path'] = '/var/www'
	args['site_id'] = 1

	ftp_pass = ftp.create_ftp(args)
	utils.exec_cmd('service vsftpd restart')


	logging.info('setting up system...')
	# Set iptables
	utils.cp('<APPROOT>/files/iptables_rules', '/etc/iptables/rules.v4')
	utils.exec_cmd('service iptables-persistent restart')

	#load kernel ip_nat_ftp
  	utils.exec_cmd('modprobe nf_nat_ftp')
  	utils.exec_cmd('echo "nf_nat_ftp" >> /etc/modules')


  	# Add auto start at boot
	utils.exec_cmd('update-rc.d apache2 defaults')
	utils.exec_cmd('update-rc.d mysql defaults')
	utils.exec_cmd('update-rc.d vsftpd defaults')

	finish_install(mysql_root_pass, ftp_pass, 'apt-get upgrade -y')
Пример #53
0
 def modify_ip(self, device, new_ip, gateway, netmask=24):
     connection_name = 'vtel_' + device
     cmd = f"nmcli connection modify {connection_name} ipv4.address {new_ip}/{netmask} ipv4.gateway {gateway}"
     utils.exec_cmd(cmd, self.conn)
Пример #54
0
 def clear_crm_node(self, node):
     utils.exec_cmd(f"crm conf del {node}", self.conn)
Пример #55
0
 def uninstall(self):
     cmd = 'apt purge -y pacemaker crmsh corosync ntpdate'
     utils.exec_cmd(cmd, self.conn)
Пример #56
0
    def cmdloop(self, intro=None):
        """Repeatedly issue a prompt, accept input, parse an initial prefix    \
        off the received input, and dispatch to action methods, passing them   \
        the remainder of the line as argument.
        """

        self.preloop()
        if self.use_rawinput and self.completekey:
            try:
                readline.read_history_file(self.conf['history_file'])
                readline.set_history_length(self.conf['history_size'])
            except IOError:
                # if history file does not exist
                try:
                    open(self.conf['history_file'], 'w').close()
                    readline.read_history_file(self.conf['history_file'])
                except IOError:
                    pass
            readline.set_completer_delims(readline.get_completer_delims().replace('-', ''))
            self.old_completer = readline.get_completer()
            readline.set_completer(self.complete)
            readline.parse_and_bind(self.completekey+": complete")
        try:
            if self.intro and isinstance(self.intro, str):
                self.stdout.write("%s\n" % self.intro)
            if self.conf['login_script']:
                retcode = exec_cmd(self.conf['login_script'])
            stop = None
            while not stop:
                if self.cmdqueue:
                    line = self.cmdqueue.pop(0)
                else:
                    if self.use_rawinput:
                        try:
                            line = raw_input(self.prompt)
                        except EOFError:
                            line = 'EOF'
                        except KeyboardInterrupt:
                            self.stdout.write('\n')
                            line = ''
                    else:
                        self.stdout.write(self.prompt)
                        self.stdout.flush()
                        line = self.stdin.readline()
                        if not len(line):
                            line = 'EOF'
                        else:
                            line = line[:-1] # chop \n
                line = self.precmd(line)
                stop = self.onecmd(line)
                stop = self.postcmd(stop, line)
            self.postloop()
        finally:
            if self.use_rawinput and self.completekey:
                try:
                    readline.set_completer_delims(readline.get_completer_delims().replace('-', ''))
                    readline.set_completer(self.old_completer)
                except ImportError:
                    pass
            try:
                readline.write_history_file(self.conf['history_file'])
            except IOError:
                self.log.error('WARN: couldn\'t write history '                \
                                   'to file %s\n' % self.conf['history_file'])
Пример #57
0
 def set_auto_add_default_portal(self):
     cmd = "targetcli set global auto_add_default_portal=false"
     utils.exec_cmd(cmd, self.conn)
Пример #58
0
 def get_version(self):
     cmd = 'crm st | grep Current | cat'
     result = utils.exec_cmd(cmd, self.conn)
     version = re.findall('\(version\s(.*)\)\s', result)
     if version:
         return version[0]
Пример #59
0
def filter_bam(logfp, samtools, in_sam, filter_sort_bam, thread, align_rate,
               iden_rate, best_rate, min_intron_len, intron_n, rRNA):
    in_fp = ps.AlignmentFile(in_sam, 'r')
    filtered_bam = in_sam + '.filter'
    filter_fp = ps.AlignmentFile(filtered_bam, 'wb', template=in_fp)
    if rRNA is not None:
        rRNA_db_fn = os.path.dirname(in_sam) + '/' + rRNA + '.db'
        if not os.path.isfile(rRNA_db_fn):
            try:
                rRNA_db = gu.create_db(rRNA, rRNA_db_fn)
            except:
                logfp.write('Error in parsing %s\n' % (rRNA))
                sys.exit(IOError)
        else:
            try:
                rRNA_db = gu.FeatureDB(rRNA_db_fn)
            except:
                logfp.write('Error in parsing %s\n' % (rRNA_db_fn))
                sys.exit(IOError)

    last_qname = ''
    b_score = 0
    s_score = 0
    cnt = 0
    utils.format_time(logfp, __name__, 'Filtering alignments\n')
    for record in in_fp.fetch():
        if record.is_unmapped:
            continue
        # 0. intron number
        N_n = [
            c for c in record.cigartuples
            if c[0] == 3 and c[1] >= min_intron_len
        ]
        if len(N_n) < intron_n:
            continue
        # 1. aligned bases
        if filter_align_rate(record, align_rate):
            continue
        # 2. identical rate
        filter_iden, score = filter_iden_rate(record, iden_rate)
        if filter_iden:
            continue
        # 3. rRNA
        if rRNA and filter_rRNA(record, rRNA_db):
            continue
        # 4. best
        if record.query_name is last_qname:
            if score > b_score:
                b_record = record
                s_score = b_score
                b_score = score
            elif score > s_score:
                s_score = score
        else:
            if last_qname is not '' and s_score < best_rate * b_score:
                filter_fp.write(b_record)
                cnt += 1
            b_record = record
            b_score = score
            s_score = 0
            last_qname = record.query_name

    if last_qname is not '' and s_score < best_rate * b_score:
        filter_fp.write(b_record)
        cnt += 1

    in_fp.close()
    filter_fp.close()

    utils.format_time(logfp, __name__,
                      'Filtered alignments: ' + str(cnt) + '\n')

    utils.exec_cmd(
        logfp, __name__, '%s sort -@ %d %s > %s' %
        (samtools, thread, filtered_bam, filter_sort_bam))
    utils.exec_cmd(logfp, __name__,
                   '%s index %s' % (samtools, filter_sort_bam))
    utils.exec_cmd(logfp, __name__, 'rm %s' % filtered_bam)