Skip to content

Commit

Permalink
Merge pull request #46 from Psiphon-Inc/v156
Browse files Browse the repository at this point in the history
v156
  • Loading branch information
adamkruger authored Jun 1, 2020
2 parents 22286b8 + a8d0764 commit f028faf
Show file tree
Hide file tree
Showing 18 changed files with 1,416 additions and 806 deletions.
21 changes: 4 additions & 17 deletions src/coretransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ bool CoreTransport::WriteParameterFiles(tstring& configFilename, tstring& server
config["DeviceRegion"] = WStringToUTF8(GetDeviceRegion());
config["EmitDiagnosticNotices"] = true;
config["EmitDiagnosticNetworkParameters"] = true;
config["EmitServerAlerts"] = true;

// Don't use an upstream proxy when in VPN mode. If the proxy is on a private network,
// we may not be able to route to it. If the proxy is on a public network we prefer not
Expand Down Expand Up @@ -540,22 +541,7 @@ bool CoreTransport::WriteParameterFiles(tstring& configFilename, tstring& server
.append(LOCAL_SETTINGS_APPDATA_SERVER_LIST_FILENAME);
serverListFilename = serverListPath;

string serverList = EMBEDDED_SERVER_LIST;

// Retain some existing server entries that were used by the legacy client
ServerEntries legacyEntries = ServerList::GetListFromSystem(LEGACY_SERVER_ENTRY_LIST_NAME);
if (legacyEntries.size() > MAX_LEGACY_SERVER_ENTRIES)
{
legacyEntries.resize(MAX_LEGACY_SERVER_ENTRIES);
}
if (legacyEntries.size() > 0 && serverList.length() > 0)
{
// EMBEDDED_SERVER_LIST may be LF-delimited, not LF-terminated
serverList += "\n";
}
serverList += ServerList::EncodeServerEntries(legacyEntries);

if (!WriteFile(serverListFilename, serverList))
if (!WriteFile(serverListFilename, EMBEDDED_SERVER_LIST))
{
my_print(NOT_SENSITIVE, false, _T("%s - write server list file failed (%d)"), __TFUNCTION__, GetLastError());
return false;
Expand Down Expand Up @@ -594,7 +580,7 @@ string CoreTransport::GetUpstreamProxyAddress()
if (!proxyConfig.httpsProxy.empty())
{
upstreamProxyAddress <<
WStringToUTF8(proxyConfig.httpsProxy) << ":" << proxyConfig.httpsProxyPort;
WStringToUTF8(proxyConfig.httpsProxy) << ":" << proxyConfig.httpsProxyPort;
}
}

Expand Down Expand Up @@ -1016,6 +1002,7 @@ void CoreTransport::HandleCoreProcessOutputLine(const char* line)
{
string regions = data["regions"].toStyledString();
my_print(NOT_SENSITIVE, false, _T("Available egress regions: %S"), regions.c_str());
// Processing this is left to main.js
}
else if (noticeType == "ActiveAuthorizationIDs")
{
Expand Down
94 changes: 57 additions & 37 deletions src/psiclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static bool g_htmlUiFinished = false;

bool HandlePsiCashCommand(const string& jsonString);
void InitPsiCash();
void ForegroundWindow(HWND hwnd);


//==== Controls ================================================================
Expand Down Expand Up @@ -127,20 +128,22 @@ void OnCreate(HWND hWndParent)

//==== String Table helpers ==================================================

#define STRING_KEY_STATE_STOPPED_TITLE "appbackend#state-stopped-title"
#define STRING_KEY_STATE_STOPPED_BODY "appbackend#state-stopped-body"
#define STRING_KEY_STATE_STARTING_TITLE "appbackend#state-starting-title"
#define STRING_KEY_STATE_STARTING_BODY "appbackend#state-starting-body"
#define STRING_KEY_STATE_CONNECTED_TITLE "appbackend#state-connected-title"
#define STRING_KEY_STATE_CONNECTED_BODY "appbackend#state-connected-body"
#define STRING_KEY_STATE_CONNECTED_REMINDER_TITLE "appbackend#state-connected-reminder-title"
#define STRING_KEY_STATE_CONNECTED_REMINDER_BODY "appbackend#state-connected-reminder-body"
#define STRING_KEY_STATE_CONNECTED_REMINDER_BODY_2 "appbackend#state-connected-reminder-body-2"
#define STRING_KEY_STATE_STOPPING_TITLE "appbackend#state-stopping-title"
#define STRING_KEY_STATE_STOPPING_BODY "appbackend#state-stopping-body"
#define STRING_KEY_MINIMIZED_TO_SYSTRAY_TITLE "appbackend#minimized-to-systray-title"
#define STRING_KEY_MINIMIZED_TO_SYSTRAY_BODY "appbackend#minimized-to-systray-body"
#define STRING_KEY_OS_UNSUPPORTED "appbackend#os-unsupported"
#define STRING_KEY_STATE_STOPPED_TITLE "appbackend#state-stopped-title"
#define STRING_KEY_STATE_STOPPED_BODY "appbackend#state-stopped-body"
#define STRING_KEY_STATE_STARTING_TITLE "appbackend#state-starting-title"
#define STRING_KEY_STATE_STARTING_BODY "appbackend#state-starting-body"
#define STRING_KEY_STATE_CONNECTED_TITLE "appbackend#state-connected-title"
#define STRING_KEY_STATE_CONNECTED_BODY "appbackend#state-connected-body"
#define STRING_KEY_STATE_CONNECTED_REMINDER_TITLE "appbackend#state-connected-reminder-title"
#define STRING_KEY_STATE_CONNECTED_REMINDER_BODY "appbackend#state-connected-reminder-body"
#define STRING_KEY_STATE_CONNECTED_REMINDER_BODY_2 "appbackend#state-connected-reminder-body-2"
#define STRING_KEY_STATE_STOPPING_TITLE "appbackend#state-stopping-title"
#define STRING_KEY_STATE_STOPPING_BODY "appbackend#state-stopping-body"
#define STRING_KEY_MINIMIZED_TO_SYSTRAY_TITLE "appbackend#minimized-to-systray-title"
#define STRING_KEY_MINIMIZED_TO_SYSTRAY_BODY "appbackend#minimized-to-systray-body"
#define STRING_KEY_OS_UNSUPPORTED "appbackend#os-unsupported"
#define STRING_KEY_DISALLOWED_TRAFFIC_NOTIFICATION_TITLE "appbackend#disallowed-traffic-notification-title"
#define STRING_KEY_DISALLOWED_TRAFFIC_NOTIFICATION_BODY "appbackend#disallowed-traffic-notification-body"

static map<string, wstring> g_stringTable;

Expand Down Expand Up @@ -563,7 +566,14 @@ static void ShowConnectedReminderBalloon()
return;
}

if (CONNECTION_MANAGER_STATE_CONNECTED == g_connectionManager.GetState())
// We'll interpret the presence of an authorization as an indication that
// we have an active Speed Boost. (At this time there are no other uses
// for authorizations in Windows. In the future we may need to examine
// active purchases.)
bool boosting = (g_connectionManager.GetAuthorizations().size() > 0);

if (g_connectionManager.GetState() == CONNECTION_MANAGER_STATE_CONNECTED &&
!boosting)
{
HICON hIcon = g_notifyIconConnected;
wstring infoTitle, infoBody;
Expand Down Expand Up @@ -840,6 +850,7 @@ static void HtmlUI_BeforeNavigateHandler(LPCTSTR url)
const LPCTSTR appBannerClick = PSIPHON_LINK_PREFIX _T("bannerclick");
const LPCTSTR psicashCommand = PSIPHON_LINK_PREFIX _T("psicash?");
const size_t psicashCommandLen = _tcslen(psicashCommand);
const LPCTSTR disallowedTraffic = PSIPHON_LINK_PREFIX _T("disallowedtraffic");

if (_tcscmp(url, appReady) == 0)
{
Expand Down Expand Up @@ -1006,6 +1017,18 @@ static void HtmlUI_BeforeNavigateHandler(LPCTSTR url)
goto done;
}
}
else if (_tcscmp(url, disallowedTraffic) == 0)
{
// We got a disallowed-traffic alert. Foreground and show systray notification.

ForegroundWindow(g_hWnd);

wstring infoTitle, infoBody;
(void)GetStringTableEntry(STRING_KEY_DISALLOWED_TRAFFIC_NOTIFICATION_TITLE, infoTitle);
(void)GetStringTableEntry(STRING_KEY_DISALLOWED_TRAFFIC_NOTIFICATION_BODY, infoBody);

UpdateSystrayIcon(NULL, infoTitle, infoBody);
}
else {
// Not one of our links. Open it in an external browser.
OpenBrowser(url);
Expand Down Expand Up @@ -1330,17 +1353,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
HWND otherWindow = FindWindow(g_szWindowClass, g_szTitle);
if (otherWindow)
{
// Un-minimize if necessary
WINDOWPLACEMENT wp = { 0 };
wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(otherWindow, &wp) &&
wp.showCmd == SW_SHOWMINIMIZED || wp.showCmd == SW_HIDE)
{
ShowWindow(otherWindow, SW_RESTORE);
}

ShowWindow(otherWindow, SW_SHOW);
SetForegroundWindow(otherWindow);
ForegroundWindow(otherWindow);
}
return FALSE;
}
Expand Down Expand Up @@ -1526,16 +1539,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
lParam == WM_RBUTTONDBLCLK ||
lParam == NIN_BALLOONUSERCLICK)
{
WINDOWPLACEMENT wp = { 0 };
wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(g_hWnd, &wp) &&
wp.showCmd == SW_SHOWMINIMIZED || wp.showCmd == SW_HIDE)
{
ShowWindow(g_hWnd, SW_RESTORE);
}

