예제 #1
0
 def get(self):
     """Get current name servers"""
     dnsSearch = " ".join(
                 map(lambda x:x.strip().partition("search")[2].strip(),
                 filter(lambda x:x.lstrip().startswith("search"),
                 readLinesFile('/etc/resolv.conf'))))
     return "" if self.isDNSByDHCP() else dnsSearch
예제 #2
0
def checkContents(pkg,fileName,prefix='/',reservedFile=None):
    """
    Check contents with newContent
    """
    contentFile = path.join(prefix,'var/db/pkg/%s/CONTENTS'%pkg)
    if prefix != '/' and fileName.startswith(prefix):
        shortName = fileName[len(prefix):]
    else:
        shortName = fileName

    TYPE,FILENAME,MD5,MTIME=0,1,2,3
    obj = filter(lambda x:x[1] == shortName,
          map(lambda x:x.split(' '),
          filter(lambda x:x.startswith('obj'),
          readLinesFile(contentFile))))
    # if pkg not content filename
    if not obj:
        # for using reserved -CONTENTS file on postinst
        if not reservedFile or checkReserved(fileName,reservedFile):
            return True
        else:
            return False
    # if file is not exists
    if not path.exists(fileName):
        # for using reserved -CONTENTS file on postinst
        if not reservedFile or checkReserved(fileName,reservedFile):
            return True
        else:
            return False
    contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
    configMD5 = obj[0][MD5].strip()
    # if content was not changed
    if contentMD5 == configMD5:
        return True
    return False
예제 #3
0
 def get(self):
     """Get cpufreq (and other from modules_3= param) from conf.d/modules"""
     cpufreqmods = map(lambda x:x.partition('=')[2].strip("\n '\""),
                   filter(lambda x:x.startswith('modules_3'),
                   readLinesFile('/etc/conf.d/modules')))
     if cpufreqmods:
         return cpufreqmods[0]
     else:
         return ""
예제 #4
0
 def get(self):
     reMemTotal = re.compile(r'^MemTotal:\s*(\d+)\s*kB$')
     totalMemList = filter(lambda x:x,
                    map(reMemTotal.search,
                    readLinesFile('/proc/meminfo')))
     if totalMemList:
         size = int(totalMemList[0].group(1))*Sizes.K
         return str(size)
     return "0"
예제 #5
0
    def get(self):
        req_id = self.Get('cl_req_id')
        serv_certbase = self.Get('cl_core_serv_database')
        certbase = self.Get('cl_core_database')

        for line in readLinesFile(certbase):
            if line.split()[0] == str(req_id):
                return line.strip().split()
        return ['']*7
예제 #6
0
def get_server_hostname(host, path_to_cert):
    compliance_file = os.path.join(path_to_cert, 'compliance_server_names')
    if not os.path.isfile(compliance_file):
        fd = open(compliance_file, 'w')
        fd.close()
    for line in readLinesFile(compliance_file):
        adress, server_hostname = line.split(' ',1)
        if adress == host:
            return server_hostname
    return None
예제 #7
0
 def get(self):
     rootPasswd = map(lambda x:x[1],
                  filter("root".__eq__,
                  map(lambda x:x.split(':')[0:2],
                  readLinesFile('/etc/shadow'))))
     if rootPasswd:
         rootPasswd = rootPasswd[0]
     else:
         rootPasswd = ""
     # if root password is "root"
     if rootPasswd:
         salt = "".join(rootPasswd.rpartition("$")[:1])
         if salt and crypt("root", salt) == rootPasswd:
             rootPasswd = ""
     return rootPasswd or ""
예제 #8
0
def fillContents(allContent,protected,prefix='/'):
    """
    Fill dict file - package
    """
    dbPath = pathJoin(prefix,'var/db/pkg')
    for contentFile in glob.glob(dbPath+"/*/*/CONTENTS"):
        for objFile in filter(lambda x:x.startswith('obj '),
            readLinesFile(contentFile)):
            res = PkgContents.reObj.search(objFile.strip())
            if res:
                fn = res.groupdict()['filename']
                if filter(lambda x:fn.startswith(x),protected):
                    pkg = reVerSplit.search(os.path.dirname(contentFile))
                    if pkg:
                        pkg = "%s/%s"%(pkg.groups()[:2])
                        allContent[fn] = pkg
