Exemplo n.º 1
0
def test():
    testuser = user('enemali')
    try:
        # user regex to test all the results are ip
        assert testuser.ipList.index('127.0.0.1') >=0
        assert testuser.ipList.index('10.177.135.15') >= 0
        assert testuser.ipList.index('10.177.135.2') >= 0
        assert testuser.ipList.index('10.177.236.146  ') >= 0
        assert testuser.ipList.index('10.177.152.33') >= 0
        assert testuser.ipList.index('10.177.135.1') >= 0
        assert testuser.ipList.index('10.177.135.16') >= 0
        print('user.ipList ...... pass')
    except:
        print('user.ipList ...... failed')

    testuser = user('ejiaqxi')
    try:
        assert testuser.isEmergency('ejiaqxi')
        print('user.isEmergency ...... pass')
    except:
        print('userisEmergency ...... failed')
Exemplo n.º 2
0
    def main(self):
        logger = uacLog().getLog()
        disable_file_system_redirection().__enter__()
        command = 'c:\\windows\\system32\\query user'
        currentPath = sys.path[0]
        config = configparser.RawConfigParser()
        config.read(os.path.join(currentPath,'uac.conf'))
        logger.info('UAC system start.')
        currentList = []
        while True:

            result = os.popen(command).readlines()
            newList = []
            for  line in result:
                name = str(line[0:9]).replace(' ','')
                if name != 'USERNAME':
                    newList.append(name)
            diff=list(set(newList).difference(set(currentList)))
            if diff == []:
                currentList = newList
            else:
                if len(diff) == 1:
                    username = diff[0]
                    logger.info('User login:'******'Emergency mode: ' + username)
                        else:
                            firewall.activate(username,loginuser.ipList)
                            logger.info('Set firewall for: ' + username)
                    except :
                        logger.critical('Database connection fail.')
                        firewall = winFirewall()
                        firewall.allfree()
                        logger.critical('Allow all IP.')
                    currentList = newList
                else:
                    currentList = newList
                    logger.critical('User login error:')
                    logger.critical('User login befor:')
                    for name in currentList:
                        logger.critical(name)
                    logger.critical('User login after:')
                    for name in newList:
                        logger.critical(name)