fix: ip parse panic
This commit is contained in:
parent
f746290d97
commit
b1d812d07b
5 changed files with 29 additions and 9 deletions
|
@ -3,11 +3,18 @@
|
|||
{% endblock %} {% block body %} {{ macros::nav() }}
|
||||
<main class="flex flex-col gap-2">
|
||||
<div class="card-nest w-full">
|
||||
<div class="card small flex items-center gap-2">
|
||||
<div class="card small flex items-center justify-between gap-2">
|
||||
<div class="flex items-center gap-2">
|
||||
{{ icon "ban" }}
|
||||
<span>{{ text "general:link.ip_bans" }}</span>
|
||||
</div>
|
||||
|
||||
<button onclick="prompt_ban_ip()" class="quaternary small">
|
||||
{{ icon "plus" }}
|
||||
<span>{{ text "communities:action.create" }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-2">
|
||||
<!-- prettier-ignore -->
|
||||
{% for item in items %}
|
||||
|
@ -46,6 +53,16 @@
|
|||
</main>
|
||||
|
||||
<script>
|
||||
async function prompt_ban_ip() {
|
||||
const ip = await trigger("atto::prompt", ["IP address (or prefix):"]);
|
||||
|
||||
if (!ip) {
|
||||
return;
|
||||
}
|
||||
|
||||
trigger("atto::ban_ip", [ip]);
|
||||
}
|
||||
|
||||
async function remove_ipban(ip) {
|
||||
if (
|
||||
!(await trigger("atto::confirm", [
|
||||
|
@ -55,7 +72,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
fetch(`/api/v1/bans/${id}`, {
|
||||
fetch(`/api/v1/bans/${ip}`, {
|
||||
method: "DELETE",
|
||||
})
|
||||
.then((res) => res.json())
|
||||
|
|
|
@ -531,7 +531,7 @@ media_theme_pref();
|
|||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
trigger("atto::toast", [
|
||||
res.success ? "success" : "error",
|
||||
res.ok ? "success" : "error",
|
||||
res.message,
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -256,7 +256,7 @@ pub fn routes() -> Router {
|
|||
)
|
||||
// ipbans
|
||||
.route("/bans/{ip}", post(auth::ipbans::create_request))
|
||||
.route("/bans/id/{id}", delete(auth::ipbans::delete_request))
|
||||
.route("/bans/{ip}", delete(auth::ipbans::delete_request))
|
||||
// reports
|
||||
.route("/reports", post(reports::create_request))
|
||||
.route("/reports/{id}", delete(reports::delete_request))
|
||||
|
|
|
@ -39,8 +39,8 @@ impl DataManager {
|
|||
|
||||
let res = query_row!(
|
||||
&conn,
|
||||
"SELECT * FROM ipbans WHERE ip LIKE $1",
|
||||
&[&format!("{}%", addr.prefix(None))],
|
||||
"SELECT * FROM ipbans WHERE ip = $1",
|
||||
&[&addr.prefix(None)],
|
||||
|x| { Ok(Self::get_ipban_from_row(x)) }
|
||||
);
|
||||
|
||||
|
|
|
@ -25,7 +25,10 @@ impl From<&str> for RemoteAddr {
|
|||
}
|
||||
} else {
|
||||
// ipv4 (4 bytes; 32 bits)
|
||||
Self(value.parse().unwrap(), AddrProto::IPV4)
|
||||
Self(
|
||||
value.parse().unwrap_or("0.0.0.0:1000".parse().unwrap()),
|
||||
AddrProto::IPV4,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue