job_form.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. {% extends "base.html" %}
  2. {% block title %}{{ 'Éditer' if job else 'Nouveau job' }}{% endblock %}
  3. {% block content %}
  4. <div class="max-w-2xl">
  5. <h1 class="text-xl font-bold text-gray-900 mb-6">
  6. {{ 'Éditer « ' + job.name + ' »' if job else 'Nouveau job de sauvegarde' }}
  7. </h1>
  8. <form method="post"
  9. action="{{ url_for('job_edit', job_id=job.id) if job else url_for('job_new') }}"
  10. class="space-y-6">
  11. {# ── Infos générales ── #}
  12. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  13. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Général</h2>
  14. <div>
  15. <label class="block text-sm font-medium text-gray-700 mb-1">Nom du job</label>
  16. <input type="text" name="name" required
  17. value="{{ job.name if job else '' }}"
  18. placeholder="ex: Nextcloud quotidien"
  19. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  20. </div>
  21. <div>
  22. <label class="block text-sm font-medium text-gray-700 mb-1">Type</label>
  23. <select name="type" id="job-type"
  24. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  25. {% for val, label in [('ynh_app','Application YunoHost'), ('ynh_system','Système YunoHost'),
  26. ('mysql','MySQL'), ('postgresql','PostgreSQL'),
  27. ('custom_dir','Répertoire custom (Phase 2)')] %}
  28. <option value="{{ val }}"
  29. {% if job and job.type == val %}selected{% endif %}
  30. >
  31. {{ label }}
  32. </option>
  33. {% endfor %}
  34. </select>
  35. </div>
  36. {# Type-specific config : ynh_app #}
  37. <div id="cfg-ynh_app" class="type-cfg space-y-3">
  38. <div>
  39. <label class="block text-sm font-medium text-gray-700 mb-1">Application YunoHost</label>
  40. <select name="app_id"
  41. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  42. {% set current_app_id = (job.config_json | fromjson).get('app_id', '') if job and job.config_json else '' %}
  43. {% for ynh_app in ynh_apps %}
  44. <option value="{{ ynh_app.id }}"
  45. {% if ynh_app.id == current_app_id %}selected{% endif %}>
  46. {{ ynh_app.id }}{% if ynh_app.label %} — {{ ynh_app.label }}{% endif %}
  47. </option>
  48. {% endfor %}
  49. {% if not ynh_apps %}
  50. <option value="">Aucune application trouvée</option>
  51. {% endif %}
  52. </select>
  53. </div>
  54. <div class="flex items-center gap-2">
  55. {% set core_only = (job.config_json | fromjson).get('core_only', False) if job and job.config_json else False %}
  56. <input type="checkbox" name="core_only" value="1" id="core_only"
  57. {% if core_only %}checked{% endif %}
  58. class="rounded border-gray-300 text-blue-600">
  59. <label for="core_only" class="text-sm text-gray-700">
  60. Core only (BACKUP_CORE_ONLY=1) — exclut les données utilisateur
  61. </label>
  62. </div>
  63. </div>
  64. {# Type-specific config : ynh_system (rien de spécifique) #}
  65. <div id="cfg-ynh_system" class="type-cfg hidden">
  66. <p class="text-sm text-gray-500 bg-gray-50 rounded-lg p-3">
  67. Sauvegarde la configuration système YunoHost complète.
  68. Aucun paramètre supplémentaire.
  69. </p>
  70. </div>
  71. {# Type-specific config : mysql #}
  72. {% set db_cfg = (job.config_json | fromjson) if job and job.config_json else {} %}
  73. <div id="cfg-mysql" class="type-cfg hidden space-y-3">
  74. <div>
  75. <label class="block text-sm font-medium text-gray-700 mb-1">Nom de la base de données</label>
  76. <input type="text" name="db_database"
  77. value="{{ db_cfg.get('database', '') if job and job.type == 'mysql' else '' }}"
  78. placeholder="ex: nextcloud"
  79. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  80. <p class="text-xs text-gray-400 mt-1">
  81. Le dump est exécuté avec <code class="bg-gray-100 px-1 rounded">sudo mysqldump</code> — aucun mot de passe requis.
  82. </p>
  83. </div>
  84. </div>
  85. {# Type-specific config : postgresql #}
  86. <div id="cfg-postgresql" class="type-cfg hidden space-y-3">
  87. <div>
  88. <label class="block text-sm font-medium text-gray-700 mb-1">Nom de la base de données</label>
  89. <input type="text" name="db_database"
  90. value="{{ db_cfg.get('database', '') if job and job.type == 'postgresql' else '' }}"
  91. placeholder="ex: gitea"
  92. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  93. <p class="text-xs text-gray-400 mt-1">
  94. Le dump est exécuté avec <code class="bg-gray-100 px-1 rounded">sudo -u postgres pg_dump</code> — aucun mot de passe requis.
  95. </p>
  96. </div>
  97. </div>
  98. {# Type-specific config : custom_dir #}
  99. {% set cd_cfg = (job.config_json | fromjson) if job and job.config_json and job.type == 'custom_dir' else {} %}
  100. {% set cd_restore = cd_cfg.get('restore', {}) %}
  101. <div id="cfg-custom_dir" class="type-cfg hidden space-y-4">
  102. <div>
  103. <label class="block text-sm font-medium text-gray-700 mb-1">Chemin à sauvegarder</label>
  104. <input type="text" name="source_path"
  105. value="{{ cd_cfg.get('source_path', '') }}"
  106. placeholder="/opt/monapp"
  107. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  108. </div>
  109. <div>
  110. <label class="block text-sm font-medium text-gray-700 mb-1">Exclusions <span class="font-normal text-gray-400">(une par ligne)</span></label>
  111. <textarea name="excludes" rows="3" placeholder="cache/&#10;logs/&#10;*.tmp"
  112. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">{{ cd_cfg.get('excludes', []) | join('\n') }}</textarea>
  113. </div>
  114. {# Section restauration (optionnel, collapsible) #}
  115. <details {% if cd_restore %}open{% endif %} class="border border-gray-200 rounded-lg">
  116. <summary class="px-4 py-3 text-sm font-medium text-gray-700 cursor-pointer hover:bg-gray-50 select-none">
  117. Configuration de restauration <span class="text-gray-400 font-normal">(optionnel)</span>
  118. </summary>
  119. <div class="px-4 pb-4 pt-2 space-y-4 border-t border-gray-100">
  120. <div>
  121. <p class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">Utilisateur système</p>
  122. <div class="grid grid-cols-3 gap-3">
  123. <div>
  124. <label class="block text-xs text-gray-600 mb-1">Nom</label>
  125. <input type="text" name="restore_user_name"
  126. value="{{ cd_restore.get('system_user', {}).get('name', '') }}"
  127. placeholder="monapp" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  128. </div>
  129. <div>
  130. <label class="block text-xs text-gray-600 mb-1">Home</label>
  131. <input type="text" name="restore_user_home"
  132. value="{{ cd_restore.get('system_user', {}).get('home', '') }}"
  133. placeholder="/opt/monapp" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  134. </div>
  135. <div>
  136. <label class="block text-xs text-gray-600 mb-1">Shell</label>
  137. <input type="text" name="restore_user_shell"
  138. value="{{ cd_restore.get('system_user', {}).get('shell', '/bin/false') }}"
  139. placeholder="/bin/false" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  140. </div>
  141. </div>
  142. </div>
  143. <div>
  144. <p class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">Service systemd</p>
  145. <div class="grid grid-cols-2 gap-3">
  146. <div>
  147. <label class="block text-xs text-gray-600 mb-1">Nom du service</label>
  148. <input type="text" name="restore_service_name"
  149. value="{{ cd_restore.get('systemd_service', {}).get('name', '') }}"
  150. placeholder="monapp" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  151. </div>
  152. <div>
  153. <label class="block text-xs text-gray-600 mb-1">Fichier .service</label>
  154. <input type="text" name="restore_service_file"
  155. value="{{ cd_restore.get('systemd_service', {}).get('service_file', '') }}"
  156. placeholder="/opt/monapp/monapp.service" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  157. </div>
  158. </div>
  159. </div>
  160. <div>
  161. <p class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">Permissions</p>
  162. <div class="grid grid-cols-2 gap-3">
  163. <div>
  164. <label class="block text-xs text-gray-600 mb-1">Propriétaire (user:group)</label>
  165. <input type="text" name="restore_perm_owner"
  166. value="{{ cd_restore.get('permissions', {}).get('owner', '') }}"
  167. placeholder="monapp:monapp" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  168. </div>
  169. <div>
  170. <label class="block text-xs text-gray-600 mb-1">Mode (chmod)</label>
  171. <input type="text" name="restore_perm_mode"
  172. value="{{ cd_restore.get('permissions', {}).get('mode', '') }}"
  173. placeholder="750" class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">
  174. </div>
  175. </div>
  176. </div>
  177. <div>
  178. <label class="block text-xs font-semibold text-gray-500 uppercase tracking-wide mb-2">
  179. Commandes post-restauration <span class="font-normal text-gray-400">(une par ligne)</span>
  180. </label>
  181. <textarea name="restore_post_cmds" rows="3"
  182. placeholder="systemctl restart monapp"
  183. class="w-full border border-gray-300 rounded px-2 py-1.5 text-xs font-mono focus:outline-none focus:ring-1 focus:ring-blue-500">{{ cd_restore.get('post_restore_commands', []) | join('\n') }}</textarea>
  184. </div>
  185. </div>
  186. </details>
  187. </div>
  188. </div>
  189. {# ── Planification ── #}
  190. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  191. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Planification</h2>
  192. <div>
  193. <label class="block text-sm font-medium text-gray-700 mb-1">Expression cron</label>
  194. <input type="text" name="cron_expr" required
  195. value="{{ job.cron_expr if job else '0 3 * * *' }}"
  196. placeholder="0 3 * * *"
  197. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-blue-500">
  198. <p class="text-xs text-gray-400 mt-1">
  199. Format : minute heure jour mois jour_semaine
  200. — ex: <code class="bg-gray-100 px-1 rounded">0 3 * * *</code> = tous les jours à 3h
  201. · <code class="bg-gray-100 px-1 rounded">0 3 * * 1</code> = chaque lundi à 3h
  202. </p>
  203. </div>
  204. </div>
  205. {# ── Rétention ── #}
  206. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  207. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Rétention</h2>
  208. <div class="grid grid-cols-2 gap-4">
  209. <div>
  210. <label class="block text-sm font-medium text-gray-700 mb-1">Mode</label>
  211. <select name="retention_mode"
  212. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  213. {% for val, label in [('count','Count — N dernières archives'),
  214. ('daily','Daily — 1 par jour sur N jours'),
  215. ('gfs','GFS — Grand/Père/Fils (Phase 4)')] %}
  216. <option value="{{ val }}"
  217. {% if job and job.retention_mode == val %}selected{% endif %}
  218. {% if val == 'gfs' %}disabled class="text-gray-400"{% endif %}>
  219. {{ label }}
  220. </option>
  221. {% endfor %}
  222. </select>
  223. </div>
  224. <div>
  225. <label class="block text-sm font-medium text-gray-700 mb-1">Valeur</label>
  226. <input type="number" name="retention_value" min="1" max="365" required
  227. value="{{ job.retention_value if job else 7 }}"
  228. class="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
  229. </div>
  230. </div>
  231. </div>
  232. {# ── Options ── #}
  233. <div class="bg-white rounded-xl border border-gray-200 p-6">
  234. <div class="flex items-center gap-3">
  235. <input type="checkbox" name="enabled" value="1" id="enabled"
  236. {% if not job or job.enabled %}checked{% endif %}
  237. class="rounded border-gray-300 text-blue-600">
  238. <label for="enabled" class="text-sm font-medium text-gray-700">Job activé</label>
  239. </div>
  240. </div>
  241. {# ── Actions ── #}
  242. <div class="flex gap-3">
  243. <button type="submit"
  244. class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2 rounded-lg font-medium text-sm transition">
  245. {{ 'Enregistrer' if job else 'Créer le job' }}
  246. </button>
  247. <a href="{{ url_for('index') }}"
  248. class="bg-white hover:bg-gray-50 text-gray-700 border border-gray-300 px-5 py-2 rounded-lg font-medium text-sm transition">
  249. Annuler
  250. </a>
  251. </div>
  252. </form>
  253. </div>
  254. <script>
  255. function showTypeConfig() {
  256. document.querySelectorAll('.type-cfg').forEach(el => el.classList.add('hidden'));
  257. const type = document.getElementById('job-type').value;
  258. const el = document.getElementById('cfg-' + type);
  259. if (el) el.classList.remove('hidden');
  260. }
  261. document.getElementById('job-type').addEventListener('change', showTypeConfig);
  262. showTypeConfig();
  263. </script>
  264. {% endblock %}