static int add_option(options_t *options, int i, TCHAR **p) { if (streq(p[0], _T("help"))) { TCHAR caption[200]; LoadLocalizedStringBuf(caption, _countof(caption), IDS_NFO_USAGECAPTION); ShowLocalizedMsgEx(MB_OK, caption, IDS_NFO_USAGE); exit(0); } else if (streq(p[0], _T("connect")) && p[1]) { ++i; static int auto_connect_nr = 0; if (auto_connect_nr == MAX_CONFIGS) { /* Too many configs */ ShowLocalizedMsg(IDS_ERR_MANY_CONFIGS, MAX_CONFIGS); exit(1); } options->auto_connect[auto_connect_nr++] = p[1]; } else if (streq(p[0], _T("exe_path")) && p[1]) { ++i; _tcsncpy(options->exe_path, p[1], _countof(options->exe_path) - 1); } else if (streq(p[0], _T("config_dir")) && p[1]) { ++i; _tcsncpy(options->config_dir, p[1], _countof(options->config_dir) - 1); } else if (streq(p[0], _T("ext_string")) && p[1]) { ++i; _tcsncpy(options->ext_string, p[1], _countof(options->ext_string) - 1); } else if (streq(p[0], _T("log_dir")) && p[1]) { ++i; _tcsncpy(options->log_dir, p[1], _countof(options->log_dir) - 1); } else if (streq(p[0], _T("priority_string")) && p[1]) { ++i; _tcsncpy(options->priority_string, p[1], _countof(options->priority_string) - 1); } else if (streq(p[0], _T("append_string")) && p[1]) { ++i; _tcsncpy(options->append_string, p[1], _countof(options->append_string) - 1); } else if (streq(p[0], _T("log_viewer")) && p[1]) { ++i; _tcsncpy(options->log_viewer, p[1], _countof(options->log_viewer) - 1); } else if (streq(p[0], _T("editor")) && p[1]) { ++i; _tcsncpy(options->editor, p[1], _countof(options->editor) - 1); } else if (streq(p[0], _T("allow_edit")) && p[1]) { ++i; _tcsncpy(options->allow_edit, p[1], _countof(options->allow_edit) - 1); } else if (streq(p[0], _T("allow_service")) && p[1]) { ++i; _tcsncpy(options->allow_service, p[1], _countof(options->allow_service) - 1); } else if (streq(p[0], _T("allow_password")) && p[1]) { ++i; _tcsncpy(options->allow_password, p[1], _countof(options->allow_password) - 1); } else if (streq(p[0], _T("allow_proxy")) && p[1]) { ++i; _tcsncpy(options->allow_proxy, p[1], _countof(options->allow_proxy) - 1); } else if (streq(p[0], _T("show_balloon")) && p[1]) { ++i; _tcsncpy(options->show_balloon, p[1], _countof(options->show_balloon) - 1); } else if (streq(p[0], _T("service_only")) && p[1]) { ++i; _tcsncpy(options->service_only, p[1], _countof(options->service_only) - 1); } else if (streq(p[0], _T("show_script_window")) && p[1]) { ++i; _tcsncpy(options->show_script_window, p[1], _countof(options->show_script_window) - 1); } else if (streq(p[0], _T("silent_connection")) && p[1]) { ++i; _tcsncpy(options->silent_connection, p[1], _countof(options->silent_connection) - 1); } else if (streq(p[0], _T("passphrase_attempts")) && p[1]) { ++i; _tcsncpy(options->psw_attempts_string, p[1], _countof(options->psw_attempts_string) - 1); } else if (streq(p[0], _T("connectscript_timeout")) && p[1]) { ++i; _tcsncpy(options->connectscript_timeout_string, p[1], _countof(options->connectscript_timeout_string) - 1); } else if (streq(p[0], _T("disconnectscript_timeout")) && p[1]) { ++i; _tcsncpy(options->disconnectscript_timeout_string, p[1], _countof(options->disconnectscript_timeout_string) - 1); } else if (streq(p[0], _T("preconnectscript_timeout")) && p[1]) { ++i; _tcsncpy(options->preconnectscript_timeout_string, p[1], _countof(options->preconnectscript_timeout_string) - 1); } else { /* Unrecognized option or missing parameter */ ShowLocalizedMsg(IDS_ERR_BAD_OPTION, p[0]); exit(1); } return i; }
/* * Handle a state change notification from the OpenVPN management interface * Format <TIMESTAMP>,<STATE>,[<MESSAGE>],[<LOCAL_IP>][,<REMOTE_IP>] */ void OnStateChange(connection_t *c, char *data) { char *pos, *state, *message; pos = strchr(data, ','); if (pos == NULL) return; *pos = '\0'; state = pos + 1; pos = strchr(state, ','); if (pos == NULL) return; *pos = '\0'; message = pos + 1; pos = strchr(message, ','); if (pos == NULL) return; *pos = '\0'; if (strcmp(state, "CONNECTED") == 0) { /* Run Connect Script */ if (c->state == connecting || c->state == resuming) RunConnectScript(c, false); /* Save the local IP address if available */ char *local_ip = pos + 1; pos = strchr(local_ip, ','); if (pos != NULL) *pos = '\0'; /* Convert the IP address to Unicode */ MultiByteToWideChar(CP_ACP, 0, local_ip, -1, c->ip, _countof(c->ip)); /* Show connection tray balloon */ if ((c->state == connecting && o.show_balloon != 0) || (c->state == resuming && o.show_balloon != 0) || (c->state == reconnecting && o.show_balloon == 2)) { TCHAR msg[256]; LoadLocalizedStringBuf(msg, _countof(msg), IDS_NFO_NOW_CONNECTED, c->config_name); ShowTrayBalloon(msg, (_tcslen(c->ip) ? LoadLocalizedString(IDS_NFO_ASSIGN_IP, c->ip) : _T(""))); } /* Save time when we got connected. */ c->connected_since = atoi(data); c->failed_psw_attempts = 0; c->state = connected; SetMenuStatus(c, connected); SetTrayIcon(connected); SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_CONNECTED)); SetStatusWinIcon(c->hwndStatus, ID_ICO_CONNECTED); /* Hide Status Window */ ShowWindow(c->hwndStatus, SW_HIDE); } else if (strcmp(state, "RECONNECTING") == 0) { if (strcmp(message, "auth-failure") == 0 || strcmp(message, "private-key-password-failure") == 0) c->failed_psw_attempts++; if (strcmp(message, "auth-failure") == 0 && (c->flags & FLAG_SAVE_AUTH_PASS)) SaveAuthPass(c->config_name, L""); else if (strcmp(message, "private-key-password-failure") == 0 && (c->flags & FLAG_SAVE_KEY_PASS)) SaveKeyPass(c->config_name, L""); c->state = reconnecting; CheckAndSetTrayIcon(); SetDlgItemText(c->hwndStatus, ID_TXT_STATUS, LoadLocalizedString(IDS_NFO_STATE_RECONNECTING)); SetStatusWinIcon(c->hwndStatus, ID_ICO_CONNECTING); } }