首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

ubuntu/linux 服务器操作面板

操作系统 10.88KB 16 需要积分: 1
立即下载

资源介绍:

ubuntu/linux 服务器操作面板
from flask import Flask, request, redirect, url_for, render_template, send_from_directory, abort, flash from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.triggers.cron import CronTrigger from apscheduler.triggers.interval import IntervalTrigger import os import mimetypes from docx import Document import subprocess import logging import sys app = Flask(__name__) app.config['UPLOAD_FOLDER'] = 'uploads' app.config['MAX_CONTENT_PATH'] = 16 * 1024 * 1024 # 最大文件大小:16MB app.secret_key = 'supersecretkey' # 用于flash消息 # 确保上传文件夹存在 if not os.path.exists(app.config['UPLOAD_FOLDER']): os.makedirs(app.config['UPLOAD_FOLDER']) # 配置调度器 scheduler = BackgroundScheduler() scheduler.start() # 配置日志 log_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'scheduler.log') # 创建日志记录器 logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) # 设置为最低级别,以便所有级别的日志都可以被记录 # 创建文件处理器并指定编码 file_handler = logging.FileHandler(log_filename, encoding='utf-8') file_handler.setLevel(logging.DEBUG) # 创建日志格式器 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler.setFormatter(formatter) # 确保处理器唯一 if not logger.hasHandlers(): logger.addHandler(file_handler) def enable_logging(): logger.setLevel(logging.DEBUG) def disable_logging(): logger.setLevel(logging.CRITICAL) names={} @app.route('/') def index(): files = os.listdir(app.config['UPLOAD_FOLDER']) jobs = scheduler.get_jobs() return render_template('index.html', files=files, jobs=jobs,names=names) @app.route('/upload', methods=['GET', 'POST']) def upload_file(): if request.method == 'POST': file = request.files['file'] if file: filename = file.filename file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return redirect(url_for('index')) return render_template('upload.html') @app.route('/uploads/') def uploaded_file(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) @app.route('/delete/', methods=['POST']) def delete_file(filename): try: file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) if os.path.exists(file_path): os.remove(file_path) except: folder_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) if os.path.exists(folder_path) and os.path.isdir(folder_path): os.rmdir(folder_path) flash(f'文件夹 {filename} 已删除', 'success') else: flash(f'文件夹 {filename} 不存在', 'error') return redirect(url_for('index')) @app.route('/view/') def view_file(filename): file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) if not os.path.exists(file_path): abort(404) mimetype, _ = mimetypes.guess_type(file_path) if mimetype and mimetype.startswith('text') or filename.endswith('.log'): with open(file_path, 'r', encoding='utf-8') as f: content = f.read() return render_template('view_text.html', content=content, filename=filename) elif mimetype and mimetype.startswith('image'): return render_template('view_image.html', filename=filename) elif mimetype == 'application/pdf': return render_template('view_pdf.html', filename=filename) elif mimetype in ['application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']: if filename.endswith('.docx'): content = read_docx(file_path) elif filename.endswith('.doc'): content = convert_doc_to_text(file_path) return render_template('view_text.html', content=content, filename=filename) else: return redirect(url_for('uploaded_file', filename=filename)) @app.route('/command', methods=['GET', 'POST']) def command(): if request.method == 'POST': cmd = request.form['cmd'] try: result = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, universal_newlines=True) except subprocess.CalledProcessError as e: result = e.output return render_template('command.html', cmd=cmd, result=result) return render_template('command.html') @app.route('/schedule', methods=['GET', 'POST']) def schedule(): if request.method == 'POST': schedule_type = request.form['schedule_type'] script = request.form['script'] if schedule_type == 'interval': interval_seconds = int(request.form['interval_seconds']) job = scheduler.add_job(run_script, IntervalTrigger(seconds=interval_seconds), args=[script]) names[job.id]=(script) flash(f'Scheduled {script} to run every {interval_seconds} seconds.', 'success') elif schedule_type == 'cron': hour = request.form['hour'] minute = request.form['minute'] job = scheduler.add_job(run_script, CronTrigger(hour=hour, minute=minute), args=[script]) names[job.id]=(script) flash(f'Scheduled {script} to run at {hour}:{minute} every day.', 'success') return redirect(url_for('index')) scripts = [f for f in os.listdir(app.config['UPLOAD_FOLDER']) if f.endswith('.py')] return render_template('schedule.html', scripts=scripts) @app.route('/remove_job/', methods=['POST']) def remove_job(job_id): scheduler.remove_job(job_id) flash(f'Removed job {job_id}.', 'success') return redirect(url_for('index')) @app.route('/create_file', methods=['POST']) def create_file(): file_name = request.form['file_name'] if not file_name: flash('文件名不能为空', 'error') return redirect(url_for('index')) file_path = os.path.join(app.config['UPLOAD_FOLDER'], file_name) with open(file_path, 'w') as f: f.write('') flash(f'文件 {file_name} 已创建', 'success') return redirect(url_for('index')) @app.route('/create_folder', methods=['POST']) def create_folder(): folder_name = request.form['folder_name'] if not folder_name: flash('文件夹名不能为空', 'error') return redirect(url_for('index')) folder_path = os.path.join(app.config['UPLOAD_FOLDER'], folder_name) os.makedirs(folder_path, exist_ok=True) flash(f'文件夹 {folder_name} 已创建', 'success') return redirect(url_for('index')) def run_script(script): try: script_path = os.path.abspath(os.path.join(app.config['UPLOAD_FOLDER'], script)) result = subprocess.check_output(['python', script_path], stderr=subprocess.STDOUT, universal_newlines=True, encoding='utf-8', errors='ignore') enable_logging() logger.info(f"Script {script} executed successfully: {result}") disable_logging() except subprocess.CalledProcessError as e: enable_logging() logger.error(f"Error executing script {script}: {e.output}") disable_logging() except UnicodeDecodeError as e: enable_logging() logger.error(f"Unicode decoding error: {e}") disable_logging() except FileNotFoundError as e: enable_logging() logger.error(f"File not found: {e}") disable_logging() def read_docx(file_path): doc = Document(file_path) full_text = [] for para in doc.paragraphs: full_text.append(para.text) return '\n'.join(full_text) def convert_doc_to_text(file_path): # 使用libreoffice将.doc文件转换为.txt txt_path = file_path + '.txt' subprocess.run(['libreoff

