settings.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. {% extends "base.html" %}
  2. {% block title %}Paramètres{% endblock %}
  3. {% block content %}
  4. <div class="flex items-center justify-between mb-6">
  5. <h1 class="text-xl font-bold text-gray-900">Paramètres</h1>
  6. <div class="flex gap-2">
  7. <a href="{{ url_for('dest.destination_new') }}" id="btn-new-dest" class="btn-primary btn-sm hidden">
  8. + Nouvelle destination
  9. </a>
  10. <a href="{{ url_for('network.remote_instance_new') }}" id="btn-new-inst" class="btn-primary btn-sm hidden">
  11. + Ajouter une instance
  12. </a>
  13. </div>
  14. </div>
  15. {# ── Onglets ─────────────────────────────────────────────────────── #}
  16. <div class="flex border-b border-gray-200 mb-6 gap-1">
  17. <button id="tab-btn-destinations" onclick="setTab('destinations')"
  18. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-blue-600 text-blue-600 -mb-px">
  19. Destinations
  20. </button>
  21. <button id="tab-btn-instances" onclick="setTab('instances')"
  22. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 -mb-px">
  23. Instances
  24. </button>
  25. <button id="tab-btn-config" onclick="setTab('config')"
  26. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-transparent text-gray-500 hover:text-gray-700 -mb-px">
  27. Configuration
  28. </button>
  29. </div>
  30. {# ══════════════════ PANNEAU : DESTINATIONS ═══════════════════════ #}
  31. <div id="pane-destinations">
  32. {% if not destinations %}
  33. <div class="bg-white rounded-xl border border-gray-200 px-6 py-12 text-center text-gray-400">
  34. <p class="text-lg">Aucune destination configurée.</p>
  35. <p class="text-sm mt-2">Les archives sont conservées localement uniquement.</p>
  36. <a href="{{ url_for('dest.destination_new') }}" class="mt-4 inline-block text-blue-600 hover:underline text-sm">
  37. Configurer une première destination →
  38. </a>
  39. </div>
  40. {% else %}
  41. <div class="space-y-4">
  42. {% for dest in destinations %}
  43. <div class="bg-white rounded-xl border border-gray-200 shadow-sm p-5">
  44. <div class="flex items-start justify-between gap-4">
  45. <div class="space-y-1 min-w-0">
  46. <div class="flex items-center gap-2">
  47. <span class="font-semibold text-gray-900">{{ dest.name }}</span>
  48. {% if dest.enabled %}
  49. <span class="bg-green-100 text-green-700 text-xs px-2 py-0.5 rounded-full font-medium">actif</span>
  50. {% else %}
  51. <span class="bg-gray-100 text-gray-500 text-xs px-2 py-0.5 rounded-full font-medium">inactif</span>
  52. {% endif %}
  53. </div>
  54. <p class="text-sm font-mono text-gray-600">
  55. {{ dest.user }}@{{ dest.host }}:{{ dest.port }} → {{ dest.remote_path }}
  56. </p>
  57. {% if dest.jobs %}
  58. <p class="text-xs text-gray-400">
  59. Utilisée par : {{ dest.jobs | map(attribute='name') | join(', ') }}
  60. </p>
  61. {% endif %}
  62. </div>
  63. <div class="flex items-center gap-2 shrink-0">
  64. <form method="post" action="{{ url_for('dest.destination_test', dest_id=dest.id) }}">
  65. <button type="submit" class="btn-secondary btn-sm">Tester</button>
  66. </form>
  67. <a href="{{ url_for('dest.destination_edit', dest_id=dest.id) }}"
  68. class="btn-secondary btn-sm">Éditer</a>
  69. <form method="post" action="{{ url_for('dest.destination_delete', dest_id=dest.id) }}"
  70. onsubmit="return confirm('Supprimer la destination « {{ dest.name }} » ?')">
  71. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  72. </form>
  73. </div>
  74. </div>
  75. </div>
  76. {% endfor %}
  77. </div>
  78. {% endif %}
  79. </div>{# /pane-destinations #}
  80. {# ══════════════════ PANNEAU : INSTANCES ══════════════════════════ #}
  81. <div id="pane-instances" class="hidden">
  82. {% if not instances %}
  83. <div class="bg-white rounded-xl border border-gray-200 px-6 py-12 text-center text-gray-400">
  84. <p class="text-lg">Aucune instance distante configurée.</p>
  85. <p class="text-sm mt-2">Ajoutez une instance pour voir son état et déclencher des sauvegardes à distance.</p>
  86. <a href="{{ url_for('network.remote_instance_new') }}" class="mt-4 inline-block text-blue-600 hover:underline text-sm">
  87. Ajouter une première instance →
  88. </a>
  89. </div>
  90. {% else %}
  91. <div class="space-y-4">
  92. {% for inst in instances %}
  93. {% set status_color = {
  94. 'online': 'bg-green-100 text-green-700',
  95. 'error': 'bg-red-100 text-red-700',
  96. 'offline': 'bg-gray-100 text-gray-500',
  97. }.get(inst.status, 'bg-gray-100 text-gray-400') %}
  98. <div class="bg-white rounded-xl border border-gray-200 shadow-sm p-5">
  99. <div class="flex items-start justify-between gap-4">
  100. <div class="space-y-1 min-w-0 flex-1">
  101. <div class="flex items-center gap-2 flex-wrap">
  102. <span class="font-semibold text-gray-900">{{ inst.name }}</span>
  103. <span class="text-xs px-2 py-0.5 rounded-full font-medium {{ status_color }}">
  104. {{ inst.status or 'unknown' }}
  105. </span>
  106. {% if inst.last_seen %}
  107. <span class="text-xs text-gray-400">vu {{ inst.last_seen.strftime('%d/%m %H:%M') }}</span>
  108. {% endif %}
  109. </div>
  110. <p class="text-sm font-mono text-gray-500">{{ inst.url_display }}</p>
  111. {% if inst.remote_runs %}
  112. <p class="text-xs text-gray-400">
  113. {{ inst.remote_runs | length }} job{{ 's' if inst.remote_runs | length != 1 }} synchronisé{{ 's' if inst.remote_runs | length != 1 }}
  114. </p>
  115. {% endif %}
  116. </div>
  117. <div class="flex items-center gap-2 shrink-0">
  118. <form method="post" action="{{ url_for('network.remote_instance_test', inst_id=inst.id) }}">
  119. <button type="submit" class="btn-secondary btn-sm">Tester</button>
  120. </form>
  121. <form method="post" action="{{ url_for('network.remote_instance_sync', inst_id=inst.id) }}">
  122. <button type="submit" class="btn-secondary btn-sm">Sync</button>
  123. </form>
  124. <a href="{{ url_for('network.remote_instance_edit', inst_id=inst.id) }}"
  125. class="btn-secondary btn-sm">Éditer</a>
  126. <form method="post" action="{{ url_for('network.remote_instance_delete', inst_id=inst.id) }}"
  127. onsubmit="return confirm('Supprimer l\'instance « {{ inst.name }} » ?')">
  128. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  129. </form>
  130. </div>
  131. </div>
  132. </div>
  133. {% endfor %}
  134. </div>
  135. {% endif %}
  136. </div>{# /pane-instances #}
  137. {# ══════════════════ PANNEAU : CONFIGURATION ══════════════════════ #}
  138. <div id="pane-config" class="hidden max-w-xl">
  139. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-3 mb-6">
  140. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">API — Token d'accès</h2>
  141. <p class="text-xs text-gray-500">
  142. Communiquez ce token aux autres instances BackupManager pour qu'elles puissent se connecter à celle-ci.
  143. </p>
  144. <div class="flex items-center gap-2">
  145. <input type="text" id="api-token" readonly value="{{ api_token }}"
  146. class="flex-1 border border-gray-200 bg-gray-50 rounded-lg px-3 py-2 text-sm font-mono text-gray-700 focus:outline-none select-all">
  147. <button type="button" onclick="copyToken()"
  148. class="btn-secondary btn-sm shrink-0">Copier</button>
  149. </div>
  150. {% if instance_url %}
  151. <p class="text-xs text-gray-400">
  152. URL de cette instance : <span class="font-mono">{{ instance_url }}</span>
  153. </p>
  154. {% endif %}
  155. </div>
  156. <form method="post" class="space-y-6">
  157. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  158. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Serveur SMTP</h2>
  159. <div class="grid grid-cols-3 gap-3">
  160. <div class="col-span-2">
  161. <label class="block text-sm font-medium text-gray-700 mb-1">Hôte SMTP</label>
  162. <input type="text" name="smtp_host" value="{{ cfg.smtp_host }}"
  163. placeholder="smtp.exemple.fr"
  164. 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">
  165. </div>
  166. <div>
  167. <label class="block text-sm font-medium text-gray-700 mb-1">Port</label>
  168. <input type="number" name="smtp_port" min="1" max="65535"
  169. value="{{ cfg.smtp_port or 587 }}"
  170. 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">
  171. </div>
  172. </div>
  173. <div class="grid grid-cols-2 gap-3">
  174. <div>
  175. <label class="block text-sm font-medium text-gray-700 mb-1">Utilisateur</label>
  176. <input type="text" name="smtp_user" value="{{ cfg.smtp_user }}"
  177. placeholder="user@exemple.fr"
  178. 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">
  179. </div>
  180. <div>
  181. <label class="block text-sm font-medium text-gray-700 mb-1">Mot de passe</label>
  182. <input type="password" name="smtp_password" value="{{ cfg.smtp_password }}"
  183. placeholder="••••••••"
  184. 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">
  185. </div>
  186. </div>
  187. <div class="grid grid-cols-2 gap-3">
  188. <div>
  189. <label class="block text-sm font-medium text-gray-700 mb-1">Expéditeur (From)</label>
  190. <input type="email" name="smtp_from" value="{{ cfg.smtp_from }}"
  191. placeholder="backup@exemple.fr"
  192. 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">
  193. <p class="text-xs text-gray-400 mt-1">Si vide, utilise l'utilisateur SMTP.</p>
  194. </div>
  195. <div>
  196. <label class="block text-sm font-medium text-gray-700 mb-1">Destinataire (To)</label>
  197. <input type="email" name="smtp_to" value="{{ cfg.smtp_to }}"
  198. placeholder="admin@exemple.fr"
  199. 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">
  200. </div>
  201. </div>
  202. <div class="flex items-center gap-6">
  203. <label class="flex items-center gap-2">
  204. <input type="checkbox" name="smtp_tls" value="1"
  205. {% if cfg.smtp_tls == '1' %}checked{% endif %}
  206. class="rounded border-gray-300 text-blue-600">
  207. <span class="text-sm font-medium text-gray-700">STARTTLS</span>
  208. </label>
  209. <label class="flex items-center gap-2">
  210. <input type="checkbox" name="smtp_ssl" value="1"
  211. {% if cfg.smtp_ssl == '1' %}checked{% endif %}
  212. class="rounded border-gray-300 text-blue-600">
  213. <span class="text-sm font-medium text-gray-700">SSL/TLS direct (port 465)</span>
  214. </label>
  215. </div>
  216. </div>
  217. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-3">
  218. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Notifications</h2>
  219. <label class="flex items-center gap-2">
  220. <input type="checkbox" name="notify_on_error" value="1"
  221. {% if cfg.notify_on_error != '0' %}checked{% endif %}
  222. class="rounded border-gray-300 text-blue-600">
  223. <span class="text-sm font-medium text-gray-700">Notifier en cas d'erreur</span>
  224. </label>
  225. <label class="flex items-center gap-2">
  226. <input type="checkbox" name="notify_on_success" value="1"
  227. {% if cfg.notify_on_success == '1' %}checked{% endif %}
  228. class="rounded border-gray-300 text-blue-600">
  229. <span class="text-sm font-medium text-gray-700">Notifier en cas de succès</span>
  230. </label>
  231. </div>
  232. <div class="flex gap-3 flex-wrap">
  233. <button type="submit" name="action" value="save" class="btn-primary btn-md">
  234. Enregistrer
  235. </button>
  236. <button type="submit" name="action" value="test_smtp" class="btn-secondary btn-md">
  237. Envoyer un email de test
  238. </button>
  239. </div>
  240. </form>
  241. {# ── Export / Import ── #}
  242. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-5 mt-6">
  243. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Export / Import de configuration</h2>
  244. <div>
  245. <p class="text-sm text-gray-600 mb-3">
  246. Exporte tous les jobs, destinations, instances distantes et paramètres SMTP dans un fichier JSON.
  247. </p>
  248. <p class="text-xs text-amber-600 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2 mb-3">
  249. Les fichiers de clés SSH ne sont <strong>pas inclus</strong> dans l'export — ils devront être restaurés manuellement dans <code class="font-mono">data_dir/keys/</code>.
  250. </p>
  251. <a href="{{ url_for('cfg.export_config') }}"
  252. class="btn-secondary btn-md inline-block">
  253. Télécharger la configuration
  254. </a>
  255. </div>
  256. <hr class="border-gray-100">
  257. <div>
  258. <p class="text-sm text-gray-600 mb-3">
  259. Importe un fichier exporté par BackupManager. Les jobs et destinations existants portant le même nom seront mis à jour.
  260. </p>
  261. <form method="post" enctype="multipart/form-data"
  262. action="{{ url_for('cfg.import_config') }}"
  263. class="flex items-center gap-3 flex-wrap">
  264. <input type="file" name="config_file" accept=".json"
  265. required
  266. class="text-sm text-gray-600 file:mr-3 file:py-1.5 file:px-3 file:rounded-lg file:border file:border-gray-300 file:bg-white file:text-sm file:font-medium file:text-gray-700 hover:file:bg-gray-50">
  267. <button type="submit" class="btn-primary btn-md"
  268. onclick="return confirm('Importer cette configuration ? Les jobs et destinations portant le même nom seront mis à jour.')">
  269. Importer
  270. </button>
  271. </form>
  272. </div>
  273. </div>
  274. </div>{# /pane-config #}
  275. <script>
  276. const TAB_NAMES = ['destinations', 'instances', 'config'];
  277. function setTab(name) {
  278. TAB_NAMES.forEach(function(t) {
  279. const pane = document.getElementById('pane-' + t);
  280. const btn = document.getElementById('tab-btn-' + t);
  281. const active = t === name;
  282. pane.classList.toggle('hidden', !active);
  283. btn.classList.toggle('border-blue-600', active);
  284. btn.classList.toggle('text-blue-600', active);
  285. btn.classList.toggle('border-transparent', !active);
  286. btn.classList.toggle('text-gray-500', !active);
  287. });
  288. document.getElementById('btn-new-dest').classList.toggle('hidden', name !== 'destinations');
  289. document.getElementById('btn-new-inst').classList.toggle('hidden', name !== 'instances');
  290. history.replaceState(null, '', location.pathname + '?tab=' + name);
  291. }
  292. function copyToken() {
  293. const input = document.getElementById('api-token');
  294. navigator.clipboard.writeText(input.value).then(() => {
  295. const btn = event.target;
  296. btn.textContent = 'Copié !';
  297. setTimeout(() => btn.textContent = 'Copier', 2000);
  298. });
  299. }
  300. // Restore tab from URL
  301. const urlTab = new URLSearchParams(location.search).get('tab');
  302. if (TAB_NAMES.includes(urlTab)) {
  303. setTab(urlTab);
  304. } else {
  305. setTab('destinations');
  306. }
  307. </script>
  308. {% endblock %}