diff --git a/main.c b/main.c index ed676e3..13c09b2 100644 --- a/main.c +++ b/main.c @@ -121,6 +121,7 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, { stop, OnStop }, { needok, OnNeedOk }, { needstr, OnNeedStr }, + { echo, OnEcho }, { 0, NULL } }; InitManagement(handler); diff --git a/manage.c b/manage.c index 583e747..2891c78 100644 --- a/manage.c +++ b/manage.c @@ -322,6 +322,11 @@ OnManagement(SOCKET sk, LPARAM lParam) if (rtmsg_handler[needstr]) rtmsg_handler[needstr](c, pos + 9); } + else if (strncmp(pos, "ECHO:", 5) == 0) + { + if (rtmsg_handler[echo]) + rtmsg_handler[echo](c, pos + 5); + } } else if (c->manage.cmd_queue) { diff --git a/openvpn.c b/openvpn.c index 1ae7325..0f29ef5 100644 --- a/openvpn.c +++ b/openvpn.c @@ -108,6 +108,7 @@ OnReady(connection_t *c, UNUSED char *msg) { ManagementCommand(c, "state on", NULL, regular); ManagementCommand(c, "log all on", OnLogLine, combined); + ManagementCommand(c, "echo all on", OnEcho, combined); } @@ -693,6 +694,38 @@ out: return ret; } +/* + * Handle >ECHO: request from OpenVPN management interface + * Expect msg = timestamp,message + */ +void +OnEcho(connection_t *c, char *msg) +{ + WCHAR errmsg[256]; + + PrintDebug(L"OnEcho with msg = %S", msg); + if (!(msg = strchr(msg, ','))) + { + PrintDebug(L"OnEcho: msg format not recognized"); + return; + } + msg++; + + if (strcmp(msg, "forget-passwords") == 0) + { + DeleteSavedPasswords(c->config_name); + } + else if (strcmp(msg, "save-passwords") == 0) + { + c->flags |= (FLAG_SAVE_KEY_PASS | FLAG_SAVE_AUTH_PASS); + } + else + { + _sntprintf_0(errmsg, L"WARNING: Unknown ECHO directive '%S' ignored.", msg); + WriteStatusLog(c, L"GUI> ", errmsg, false); + } +} + /* * Handle >PASSWORD: request from OpenVPN management interface */ diff --git a/openvpn.h b/openvpn.h index 9551010..2bfa1d2 100644 --- a/openvpn.h +++ b/openvpn.h @@ -37,6 +37,7 @@ void OnPassword(connection_t *, char *); void OnStop(connection_t *, char *); void OnNeedOk(connection_t *, char *); void OnNeedStr(connection_t *, char *); +void OnEcho(connection_t *, char *); void ResetSavePasswords(connection_t *);