Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Incorrect radius error & retry handling #3490

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 13 additions & 23 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,29 +759,19 @@ class Monitor extends BeanModel {
port = this.port;
}

try {
const resp = await radius(
this.hostname,
this.radiusUsername,
this.radiusPassword,
this.radiusCalledStationId,
this.radiusCallingStationId,
this.radiusSecret,
port,
this.interval * 1000 * 0.8,
);
if (resp.code) {
bean.msg = resp.code;
}
bean.status = UP;
} catch (error) {
bean.status = DOWN;
if (error.response?.code) {
bean.msg = error.response.code;
} else {
bean.msg = error.message;
}
}
const resp = await radius(
this.hostname,
this.radiusUsername,
this.radiusPassword,
this.radiusCalledStationId,
this.radiusCallingStationId,
this.radiusSecret,
port,
this.interval * 1000 * 0.4,
);

bean.msg = resp.code;
bean.status = UP;
bean.ping = dayjs().valueOf() - startTime;
} else if (this.type === "redis") {
let startTime = dayjs().valueOf();
Expand Down
7 changes: 7 additions & 0 deletions server/util-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ exports.radius = function (
host: hostname,
hostPort: port,
timeout: timeout,
retries: 1,
dictionaries: [ file ],
});

Expand All @@ -497,6 +498,12 @@ exports.radius = function (
[ attributes.CALLING_STATION_ID, callingStationId ],
[ attributes.CALLED_STATION_ID, calledStationId ],
],
}).catch((error) => {
if (error.response?.code) {
throw Error(error.response.code);
} else {
throw Error(error.message);
}
});
};

Expand Down
13 changes: 13 additions & 0 deletions test/test-radius.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Container running a test radius server
# More instructions in https://github.com/louislam/uptime-kuma/pull/1635

FROM freeradius/freeradius-server:latest

RUN mkdir -p /etc/raddb/mods-config/files/

RUN echo "client net {" > /etc/raddb/clients.conf
RUN echo " ipaddr = 172.17.0.0/16" >> /etc/raddb/clients.conf
RUN echo " secret = testing123" >> /etc/raddb/clients.conf
RUN echo "}" >> /etc/raddb/clients.conf

RUN echo "bob Cleartext-Password := \"testpw\"" > /etc/raddb/mods-config/files/authorize