Add backup delete action and return button
This commit is contained in:
1 parent
104bf8f390
commit
916e50fa5a
1 file changed
+50
-14
@@ -145,6 +145,49 @@ download_file() {
|
||||
exit 0
|
||||
}
|
||||
|
||||
handle_delete_backup() {
|
||||
local file confirm
|
||||
file="$(param file)"
|
||||
confirm="$(param confirm)"
|
||||
RESULT_TITLE="Удаление бэкапа"
|
||||
RESULT_FILE="${TMPDIR:-/tmp}/owrt-full-backup-result.$$"
|
||||
|
||||
if [ "$confirm" != "DELETE" ]; then
|
||||
RESULT_CODE=2
|
||||
printf 'Для удаления введи DELETE.\n' >"$RESULT_FILE"
|
||||
return
|
||||
fi
|
||||
|
||||
valid_abs_path "$file" || {
|
||||
RESULT_CODE=2
|
||||
printf 'Неверный путь к файлу.\n' >"$RESULT_FILE"
|
||||
return
|
||||
}
|
||||
|
||||
case "$file" in
|
||||
*.tar.gz|*.tar.gz.sha256) ;;
|
||||
*)
|
||||
RESULT_CODE=2
|
||||
printf 'Удалять можно только архивы бэкапа и checksum-файлы.\n' >"$RESULT_FILE"
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ ! -f "$file" ]; then
|
||||
RESULT_CODE=2
|
||||
printf 'Файл не найден: %s\n' "$file" >"$RESULT_FILE"
|
||||
return
|
||||
fi
|
||||
|
||||
if rm -f "$file" "$file.sha256" 2>"$RESULT_FILE"; then
|
||||
RESULT_CODE=0
|
||||
printf 'Удалено: %s\n' "$file" >"$RESULT_FILE"
|
||||
else
|
||||
RESULT_CODE=1
|
||||
printf 'Не удалось удалить: %s\n' "$file" >>"$RESULT_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
run_backend() {
|
||||
RESULT_TITLE="$1"
|
||||
shift
|
||||
@@ -264,6 +307,7 @@ handle_action() {
|
||||
inspect) handle_inspect ;;
|
||||
restore) handle_restore ;;
|
||||
save_defaults) handle_save_defaults ;;
|
||||
delete_backup) handle_delete_backup ;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -305,8 +349,8 @@ backup_rows() {
|
||||
base="$(basename "$file")"
|
||||
size="$(ls -lh "$file" 2>/dev/null | awk '{print $5}')"
|
||||
mtime="$(ls -l "$file" 2>/dev/null | awk '{print $6" "$7" "$8}')"
|
||||
printf '<tr><td><code>%s</code></td><td>%s</td><td>%s</td><td><a href="%s?key=%s&action=download&file=%s">скачать</a></td></tr>' \
|
||||
"$(h "$base")" "$(h "$size")" "$(h "$mtime")" "$(self_url)" "$key" "$(h "$file")"
|
||||
printf '<tr><td><code>%s</code></td><td>%s</td><td>%s</td><td class="actions"><a class="button small" href="%s?key=%s&action=download&file=%s">Скачать</a><form method="post" action="%s" onsubmit="return confirm('"'"'Удалить этот бэкап?'"'"');"><input type="hidden" name="key" value="%s"><input type="hidden" name="action" value="delete_backup"><input type="hidden" name="file" value="%s"><input type="hidden" name="confirm" value="DELETE"><button class="danger small" type="submit">Удалить</button></form></td></tr>' \
|
||||
"$(h "$base")" "$(h "$size")" "$(h "$mtime")" "$(self_url)" "$key" "$(h "$file")" "$(self_url)" "$key" "$(h "$file")"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -351,12 +395,15 @@ label { display: block; margin: 9px 0 4px; font-weight: 600; }
|
||||
input[type=text], input[type=number] { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--text); padding: 9px; }
|
||||
.checks label { font-weight: 500; display: flex; gap: 8px; align-items: center; margin: 8px 0; }
|
||||
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; padding: 8px 12px; text-decoration: none; font-weight: 700; cursor: pointer; }
|
||||
.small { min-height: 30px; padding: 6px 9px; font-size: 12px; }
|
||||
.danger { background: var(--bad); }
|
||||
.muted { color: var(--muted); }
|
||||
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
||||
pre { overflow: auto; background: rgba(127,127,127,.12); border-radius: 6px; padding: 10px; }
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
td, th { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
|
||||
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
|
||||
.actions form { margin: 0; }
|
||||
.status { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.pill { border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; color: var(--muted); }
|
||||
@media (max-width: 820px) { .span4, .span6, .span8, .span12 { grid-column: 1 / -1; } main { padding: 12px; } .hero { align-items: flex-start; flex-direction: column; } .hero-actions { justify-content: flex-start; min-width: 0; } }
|
||||
@@ -370,7 +417,7 @@ td, th { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: lef
|
||||
<p>Веб-панель для полного бэкапа OpenWrt без сборки IPK. Держи эту ссылку в секрете.</p>
|
||||
</div>
|
||||
<div class="hero-actions">
|
||||
<span class="pill">LuCI: Службы</span>
|
||||
<a class="button" href="/cgi-bin/luci/admin/status/overview">Вернуться в OpenWrt</a>
|
||||
<span class="pill">Backup / Restore</span>
|
||||
<span class="pill">OpenWrt 22-25</span>
|
||||
</div>
|
||||
@@ -462,17 +509,6 @@ $(backup_rows)
|
||||
<button type="submit">Сохранить настройки</button>
|
||||
</form>
|
||||
|
||||
<div class="panel span6">
|
||||
<h2>Установка / удаление через Git</h2>
|
||||
<p>Установка через clone:</p>
|
||||
<pre>git clone $(h "$PROJECT_URL").git
|
||||
cd luci-app-owrt-full-backup
|
||||
sh install.sh</pre>
|
||||
<p>Установка одной командой:</p>
|
||||
<pre>wget -O - $(h "$RAW_URL")/install.sh | sh</pre>
|
||||
<p>Удаление:</p>
|
||||
<pre>wget -O - $(h "$RAW_URL")/uninstall.sh | sh</pre>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
Reference in new issue
Block a user