Initial import from running container + overrides
This commit is contained in:
commit
d9864f0cfd
27 files changed
+891
No files matched your search
@@ -0,0 +1,6 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
venv/
|
||||
.env
|
||||
.env.*
|
||||
instance/
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
FROM python:3.11-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl dumb-init && rm -rf /var/lib/apt/lists/*
|
||||
# docker cli + compose plugin
|
||||
RUN mkdir -p /usr/lib/docker/cli-plugins && curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-26.1.4.tgz | tar xz -C /usr/local/bin --strip-components=1 docker/docker && curl -fsSL https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64 -o /usr/lib/docker/cli-plugins/docker-compose && chmod +x /usr/lib/docker/cli-plugins/docker-compose
|
||||
WORKDIR /opt/ihm
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt gunicorn
|
||||
COPY . .
|
||||
ENV FLASK_ENV=production
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/usr/bin/dumb-init","--"]
|
||||
CMD ["gunicorn","-b","0.0.0.0:8080","app:app","--workers","2","--threads","4","--timeout","300"]
|
||||
@@ -0,0 +1,23 @@
|
||||
# IHM Playbooks (Flask) — v2
|
||||
|
||||
- **Admin** `/admin` : upload de playbooks par *domaine* (`.yml/.yaml`).
|
||||
- **User** `/` : liste triable et page pour **lancer** un playbook (extra-vars, check, logs temps réel).
|
||||
|
||||
## Build & Run (Docker)
|
||||
```bash
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
# IHM sur http://<srv>:15080
|
||||
```
|
||||
|
||||
## Variables importantes
|
||||
- `ADMIN_TOKEN` : jeton d'upload (POC).
|
||||
- `PLAYBOOK_ROOT` : répertoire host qui contient vos playbooks (monté dans le conteneur sous /runner/project).
|
||||
- `DOCKER_COMPOSE_FILE` / `ANSIBLE_SERVICE` : pour `docker compose exec ansible ...`.
|
||||
- `ANSIBLE_CONFIG_IN_CONTAINER` : ex `/runner/ansible.cfg`.
|
||||
|
||||
## Reverse proxy
|
||||
Exposez via Nginx RP avec votre FQDN (TLS LE), proxy_pass vers `srv:15080`.
|
||||
|
||||
## Sécurité (POC)
|
||||
Prévoyez une auth vraie (SSO/LDAP) si utilisation client.
|
||||
@@ -0,0 +1,159 @@
|
||||
import os, subprocess, shlex, uuid, time, hashlib, pathlib, json
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, request, redirect, url_for, flash, Response, jsonify, send_from_directory
|
||||
from werkzeug.utils import secure_filename
|
||||
import yaml
|
||||
import config
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = config.SECRET_KEY
|
||||
|
||||
JOBS = {}
|
||||
|
||||
def _human(n):
|
||||
for u in ['B','KB','MB','GB','TB']:
|
||||
if n < 1024: return f"{n:.0f} {u}"
|
||||
n/=1024
|
||||
return f"{n:.0f} PB"
|
||||
|
||||
def _sha256(fp, chunk=8192):
|
||||
h = hashlib.sha256()
|
||||
with open(fp, 'rb') as f:
|
||||
while True:
|
||||
b = f.read(chunk)
|
||||
if not b: break
|
||||
h.update(b)
|
||||
return h.hexdigest()
|
||||
|
||||
def _scan_playbooks(root, q=None, sort='mtime'):
|
||||
p = pathlib.Path(root)
|
||||
if not p.exists():
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
rows = []
|
||||
for file in p.rglob("*"):
|
||||
if file.is_file() and file.suffix.lower() in config.ALLOWED_EXT:
|
||||
rel = file.relative_to(p)
|
||||
parts = rel.parts
|
||||
if len(parts) < 2: # expect domain/filename
|
||||
continue
|
||||
domain = parts[0]
|
||||
name = parts[-1]
|
||||
if q and q.lower() not in name.lower():
|
||||
continue
|
||||
stat = file.stat()
|
||||
rows.append({
|
||||
"domain": domain,
|
||||
"name": name,
|
||||
"path": str(file),
|
||||
"rel_path": str(rel),
|
||||
"size": stat.st_size,
|
||||
"size_h": _human(stat.st_size),
|
||||
"mtime": stat.st_mtime,
|
||||
"mtime_h": datetime.fromtimestamp(stat.st_mtime).strftime("%Y-%m-%d %H:%M"),
|
||||
"sha256": _sha256(str(file))[:64],
|
||||
})
|
||||
key = {"mtime": lambda x: -x["mtime"], "name": lambda x: x["name"].lower(), "size": lambda x: -x["size"]}.get(sort, lambda x: -x["mtime"])
|
||||
grouped = {}
|
||||
for row in sorted(rows, key=key):
|
||||
grouped.setdefault(row["domain"], []).append(row)
|
||||
return grouped
|
||||
|
||||
@app.route("/")
|
||||
def user_home():
|
||||
q = request.args.get("q","").strip() or None
|
||||
sort = request.args.get("sort","mtime")
|
||||
grouped = _scan_playbooks(config.PLAYBOOK_ROOT, q=q, sort=sort)
|
||||
return render_template("user.html", grouped=grouped, q=q, sort=sort, title="Playbooks")
|
||||
|
||||
@app.route("/admin", methods=["GET","POST"])
|
||||
def admin_home():
|
||||
if request.method == "POST":
|
||||
token = request.form.get("token","")
|
||||
if config.REQUIRE_ADMIN_TOKEN and token != config.ADMIN_TOKEN:
|
||||
flash("Token d'administration invalide.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
domain = (request.form.get("domain") or "").strip().lower().replace(" ","-")
|
||||
f = request.files.get("file")
|
||||
if not domain or not f:
|
||||
flash("Domaine et fichier requis.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
ext = os.path.splitext(f.filename)[1].lower()
|
||||
if ext not in config.ALLOWED_EXT:
|
||||
flash("Extension non autorisée. Utilise .yml ou .yaml.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
try:
|
||||
yaml.safe_load(f.read().decode("utf-8"))
|
||||
f.seek(0)
|
||||
except Exception as e:
|
||||
flash(f"YAML invalide: {e}", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
dest_dir = os.path.join(config.PLAYBOOK_ROOT, domain)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
fname = secure_filename(f.filename)
|
||||
path = os.path.join(dest_dir, fname)
|
||||
f.save(path)
|
||||
flash(f"Playbook chargé: {domain}/{fname}", "ok")
|
||||
return redirect(url_for("admin_home"))
|
||||
grouped = _scan_playbooks(config.PLAYBOOK_ROOT)
|
||||
return render_template("admin.html", grouped=grouped, title="Admin", require_token=config.REQUIRE_ADMIN_TOKEN)
|
||||
|
||||
@app.route("/run/<domain>/<name>")
|
||||
def user_run(domain, name):
|
||||
rel = f"{domain}/{name}"
|
||||
full = os.path.join(config.PLAYBOOK_ROOT, rel)
|
||||
if not os.path.isfile(full):
|
||||
flash("Playbook introuvable.", "error")
|
||||
return redirect(url_for("user_home"))
|
||||
return render_template("run.html", domain=domain, name=name, rel_path=rel, title="Lancer")
|
||||
|
||||
@app.post("/api/run/<domain>/<name>")
|
||||
def api_run_start(domain, name):
|
||||
rel = f"{domain}/{name}"
|
||||
full = os.path.join(config.PLAYBOOK_ROOT, rel)
|
||||
if not os.path.isfile(full):
|
||||
return jsonify({"error":"not found"}), 404
|
||||
extra_vars = (request.form.get("extra_vars") or "").strip()
|
||||
check = request.form.get("check") == "yes"
|
||||
vvv = request.form.get("vvv") or "-vvv"
|
||||
if config.RUN_MODE == "docker":
|
||||
playbook_in_container = f"/runner/project/{rel}"
|
||||
shell = f'ANSIBLE_CONFIG={shlex.quote(config.ANSIBLE_CONFIG_IN_CONTAINER)} ansible-playbook {shlex.quote(playbook_in_container)} {vvv}'
|
||||
if check: shell += " --check"
|
||||
if extra_vars:
|
||||
shell += f" --extra-vars {shlex.quote(extra_vars)}"
|
||||
cmd = ["docker","compose","-f",config.DOCKER_COMPOSE_FILE,"exec","-T",config.ANSIBLE_SERVICE,"bash","-lc", shell]
|
||||
else:
|
||||
shell = f'ansible-playbook {shlex.quote(full)} {vvv}'
|
||||
if check: shell += " --check"
|
||||
if extra_vars:
|
||||
shell += f" --extra-vars {shlex.quote(extra_vars)}"
|
||||
cmd = ["bash","-lc", shell]
|
||||
job_id = uuid.uuid4().hex[:12]
|
||||
log_path = os.path.join(config.JOB_LOG_DIR, f"{job_id}.log")
|
||||
with open(log_path, "w") as lf:
|
||||
lf.write(f"$ {' '.join(cmd)}\n\n")
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True)
|
||||
JOBS[job_id] = {"proc":proc, "log_path":log_path, "started": time.time()}
|
||||
return jsonify({"job_id": job_id})
|
||||
|
||||
@app.get("/api/stream/<job_id>")
|
||||
def api_stream(job_id):
|
||||
job = JOBS.get(job_id)
|
||||
if not job: return Response("not found", status=404)
|
||||
def generate():
|
||||
proc = job["proc"]
|
||||
with open(job["log_path"], "a+") as lf:
|
||||
while True:
|
||||
line = proc.stdout.readline()
|
||||
if not line:
|
||||
if proc.poll() is not None:
|
||||
yield f"data: [Exit code {proc.returncode}]\n\n"
|
||||
break
|
||||
time.sleep(0.05); continue
|
||||
lf.write(line)
|
||||
lf.flush()
|
||||
yield f"data: {line.rstrip()}\n\n"
|
||||
return Response(generate(), mimetype="text/event-stream")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5080, debug=True)
|
||||
@@ -0,0 +1,12 @@
|
||||
import os
|
||||
PLAYBOOK_ROOT = os.environ.get("PLAYBOOK_ROOT", "/runner/project")
|
||||
RUN_MODE = os.environ.get("RUN_MODE", "docker")
|
||||
DOCKER_COMPOSE_FILE = os.environ.get("DOCKER_COMPOSE_FILE", "/srv/clients/ephapoc/ansible/docker-compose.yml")
|
||||
ANSIBLE_SERVICE = os.environ.get("ANSIBLE_SERVICE", "ansible")
|
||||
ANSIBLE_CONFIG_IN_CONTAINER = os.environ.get("ANSIBLE_CONFIG_IN_CONTAINER", "/runner/ansible.cfg")
|
||||
ADMIN_TOKEN = os.environ.get("ADMIN_TOKEN", "CHANGE_ME")
|
||||
REQUIRE_ADMIN_TOKEN = os.environ.get("ADMIN_TOKEN_PROMPT","1").lower() not in {"0","false","no","off"}
|
||||
ALLOWED_EXT = {".yml", ".yaml"}
|
||||
JOB_LOG_DIR = os.environ.get("JOB_LOG_DIR", "/tmp/ansible_jobs")
|
||||
os.makedirs(JOB_LOG_DIR, exist_ok=True)
|
||||
SECRET_KEY = os.environ.get("FLASK_SECRET_KEY", "dev-key-not-secure")
|
||||
@@ -0,0 +1,20 @@
|
||||
services:
|
||||
ihm:
|
||||
build: .
|
||||
image: ephaitek/ihm-playbooks:latest
|
||||
container_name: ihm-ephapoc
|
||||
ports:
|
||||
- "15080:8080"
|
||||
environment:
|
||||
ADMIN_TOKEN: "fa649b20b66adbf57b410ccba7440460e63c190800b3a26f"
|
||||
PLAYBOOK_ROOT: "/runner/project"
|
||||
RUN_MODE: "docker"
|
||||
DOCKER_COMPOSE_FILE: "/srv/clients/ephapoc/ansible/docker-compose.yml"
|
||||
ANSIBLE_SERVICE: "ansible"
|
||||
ANSIBLE_CONFIG_IN_CONTAINER: "/runner/ansible.cfg"
|
||||
FLASK_SECRET_KEY: "fa649b20b66adbf57b410ccba7440460e63c190800b3a26f_TOO"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /srv/clients/ephapoc/ansible:/srv/clients/ephapoc/ansible:ro
|
||||
- /srv/clients/ephapoc/ansible/playbooks:/runner/project:Z
|
||||
restart: unless-stopped
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM python:3.11-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl dumb-init && rm -rf /var/lib/apt/lists/*
|
||||
# docker cli + compose plugin
|
||||
RUN mkdir -p /usr/lib/docker/cli-plugins && curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-26.1.4.tgz | tar xz -C /usr/local/bin --strip-components=1 docker/docker && curl -fsSL https://github.com/docker/compose/releases/download/v2.29.7/docker-compose-linux-x86_64 -o /usr/lib/docker/cli-plugins/docker-compose && chmod +x /usr/lib/docker/cli-plugins/docker-compose
|
||||
WORKDIR /opt/ihm
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt gunicorn
|
||||
COPY . .
|
||||
ENV FLASK_ENV=production
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/usr/bin/dumb-init","--"]
|
||||
CMD ["gunicorn","-b","0.0.0.0:8080","app:app","--workers","2","--threads","4","--timeout","300"]
|
||||
@@ -0,0 +1,23 @@
|
||||
# IHM Playbooks (Flask) — v2
|
||||
|
||||
- **Admin** `/admin` : upload de playbooks par *domaine* (`.yml/.yaml`).
|
||||
- **User** `/` : liste triable et page pour **lancer** un playbook (extra-vars, check, logs temps réel).
|
||||
|
||||
## Build & Run (Docker)
|
||||
```bash
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
# IHM sur http://<srv>:15080
|
||||
```
|
||||
|
||||
## Variables importantes
|
||||
- `ADMIN_TOKEN` : jeton d'upload (POC).
|
||||
- `PLAYBOOK_ROOT` : répertoire host qui contient vos playbooks (monté dans le conteneur sous /runner/project).
|
||||
- `DOCKER_COMPOSE_FILE` / `ANSIBLE_SERVICE` : pour `docker compose exec ansible ...`.
|
||||
- `ANSIBLE_CONFIG_IN_CONTAINER` : ex `/runner/ansible.cfg`.
|
||||
|
||||
## Reverse proxy
|
||||
Exposez via Nginx RP avec votre FQDN (TLS LE), proxy_pass vers `srv:15080`.
|
||||
|
||||
## Sécurité (POC)
|
||||
Prévoyez une auth vraie (SSO/LDAP) si utilisation client.
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
import os, subprocess, shlex, uuid, time, hashlib, pathlib, json
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, request, redirect, url_for, flash, Response, jsonify, send_from_directory
|
||||
from werkzeug.utils import secure_filename
|
||||
import yaml
|
||||
import config
|
||||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = config.SECRET_KEY
|
||||
|
||||
JOBS = {}
|
||||
|
||||
def _human(n):
|
||||
for u in ['B','KB','MB','GB','TB']:
|
||||
if n < 1024: return f"{n:.0f} {u}"
|
||||
n/=1024
|
||||
return f"{n:.0f} PB"
|
||||
|
||||
def _sha256(fp, chunk=8192):
|
||||
h = hashlib.sha256()
|
||||
with open(fp, 'rb') as f:
|
||||
while True:
|
||||
b = f.read(chunk)
|
||||
if not b: break
|
||||
h.update(b)
|
||||
return h.hexdigest()
|
||||
|
||||
def _scan_playbooks(root, q=None, sort='mtime'):
|
||||
p = pathlib.Path(root)
|
||||
if not p.exists():
|
||||
p.mkdir(parents=True, exist_ok=True)
|
||||
rows = []
|
||||
for file in p.rglob("*"):
|
||||
if file.is_file() and file.suffix.lower() in config.ALLOWED_EXT:
|
||||
rel = file.relative_to(p)
|
||||
parts = rel.parts
|
||||
if len(parts) < 2: # expect domain/filename
|
||||
continue
|
||||
domain = parts[0]
|
||||
name = parts[-1]
|
||||
if q and q.lower() not in name.lower():
|
||||
continue
|
||||
stat = file.stat()
|
||||
rows.append({
|
||||
"domain": domain,
|
||||
"name": name,
|
||||
"path": str(file),
|
||||
"rel_path": str(rel),
|
||||
"size": stat.st_size,
|
||||
"size_h": _human(stat.st_size),
|
||||
"mtime": stat.st_mtime,
|
||||
"mtime_h": datetime.fromtimestamp(stat.st_mtime).strftime("%Y-%m-%d %H:%M"),
|
||||
"sha256": _sha256(str(file))[:64],
|
||||
})
|
||||
key = {"mtime": lambda x: -x["mtime"], "name": lambda x: x["name"].lower(), "size": lambda x: -x["size"]}.get(sort, lambda x: -x["mtime"])
|
||||
grouped = {}
|
||||
for row in sorted(rows, key=key):
|
||||
grouped.setdefault(row["domain"], []).append(row)
|
||||
return grouped
|
||||
|
||||
@app.route("/")
|
||||
def user_home():
|
||||
q = request.args.get("q","").strip() or None
|
||||
sort = request.args.get("sort","mtime")
|
||||
grouped = _scan_playbooks(config.PLAYBOOK_ROOT, q=q, sort=sort)
|
||||
return render_template("user.html", grouped=grouped, q=q, sort=sort, title="Playbooks")
|
||||
|
||||
@app.route("/admin", methods=["GET","POST"])
|
||||
def admin_home():
|
||||
if request.method == "POST":
|
||||
token = request.form.get("token","")
|
||||
if config.REQUIRE_ADMIN_TOKEN and token != config.ADMIN_TOKEN:
|
||||
flash("Token d'administration invalide.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
domain = (request.form.get("domain") or "").strip().lower().replace(" ","-")
|
||||
f = request.files.get("file")
|
||||
if not domain or not f:
|
||||
flash("Domaine et fichier requis.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
ext = os.path.splitext(f.filename)[1].lower()
|
||||
if ext not in config.ALLOWED_EXT:
|
||||
flash("Extension non autorisée. Utilise .yml ou .yaml.", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
try:
|
||||
yaml.safe_load(f.read().decode("utf-8"))
|
||||
f.seek(0)
|
||||
except Exception as e:
|
||||
flash(f"YAML invalide: {e}", "error")
|
||||
return redirect(url_for("admin_home"))
|
||||
dest_dir = os.path.join(config.PLAYBOOK_ROOT, domain)
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
fname = secure_filename(f.filename)
|
||||
path = os.path.join(dest_dir, fname)
|
||||
f.save(path)
|
||||
flash(f"Playbook chargé: {domain}/{fname}", "ok")
|
||||
return redirect(url_for("admin_home"))
|
||||
grouped = _scan_playbooks(config.PLAYBOOK_ROOT)
|
||||
return render_template("admin.html", grouped=grouped, title="Admin", require_token=config.REQUIRE_ADMIN_TOKEN)
|
||||
|
||||
@app.route("/run/<domain>/<name>")
|
||||
def user_run(domain, name):
|
||||
rel = f"{domain}/{name}"
|
||||
full = os.path.join(config.PLAYBOOK_ROOT, rel)
|
||||
if not os.path.isfile(full):
|
||||
flash("Playbook introuvable.", "error")
|
||||
return redirect(url_for("user_home"))
|
||||
return render_template("run.html", domain=domain, name=name, rel_path=rel, title="Lancer")
|
||||
|
||||
@app.post("/api/run/<domain>/<name>")
|
||||
def api_run_start(domain, name):
|
||||
rel = f"{domain}/{name}"
|
||||
full = os.path.join(config.PLAYBOOK_ROOT, rel)
|
||||
if not os.path.isfile(full):
|
||||
return jsonify({"error":"not found"}), 404
|
||||
extra_vars = (request.form.get("extra_vars") or "").strip()
|
||||
check = request.form.get("check") == "yes"
|
||||
vvv = request.form.get("vvv") or "-vvv"
|
||||
if config.RUN_MODE == "docker":
|
||||
playbook_in_container = f"/runner/project/{rel}"
|
||||
shell = f'ANSIBLE_CONFIG={shlex.quote(config.ANSIBLE_CONFIG_IN_CONTAINER)} ansible-playbook {shlex.quote(playbook_in_container)} {vvv}'
|
||||
if check: shell += " --check"
|
||||
if extra_vars:
|
||||
shell += f" --extra-vars {shlex.quote(extra_vars)}"
|
||||
cmd = ["docker","compose","-f",config.DOCKER_COMPOSE_FILE,"exec","-T",config.ANSIBLE_SERVICE,"bash","-lc", shell]
|
||||
else:
|
||||
shell = f'ansible-playbook {shlex.quote(full)} {vvv}'
|
||||
if check: shell += " --check"
|
||||
if extra_vars:
|
||||
shell += f" --extra-vars {shlex.quote(extra_vars)}"
|
||||
cmd = ["bash","-lc", shell]
|
||||
job_id = uuid.uuid4().hex[:12]
|
||||
log_path = os.path.join(config.JOB_LOG_DIR, f"{job_id}.log")
|
||||
with open(log_path, "w") as lf:
|
||||
lf.write(f"$ {' '.join(cmd)}\n\n")
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1, universal_newlines=True)
|
||||
JOBS[job_id] = {"proc":proc, "log_path":log_path, "started": time.time()}
|
||||
return jsonify({"job_id": job_id})
|
||||
|
||||
@app.get("/api/stream/<job_id>")
|
||||
def api_stream(job_id):
|
||||
job = JOBS.get(job_id)
|
||||
if not job: return Response("not found", status=404)
|
||||
def generate():
|
||||
proc = job["proc"]
|
||||
with open(job["log_path"], "a+") as lf:
|
||||
while True:
|
||||
line = proc.stdout.readline()
|
||||
if not line:
|
||||
if proc.poll() is not None:
|
||||
yield f"data: [Exit code {proc.returncode}]\n\n"
|
||||
break
|
||||
time.sleep(0.05); continue
|
||||
lf.write(line)
|
||||
lf.flush()
|
||||
yield f"data: {line.rstrip()}\n\n"
|
||||
return Response(generate(), mimetype="text/event-stream")
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=5080, debug=True)
|
||||
@@ -0,0 +1,12 @@
|
||||
import os
|
||||
PLAYBOOK_ROOT = os.environ.get("PLAYBOOK_ROOT", "/runner/project")
|
||||
RUN_MODE = os.environ.get("RUN_MODE", "docker")
|
||||
DOCKER_COMPOSE_FILE = os.environ.get("DOCKER_COMPOSE_FILE", "/srv/clients/ephapoc/ansible/docker-compose.yml")
|
||||
ANSIBLE_SERVICE = os.environ.get("ANSIBLE_SERVICE", "ansible")
|
||||
ANSIBLE_CONFIG_IN_CONTAINER = os.environ.get("ANSIBLE_CONFIG_IN_CONTAINER", "/runner/ansible.cfg")
|
||||
ADMIN_TOKEN = os.environ.get("ADMIN_TOKEN", "CHANGE_ME")
|
||||
REQUIRE_ADMIN_TOKEN = os.environ.get("ADMIN_TOKEN_PROMPT","1").lower() not in {"0","false","no","off"}
|
||||
ALLOWED_EXT = {".yml", ".yaml"}
|
||||
JOB_LOG_DIR = os.environ.get("JOB_LOG_DIR", "/tmp/ansible_jobs")
|
||||
os.makedirs(JOB_LOG_DIR, exist_ok=True)
|
||||
SECRET_KEY = os.environ.get("FLASK_SECRET_KEY", "dev-key-not-secure")
|
||||
@@ -0,0 +1,20 @@
|
||||
services:
|
||||
ihm:
|
||||
build: .
|
||||
image: ephaitek/ihm-playbooks:latest
|
||||
container_name: ihm-ephapoc
|
||||
ports:
|
||||
- "15080:8080"
|
||||
environment:
|
||||
ADMIN_TOKEN: "fa649b20b66adbf57b410ccba7440460e63c190800b3a26f"
|
||||
PLAYBOOK_ROOT: "/runner/project"
|
||||
RUN_MODE: "docker"
|
||||
DOCKER_COMPOSE_FILE: "/srv/clients/ephapoc/ansible/docker-compose.yml"
|
||||
ANSIBLE_SERVICE: "ansible"
|
||||
ANSIBLE_CONFIG_IN_CONTAINER: "/runner/ansible.cfg"
|
||||
FLASK_SECRET_KEY: "fa649b20b66adbf57b410ccba7440460e63c190800b3a26f_TOO"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /srv/clients/ephapoc/ansible:/srv/clients/ephapoc/ansible:ro
|
||||
- /srv/clients/ephapoc/ansible/playbooks:/runner/project:Z
|
||||
restart: unless-stopped
|
||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
Flask==3.0.3
|
||||
PyYAML==6.0.2
|
||||
@@ -0,0 +1,24 @@
|
||||
:root { --bg:#0b1220; --panel:#111827; --muted:#9CA3AF; --accent:#6EE7B7; --accent2:#60A5FA; --danger:#F87171; }
|
||||
*{box-sizing:border-box} body{margin:0;font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:#e5e7eb}
|
||||
a{color:var(--accent2);text-decoration:none}
|
||||
.header{display:flex;gap:12px;align-items:center;justify-content:space-between;padding:16px 24px;background:#0f172a;border-bottom:1px solid #1f2937}
|
||||
.header h1{margin:0;font-size:18px;color:#fff}
|
||||
.nav a{margin-right:12px;color:#cbd5e1}
|
||||
.container{max-width:1100px;margin:24px auto;padding:0 16px}
|
||||
.card{background:var(--panel);border:1px solid #1f2937;border-radius:16px;padding:16px;margin-bottom:16px;box-shadow:0 4px 24px rgba(0,0,0,.25)}
|
||||
.grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
|
||||
input[type=text], input[type=password], select, textarea{width:100%;padding:10px 12px;border-radius:10px;border:1px solid #374151;background:#0b1220;color:#e5e7eb}
|
||||
input[type=file]{width:100%}
|
||||
button{background:linear-gradient(90deg,var(--accent),var(--accent2));color:#0b1220;font-weight:600;border:none;border-radius:10px;padding:10px 14px;cursor:pointer}
|
||||
button.secondary{background:#0b1220;color:#cbd5e1;border:1px solid #334155}
|
||||
.badge{display:inline-block;padding:2px 8px;border-radius:999px;background:#0b1220;border:1px solid #334155;color:#cbd5e1;font-size:12px}
|
||||
.table{width:100%;border-collapse:separate;border-spacing:0 8px}
|
||||
.table th{color:#9CA3AF;text-align:left;font-weight:600;padding:0 8px}
|
||||
.table td{padding:10px 8px;background:#0b1220;border:1px solid #1f2937}
|
||||
.table tr td:first-child{border-radius:10px 0 0 10px}
|
||||
.table tr td:last-child{border-radius:0 10px 10px 0}
|
||||
pre.log{white-space:pre-wrap;background:#0b1220;border:1px solid #1f2937;padding:12px;border-radius:12px;max-height:55vh;overflow:auto}
|
||||
.footer{color:#94a3b8;text-align:center;margin:32px 0}
|
||||
.small{font-size:12px;color:#94a3b8}
|
||||
.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
|
||||
hr{border:0;border-top:1px solid #1f2937;margin:16px 0}
|
||||
@@ -0,0 +1,54 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Administration — Upload de playbooks</h2>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label>Domaine</label>
|
||||
<input type="text" name="domain" placeholder="ex: ipam, discovery, network" required>
|
||||
</div>
|
||||
<div>
|
||||
{% if require_token %}
|
||||
<label>Token Administrateur</label>
|
||||
<input type="password" name="token" placeholder="ADMIN_TOKEN" required>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div style="margin-top:10px">
|
||||
<input type="file" name="file" accept=".yml,.yaml" required>
|
||||
</div>
|
||||
<div class="row" style="margin-top:12px">
|
||||
<button type="submit">Charger le playbook</button>
|
||||
<a href="{{ url_for('user_home') }}" class="badge">Aller à la vue Utilisateurs</a>
|
||||
</div>
|
||||
<div class="small" style="margin-top:8px">Seuls les fichiers .yml/.yaml sont acceptés. Le fichier est stocké par domaine et visible dans la vue Utilisateurs.</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">Playbooks disponibles</h3>
|
||||
{% if grouped %}
|
||||
{% for domain, items in grouped.items() %}
|
||||
<h4>{{ domain }} <span class="badge">{{ items|length }} playbook(s)</span></h4>
|
||||
<table class="table">
|
||||
<tr><th>Nom</th><th>Taille</th><th>Modifié</th><th>SHA256</th><th>Actions</th></tr>
|
||||
{% for pb in items %}
|
||||
<tr>
|
||||
<td>{{ pb.name }}</td>
|
||||
<td>{{ pb.size_h }}</td>
|
||||
<td>{{ pb.mtime_h }}</td>
|
||||
<td class="small">{{ pb.sha256[:16] }}…</td>
|
||||
<td>
|
||||
<a class="badge" href="{{ url_for('user_run', domain=domain, name=pb.name) }}">Ouvrir</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<hr/>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="small">Aucun playbook pour le moment.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{ title or "IHM Playbooks" }}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>🧰 IHM Playbooks</h1>
|
||||
<div class="nav">
|
||||
<a href="{{ url_for('user_home') }}">Utilisateurs</a>
|
||||
<a href="{{ url_for('admin_home') }}">Administration</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for cat,msg in messages %}
|
||||
<div class="card" style="border-left:6px solid {% if cat=='error' %}#F87171{% elif cat=='ok' %}#6EE7B7{% else %}#60A5FA{% endif %};">
|
||||
{{ msg }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
<div class="footer small">POC — Ephaitek • Flask</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Lancer un playbook</h2>
|
||||
<div class="row">
|
||||
<div class="badge">Domaine: {{ domain }}</div>
|
||||
<div class="badge">Playbook: {{ name }}</div>
|
||||
<div class="badge">Chemin: {{ rel_path }}</div>
|
||||
</div>
|
||||
<form id="runForm" class="grid" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Extra Vars (YAML or key1=val1 key2=val2)</label>
|
||||
<textarea name="extra_vars" rows="4" placeholder='{"netbox_url":"...", "netbox_token":"..."}'></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label>Vérification (dry-run)</label>
|
||||
<select name="check">
|
||||
<option value="no" selected>Non</option>
|
||||
<option value="yes">Oui (ansible-playbook --check)</option>
|
||||
</select>
|
||||
<label style="margin-top:8px;display:block">Verbosity</label>
|
||||
<select name="vvv">
|
||||
<option value="">-v (léger)</option>
|
||||
<option value="-vv">-vv</option>
|
||||
<option value="-vvv" selected>-vvv</option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row" style="margin-top:10px">
|
||||
<button id="btnRun">Exécuter</button>
|
||||
<a class="badge" href="{{ url_for('user_home') }}">Retour</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">Sortie</h3>
|
||||
<pre id="log" class="log"></pre>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const logEl = document.getElementById('log');
|
||||
const btn = document.getElementById('btnRun');
|
||||
btn.addEventListener('click', async ()=>{
|
||||
logEl.textContent = 'Démarrage…\n';
|
||||
const form = document.getElementById('runForm');
|
||||
const data = new FormData(form);
|
||||
const res = await fetch('{{ url_for("api_run_start", domain=domain, name=name) }}', {method:"POST", body:data});
|
||||
if(!res.ok){ logEl.textContent += 'Erreur démarrage ('+res.status+')'; return; }
|
||||
const { job_id } = await res.json();
|
||||
const src = new EventSource('{{ url_for("api_stream", job_id="") }}'+job_id);
|
||||
src.onmessage = (e)=>{ logEl.textContent += e.data + "\n"; logEl.scrollTop = logEl.scrollHeight; };
|
||||
src.onerror = ()=>{ src.close(); logEl.textContent += "\n[Flux terminé]"; };
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,36 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Catalogue de playbooks</h2>
|
||||
<form method="get" class="row">
|
||||
<input type="text" name="q" placeholder="Rechercher…" value="{{ q or '' }}" style="flex:1">
|
||||
<select name="sort">
|
||||
<option value="mtime" {% if sort=='mtime' %}selected{% endif %}>Tri: récents</option>
|
||||
<option value="name" {% if sort=='name' %}selected{% endif %}>Tri: nom</option>
|
||||
<option value="size" {% if sort=='size' %}selected{% endif %}>Tri: taille</option>
|
||||
</select>
|
||||
<button type="submit" class="secondary">Appliquer</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% for domain, items in grouped.items() %}
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">{{ domain }} <span class="badge">{{ items|length }} playbook(s)</span></h3>
|
||||
<table class="table">
|
||||
<tr><th>Nom</th><th>Taille</th><th>Modifié</th><th></th></tr>
|
||||
{% for pb in items %}
|
||||
<tr>
|
||||
<td>{{ pb.name }}</td><td>{{ pb.size_h }}</td><td>{{ pb.mtime_h }}</td>
|
||||
<td style="text-align:right">
|
||||
<a class="badge" href="{{ url_for('user_run', domain=domain, name=pb.name) }}">Lancer</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% if not grouped %}
|
||||
<div class="card small">Aucun playbook disponible. Demandez à l’admin d’en charger un via la page d’administration.</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
blinker==1.9.0
|
||||
click==8.2.1
|
||||
Flask==3.0.3
|
||||
gunicorn==23.0.0
|
||||
itsdangerous==2.2.0
|
||||
Jinja2==3.1.6
|
||||
MarkupSafe==3.0.2
|
||||
packaging==25.0
|
||||
PyYAML==6.0.2
|
||||
Werkzeug==3.1.3
|
||||
@@ -0,0 +1,2 @@
|
||||
Flask==3.0.3
|
||||
PyYAML==6.0.2
|
||||
@@ -0,0 +1,19 @@
|
||||
Image: ephaitek/ihm-playbooks:latest
|
||||
Entrypoint: [/usr/bin/dumb-init --]
|
||||
Cmd: [gunicorn -b 0.0.0.0:8080 app:app --workers 2 --threads 4 --timeout 300]
|
||||
Env:
|
||||
ADMIN_TOKEN=45d1e8b744d3b7f218762c953587ff0566630f22
|
||||
ADMIN_TOKEN_PROMPT=0
|
||||
PLAYBOOK_ROOT=/runner/project
|
||||
RUN_MODE=docker
|
||||
DOCKER_COMPOSE_FILE=/srv/clients/ephapoc/ansible/docker-compose.yml
|
||||
ANSIBLE_SERVICE=ansible
|
||||
JOB_LOG_DIR=/tmp/ansible_jobs
|
||||
PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
LANG=C.UTF-8
|
||||
GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D
|
||||
PYTHON_VERSION=3.11.13
|
||||
PYTHON_SHA256=8fb5f9fbc7609fa822cb31549884575db7fd9657cbffb89510b5d7975963a83a
|
||||
FLASK_ENV=production
|
||||
|
||||
WorkingDir: /opt/ihm
|
||||
@@ -0,0 +1,24 @@
|
||||
:root { --bg:#0b1220; --panel:#111827; --muted:#9CA3AF; --accent:#6EE7B7; --accent2:#60A5FA; --danger:#F87171; }
|
||||
*{box-sizing:border-box} body{margin:0;font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;background:var(--bg);color:#e5e7eb}
|
||||
a{color:var(--accent2);text-decoration:none}
|
||||
.header{display:flex;gap:12px;align-items:center;justify-content:space-between;padding:16px 24px;background:#0f172a;border-bottom:1px solid #1f2937}
|
||||
.header h1{margin:0;font-size:18px;color:#fff}
|
||||
.nav a{margin-right:12px;color:#cbd5e1}
|
||||
.container{max-width:1100px;margin:24px auto;padding:0 16px}
|
||||
.card{background:var(--panel);border:1px solid #1f2937;border-radius:16px;padding:16px;margin-bottom:16px;box-shadow:0 4px 24px rgba(0,0,0,.25)}
|
||||
.grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
|
||||
input[type=text], input[type=password], select, textarea{width:100%;padding:10px 12px;border-radius:10px;border:1px solid #374151;background:#0b1220;color:#e5e7eb}
|
||||
input[type=file]{width:100%}
|
||||
button{background:linear-gradient(90deg,var(--accent),var(--accent2));color:#0b1220;font-weight:600;border:none;border-radius:10px;padding:10px 14px;cursor:pointer}
|
||||
button.secondary{background:#0b1220;color:#cbd5e1;border:1px solid #334155}
|
||||
.badge{display:inline-block;padding:2px 8px;border-radius:999px;background:#0b1220;border:1px solid #334155;color:#cbd5e1;font-size:12px}
|
||||
.table{width:100%;border-collapse:separate;border-spacing:0 8px}
|
||||
.table th{color:#9CA3AF;text-align:left;font-weight:600;padding:0 8px}
|
||||
.table td{padding:10px 8px;background:#0b1220;border:1px solid #1f2937}
|
||||
.table tr td:first-child{border-radius:10px 0 0 10px}
|
||||
.table tr td:last-child{border-radius:0 10px 10px 0}
|
||||
pre.log{white-space:pre-wrap;background:#0b1220;border:1px solid #1f2937;padding:12px;border-radius:12px;max-height:55vh;overflow:auto}
|
||||
.footer{color:#94a3b8;text-align:center;margin:32px 0}
|
||||
.small{font-size:12px;color:#94a3b8}
|
||||
.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
|
||||
hr{border:0;border-top:1px solid #1f2937;margin:16px 0}
|
||||
@@ -0,0 +1,54 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Administration — Upload de playbooks</h2>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div class="grid">
|
||||
<div>
|
||||
<label>Domaine</label>
|
||||
<input type="text" name="domain" placeholder="ex: ipam, discovery, network" required>
|
||||
</div>
|
||||
<div>
|
||||
{% if require_token %}
|
||||
<label>Token Administrateur</label>
|
||||
<input type="password" name="token" placeholder="ADMIN_TOKEN" required>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div style="margin-top:10px">
|
||||
<input type="file" name="file" accept=".yml,.yaml" required>
|
||||
</div>
|
||||
<div class="row" style="margin-top:12px">
|
||||
<button type="submit">Charger le playbook</button>
|
||||
<a href="{{ url_for('user_home') }}" class="badge">Aller à la vue Utilisateurs</a>
|
||||
</div>
|
||||
<div class="small" style="margin-top:8px">Seuls les fichiers .yml/.yaml sont acceptés. Le fichier est stocké par domaine et visible dans la vue Utilisateurs.</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">Playbooks disponibles</h3>
|
||||
{% if grouped %}
|
||||
{% for domain, items in grouped.items() %}
|
||||
<h4>{{ domain }} <span class="badge">{{ items|length }} playbook(s)</span></h4>
|
||||
<table class="table">
|
||||
<tr><th>Nom</th><th>Taille</th><th>Modifié</th><th>SHA256</th><th>Actions</th></tr>
|
||||
{% for pb in items %}
|
||||
<tr>
|
||||
<td>{{ pb.name }}</td>
|
||||
<td>{{ pb.size_h }}</td>
|
||||
<td>{{ pb.mtime_h }}</td>
|
||||
<td class="small">{{ pb.sha256[:16] }}…</td>
|
||||
<td>
|
||||
<a class="badge" href="{{ url_for('user_run', domain=domain, name=pb.name) }}">Ouvrir</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<hr/>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="small">Aucun playbook pour le moment.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,31 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>{{ title or "IHM Playbooks" }}</title>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='app.css') }}">
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>🧰 IHM Playbooks</h1>
|
||||
<div class="nav">
|
||||
<a href="{{ url_for('user_home') }}">Utilisateurs</a>
|
||||
<a href="{{ url_for('admin_home') }}">Administration</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for cat,msg in messages %}
|
||||
<div class="card" style="border-left:6px solid {% if cat=='error' %}#F87171{% elif cat=='ok' %}#6EE7B7{% else %}#60A5FA{% endif %};">
|
||||
{{ msg }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% block content %}{% endblock %}
|
||||
<div class="footer small">POC — Ephaitek • Flask</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Lancer un playbook</h2>
|
||||
<div class="row">
|
||||
<div class="badge">Domaine: {{ domain }}</div>
|
||||
<div class="badge">Playbook: {{ name }}</div>
|
||||
<div class="badge">Chemin: {{ rel_path }}</div>
|
||||
</div>
|
||||
<form id="runForm" class="grid" style="margin-top:10px">
|
||||
<div>
|
||||
<label>Extra Vars (YAML or key1=val1 key2=val2)</label>
|
||||
<textarea name="extra_vars" rows="4" placeholder='{"netbox_url":"...", "netbox_token":"..."}'></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label>Vérification (dry-run)</label>
|
||||
<select name="check">
|
||||
<option value="no" selected>Non</option>
|
||||
<option value="yes">Oui (ansible-playbook --check)</option>
|
||||
</select>
|
||||
<label style="margin-top:8px;display:block">Verbosity</label>
|
||||
<select name="vvv">
|
||||
<option value="">-v (léger)</option>
|
||||
<option value="-vv">-vv</option>
|
||||
<option value="-vvv" selected>-vvv</option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
<div class="row" style="margin-top:10px">
|
||||
<button id="btnRun">Exécuter</button>
|
||||
<a class="badge" href="{{ url_for('user_home') }}">Retour</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">Sortie</h3>
|
||||
<pre id="log" class="log"></pre>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const logEl = document.getElementById('log');
|
||||
const btn = document.getElementById('btnRun');
|
||||
btn.addEventListener('click', async ()=>{
|
||||
logEl.textContent = 'Démarrage…\n';
|
||||
const form = document.getElementById('runForm');
|
||||
const data = new FormData(form);
|
||||
const res = await fetch('{{ url_for("api_run_start", domain=domain, name=name) }}', {method:"POST", body:data});
|
||||
if(!res.ok){ logEl.textContent += 'Erreur démarrage ('+res.status+')'; return; }
|
||||
const { job_id } = await res.json();
|
||||
const src = new EventSource('{{ url_for("api_stream", job_id="") }}'+job_id);
|
||||
src.onmessage = (e)=>{ logEl.textContent += e.data + "\n"; logEl.scrollTop = logEl.scrollHeight; };
|
||||
src.onerror = ()=>{ src.close(); logEl.textContent += "\n[Flux terminé]"; };
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,36 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<div class="card">
|
||||
<h2 style="margin-top:0">Catalogue de playbooks</h2>
|
||||
<form method="get" class="row">
|
||||
<input type="text" name="q" placeholder="Rechercher…" value="{{ q or '' }}" style="flex:1">
|
||||
<select name="sort">
|
||||
<option value="mtime" {% if sort=='mtime' %}selected{% endif %}>Tri: récents</option>
|
||||
<option value="name" {% if sort=='name' %}selected{% endif %}>Tri: nom</option>
|
||||
<option value="size" {% if sort=='size' %}selected{% endif %}>Tri: taille</option>
|
||||
</select>
|
||||
<button type="submit" class="secondary">Appliquer</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% for domain, items in grouped.items() %}
|
||||
<div class="card">
|
||||
<h3 style="margin-top:0">{{ domain }} <span class="badge">{{ items|length }} playbook(s)</span></h3>
|
||||
<table class="table">
|
||||
<tr><th>Nom</th><th>Taille</th><th>Modifié</th><th></th></tr>
|
||||
{% for pb in items %}
|
||||
<tr>
|
||||
<td>{{ pb.name }}</td><td>{{ pb.size_h }}</td><td>{{ pb.mtime_h }}</td>
|
||||
<td style="text-align:right">
|
||||
<a class="badge" href="{{ url_for('user_run', domain=domain, name=pb.name) }}">Lancer</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% if not grouped %}
|
||||
<div class="card small">Aucun playbook disponible. Demandez à l’admin d’en charger un via la page d’administration.</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user