def update_backend(configuration, update_dict): """Update backend by calling imagepreview.py refresh through fakecgi""" status = True logger = configuration.logger logger.info('==============================================') logger.info('Updating backend') logger.info('==============================================') # Refresh previews logger.info('----------------------------------------------') logger.info('Updating previews') if status: for key in update_dict.keys(): vgrid = update_dict[key]['vgrid'] vgridpath = update_dict[key]['vgridpath'] run_as = update_dict[key]['run_as'] logger.info('----------------------------------------------') logger.info('Imagesettings: %s' % str(key)) logger.info('vgrid: %s' % vgrid) logger.info('vgridpath: %s' % vgridpath) logger.info('run_as: %s' % run_as) if len(run_as.keys()) == 1: command = [ 'python', '%s/fakecgi.py' % MIG_CGI_BIN, '%s/imagepreview.py' % MIG_CGI_BIN, 'POST', 'action=refresh;path=%s;output_format=text' % vgridpath, '%s' % run_as.keys()[0], 'true', ] logger.info(command) logger.info( '*****************************************************') subprocess_call(command, stdin=open('/dev/null', 'r')) logger.info( '*****************************************************') return status
# # --- END_HEADER --- # """Grep for a regular expression in all code files""" from __future__ import print_function from __future__ import absolute_import import glob import os import sys from mig.shared.projcode import code_root, code_files from mig.shared.safeeval import subprocess_call if '__main__' == __name__: if len(sys.argv) < 2: print('Usage: %s PATTERN' % sys.argv[0]) print('Grep for PATTERN in all code files') sys.exit(1) mig_code_base = os.path.dirname(sys.argv[0]) pattern = sys.argv[1] expanded_paths = [] for code_path in code_files: path_pattern = os.path.join(mig_code_base, code_root, code_path) expanded_paths += glob.glob(os.path.normpath(path_pattern)) command_list = ["grep", "-E", "%s" % pattern] + expanded_paths # NOTE: we use command list to avoid shell requirement subprocess_call(command_list)
def remove_triggers(configuration, vgrids_dict): """Remove old triggers""" status = True logger = configuration.logger logger.info('==============================================') logger.info('Removing triggers') logger.info('==============================================') triggers_removed = {} for key in vgrids_dict.keys(): vgrid = vgrids_dict[key]['vgrid'] vgridpath = vgrids_dict[key]['vgridpath'] logger.info('----------------------------------------------') logger.info('Imagesettings: %s' % str(key)) logger.info('vgrid: %s' % vgrid) logger.info('vgridpath: %s' % vgridpath) logger.info('----------------------------------------------') if vgrid not in triggers_removed: triggers_removed[vgrid] = [] for trigger in vgrids_dict[key]['triggers']: rule_id = trigger['rule_id'] run_as = trigger['run_as'] logger.info('Removing trigger:') logger.info("rule_id: '%s'" % rule_id) logger.info("run_as: '%s'" % run_as) # Skip image setting triggers that were previously removed, # System triggers such as: # 'system_imagesettings_meta_created' and # 'system_imagesettings_dir_deleted' are represented # are present for each settings file in vgrids_dict if rule_id in triggers_removed[vgrid]: logger.info( "Skipping trigger '%s' previously removed from vgrid: '%s'" % (rule_id, vgrid)) else: command = [ 'python', '%s/fakecgi.py' % MIG_CGI_BIN, '%s/rmvgridtrigger.py' % MIG_CGI_BIN, 'POST', 'rule_id=%s;vgrid_name=%s;output_format=text' % (rule_id, vgrid), '%s' % run_as, 'true', ] logger.info(command) logger.info( '*****************************************************') subprocess_call(command, stdin=open('/dev/null', 'r')) logger.info( '*****************************************************') triggers_removed[vgrid].append(rule_id) return status
'SSL_CLIENT_S_DN_L': run_as_user['locality'], 'SSL_CLIENT_S_DN_CN': run_as_user['full_name'], 'SSL_CLIENT_I_DN': '/C=DK/ST=Denmark/O=IMADA/OU=MiG/CN=MiGCA', 'SSL_CLIENT_I_DN_C': 'DK', 'SSL_CLIENT_I_DN_ST': 'Denmark', 'SSL_CLIENT_I_DN_O': 'IMADA', 'SSL_CLIENT_I_DN_OU': 'MiGCA', 'SSL_CLIENT_I_DN_CN': 'MiGCA', } extra_environment['SCRIPT_FILENAME'] = script extra_environment['QUERY_STRING'] = query extra_environment['REQUEST_URI'] = '%s%s' % (script, query) extra_environment['SCRIPT_URL'] = script extra_environment['SCRIPT_NAME'] = script extra_environment['SCRIPT_URI'] = 'https://localhost/cgi-bin/%s'\ % script if remote_user: extra_environment['REMOTE_USER'] = remote_user if remote_addr: extra_environment['REMOTE_ADDR'] = remote_addr os.environ.update(extra_environment) if not os.path.isabs(script): script = os.path.abspath(script) print("Running %s with environment:\n%s" % (script, os.environ)) subprocess_call(script, stdin=open('/dev/null', 'r'))