ShowWindow(g_hWnd, SW_SHOW);
SetForegroundWindow(g_hWnd);
ForegroundWindow(g_hWnd);
}
break;

Expand Down Expand Up @@ -1579,6 +1583,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}

/// Make the given window visible and foreground
void ForegroundWindow(HWND hwnd)
{
// Un-minimize if necessary
WINDOWPLACEMENT wp = { 0 };
wp.length = sizeof(WINDOWPLACEMENT);
if (GetWindowPlacement(hwnd, &wp) &&
wp.showCmd == SW_SHOWMINIMIZED || wp.showCmd == SW_HIDE)
{
ShowWindow(hwnd, SW_RESTORE);
}

ShowWindow(hwnd, SW_SHOW);
SetForegroundWindow(hwnd);
}


//
// PsiCash
Expand Down Expand Up @@ -1625,7 +1645,7 @@ void InitPsiCash() {

auto err = psicash::Lib::_().Init(false);
if (err) {
// Init failed, indicating file corruption or disk access problems.
// Init failed, indicating file corruption or disk access problems.
// We'll try to reset.
auto retryErr = psicash::Lib::_().Init(true);

Expand Down
21 changes: 18 additions & 3 deletions src/usersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
#define SYSTRAY_MINIMIZE_NAME "SystrayMinimize"
#define SYSTRAY_MINIMIZE_DEFAULT FALSE

#define DISABLE_DISALLOWED_TRAFFIC_ALERT_NAME "DisableDisallowedTrafficAlert"
#define DISABLE_DISALLOWED_TRAFFIC_ALERT_DEFAULT FALSE

#define COOKIES_NAME "UICookies"
#define COOKIES_DEFAULT ""

Expand Down Expand Up @@ -192,8 +195,11 @@ void Settings::ToJson(Json::Value& o_json)
o_json["EgressRegion"] = Settings::EgressRegion();
o_json["defaults"]["EgressRegion"] = EGRESS_REGION_DEFAULT;

o_json["SystrayMinimize"] = Settings::SystrayMinimize() ? TRUE : FALSE;;
o_json["SystrayMinimize"] = Settings::SystrayMinimize() ? TRUE : FALSE;
o_json["defaults"]["SystrayMinimize"] = SYSTRAY_MINIMIZE_DEFAULT;

o_json["DisableDisallowedTrafficAlert"] = Settings::DisableDisallowedTrafficAlert() ? TRUE : FALSE;
o_json["defaults"]["DisableDisallowedTrafficAlert"] = DISABLE_DISALLOWED_TRAFFIC_ALERT_DEFAULT;
}

// FromJson updates the stores settings from an object stored in JSON format.
Expand Down Expand Up @@ -284,6 +290,10 @@ bool Settings::FromJson(
BOOL systrayMinimize = json.get("SystrayMinimize", SYSTRAY_MINIMIZE_DEFAULT).asUInt();
// Does not require reconnect to apply change.
WriteRegistryDwordValue(SYSTRAY_MINIMIZE_NAME, systrayMinimize);

BOOL disableDisallowedTrafficAlert = json.get("DisableDisallowedTrafficAlert", DISABLE_DISALLOWED_TRAFFIC_ALERT_DEFAULT).asUInt();
// Does not require reconnect to apply change.
WriteRegistryDwordValue(DISABLE_DISALLOWED_TRAFFIC_ALERT_NAME, disableDisallowedTrafficAlert);
}
catch (exception& e)
{
Expand Down Expand Up @@ -346,12 +356,12 @@ string Settings::UpstreamProxyType()
string Settings::UpstreamProxyHostname()
{
string hostname = GetSettingString(UPSTREAM_PROXY_HOSTNAME_NAME, UPSTREAM_PROXY_HOSTNAME_DEFAULT);

int splitIndex = hostname.find_first_of("@");
if (splitIndex != string::npos) {
hostname = hostname.substr(splitIndex + 1, hostname.length() - 1);
}

return hostname;
}

Expand Down Expand Up @@ -435,6 +445,11 @@ bool Settings::SystrayMinimize()
return !!GetSettingDword(SYSTRAY_MINIMIZE_NAME, SYSTRAY_MINIMIZE_DEFAULT);
}

bool Settings::DisableDisallowedTrafficAlert()
{
return !!GetSettingDword(DISABLE_DISALLOWED_TRAFFIC_ALERT_NAME, DISABLE_DISALLOWED_TRAFFIC_ALERT_DEFAULT);
}

/*
Settings that are not exposed in the UI.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/usersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace Settings

bool SystrayMinimize();

bool DisableDisallowedTrafficAlert();

bool SkipProxySettings();
bool SkipAutoConnect();

Expand Down
2 changes: 1 addition & 1 deletion src/webui/_locales/ar/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@
"description": "Body text of a modal dialog shown when a PsiCash transaction (like Speed Boost purchase) fails. The word 'PsiCash' must not be translated or transliterated."
},
"psicash#transaction-InsufficientBalance-title": {
"message": "Insufficient PsiCash balance",
"message": "رصيد PsiCash غير كاف",
"description": "Title of a modal dialog shown when a PsiCash transaction (like Speed Boost purchase) fails. The user doesn't have enough PsiCash to make the attempted purchase. The word 'PsiCash' must not be translated or transliterated."
},
"psicash#transaction-InsufficientBalance-body": {
Expand Down
Loading

0 comments on commit f028faf

Please sign in to comment.