コード例 #1
0
def fix(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*SSLInsecureRenegotiation .+',
                     'SSLInsecureRenegotiation off\n',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #2
0
def fix_directive(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*MaxKeepAliveRequests .+',
                     'MaxKeepAliveRequests 100\n',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #3
0
def fix_directive(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*LimitRequestline .+',
                     'LimitRequestline 512',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #4
0
def exist_file_in_out(ch, props):
    """
    функция проверяет наличие файлов от внутренней и внешней базы,
    создаем файл с общим ок от внутренней и внешней базы,
    отправляем итоговый файл комитету,
    после чего удаляем созданные файлы in.json, ex.json
    :param ch: канал, который передаем от callback-функции
    """
    if os.path.isfile('./in_{}.json'.format(props.correlation_id)) and \
            os.path.isfile('./ex_{}.json'.format(props.correlation_id)):

        with open('in_{}.json'.format(props.correlation_id), "r") as read_file:
            in_file = helper.unpack_file(read_file)
            in_file.update({'internal': 'ok', 'external': 'ok'})

            helper.write_file(
                'response_from_mvd_{}.json'.format(props.correlation_id),
                in_file)

        ch.basic_publish(exchange='direct_mid_mvd',
                         routing_key=routing_key_for_mid_mvd,
                         properties=pika.BasicProperties(
                             correlation_id=props.correlation_id),
                         body='response_from_mvd_{}.json'.format(
                             props.correlation_id))
        os.remove('./in_{}.json'.format(props.correlation_id))
        os.remove('./ex_{}.json'.format(props.correlation_id))
コード例 #5
0
def fix_directive(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*KeepAlive .+',
                     'KeepAlive On\n',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #6
0
def init_config_file():
    vhost_log = helper.read_file(
        '/etc/apache2/conf-available/other-vhosts-access-log.conf')
    security = helper.read_file('/etc/apache2/conf-available/security.conf')
    apache2_conf = helper.read_file('/etc/apache2/apache211.conf')
    apache2_conf_new = apache2_conf + security + vhost_log
    helper.write_file('/etc/apache2/apache211.conf', apache2_conf_new)
コード例 #7
0
def set_ErrorLog_config(path):
    result = helper.read_file(path)
    result = re.sub(r'^\s*ErrorLog (.+)',
                    'ErrorLog ${APACHE_LOG_DIR}/error.log\n',
                    result,
                    flags=re.MULTILINE)
    helper.write_file(path, result)
コード例 #8
0
ファイル: disable_sslv.py プロジェクト: hungvuong97/firewall
def fix_directive(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*SSLProtocol\s+.+',
                     '\t\tSSLProtocol TLSv1.1 TLS1.2',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #9
0
def set_logdir_config():
    result = helper.read_file(helper.envvars)
    result = re.sub(r'^\s*export APACHE_LOG_DIR=(.+)',
                    'export APACHE_LOG_DIR=/var/log/apache2$SUFFIX',
                    result,
                    flags=re.MULTILINE)
    helper.write_file(helper.envvars, result)
コード例 #10
0
def set_LogLevel_config(path):
    result = helper.read_file(path)
    result = re.sub(r'^\s*LogLevel (.+)',
                    'LogLevel notice core:info\n',
                    result,
                    flags=re.MULTILINE)
    helper.write_file(path, result)
コード例 #11
0
def set_directive(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*ServerSignature (?:.+)',
                     'ServerSignature Off\n',
                     result,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #12
0
ファイル: enable_hsts.py プロジェクト: hungvuong97/firewall
def fix_directory(path):
    result = helper.read_file(path)
    replace = re.sub(
        r'^\s*Header .+',
        '\t\tHeader always set Strict-Transport-Security "max-age=600"',
        result,
        flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #13
0
def main():
    args = get_args()
    files = glob(os.path.join(args.csv_folder, '*.csv'))
    for file in files:
        new_file = os.path.join(args.txt_folder, helper.get_filename(file, False) + '.anki.txt')
        rows = helper.get_csv(file)
        lines = [helper.csv_line_to_txt(x) for x in rows]
        helper.write_file(new_file, '\n\n'.join(lines))
コード例 #14
0
 def write_image_to_folder(self, filename, destination, date, img_file_orig):
     """ Writes image to given destination folder """
     if len(destination) > 0:
         helper.write_file(filename, destination + '/' +
                           date + '/', img_file_orig)
     else:
         helper.write_file(filename, date + '/', img_file_orig)
     super.write_image_to_folder(filename, destination, date, img_file_orig)
コード例 #15
0
def main():
    args = get_args()
    files = glob(os.path.join(args.csv_folder, '*.csv'))
    for file in files:
        new_file = os.path.join(args.txt_folder,
                                helper.get_filename(file, False) + '.anki.txt')
        rows = helper.get_csv(file)
        lines = [helper.csv_line_to_txt(x) for x in rows]
        helper.write_file(new_file, '\n\n'.join(lines))
コード例 #16
0
 def write_image_to_folder(self, filename, destination, date,
                           img_file_orig):
     """ Writes image to given destination folder """
     if len(destination) > 0:
         helper.write_file(filename, destination + '/' + date + '/',
                           img_file_orig)
     else:
         helper.write_file(filename, date + '/', img_file_orig)
     super.write_image_to_folder(filename, destination, date, img_file_orig)
コード例 #17
0
ファイル: disable_sslv.py プロジェクト: hungvuong97/firewall
def add_directive(ident, path, content):
    result = helper.read_file(path)
    replace = content + '\tSSLProtocol TLSv1.1 TLS1.2\n'
    replace = re.sub(r'[^#]<VirtualHost ' + ident + r'>.*?<\/VirtualHost>',
                     '\t<VirtualHost ' + ident + '>' + replace +
                     '\t</VirtualHost>',
                     result,
                     flags=re.DOTALL)
    helper.write_file(path, replace)
コード例 #18
0
def fix(path):
    result = helper.read_file(path)
    obj = re.findall(
        r'(^\s*Header always append X-Frame-Options SAMEORIGIN|Header always append X-Frame-Options DENY)',
        result, re.MULTILINE)
    if len(obj) == 0:
        result = helper.read_file(path)
        replace = result + 'Header always append X-Frame-Options SAMEORIGIN\n'
        helper.write_file(path, replace)
コード例 #19
0
def add_allowoverride(path):
    result = helper.read_file(path)
    obj = re.compile(r'<Directory \/>(.*?)<\/Directory>',
                     re.DOTALL).findall(result)
    replace = obj[0] + '\tAllowOverride None\n'
    replace1 = re.sub(r'<Directory \/>(.*?)<\/Directory>',
                      '\n<Directory />' + replace + '</Directory>',
                      result,
                      flags=re.DOTALL)
    helper.write_file(path, replace1)
コード例 #20
0
def fix(path):
    result = helper.read_file(path)
    obj = re.compile(r'^\s*Options Includes\s*?\n',
                     re.MULTILINE).findall(result)
    if len(obj) != 0:
        replace = re.sub(r'^\s*Options Includes\s*?\n',
                         '\tOptions None\n',
                         result,
                         flags=re.MULTILINE)
        helper.write_file(path, replace)
コード例 #21
0
def add_require_directive(path):
    result = helper.read_file(path)
    obj = re.compile(r'<Directory \/>(.*?)<\/Directory>',
                     re.DOTALL).findall(result)
    replace = obj[0] + '\tRequire all denied\n'
    replace1 = re.sub(r'<Directory \/>(.*?)<\/Directory>',
                      '\n<Directory />' + replace + '</Directory>',
                      result,
                      flags=re.DOTALL)
    helper.write_file(path, replace1)
コード例 #22
0
def add_options(path):
    result = helper.read_file(path)
    obj = re.compile(r'[^#]<Directory \/>(.*?)<\/Directory>',
                     re.DOTALL).findall(result)
    replace = obj[0] + '\n\tOptions None\n'
    replace1 = re.sub(r'[^#]<Directory \/>(.*?)<\/Directory>',
                      '\n<Directory />' + replace + '</Directory>',
                      result,
                      flags=re.DOTALL)
    helper.write_file(path, replace1)
コード例 #23
0
    def place_image_in_folder(self, sort_option, img_file_orig, file_info):
        data = file_info.data
        tag_keys = list(data.keys())
        tag_keys.sort()

        key = helper.get_existing_exif_key(tag_keys)
        ext = file_info.filename.split('.')[1]
        filename = helper.create_filename_for_file(sort_option, ext, data[key].printable)

        helper.write_file(filename, file_info.destination+"/", img_file_orig)
コード例 #24
0
ファイル: sail2pvs.py プロジェクト: ssrg-vt/sail2pvs
def patch_lem_src(name):
    patch_info = data['patch']
    patch_path = os.path.join(helper.dir_path,
                              os.path.join(patch_info['patch_path'], name))
    patch_data = patch_path_to_absolute(patch_path + '.patch')
    abs_patch_path = patch_path + '_abs.patch'
    helper.write_file(abs_patch_path, patch_data)
    cmd = 'patch -p0 -d / < ' + abs_patch_path + '; '
    cmd += 'rm ' + abs_patch_path + '; '
    return cmd
コード例 #25
0
    def place_image_in_folder(self, sort_option, img_file_orig, file_info):
        data = file_info.data
        tag_keys = list(data.keys())
        tag_keys.sort()

        key = helper.get_existing_exif_key(tag_keys)
        ext = file_info.filename.split('.')[1]
        filename = helper.create_filename_for_file(sort_option, ext,
                                                   data[key].printable)

        helper.write_file(filename, file_info.destination + "/", img_file_orig)
コード例 #26
0
def fix_directory(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*SSLUseStapling .+',
                     '\t\tSSLUseStapling On',
                     result,
                     flags=re.MULTILINE)
    replace = re.sub(r'^\s*SSLStaplingCache .+',
                     '\t\tSSLStaplingCache dc:UNIX:logs/ssl_staple_socket',
                     replace,
                     flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #27
0
def fix_directory(path):
    result = helper.read_file(path)
    replace = re.sub(r'^\s*SSLHonorCipherOrder .+',
                     '\t\tSSLHonorCipherOrder On',
                     result,
                     flags=re.MULTILINE)
    replace = re.sub(
        r'^\s*SSLCipherSuite .+',
        '\t\tSSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW:!SSLv2:!SSLv3:!MD5:!RC4',
        replace,
        flags=re.MULTILINE)
    helper.write_file(path, replace)
コード例 #28
0
def add_ErrorLog_config(path):
    if path == helper.config_path:
        result = helper.read_file(path)
        result = re.sub(r'^\s*ErrorLog (.+)', '', result, flags=re.MULTILINE)
        replace = result + 'ErrorLog ${APACHE_LOG_DIR}/error.log\n'
        helper.write_file(path, replace)
    else:
        result = helper.read_file(path)
        result = re.sub(r'^\s*ErrorLog (.+)', '', result, flags=re.MULTILINE)
        result = re.sub(r'^\s*<\/VirtualHost>', '', result, flags=re.MULTILINE)
        replace = result + '\tErrorLog ${APACHE_LOG_DIR}/error.log\n</VirtualHost>\n'
        helper.write_file(path, replace)
コード例 #29
0
ファイル: enable_hsts.py プロジェクト: hungvuong97/firewall
def add_directive(ident, path, direct):
    result = helper.read_file(path)
    vtconf = re.findall(
        r'[^#]<VirtualHost ' + ident + r'>(.*?)<\/VirtualHost>', result,
        re.DOTALL)
    replace = vtconf[0] + direct
    replace = re.sub(r'[^#]<VirtualHost ' + ident + r'>.*?<\/VirtualHost>',
                     '\t<VirtualHost ' + ident + '>' + replace +
                     '\t</VirtualHost>',
                     result,
                     flags=re.DOTALL)
    helper.write_file(path, replace)
コード例 #30
0
def bank_request(ch, method, props, body):
    """
    callback-функция для приема ответов от банка,
    пакуем данные файл
    """
    dict_bank_resp = helper.unpack_str(body)

    helper.write_file("data_from_bank_{}.json".format(props.correlation_id),
                      {'transaction_id': dict_bank_resp['transaction_id'],
                       'person_id': props.correlation_id})

    ch.basic_ack(delivery_tag=method.delivery_tag)
コード例 #31
0
def fix_require_value(path):
    result = helper.read_file(path)
    obj = re.compile(r'<Directory \/>(.*?)<\/Directory>',
                     re.DOTALL).findall(result)
    replace = re.sub(r'^\s*Require (.*?)\n',
                     '\tRequire all denied\n',
                     obj[0],
                     flags=re.MULTILINE)
    replace1 = re.sub(r'<Directory \/>(.*?)<\/Directory>',
                      '\n<Directory />' + replace + '</Directory>',
                      result,
                      flags=re.DOTALL)
    helper.write_file(path, replace1)
コード例 #32
0
def gen_rm_vote_0(username):
    message = f"Deleting all current votes for {username}...\n"
    voted_fm = open_file("FM" ".train")
    voted_tn = open_file("TN" ".train")
    for votes, event in zip([voted_fm, voted_tn], ["FM", "TN"]):
        if username in [item['who'] for item in votes]:
            old_vote = next(item for item in votes if item["who"] == username)
            message += f"{username} has taken back their vote for {old_vote['event']} ({old_vote['where']}).\n"
            votes.remove(old_vote)
            write_file(f"{event}.train", votes)
    if message == f"Deleting all current votes for {username}...\n":
        message = "You have no vote to delete."
    return message
コード例 #33
0
def set_allowoverride(path):
    result = helper.read_file(path)
    obj = re.compile(r'<Directory \/>(.*?)<\/Directory>',
                     re.DOTALL).findall(result)
    replace = re.sub(r'^\s*AllowOverride (?:.*?)\n',
                     '\tAllowOverride None\n',
                     obj[0],
                     flags=re.MULTILINE)
    replace1 = re.sub(r'<Directory \/>(.*?)<\/Directory>',
                      '\n<Directory />' + replace + '</Directory>',
                      result,
                      flags=re.DOTALL)
    helper.write_file(path, replace1)
コード例 #34
0
    def process_file(self, file_info, sort_option):
        """
            Look at the modified time
        """
        video_orig_writeback = open(
            str(file_info.current_folder + '/' + file_info.filename), 'rb')

        video_file_orig = video_orig_writeback.read()
        video_orig_writeback.close()

        time = os.path.getmtime(
            file_info.current_folder + "\\" + file_info.filename)
        date = datetime.datetime.fromtimestamp(
            time).strftime('%Y-%m-%d %H:%M:%S')
        file_name = helper.create_filename_for_file(
            sort_option, MP4[1:], date)
        helper.write_file(file_name, file_info.destination + "\\", video_file_orig)
        self.incr_writes()
コード例 #35
0
ファイル: gofs-clinet.py プロジェクト: raksha0704/goffish
	
		cmd_arg = dict((k, v) for k, v in cmd_dic.items() if v != None)

	graph_data = Graph(**cmd_args)


	return (args.option, conf, graph_data)



(option, conf, graph_data) = parse_arguments()

gofs_config_string = gen_gofs_config(conf.head_node, conf.machine_list)
gofs_config_path = conf.head_node.path.bin + '/gofs-bin/conf/gofs.config'
helper.write_file(gofs_config_path , gofs_config_string)


list_xml_path = conf.head_node.path.bin + '/gofs-bin/conf/list.xml'

if option == 'LOAD':
	list_xml_string = gen_list_xml(conf.head_node, graph_data)
	helper.write_file(list_xml_path, list_xml_string)


if option == 'START':
	start(conf.head_node, graph_data.graph_index_file, 9998)
elif option == 'FORMAT':
	format(conf.head_node)
elif option == 'LOAD':
	load(conf.head_node, graph_data, list_xml_path, conf.machine_list)