예제 #9
0
 def get(self):
     def get_linguas(lines):
         linguas = map(lambda x:x.strip().rpartition('=')[-1].strip('"\''),
                    filter(lambda x: x.startswith("LINGUAS="),
                           lines))
         return linguas[-1] if linguas else ""
     makeconf = '/etc/make.conf'
     infocommand = ['emerge','--info']
     defaultLinguas = "bg en de es fr it pl pt_BR ru uk"
     # get linguas from make.conf, emerge --info or default
     curlanguage = self.Get('os_install_locale_language')
     return get_linguas(readLinesFile(makeconf)) or \
            " ".join(filter(lambda x:x=="en" or x==curlanguage,
                     get_linguas(
                     process(*infocommand).readlines() or "").split())) or \
            defaultLinguas
예제 #10
0
    def get(self):
        homeDir = self.Get("ur_home_path")
        if not homeDir:
            return []
        dirStart, dirEnd = path.split(homeDir)
        mountProfileDir = path.join(dirStart, ".%s" %dirEnd)
        mountRemoteProfileDir = path.join(dirStart, ".%s.remote" %dirEnd)

        directories = filter(lambda x:x != homeDir,
               filter(lambda x: (x.startswith(homeDir) or
                                 x.startswith(mountProfileDir) or
                                 x.startswith(mountRemoteProfileDir)),
               map(lambda x: x.split(" ")[1],
               readLinesFile('/proc/mounts'))))
        #if isMount(homeDir):
        #    directories.append(homeDir)
        return sorted(directories,reverse=True)
예제 #11
0
    def change_group_meth(self, dv):
        try:
            group_rights_file = dv.Get('cl_core_group_rights')

            cl_group_name = str(dv.Get('cl_group_name'))
            cl_group_rights = dv.Get('cl_group_rights')
            #self.startTask('Request confirmation')
            changed_flag = False
            result = []

            for line in readLinesFile(group_rights_file):
                if line.startswith('#') or not line:
                    result.append(line)
                    continue
                words = line.split(' ',1)
                # first word in line equal name input method
                if words[0] == cl_group_name:
                    line = cl_group_name + ' ' + ','.join(cl_group_rights)
                    changed_flag = True
                result.append(line)

            if cl_group_name == 'all' and not changed_flag:
                result.append(cl_group_name + ' ' + ','.join(cl_group_rights))
                changed_flag = True

            fd = open (group_rights_file, 'w')
            for lines in result:
                fd.write(lines + '\n')
            fd.close()

            if changed_flag:
                self.printSUCCESS ('<b>'+_('Group changed')+'</b>')
            else:
                self.printSUCCESS ('<b>'+ _('Group not changed')+'</b>')
            self.printSUCCESS (_('Group name') + " = %s" %cl_group_name)
            self.printSUCCESS (_('Group permissions') + " = %s" 
                               %','.join(cl_group_rights))
            return True
        except (KeyboardInterrupt,):
            self.printERROR('Process is interrupted!')
            return False
예제 #12
0
def checkReserved(fileName,contentFile):
    """
    Check contents with newContent
    """
    TYPE,FILENAME,MD5,MTIME=0,1,2,3
    obj = filter(lambda x:x[1] == fileName,
          map(lambda x:x.split(' '),
          filter(lambda x:x.startswith('obj'),
          readLinesFile(contentFile))))
    # if pkg not content filename
    if not obj:
        return True
    # if file is not exists
    if not path.exists(fileName):
        return True
    contentMD5 = hashlib.md5(readFile(fileName)).hexdigest().strip()
    configMD5 = obj[0][MD5].strip()
    # if content was not changed
    if contentMD5 == configMD5:
        return True
    return False
예제 #13
0
    def add_group_meth(self, dv):
        try:
            group_rights_file = dv.Get('cl_core_group_rights')
            cl_group_add = str(dv.Get('cl_group_add'))
            cl_group_rights = ', '.join(dv.Get('cl_group_rights'))

            self.printSUCCESS (_('Group name') + " = %s" %cl_group_add)
            self.printSUCCESS (_('Group permissions')+" = %s"%cl_group_rights)

            result = []
            for line in readLinesFile(group_rights_file):
                if line.startswith('#') or not line:
                    result.append(line)
                    continue
                words = line.split(' ',1)
                # first word in line equal name input method
                if words[0] == cl_group_add:
                    self.printSUCCESS (_('Group %s already exists!') \
                                       %cl_group_add)
                    return True
                result.append(line)

            result.append(cl_group_add + ' ' + cl_group_rights)

            fd = open (group_rights_file, 'w')
            for lines in result:
                fd.write(lines + '\n')
            fd.close()
            self.printSUCCESS (_("Group %s added") %cl_group_add)

            return True
        except KeyboardInterrupt:
            self.endTask()
            return False
        except Exception, e:
            msg = e.message
            if not msg:
                msg = e.reason
            self.printERROR (_("Exception: %s") %msg)
            return False
