Exemple #1
0
def zip_new(system: str):
    if request.method == 'GET':
        if system.upper() not in ['ICP', 'PU5', 'ICX', 'XU5']:
            abort(404)
        command = "ssh -n {user}@{server} 'python {zip_script} {system}'".format(system=system, **config[system])
        stdin, stdout, stderr = ssh.exec_command(command)
        lines = stdout.readlines()
        content = list()
        for line in lines:
            json_data = json.loads(line)
            json_data["create"] = datetime.datetime.fromtimestamp(json_data["create"])
            content.append(json_data)
        return jsonify(content)
    elif request.method == 'POST':
        if system not in ['icx', 'xu5']:
            return json.dumps({'error': True}), 200, {'ContentType':'application/json'}
        filename = request.get_json().get('filename', None)
        current_app.logger.warning("user: {0}, resent: {1}".format(flask_login.current_user.id, filename))
        command = "ssh -n {user}@{server} 'cp {zip}/{filename} {uc4}/{zip_filename}'".format(filename=filename, zip_filename=filename.replace('.zin', '.zik').replace('zip', 'zik'), **config[system])
        _, _, stderr = ssh.exec_command(command)
        if stderr.readlines():
            return json.dumps({'success': True}), 200, {'ContentType':'application/json'}
        return json.dumps({'error': True}), 200, {'ContentType':'application/json'}
    else:
        abort(500)
    return 
Exemple #2
0
def get_file(for_download):
    local_tmp_dir = "/tmp/"
    __local_file = os.path.join(local_tmp_dir, os.path.basename(for_download))
    sftp = ssh.open_sftp()
    sftp.get(for_download, __local_file)
    sftp.close()
    ssh.exec_command('rm {0}'.format(for_download))
    return __local_file
def send():
    lekerdezo_form = SystemForm()
    content_form = EmailForm()
    if content_form.validate_on_submit():
        mail_to_send = {
            "subject":
            "Spool feldolgozas {0}".format(
                datetime.datetime.now().strftime('%Y.%m.%d %H:%M:%S')),
            "from":
            "*****@*****.**",
            "to":
            content_form.to.data,
            "cc":
            content_form.cc.data,
            "content":
            content_form.content.data
        }
        try:
            stdin, _, stderr = ssh.exec_command(
                config["nstrs2"]["email_to_everyone"])
            stdin.write(json.dumps(mail_to_send))
            stdin.write('\n')
            stdin.flush()
            error = stderr.readlines()
            flash("Kikuldve!")
            if error:
                return "<h1>Valami hiba tortent: {0}</h1>".format(
                    ', '.join(error))
        except Exception as e:
            return "<h1>Valami hiba tortent: {0}</h1>".format(e)
        return redirect("/bzmail")
    else:
        abort(404)
Exemple #4
0
def get_afp(system: str):
    if request.method == 'GET':
        if system not in config.sections():
            abort(404)
        command = "ssh -n {user}@{server} 'python {afp_scpipt} {system}'".format(system=system, **config[system.lower()])
        stdin, stdout, stderr = ssh.exec_command(command)
        return jsonify([json.loads(line) for line in stdout.readlines()])
    else:
        abort(500)
def bzget_content(system):
    command = "ssh -n {user}@{server} 'cd {sav}; find . -type f -newermt $(date -d \"now\" \"+%Y-%m-%d\") | cut -d \"_\" -f 3 | sort | uniq'".format(
        **config[system])
    stdin, stdout, stderr = ssh.exec_command(command)
    spools = [x.strip() for x in stdout.readlines() if len(x) > 3]
    error = stderr.readlines()
    if error:
        raise RunetimeError(', '.join(error))
    return "Spoolok a {0} rendszerben ({1}):\n{2}".format(
        system,
        datetime.datetime.now().strftime('%Y.%m.%d %H:%M:%S'),
        '\n'.join(spools))
Exemple #6
0
def get_file_content(folder):
    stdin, stdout, stderr = ssh.exec_command(last_file_in_folder(folder))
    fn = stdout.readline().strip('\n \t')
    if not fn:
        return "<h2>Nem talaltam meg a fajlt.</h2>"
    ftp = ssh.open_sftp()
    remote_file = ftp.open(fn)
    try:
        content = [line for line in remote_file]
    finally:
        remote_file.close()
        ftp.close()
    if not content:
        return "<h1>Ures volt a fajl</h2>"
    return '\n'.join(content)
Exemple #7
0
def download(system: str, filename: str) -> Response:
    if filename:
        command = "source {webserver_download} {system} {file}".format(system=system, file=os.path.basename(filename), **config['nstrs2'])
        stdin, stdout, stderr = ssh.exec_command(command)
        for_download = stdout.readlines()[-1].strip("\n")
        if for_download == "-1":
            return abort(404)
        
        __local_file = get_file(for_download)
        print(__local_file)
        
        @after_this_request
        def remove_everything(response):
          try:
              os.remove(__local_file)
          except Exception as error:
              print("Valami hiba volt a fajl torlesenel: {0}".format(__local_file))
          return response

        return send_file(__local_file, 
                        attachment_filename=os.path.basename(__local_file), 
                        as_attachment=True, mimetype='application/zip'
                        )
Exemple #8
0
 def ask_running(system_name):
     stdin, stdout, stderr = ssh.exec_command(
         "ssh {user}@{server} 'ps -ef | grep \"[S]PG\"'".format(
             **config[system_name.lower()]))
     return True if len(stdout.readlines()) else False