资源文件列表:

服务器操作面板.zip 大约有18个文件
  1. main.py 10.41KB
  2. static/
  3. static/css/
  4. static/css/styles.css 581B
  5. static/js/
  6. static/js/scripts.js 443B
  7. templates/
  8. templates/browse.html 2.4KB
  9. templates/command.html 1011B
  10. templates/index.html 2KB
  11. templates/schedule.html 2.68KB
  12. templates/select_disk.html 627B
  13. templates/upload.html 1.56KB
  14. templates/view_image.html 693B
  15. templates/view_pdf.html 705B
  16. templates/view_text.html 644B
  17. uploads/
  18. uploads/scheduler.log
0评论
提交 加载更多评论
其他资源 python-crawler-python爬虫
学习 Python 爬虫需要掌握以下几个方面的知识:首先,需要了解 Python 基础知识,包括变量、数据类型、控制结构、函数、模块等。 Python 是一种易于学习的语言,对于初学者来说,学习 Python 基础知识并不困难。其次,需要了解 HTML 和 CSS,这是因为爬虫需要解析网页的结构和内容。 HTML 是用来描述网页结构的标记语言,而 CSS 是用来描述网页样式的语言。了解 HTML 和 CSS 可以帮助你更好地理解网页的结构和内容,从而更好地爬取数据。第三,需要了解爬虫的基本概念,包括爬虫的类型、爬虫的工作流程、爬虫的优缺点等。了解这些概念可以帮助你更好地理解爬虫的原理和实现。第四,需要选择合适的爬虫框架,Python 中有多种爬虫框架可供选择,如 Scrapy、BeautifulSoup、Requests 等。不同的框架有其特点和优缺点,选择合适的框架可以帮助你更好地实现爬虫。第五,需要了解爬虫的反爬虫机制,包括 User Agent、Cookies、验证码等。了解这些机制可以帮助你更好地避免被反爬虫。最后,需要实践爬虫,通过实践爬虫可以帮助你更好地掌握爬虫的知识和技能
NetORMSetup1030.zip
NetORMSetup1030.zip
qBittorrent Enhanced Edition v4.5.3.zip
qBittorrent Enhanced Edition v4.5.3.zip
111111111111111111111111111111111111111
1111111111111111111111111111111111111111
111111111111111111111111111111111111111 111111111111111111111111111111111111111 111111111111111111111111111111111111111
汇顶ble-long rang添加
汇顶ble-long rang添加
汇顶ble-long rang添加 汇顶ble-long rang添加 汇顶ble-long rang添加
ppt课件(6-9,16章).zip
ppt课件(6-9,16章).zip
ppt课件(6-9,16章).zip ppt课件(6-9,16章).zip ppt课件(6-9,16章).zip
Commons-io-2.11.0.jar
Apache Commons IO是Apache软件基金会的一个开源项目,它提供了一组用于处理输入/输出操作的Java工具类,旨在简化文件操作、流处理和其他与I/O相关的任务。commons-io-2.11.0.jar是这个项目在版本2.11.0时的jar文件,用于在Java应用程序中引入这些实用功能。 主要功能: 文件和目录操作工具:例如文件复制、移动、删除、查找等。 流处理工具:提供了易于使用的包装器和工具方法来简化对InputStreams, OutputStreams, Readers, Writers等的处理。 文本文件处理:包括读取整个文件为字符串、行操作、按行读写文件等。 IO过滤器:一系列的装饰器类,可以轻松地在现有流上添加缓冲、计数、关闭监听、线路结束符转换等功能。 目录遍历和文件查找工具。 字节顺序标记(BOM)处理。 大文件支持:部分方法设计用于处理大型文件,避免一次性加载到内存中。 应用场景: 任何需要进行文件或数据流操作的Java应用,包括但不限于文件上传下载、日志处理、数据导入导出、备份恢复等场景。
20225348张子贤.zip
20225348张子贤.zip