1520 lines
48 KiB
HTML
1520 lines
48 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="mobile-web-app-capable" content="yes">
|
|
<title>Mailcow Alias Manager</title>
|
|
<link rel="icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
|
|
<link rel="shortcut icon" type="image/png" href="{{ url_for('static', filename='favicon.png') }}">
|
|
<link rel="apple-touch-icon" href="{{ url_for('static', filename='favicon.png') }}">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
.footer {
|
|
font-size: 16px !important;
|
|
color: #707170FF;
|
|
text-align: center;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background-color: #1a1a1a;
|
|
color: #e0e0e0;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
h1 {
|
|
color: #ffffff;
|
|
margin-bottom: 30px;
|
|
text-align: center;
|
|
}
|
|
|
|
.action-buttons {
|
|
display: flex;
|
|
gap: 15px;
|
|
margin-bottom: 30px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.btn {
|
|
background-color: #2d2d2d;
|
|
color: #ffffff;
|
|
border: 1px solid #404040;
|
|
padding: 12px 24px;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.btn:hover {
|
|
background-color: #3d3d3d;
|
|
border-color: #505050;
|
|
}
|
|
|
|
.btn:active {
|
|
background-color: #252525;
|
|
}
|
|
|
|
.btn-primary {
|
|
background-color: #0066cc;
|
|
border-color: #0066cc;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background-color: #0052a3;
|
|
}
|
|
|
|
.btn-config {
|
|
background-color: #cc6600;
|
|
border-color: #cc6600;
|
|
margin-left: auto;
|
|
}
|
|
|
|
.btn-config:hover {
|
|
background-color: #a35200;
|
|
}
|
|
|
|
.btn-logout {
|
|
background-color: #8b0000;
|
|
border-color: #8b0000;
|
|
}
|
|
|
|
.btn-logout:hover {
|
|
background-color: #6b0000;
|
|
}
|
|
|
|
.header-bar {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.header-bar h1 {
|
|
margin: 0;
|
|
}
|
|
|
|
.search-section {
|
|
background-color: #2d2d2d;
|
|
padding: 25px;
|
|
border-radius: 8px;
|
|
margin-bottom: 30px;
|
|
border: 1px solid #404040;
|
|
}
|
|
|
|
.search-container {
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
.search-input {
|
|
flex: 1;
|
|
padding: 12px;
|
|
background-color: #1a1a1a;
|
|
border: 1px solid #404040;
|
|
border-radius: 5px;
|
|
color: #ffffff;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.search-input:focus {
|
|
outline: none;
|
|
border-color: #0066cc;
|
|
}
|
|
|
|
.result-section {
|
|
background-color: #2d2d2d;
|
|
padding: 25px;
|
|
border-radius: 8px;
|
|
border: 1px solid #404040;
|
|
min-height: 100px;
|
|
}
|
|
|
|
.result-section h2 {
|
|
color: #ffffff;
|
|
margin-bottom: 15px;
|
|
font-size: 20px;
|
|
}
|
|
|
|
.result-content {
|
|
color: #b0b0b0;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.success {
|
|
color: #4CAF50;
|
|
}
|
|
|
|
.error {
|
|
color: #f44336;
|
|
}
|
|
|
|
.alias-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.alias-table th {
|
|
background-color: #1a1a1a;
|
|
color: #ffffff;
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 2px solid #404040;
|
|
}
|
|
|
|
.alias-table td {
|
|
padding: 10px 12px;
|
|
border-bottom: 1px solid #404040;
|
|
color: #e0e0e0;
|
|
}
|
|
|
|
.alias-table tr:hover {
|
|
background-color: #252525;
|
|
}
|
|
|
|
.pagination {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 10px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.pagination button {
|
|
padding: 8px 16px;
|
|
background-color: #2d2d2d;
|
|
color: #ffffff;
|
|
border: 1px solid #404040;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.pagination button:hover:not(:disabled) {
|
|
background-color: #3d3d3d;
|
|
}
|
|
|
|
.pagination button:disabled {
|
|
opacity: 0.5;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.pagination .page-info {
|
|
color: #b0b0b0;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.config-modal {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.8);
|
|
z-index: 1000;
|
|
}
|
|
|
|
.config-modal.active {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.config-content {
|
|
background-color: #2d2d2d;
|
|
padding: 30px;
|
|
border-radius: 8px;
|
|
border: 1px solid #404040;
|
|
max-width: 500px;
|
|
width: 90%;
|
|
}
|
|
|
|
.config-content h2 {
|
|
color: #ffffff;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #e0e0e0;
|
|
}
|
|
|
|
.form-group input {
|
|
width: 100%;
|
|
padding: 10px;
|
|
background-color: #1a1a1a;
|
|
border: 1px solid #404040;
|
|
border-radius: 5px;
|
|
color: #ffffff;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: #0066cc;
|
|
}
|
|
|
|
.modal-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.footer {
|
|
font-size: 12px;
|
|
color: #707170FF;
|
|
align: center;
|
|
padding-top: 20%;
|
|
}
|
|
|
|
/* Mobile Responsive Styles */
|
|
@media (max-width: 768px) {
|
|
body {
|
|
padding: 10px;
|
|
}
|
|
|
|
.header-bar {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.header-bar h1 {
|
|
font-size: 24px;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn-logout {
|
|
width: 100%;
|
|
}
|
|
|
|
.action-buttons {
|
|
gap: 10px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.btn {
|
|
flex: 1 1 calc(50% - 5px);
|
|
min-width: calc(50% - 5px);
|
|
padding: 14px 16px;
|
|
font-size: 14px;
|
|
text-align: center;
|
|
}
|
|
|
|
.btn-config {
|
|
margin-left: 0;
|
|
flex: 1 1 100%;
|
|
min-width: 100%;
|
|
}
|
|
|
|
.search-section {
|
|
padding: 20px 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.search-section h2 {
|
|
font-size: 18px;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.search-container {
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
|
|
.search-input {
|
|
width: 100%;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.btn-primary {
|
|
width: 100%;
|
|
}
|
|
|
|
.result-section {
|
|
padding: 20px 15px;
|
|
}
|
|
|
|
.result-section h2 {
|
|
font-size: 18px;
|
|
}
|
|
|
|
.alias-table {
|
|
font-size: 14px;
|
|
display: block;
|
|
overflow-x: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
|
|
.alias-table thead {
|
|
display: none;
|
|
}
|
|
|
|
.alias-table tbody {
|
|
display: block;
|
|
}
|
|
|
|
.alias-table tr {
|
|
display: block;
|
|
margin-bottom: 15px;
|
|
background-color: #252525;
|
|
border-radius: 5px;
|
|
padding: 10px;
|
|
border: 1px solid #404040;
|
|
}
|
|
|
|
.alias-table td {
|
|
display: block;
|
|
text-align: left;
|
|
padding: 8px 0;
|
|
border: none;
|
|
}
|
|
|
|
.alias-table td:first-child::before {
|
|
content: "Alias: ";
|
|
font-weight: bold;
|
|
color: #0066cc;
|
|
}
|
|
|
|
.alias-table td:last-child::before {
|
|
content: "Goes to: ";
|
|
font-weight: bold;
|
|
color: #0066cc;
|
|
}
|
|
|
|
.pagination {
|
|
flex-direction: row;
|
|
gap: 8px;
|
|
padding: 10px 0;
|
|
}
|
|
|
|
.pagination button {
|
|
flex: 1;
|
|
padding: 12px 10px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.pagination .page-info {
|
|
width: 100%;
|
|
text-align: center;
|
|
order: -1;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.config-modal {
|
|
padding: 10px;
|
|
}
|
|
|
|
.config-content {
|
|
max-width: 100%;
|
|
width: 100%;
|
|
padding: 20px 15px;
|
|
max-height: 90vh;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.config-content h2 {
|
|
font-size: 20px;
|
|
}
|
|
|
|
.config-content h3 {
|
|
font-size: 16px;
|
|
}
|
|
|
|
.modal-buttons {
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
|
|
.modal-buttons .btn {
|
|
width: 100%;
|
|
min-width: 100%;
|
|
}
|
|
|
|
.form-group input {
|
|
font-size: 16px;
|
|
}
|
|
|
|
/* Delete modal responsive styles */
|
|
.delete-results-table {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.delete-results-table thead {
|
|
display: none;
|
|
}
|
|
|
|
.delete-results-table tbody {
|
|
display: block;
|
|
}
|
|
|
|
.delete-results-table tr {
|
|
display: block;
|
|
margin-bottom: 15px;
|
|
background-color: #252525;
|
|
border-radius: 5px;
|
|
padding: 50px 15px 15px 15px;
|
|
border: 1px solid #404040;
|
|
position: relative;
|
|
}
|
|
|
|
.delete-results-table td {
|
|
display: block;
|
|
text-align: left;
|
|
padding: 6px 0;
|
|
border: none;
|
|
}
|
|
|
|
/* Checkbox in top-left corner */
|
|
.delete-results-table td:first-child {
|
|
position: absolute;
|
|
top: 15px;
|
|
left: 15px;
|
|
padding: 0;
|
|
}
|
|
|
|
.delete-checkbox {
|
|
width: 24px;
|
|
height: 24px;
|
|
}
|
|
|
|
/* Trash icon in top-right corner */
|
|
.delete-results-table td:last-child {
|
|
position: absolute;
|
|
top: 15px;
|
|
right: 15px;
|
|
padding: 0;
|
|
}
|
|
|
|
.delete-icon {
|
|
font-size: 24px;
|
|
}
|
|
|
|
/* Alias content with labels */
|
|
.delete-results-table td:nth-child(2)::before {
|
|
content: "Alias: ";
|
|
font-weight: bold;
|
|
color: #0066cc;
|
|
}
|
|
|
|
.delete-results-table td:nth-child(3)::before {
|
|
content: "Goes to: ";
|
|
font-weight: bold;
|
|
color: #0066cc;
|
|
}
|
|
|
|
/* Bulk controls stack vertically */
|
|
.bulk-controls {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.bulk-controls .btn {
|
|
width: 100%;
|
|
}
|
|
|
|
/* Delete confirm modal */
|
|
.delete-confirm-list {
|
|
max-height: 200px;
|
|
}
|
|
|
|
/* Results warning */
|
|
.results-warning {
|
|
font-size: 13px;
|
|
padding: 8px;
|
|
}
|
|
}
|
|
|
|
/* Tablet Styles */
|
|
@media (min-width: 769px) and (max-width: 1024px) {
|
|
.container {
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.btn {
|
|
flex: 1 1 calc(33.333% - 10px);
|
|
}
|
|
|
|
.btn-config {
|
|
margin-left: 0;
|
|
flex: 1 1 100%;
|
|
}
|
|
|
|
/* Delete table on tablets - keep table format but adjust sizing */
|
|
.delete-results-table {
|
|
font-size: 14px;
|
|
}
|
|
|
|
.delete-results-table th,
|
|
.delete-results-table td {
|
|
padding: 10px 8px;
|
|
}
|
|
|
|
.delete-checkbox {
|
|
width: 22px;
|
|
height: 22px;
|
|
}
|
|
|
|
.delete-icon {
|
|
font-size: 22px;
|
|
}
|
|
}
|
|
|
|
/* Small Mobile Devices */
|
|
@media (max-width: 480px) {
|
|
.header-bar h1 {
|
|
font-size: 20px;
|
|
}
|
|
|
|
.btn {
|
|
flex: 1 1 100%;
|
|
min-width: 100%;
|
|
}
|
|
|
|
.result-section h2 {
|
|
font-size: 16px;
|
|
}
|
|
|
|
/* Delete modal adjustments for very small screens */
|
|
.config-content {
|
|
padding: 15px 12px;
|
|
}
|
|
|
|
.delete-results-table tr {
|
|
padding: 45px 12px 12px 12px;
|
|
}
|
|
|
|
.delete-results-table td:first-child {
|
|
top: 12px;
|
|
left: 12px;
|
|
}
|
|
|
|
.delete-results-table td:last-child {
|
|
top: 12px;
|
|
right: 12px;
|
|
}
|
|
|
|
.delete-confirm-list {
|
|
max-height: 150px;
|
|
font-size: 14px;
|
|
}
|
|
}
|
|
|
|
/* Delete Aliases Modal Specific Styles */
|
|
.delete-checkbox {
|
|
width: 20px;
|
|
height: 20px;
|
|
cursor: pointer;
|
|
accent-color: #0066cc;
|
|
margin: 0;
|
|
}
|
|
|
|
.delete-icon {
|
|
cursor: pointer;
|
|
font-size: 20px;
|
|
transition: transform 0.2s, filter 0.2s;
|
|
display: inline-block;
|
|
user-select: none;
|
|
}
|
|
|
|
.delete-icon:hover {
|
|
transform: scale(1.3);
|
|
filter: brightness(1.4);
|
|
}
|
|
|
|
.delete-icon:active {
|
|
transform: scale(1.1);
|
|
}
|
|
|
|
.delete-results-table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
.delete-results-table th {
|
|
background-color: #1a1a1a;
|
|
color: #ffffff;
|
|
padding: 12px;
|
|
text-align: left;
|
|
border-bottom: 2px solid #404040;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.delete-results-table td {
|
|
padding: 12px;
|
|
border-bottom: 1px solid #404040;
|
|
color: #e0e0e0;
|
|
}
|
|
|
|
.delete-table-row {
|
|
transition: background-color 0.2s;
|
|
}
|
|
|
|
.delete-table-row:hover {
|
|
background-color: #252525;
|
|
}
|
|
|
|
.delete-table-row.selected {
|
|
background-color: #1a3a5a !important;
|
|
}
|
|
|
|
.delete-table-row.selected:hover {
|
|
background-color: #244b6b !important;
|
|
}
|
|
|
|
.results-warning {
|
|
color: #ff9800;
|
|
font-size: 14px;
|
|
margin-top: 10px;
|
|
padding: 10px;
|
|
background-color: rgba(255, 152, 0, 0.1);
|
|
border-radius: 5px;
|
|
border-left: 3px solid #ff9800;
|
|
}
|
|
|
|
.delete-confirm-list {
|
|
margin: 15px 0;
|
|
padding: 15px;
|
|
background-color: #1a1a1a;
|
|
border-radius: 5px;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.delete-confirm-list ul {
|
|
list-style: none;
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
|
|
.delete-confirm-list li {
|
|
padding: 8px 0;
|
|
border-bottom: 1px solid #404040;
|
|
color: #e0e0e0;
|
|
}
|
|
|
|
.delete-confirm-list li:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.delete-confirm-list li::before {
|
|
content: "• ";
|
|
color: #f44336;
|
|
font-weight: bold;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
/* Column widths for delete table */
|
|
.delete-results-table th:first-child,
|
|
.delete-results-table td:first-child {
|
|
width: 50px;
|
|
text-align: center;
|
|
}
|
|
|
|
.delete-results-table th:last-child,
|
|
.delete-results-table td:last-child {
|
|
width: 60px;
|
|
text-align: center;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header-bar">
|
|
<h1>Mailcow Alias Manager</h1>
|
|
<a href="/logout" class="btn btn-logout">Logout</a>
|
|
</div>
|
|
|
|
<div class="action-buttons">
|
|
<button class="btn" onclick="executeAction('list_aliases')">List All Aliases</button>
|
|
<button class="btn" onclick="executeAction('sync_aliases')">Sync Aliases</button>
|
|
<button class="btn" onclick="executeAction('get_domains')">Show Domains</button>
|
|
<button class="btn" onclick="openCreateAlias()">Create Alias</button>
|
|
<button class="btn" onclick="openDeleteAliasesModal()">Delete Aliases</button>
|
|
<button class="btn" onclick="openTimedAlias()">Create Timed Alias</button>
|
|
<button class="btn btn-config" onclick="openConfig()">Configuration</button>
|
|
</div>
|
|
|
|
<div class="search-section">
|
|
<h2 style="margin-bottom: 15px; color: #ffffff;">Search Aliases</h2>
|
|
<div class="search-container">
|
|
<input type="text" class="search-input" id="searchInput" placeholder="Start typing alias address (e.g., power...)">
|
|
<button class="btn btn-primary" onclick="performSearch()">Search</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="result-section">
|
|
<h2>Results</h2>
|
|
<div class="result-content" id="resultContent">
|
|
Ready to execute actions or perform searches...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Configuration Modal -->
|
|
<div class="config-modal" id="configModal">
|
|
<div class="config-content">
|
|
<h2>Configuration</h2>
|
|
|
|
<h3 style="color: #ffffff; margin-top: 20px; margin-bottom: 10px; font-size: 16px;">Mailcow Settings</h3>
|
|
<div class="form-group">
|
|
<label for="mailcowServer">Mailcow Server (without https://)</label>
|
|
<input type="text" id="mailcowServer" placeholder="mail.example.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="mailcowApiKey">Mailcow API Key</label>
|
|
<input type="text" id="mailcowApiKey" placeholder="Enter API key">
|
|
</div>
|
|
|
|
<h3 style="color: #ffffff; margin-top: 30px; margin-bottom: 10px; font-size: 16px;">Change Password</h3>
|
|
<div class="form-group">
|
|
<label for="oldPassword">Current Password</label>
|
|
<input type="password" id="oldPassword" placeholder="Enter current password">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="newPassword">New Password</label>
|
|
<input type="password" id="newPassword" placeholder="Enter new password">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="confirmPassword">Confirm New Password</label>
|
|
<input type="password" id="confirmPassword" placeholder="Confirm new password">
|
|
</div>
|
|
|
|
<div class="modal-buttons">
|
|
<button class="btn" onclick="closeConfig()">Cancel</button>
|
|
<button class="btn btn-primary" onclick="changePassword()">Change Password</button>
|
|
<button class="btn btn-primary" onclick="saveConfig()">Save Mailcow Config</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Create Alias Modal -->
|
|
<div class="config-modal" id="createAliasModal">
|
|
<div class="config-content">
|
|
<h2>Create New Alias</h2>
|
|
<div class="form-group">
|
|
<label for="newAlias">Alias Email</label>
|
|
<input type="text" id="newAlias" placeholder="alias@example.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="aliasGoto">Destination Email</label>
|
|
<input type="text" id="aliasGoto" placeholder="destination@example.com">
|
|
</div>
|
|
<div class="modal-buttons">
|
|
<button class="btn" onclick="closeCreateAlias()">Cancel</button>
|
|
<button class="btn btn-primary" onclick="createAlias()">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Delete Aliases Modal -->
|
|
<div class="config-modal" id="deleteAliasModal">
|
|
<div class="config-content" style="max-width: 800px;">
|
|
<h2>Delete Aliases</h2>
|
|
|
|
<!-- Search Section -->
|
|
<div class="form-group">
|
|
<label for="deleteSearchInput">Search for aliases to delete</label>
|
|
<div class="search-container">
|
|
<input type="text" class="search-input" id="deleteSearchInput" placeholder="Start typing alias address (e.g., power...)">
|
|
<button class="btn btn-primary" onclick="searchAliasesForDeletion()">Search</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Results Section (initially hidden) -->
|
|
<div id="deleteResultsSection" style="display: none; margin-top: 20px;">
|
|
<div id="deleteResultsInfo" style="margin-bottom: 10px; color: #4CAF50;"></div>
|
|
<div id="deleteResultsTable" style="max-height: 400px; overflow-y: auto;"></div>
|
|
|
|
<!-- Bulk Selection Controls -->
|
|
<div class="bulk-controls" style="display: flex; gap: 10px; margin: 15px 0; justify-content: center;">
|
|
<button class="btn" onclick="selectAllDeleteAliases()">Select All</button>
|
|
<button class="btn" onclick="deselectAllDeleteAliases()">Deselect All</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Action Buttons -->
|
|
<div class="modal-buttons">
|
|
<button class="btn" onclick="closeDeleteAliasesModal()">Cancel</button>
|
|
<button class="btn btn-primary" id="deleteSelectedBtn" onclick="confirmDeleteSelected()" disabled>
|
|
Delete Selected (0)
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Confirmation Dialog -->
|
|
<div class="config-modal" id="deleteConfirmModal">
|
|
<div class="config-content">
|
|
<h2 style="color: #f44336;">⚠️ Confirm Deletion</h2>
|
|
<div id="deleteConfirmContent"></div>
|
|
<p style="color: #f44336; margin-top: 15px; font-weight: bold;">This action cannot be undone.</p>
|
|
<div class="modal-buttons">
|
|
<button class="btn" onclick="closeDeleteConfirm()">Cancel</button>
|
|
<button class="btn" style="background-color: #d32f2f; border-color: #d32f2f;" onclick="executeDeleteSelected()">
|
|
Yes, Delete All
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Timed Alias Modal -->
|
|
<div class="config-modal" id="timedAliasModal">
|
|
<div class="config-content">
|
|
<h2>Create Timed Alias</h2>
|
|
<div class="form-group">
|
|
<label for="timedUsername">Destination Email (user@domain.com)</label>
|
|
<input type="text" id="timedUsername" placeholder="user@example.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="timedDomain">Domain for New Alias</label>
|
|
<input type="text" id="timedDomain" placeholder="example.com">
|
|
</div>
|
|
<div class="modal-buttons">
|
|
<button class="btn" onclick="closeTimedAlias()">Cancel</button>
|
|
<button class="btn btn-primary" onclick="createTimedAlias()">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let currentPage = 1;
|
|
|
|
function showResult(message, isSuccess = true) {
|
|
const resultContent = document.getElementById('resultContent');
|
|
resultContent.innerHTML = `<span class="${isSuccess ? 'success' : 'error'}">${message}</span>`;
|
|
}
|
|
|
|
function showAliasTable(data) {
|
|
const resultContent = document.getElementById('resultContent');
|
|
|
|
let html = `
|
|
<div style="color: #4CAF50; margin-bottom: 15px;">
|
|
Showing ${data.aliases.length} of ${data.total} aliases (Page ${data.page} of ${data.total_pages})
|
|
</div>
|
|
<table class="alias-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Alias</th>
|
|
<th>Goes To</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
for (const alias of data.aliases) {
|
|
html += `
|
|
<tr>
|
|
<td>${alias.alias}</td>
|
|
<td>${alias.goto}</td>
|
|
</tr>
|
|
`;
|
|
}
|
|
|
|
html += `
|
|
</tbody>
|
|
</table>
|
|
<div class="pagination">
|
|
<button onclick="loadAliases(${data.page - 1})" ${!data.has_prev ? 'disabled' : ''}>Previous</button>
|
|
<span class="page-info">Page ${data.page} of ${data.total_pages}</span>
|
|
<button onclick="loadAliases(${data.page + 1})" ${!data.has_next ? 'disabled' : ''}>Next</button>
|
|
</div>
|
|
`;
|
|
|
|
resultContent.innerHTML = html;
|
|
}
|
|
|
|
function checkAuth(response) {
|
|
if (response.status === 401) {
|
|
window.location.href = '/login';
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
async function loadAliases(page = 1) {
|
|
currentPage = page;
|
|
try {
|
|
const response = await fetch('/list_aliases', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ page: page })
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const result = await response.json();
|
|
if (result.status === 'success') {
|
|
showAliasTable(result.data);
|
|
} else {
|
|
showResult(result.message, false);
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error loading aliases: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
async function executeAction(actionName) {
|
|
if (actionName === 'list_aliases') {
|
|
loadAliases(1);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(`/${actionName}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
} catch (error) {
|
|
showResult(`Error executing ${actionName}: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
async function performSearch() {
|
|
const query = document.getElementById('searchInput').value;
|
|
|
|
if (!query.trim()) {
|
|
showResult('Please enter a search query', false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/search', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ query: query })
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
} catch (error) {
|
|
showResult(`Search error: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Allow search on Enter key
|
|
document.getElementById('searchInput').addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') {
|
|
performSearch();
|
|
}
|
|
});
|
|
|
|
async function openConfig() {
|
|
try {
|
|
const response = await fetch('/config');
|
|
const config = await response.json();
|
|
|
|
document.getElementById('mailcowServer').value = config.mailcow_server || '';
|
|
document.getElementById('mailcowApiKey').value = config.mailcow_api_key || '';
|
|
|
|
// Clear password fields
|
|
document.getElementById('oldPassword').value = '';
|
|
document.getElementById('newPassword').value = '';
|
|
document.getElementById('confirmPassword').value = '';
|
|
|
|
document.getElementById('configModal').classList.add('active');
|
|
} catch (error) {
|
|
showResult(`Error loading config: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
function closeConfig() {
|
|
document.getElementById('configModal').classList.remove('active');
|
|
}
|
|
|
|
async function saveConfig() {
|
|
const mailcowServer = document.getElementById('mailcowServer').value;
|
|
const mailcowApiKey = document.getElementById('mailcowApiKey').value;
|
|
|
|
try {
|
|
const response = await fetch('/config', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
mailcow_server: mailcowServer,
|
|
mailcow_api_key: mailcowApiKey
|
|
})
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
if (data.status === 'success') {
|
|
closeConfig();
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error saving config: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
async function changePassword() {
|
|
const oldPassword = document.getElementById('oldPassword').value;
|
|
const newPassword = document.getElementById('newPassword').value;
|
|
const confirmPassword = document.getElementById('confirmPassword').value;
|
|
|
|
if (!oldPassword || !newPassword || !confirmPassword) {
|
|
showResult('All password fields are required', false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/change_password', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
old_password: oldPassword,
|
|
new_password: newPassword,
|
|
confirm_password: confirmPassword
|
|
})
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
|
|
if (data.status === 'success') {
|
|
// Clear password fields on success
|
|
document.getElementById('oldPassword').value = '';
|
|
document.getElementById('newPassword').value = '';
|
|
document.getElementById('confirmPassword').value = '';
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error changing password: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Create Alias Modal Functions
|
|
function openCreateAlias() {
|
|
document.getElementById('createAliasModal').classList.add('active');
|
|
}
|
|
|
|
function closeCreateAlias() {
|
|
document.getElementById('createAliasModal').classList.remove('active');
|
|
}
|
|
|
|
async function createAlias() {
|
|
const alias = document.getElementById('newAlias').value;
|
|
const goto = document.getElementById('aliasGoto').value;
|
|
|
|
if (!alias || !goto) {
|
|
showResult('Both alias and destination are required', false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/create_alias', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ alias: alias, goto: goto })
|
|
});
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
if (data.status === 'success') {
|
|
document.getElementById('newAlias').value = '';
|
|
document.getElementById('aliasGoto').value = '';
|
|
closeCreateAlias();
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error creating alias: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Delete Aliases Modal Functions
|
|
let selectedAliases = new Set();
|
|
let currentDeleteResults = [];
|
|
|
|
function openDeleteAliasesModal() {
|
|
document.getElementById('deleteAliasModal').classList.add('active');
|
|
document.getElementById('deleteSearchInput').value = '';
|
|
document.getElementById('deleteResultsSection').style.display = 'none';
|
|
selectedAliases.clear();
|
|
currentDeleteResults = [];
|
|
updateDeleteButtonText();
|
|
}
|
|
|
|
function closeDeleteAliasesModal() {
|
|
document.getElementById('deleteAliasModal').classList.remove('active');
|
|
selectedAliases.clear();
|
|
currentDeleteResults = [];
|
|
}
|
|
|
|
async function searchAliasesForDeletion() {
|
|
const query = document.getElementById('deleteSearchInput').value;
|
|
|
|
if (!query.trim()) {
|
|
showResult('Please enter a search query', false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/search', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ query: query })
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
// Parse search results
|
|
const results = [];
|
|
const lines = data.message.split('\n');
|
|
|
|
for (const line of lines) {
|
|
if (line.includes('→')) {
|
|
const parts = line.split('→').map(p => p.trim());
|
|
if (parts.length === 2) {
|
|
results.push({
|
|
alias: parts[0],
|
|
goto: parts[1]
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// Limit to 100 results
|
|
const limited = results.slice(0, 100);
|
|
const hasMore = results.length > 100;
|
|
|
|
currentDeleteResults = limited;
|
|
renderDeleteResults(limited, hasMore, results.length);
|
|
} else {
|
|
document.getElementById('deleteResultsSection').style.display = 'none';
|
|
showResult(data.message, false);
|
|
}
|
|
} catch (error) {
|
|
showResult(`Search error: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
function renderDeleteResults(results, hasMore, totalCount) {
|
|
if (results.length === 0) {
|
|
document.getElementById('deleteResultsSection').style.display = 'none';
|
|
showResult('No aliases found matching your search', false);
|
|
return;
|
|
}
|
|
|
|
document.getElementById('deleteResultsSection').style.display = 'block';
|
|
|
|
// Info text
|
|
let infoText = `Found ${results.length} alias(es)`;
|
|
if (hasMore) {
|
|
infoText += ` (showing first 100 of ${totalCount})`;
|
|
}
|
|
document.getElementById('deleteResultsInfo').innerHTML = infoText;
|
|
|
|
// Warning for too many results
|
|
let warningHtml = '';
|
|
if (hasMore) {
|
|
warningHtml = `<div class="results-warning">⚠️ Showing first 100 of ${totalCount} results. Please refine your search for more specific results.</div>`;
|
|
}
|
|
|
|
// Build table
|
|
let html = warningHtml + `
|
|
<table class="delete-results-table">
|
|
<thead>
|
|
<tr>
|
|
<th>Select</th>
|
|
<th>Alias</th>
|
|
<th>Goes To</th>
|
|
<th>Delete</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
`;
|
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
const result = results[i];
|
|
const isSelected = selectedAliases.has(result.alias);
|
|
html += `
|
|
<tr class="delete-table-row ${isSelected ? 'selected' : ''}" id="delete-row-${i}">
|
|
<td>
|
|
<input type="checkbox"
|
|
class="delete-checkbox"
|
|
id="checkbox-${i}"
|
|
${isSelected ? 'checked' : ''}
|
|
onchange="toggleAliasSelection('${escapeHtml(result.alias)}', ${i})">
|
|
</td>
|
|
<td>${escapeHtml(result.alias)}</td>
|
|
<td>${escapeHtml(result.goto)}</td>
|
|
<td>
|
|
<span class="delete-icon" onclick="deleteSingleAliasQuick('${escapeHtml(result.alias)}', ${i})">🗑️</span>
|
|
</td>
|
|
</tr>
|
|
`;
|
|
}
|
|
|
|
html += '</tbody></table>';
|
|
document.getElementById('deleteResultsTable').innerHTML = html;
|
|
}
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function toggleAliasSelection(alias, rowIndex) {
|
|
const row = document.getElementById(`delete-row-${rowIndex}`);
|
|
const checkbox = document.getElementById(`checkbox-${rowIndex}`);
|
|
|
|
if (selectedAliases.has(alias)) {
|
|
selectedAliases.delete(alias);
|
|
row.classList.remove('selected');
|
|
} else {
|
|
selectedAliases.add(alias);
|
|
row.classList.add('selected');
|
|
}
|
|
|
|
updateDeleteButtonText();
|
|
}
|
|
|
|
function selectAllDeleteAliases() {
|
|
selectedAliases.clear();
|
|
for (const result of currentDeleteResults) {
|
|
selectedAliases.add(result.alias);
|
|
}
|
|
|
|
// Update UI
|
|
const checkboxes = document.querySelectorAll('.delete-checkbox');
|
|
const rows = document.querySelectorAll('.delete-table-row');
|
|
checkboxes.forEach(cb => cb.checked = true);
|
|
rows.forEach(row => row.classList.add('selected'));
|
|
|
|
updateDeleteButtonText();
|
|
}
|
|
|
|
function deselectAllDeleteAliases() {
|
|
selectedAliases.clear();
|
|
|
|
// Update UI
|
|
const checkboxes = document.querySelectorAll('.delete-checkbox');
|
|
const rows = document.querySelectorAll('.delete-table-row');
|
|
checkboxes.forEach(cb => cb.checked = false);
|
|
rows.forEach(row => row.classList.remove('selected'));
|
|
|
|
updateDeleteButtonText();
|
|
}
|
|
|
|
function updateDeleteButtonText() {
|
|
const btn = document.getElementById('deleteSelectedBtn');
|
|
const count = selectedAliases.size;
|
|
btn.textContent = `Delete Selected (${count})`;
|
|
btn.disabled = count === 0;
|
|
}
|
|
|
|
function confirmDeleteSelected() {
|
|
if (selectedAliases.size === 0) return;
|
|
|
|
const aliasArray = Array.from(selectedAliases);
|
|
let confirmHtml = `
|
|
<p>You are about to delete <strong>${aliasArray.length}</strong> alias(es):</p>
|
|
<div class="delete-confirm-list">
|
|
<ul>
|
|
`;
|
|
|
|
for (const alias of aliasArray) {
|
|
confirmHtml += `<li>${escapeHtml(alias)}</li>`;
|
|
}
|
|
|
|
confirmHtml += '</ul></div>';
|
|
|
|
document.getElementById('deleteConfirmContent').innerHTML = confirmHtml;
|
|
document.getElementById('deleteConfirmModal').classList.add('active');
|
|
}
|
|
|
|
function closeDeleteConfirm() {
|
|
document.getElementById('deleteConfirmModal').classList.remove('active');
|
|
}
|
|
|
|
async function executeDeleteSelected() {
|
|
const aliasArray = Array.from(selectedAliases);
|
|
|
|
if (aliasArray.length === 0) return;
|
|
|
|
closeDeleteConfirm();
|
|
|
|
try {
|
|
const response = await fetch('/delete_aliases_bulk', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ aliases: aliasArray })
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success' || data.status === 'partial');
|
|
|
|
// Refresh search results
|
|
if (data.status === 'success' || data.status === 'partial') {
|
|
// Clear selection
|
|
selectedAliases.clear();
|
|
updateDeleteButtonText();
|
|
|
|
// Re-run search to show updated results
|
|
await searchAliasesForDeletion();
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error deleting aliases: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
async function deleteSingleAliasQuick(alias, rowIndex) {
|
|
if (!confirm(`Delete ${alias}?`)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/delete_alias', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ alias: alias })
|
|
});
|
|
|
|
if (checkAuth(response)) return;
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
// Remove from selected if it was selected
|
|
selectedAliases.delete(alias);
|
|
|
|
// Remove from current results
|
|
currentDeleteResults = currentDeleteResults.filter(r => r.alias !== alias);
|
|
|
|
// Re-render table
|
|
renderDeleteResults(currentDeleteResults, false, currentDeleteResults.length);
|
|
|
|
showResult(`Alias ${alias} deleted successfully`, true);
|
|
} else {
|
|
showResult(data.message, false);
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error deleting alias: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Allow search on Enter key in delete modal
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const deleteSearchInput = document.getElementById('deleteSearchInput');
|
|
if (deleteSearchInput) {
|
|
deleteSearchInput.addEventListener('keypress', function(e) {
|
|
if (e.key === 'Enter') {
|
|
searchAliasesForDeletion();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Timed Alias Modal Functions
|
|
function openTimedAlias() {
|
|
document.getElementById('timedAliasModal').classList.add('active');
|
|
}
|
|
|
|
function closeTimedAlias() {
|
|
document.getElementById('timedAliasModal').classList.remove('active');
|
|
}
|
|
|
|
async function createTimedAlias() {
|
|
const username = document.getElementById('timedUsername').value;
|
|
const domain = document.getElementById('timedDomain').value;
|
|
|
|
if (!username || !domain) {
|
|
showResult('Both username and domain are required', false);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch('/create_timed_alias', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ username: username, domain: domain })
|
|
});
|
|
|
|
const data = await response.json();
|
|
showResult(data.message, data.status === 'success');
|
|
if (data.status === 'success') {
|
|
document.getElementById('timedUsername').value = '';
|
|
document.getElementById('timedDomain').value = '';
|
|
closeTimedAlias();
|
|
}
|
|
} catch (error) {
|
|
showResult(`Error creating timed alias: ${error.message}`, false);
|
|
}
|
|
}
|
|
|
|
// Close modals when clicking outside
|
|
document.getElementById('configModal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeConfig();
|
|
});
|
|
document.getElementById('createAliasModal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeCreateAlias();
|
|
});
|
|
document.getElementById('deleteAliasModal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeDeleteAliasesModal();
|
|
});
|
|
document.getElementById('deleteConfirmModal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeDeleteConfirm();
|
|
});
|
|
document.getElementById('timedAliasModal').addEventListener('click', function(e) {
|
|
if (e.target === this) closeTimedAlias();
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
<div class="footer">
|
|
<p style="padding-top:2%">© <a href="https://opensource.org/license/mit">MIT</a> 2026 Rune Olsen <a href="https://blog.rune.pm">Blog</a> — <a href="https://gitlab.pm/rune/malias-web">Source Code</a></p>
|
|
</div>
|
|
</html>
|