예제 #14
0
    def del_group_meth(self, dv):
        try:
            group_rights_file = dv.Get('cl_core_group_rights')
            cl_group_name = str(dv.Get('cl_group_name'))

            result = []
            deleted_flag = False
            for line in readLinesFile(group_rights_file):
                if line.startswith('#') or not line:
                    result.append(line)
                    continue
                words = line.split(' ',1)
                # first word in line equal name input method
                if words[0] != cl_group_name:
                    result.append(line)
                else:
                    deleted_flag = True

            fd = open (group_rights_file, 'w')
            for lines in result:
                fd.write(lines + '\n')
            fd.close()

            if deleted_flag:
                self.printSUCCESS ('<b>'+_('Group %s deleted') %cl_group_name\
                                   + '!</b>')
            else:
                self.printSUCCESS ('<b>'+_('Group %s has not been deleted.') \
                                   %cl_group_name + '!</b>')
            return True

        except KeyboardInterrupt:
            self.endTask()
            return False
        except Exception as e:
            msg = e.message
            if not msg:
                msg = e.reason
            self.printERROR (_("Exception: %s") %msg)
            return False
예제 #15
0
def add_server_hostname(host, path_to_cert, server_hostname):
    try:
        compliance_file = os.path.join(path_to_cert, 'compliance_server_names')
        if not os.path.isfile(compliance_file):
            fd = open(compliance_file, 'w')
            fd.close()
        temp_file = ''
        find_flag = False
        for line in readLinesFile(compliance_file):
            adress, temp_server_hostname = line.split(' ',1)
            if adress == host:
                temp_file += "%s %s\n" %(adress, server_hostname)
                find_flag = True
            else:
                temp_file += line+'\n'
        if not find_flag:
            temp_file += "%s %s\n" %(host, server_hostname)
        fd = open(compliance_file, 'w')
        fd.write(temp_file)
        fd.close()
        return True
    except Exception, e:
        print e
        return False
예제 #16
0
 def get(self):
     dnsIps = filter(ip.checkIp,
              map(lambda x:x.strip().partition("nameserver")[2].strip(),
              filter(lambda x:x.lstrip().startswith("nameserver"),
              readLinesFile('/etc/resolv.conf'))))
     return "" if self.isDNSByDHCP() else " ".join(dnsIps)
예제 #17
0
 def get(self):
     cpuinfoFile = "/proc/cpuinfo"
     return str(len(filter(lambda x:x.startswith("processor"),
                    readLinesFile(cpuinfoFile))) or 1)
예제 #18
0
 def getUserDataInFile(self, login, filePasswd):
     return filter(lambda x: x[0]==login,
            map(lambda x: x.strip().split(':'),
            readLinesFile(filePasswd)))
예제 #19
0
            continue
        if os.path.isfile(link_path):
            red = '\033[31m * \033[0m'
            print red+link_path+_(' is a file, not a link!')
            continue
        try:
            os.symlink(os.path.join(path_to_link, 'cl-core'), link_path)
            fd.write(link_path + '\n')
        except OSError, e:
            print e.message
        print _('Symlink %s created') %link_path
    fd.close()

    from calculate.lib.utils.files import readLinesFile
    temp_text_file = ''
    for line in readLinesFile(symlinks_file):
        cmdname = os.path.basename(line)
        if not cmdname in meths.keys() or \
            line.startswith(path_to_link) and meths[cmdname][1] or \
            line.startswith(path_to_user_link) and not meths[cmdname][1]:
            if os.path.islink(line):
                os.unlink(line)
                print _('Symlink %s deleted') %line
        else:
            temp_text_file += line + '\n'
    fd = open(symlinks_file, 'w')
    fd.write(temp_text_file)
    fd.close()

def initialization(cl_wsdl):
    """ find modules for further added in server class """
예제 #20
0
 def readContents(self):
     """
     Re-read contents
     """
     self.content = dict(filter(None,map(self._identifyLine,
                    readLinesFile(self.contentFile))))