settings.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. <a href="{{ url_for('dest.destination_new') }}" id="btn-new-dest" class="btn-primary btn-sm hidden">
  7. + Nouvelle destination
  8. </a>
  9. </div>
  10. {# ── Onglets ─────────────────────────────────────────────────────── #}
  11. <div class="flex border-b border-gray-200 mb-6 gap-1">
  12. <button id="tab-btn-destinations" onclick="setTab('destinations')"
  13. class="tab-btn px-4 py-2 text-sm font-medium border-b-2 border-blue-600 text-blue-600 -mb-px">
  14. Destinations
  15. </button>
  16. <button id="tab-btn-config" onclick="setTab('config')"
  17. 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">
  18. Configuration
  19. </button>
  20. </div>
  21. {# ══════════════════ PANNEAU : DESTINATIONS ═══════════════════════ #}
  22. <div id="pane-destinations">
  23. {% if not destinations %}
  24. <div class="bg-white rounded-xl border border-gray-200 px-6 py-12 text-center text-gray-400">
  25. <p class="text-lg">Aucune destination configurée.</p>
  26. <p class="text-sm mt-2">Les archives sont conservées localement uniquement.</p>
  27. <a href="{{ url_for('dest.destination_new') }}" class="mt-4 inline-block text-blue-600 hover:underline text-sm">
  28. Configurer une première destination →
  29. </a>
  30. </div>
  31. {% else %}
  32. <div class="space-y-4">
  33. {% for dest in destinations %}
  34. <div class="bg-white rounded-xl border border-gray-200 shadow-sm p-5">
  35. <div class="flex items-start justify-between gap-4">
  36. <div class="space-y-1 min-w-0">
  37. <div class="flex items-center gap-2">
  38. <span class="font-semibold text-gray-900">{{ dest.name }}</span>
  39. {% if dest.enabled %}
  40. <span class="bg-green-100 text-green-700 text-xs px-2 py-0.5 rounded-full font-medium">actif</span>
  41. {% else %}
  42. <span class="bg-gray-100 text-gray-500 text-xs px-2 py-0.5 rounded-full font-medium">inactif</span>
  43. {% endif %}
  44. </div>
  45. <p class="text-sm font-mono text-gray-600">
  46. {{ dest.user }}@{{ dest.host }}:{{ dest.port }} → {{ dest.remote_path }}
  47. </p>
  48. {% if dest.jobs %}
  49. <p class="text-xs text-gray-400">
  50. Utilisée par : {{ dest.jobs | map(attribute='name') | join(', ') }}
  51. </p>
  52. {% endif %}
  53. </div>
  54. <div class="flex items-center gap-2 shrink-0">
  55. <form method="post" action="{{ url_for('dest.destination_test', dest_id=dest.id) }}">
  56. <button type="submit" class="btn-secondary btn-sm">Tester</button>
  57. </form>
  58. <a href="{{ url_for('dest.destination_edit', dest_id=dest.id) }}"
  59. class="btn-secondary btn-sm">Éditer</a>
  60. <form method="post" action="{{ url_for('dest.destination_delete', dest_id=dest.id) }}"
  61. onsubmit="return confirm('Supprimer la destination « {{ dest.name }} » ?')">
  62. <button type="submit" class="btn-danger btn-icon-sm">✕</button>
  63. </form>
  64. </div>
  65. </div>
  66. </div>
  67. {% endfor %}
  68. </div>
  69. {% endif %}
  70. </div>{# /pane-destinations #}
  71. {# ══════════════════ PANNEAU : CONFIGURATION ══════════════════════ #}
  72. <div id="pane-config" class="hidden max-w-xl">
  73. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-3 mb-6">
  74. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">API — Token d'accès</h2>
  75. <p class="text-xs text-gray-500">
  76. Communiquez ce token aux autres instances BackupManager pour qu'elles puissent se connecter à celle-ci.
  77. </p>
  78. <div class="flex items-center gap-2">
  79. <input type="text" id="api-token" readonly value="{{ api_token }}"
  80. 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">
  81. <button type="button" onclick="copyToken()"
  82. class="btn-secondary btn-sm shrink-0">Copier</button>
  83. </div>
  84. {% if instance_url %}
  85. <p class="text-xs text-gray-400">
  86. URL de cette instance : <span class="font-mono">{{ instance_url }}</span>
  87. </p>
  88. {% endif %}
  89. </div>
  90. <form method="post" class="space-y-6">
  91. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-4">
  92. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Serveur SMTP</h2>
  93. <div class="grid grid-cols-3 gap-3">
  94. <div class="col-span-2">
  95. <label class="block text-sm font-medium text-gray-700 mb-1">Hôte SMTP</label>
  96. <input type="text" name="smtp_host" value="{{ cfg.smtp_host }}"
  97. placeholder="smtp.exemple.fr"
  98. 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">
  99. </div>
  100. <div>
  101. <label class="block text-sm font-medium text-gray-700 mb-1">Port</label>
  102. <input type="number" name="smtp_port" min="1" max="65535"
  103. value="{{ cfg.smtp_port or 587 }}"
  104. 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">
  105. </div>
  106. </div>
  107. <div class="grid grid-cols-2 gap-3">
  108. <div>
  109. <label class="block text-sm font-medium text-gray-700 mb-1">Utilisateur</label>
  110. <input type="text" name="smtp_user" value="{{ cfg.smtp_user }}"
  111. placeholder="user@exemple.fr"
  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">
  113. </div>
  114. <div>
  115. <label class="block text-sm font-medium text-gray-700 mb-1">Mot de passe</label>
  116. <input type="password" name="smtp_password" value="{{ cfg.smtp_password }}"
  117. placeholder="••••••••"
  118. 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">
  119. </div>
  120. </div>
  121. <div class="grid grid-cols-2 gap-3">
  122. <div>
  123. <label class="block text-sm font-medium text-gray-700 mb-1">Expéditeur (From)</label>
  124. <input type="email" name="smtp_from" value="{{ cfg.smtp_from }}"
  125. placeholder="backup@exemple.fr"
  126. 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">
  127. <p class="text-xs text-gray-400 mt-1">Si vide, utilise l'utilisateur SMTP.</p>
  128. </div>
  129. <div>
  130. <label class="block text-sm font-medium text-gray-700 mb-1">Destinataire (To)</label>
  131. <input type="email" name="smtp_to" value="{{ cfg.smtp_to }}"
  132. placeholder="admin@exemple.fr"
  133. 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">
  134. </div>
  135. </div>
  136. <div class="flex items-center gap-6">
  137. <label class="flex items-center gap-2">
  138. <input type="checkbox" name="smtp_tls" value="1"
  139. {% if cfg.smtp_tls == '1' %}checked{% endif %}
  140. class="rounded border-gray-300 text-blue-600">
  141. <span class="text-sm font-medium text-gray-700">STARTTLS</span>
  142. </label>
  143. <label class="flex items-center gap-2">
  144. <input type="checkbox" name="smtp_ssl" value="1"
  145. {% if cfg.smtp_ssl == '1' %}checked{% endif %}
  146. class="rounded border-gray-300 text-blue-600">
  147. <span class="text-sm font-medium text-gray-700">SSL/TLS direct (port 465)</span>
  148. </label>
  149. </div>
  150. </div>
  151. <div class="bg-white rounded-xl border border-gray-200 p-6 space-y-3">
  152. <h2 class="text-sm font-semibold text-gray-700 uppercase tracking-wide">Notifications</h2>
  153. <label class="flex items-center gap-2">
  154. <input type="checkbox" name="notify_on_error" value="1"
  155. {% if cfg.notify_on_error != '0' %}checked{% endif %}
  156. class="rounded border-gray-300 text-blue-600">
  157. <span class="text-sm font-medium text-gray-700">Notifier en cas d'erreur</span>
  158. </label>
  159. <label class="flex items-center gap-2">
  160. <input type="checkbox" name="notify_on_success" value="1"
  161. {% if cfg.notify_on_success == '1' %}checked{% endif %}
  162. class="rounded border-gray-300 text-blue-600">
  163. <span class="text-sm font-medium text-gray-700">Notifier en cas de succès</span>
  164. </label>
  165. </div>
  166. <div class="flex gap-3 flex-wrap">
  167. <button type="submit" name="action" value="save" class="btn-primary btn-md">
  168. Enregistrer
  169. </button>
  170. <button type="submit" name="action" value="test_smtp" class="btn-secondary btn-md">
  171. Envoyer un email de test
  172. </button>
  173. </div>
  174. </form>
  175. </div>{# /pane-config #}
  176. <script>
  177. function setTab(name) {
  178. ['destinations', 'config'].forEach(function(t) {
  179. const pane = document.getElementById('pane-' + t);
  180. const btn = document.getElementById('tab-btn-' + t);
  181. const active = t === name;
  182. pane.classList.toggle('hidden', !active);
  183. btn.classList.toggle('border-blue-600', active);
  184. btn.classList.toggle('text-blue-600', active);
  185. btn.classList.toggle('border-transparent', !active);
  186. btn.classList.toggle('text-gray-500', !active);
  187. if (name === 'destinations') {
  188. document.getElementById('btn-new-dest').classList.remove('hidden');
  189. } else {
  190. document.getElementById('btn-new-dest').classList.add('hidden');
  191. }
  192. });
  193. history.replaceState(null, '', location.pathname + '?tab=' + name);
  194. }
  195. function copyToken() {
  196. const input = document.getElementById('api-token');
  197. navigator.clipboard.writeText(input.value).then(() => {
  198. const btn = event.target;
  199. btn.textContent = 'Copié !';
  200. setTimeout(() => btn.textContent = 'Copier', 2000);
  201. });
  202. }
  203. // Restore tab from URL
  204. const urlTab = new URLSearchParams(location.search).get('tab');
  205. if (urlTab === 'config') setTab('config');
  206. // Show "+ Nouvelle destination" button by default (destinations tab is first)
  207. document.getElementById('btn-new-dest').classList.remove('hidden');
  208. </script>
  209. {% endblock %}