Browse Source

first commit

xiaokui 11 months ago
commit
d46dc22763
5 changed files with 135 additions and 0 deletions
  1. 14 0
      Dockerfile
  2. 39 0
      app.py
  3. 4 0
      data.json
  4. 1 0
      static/data.json
  5. 77 0
      templates/index.html

+ 14 - 0
Dockerfile

@@ -0,0 +1,14 @@
+# 使用官方 Python 镜像作为基础镜像
+FROM python:3.8
+
+# 设置工作目录
+WORKDIR /app
+ADD * .
+# 安装 Flask 应用所需的依赖
+RUN pip install --no-cache-dir flask flask_apscheduler requests
+
+# 暴露 Flask 应用运行的端口
+EXPOSE 8000
+
+# 启动 Flask 应用
+CMD ["python", "app.py"]

+ 39 - 0
app.py

@@ -0,0 +1,39 @@
+import json
+import requests
+from flask import Flask,render_template
+from flask_apscheduler import APScheduler
+
+app = Flask(__name__, template_folder="templates")
+app.jinja_env.variable_start_string = '[['
+app.jinja_env.variable_end_string = ']]'
+
+
+
+urls = []
+with open('data.json',encoding="utf-8") as f:
+    urls = json.loads(f.read())
+
+# 实例化 APScheduler
+scheduler = APScheduler()
+
+@scheduler.task('interval', id='ping', args=(),seconds=10)
+def ping():  # 运行的定时任务的函数
+    result = []
+    for i in urls:
+        name = i['name']
+        url = i['url']
+        r = requests.get(url,timeout=3)
+        result.append({'url':url,'status_code':r.status_code,'name':name})
+    with open("static\data.json",'w+',encoding="utf-8") as f:
+        f.write(json.dumps(result))
+
+@app.route("/")
+def index():
+    return render_template('index.html')
+
+
+if __name__ == '__main__':
+    
+    scheduler.start()  # 启动任务列表
+    app.debug=True
+    app.run(host='0.0.0.0',port= 8000)  # 启动 flask

+ 4 - 0
data.json

@@ -0,0 +1,4 @@
+[
+    {"url":"http://xiaokv.com/","name":"Blog"},
+    {"url":"http://findvuln.com/","name":"攻击展示"}
+]

+ 1 - 0
static/data.json

@@ -0,0 +1 @@
+[{"url": "http://xiaokv.com/", "status_code": 200, "name": "Blog"}, {"url": "http://findvuln.com/", "status_code": 200, "name": "\u653b\u51fb\u5c55\u793a"}]

+ 77 - 0
templates/index.html

@@ -0,0 +1,77 @@
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>小葵工具站</title>
+        <!-- 引入样式 -->
+        <link
+        rel="stylesheet"
+        href="https://unpkg.com/element3/lib/theme-chalk/index.css"
+        />
+        <!-- 引入Axios -->
+        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
+    </head>
+    <body>
+        <div id="app">
+        <div v-for="i in data" :key="i" class="text item">
+            <el-card class="box-card">
+              <template v-slot:header>
+                <div class="clearfix">
+                  <span>{{ i.name }}</span>
+                  <el-button style="float: right; padding: 3px 0" type="text" ><a :href="i.url">访问</a></el-button>
+                </div>
+              </template>
+              <div v-if="i.status_code == 200"><el-button type="success" :loading="true">运行中</el-button></div>
+              <div v-else><el-button type="danger" :loading="true">错误</el-button></div>
+            </el-card>
+        </div>  
+        </div>
+    </body>
+    <!-- 引入组件库 -->
+    <script src="https://unpkg.com/vue"></script>
+    <script src="https://unpkg.com/element3"></script>
+    <script>
+        Vue.createApp({
+          setup() {
+            const { ref } = Vue;
+            const data = ref([]);
+
+            // 使用Axios发起请求
+            const getData = async () =>{ 
+                try {
+                    const response = await axios.get('/static/data.json');
+                    data.value = response.data;
+                } catch (error) {
+                    console.error(error);
+                }
+            };
+            getData();
+            return {
+                data
+                
+            };
+          }
+        }).use(Element3).mount('#app')
+    </script>
+    <style>
+    .text {
+        font-size: 14px;
+    }
+
+    .item {
+        margin-bottom: 18px;
+    }
+
+    .clearfix:before,
+    .clearfix:after {
+        display: table;
+        content: '';
+    }
+    .clearfix:after {
+        clear: both;
+    }
+
+    .box-card {
+        width: 480px;
+    }
+    </style>
+</html>