mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 00:37:00 +08:00
status cmd will report the server uptime
This commit is contained in:
@@ -5,6 +5,7 @@ message status_rep
|
||||
required uint32 pid = 2;
|
||||
required uint32 sec_mod_pid = 3;
|
||||
required uint32 active_clients = 4;
|
||||
required uint32 start_time = 5;
|
||||
}
|
||||
|
||||
message bool_msg
|
||||
|
||||
@@ -156,6 +156,7 @@ static void method_status(method_ctx *ctx, int cfd, uint8_t * msg,
|
||||
|
||||
rep.status = 1;
|
||||
rep.pid = getpid();
|
||||
rep.start_time = ctx->s->start_time;
|
||||
rep.sec_mod_pid = ctx->s->sec_mod_pid;
|
||||
rep.active_clients = ctx->s->active_clients;
|
||||
|
||||
|
||||
@@ -872,6 +872,7 @@ int main(int argc, char** argv)
|
||||
s->main_pool = main_pool;
|
||||
s->worker_pool = worker_pool;
|
||||
s->creds = &creds;
|
||||
s->start_time = time(0);
|
||||
|
||||
list_head_init(&s->proc_list.head);
|
||||
list_head_init(&s->ban_list.head);
|
||||
|
||||
@@ -180,6 +180,7 @@ typedef struct main_server_st {
|
||||
pid_t sec_mod_pid;
|
||||
|
||||
unsigned active_clients;
|
||||
time_t start_time;
|
||||
|
||||
void * auth_extra;
|
||||
|
||||
|
||||
@@ -209,6 +209,9 @@ int handle_status_cmd(struct unix_ctx *ctx, const char *arg)
|
||||
int ret;
|
||||
struct cmd_reply_st raw;
|
||||
StatusRep *rep;
|
||||
char str_since[64];
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
PROTOBUF_ALLOCATOR(pa, ctx);
|
||||
|
||||
init_reply(&raw);
|
||||
@@ -224,6 +227,12 @@ int handle_status_cmd(struct unix_ctx *ctx, const char *arg)
|
||||
|
||||
printf("OpenConnect SSL VPN server\n");
|
||||
printf(" Status: %s\n", rep->status != 0 ? "online" : "error");
|
||||
|
||||
t = rep->start_time;
|
||||
tm = localtime(&t);
|
||||
strftime(str_since, sizeof(str_since), "%Y-%m-%d %H:%M", tm);
|
||||
printf(" Up since: %s\n", str_since);
|
||||
|
||||
printf(" Clients: %u\n", (unsigned)rep->active_clients);
|
||||
printf("\n");
|
||||
printf(" Server PID: %u\n", (unsigned)rep->pid);
|
||||
|
||||
Reference in New Issue
Block a user