Пример #1
0
        public static string KeyboardLayoutToStr(this GuaKeyboardLayout k, bool unknownAsDefault = false)
        {
            switch (k)
            {
            case GuaKeyboardLayout.EnglishUs: return("en-us-qwerty");

            case GuaKeyboardLayout.Japanese: return("ja-jp-qwerty");

            default:
                if (unknownAsDefault == false)
                {
                    throw new CoresLibException($"Unknown keyboard layout value: {k}");
                }
                else
                {
                    return("en-us-qwerty");
                }
            }
        }
Пример #2
0
    public async Task <IActionResult> IndexAsync(ThinWebClientModelIndex form, string?pcid, string?deleteAll, string?button_wol)
    {
        ThinWebClientProfile?historySelectedProfile = null;

        ThinWebClientProfile profile = form.CurrentProfile;

        profile.Normalize();

        ThinWebClientHistory history = ThinWebClientHistory.LoadFromCookie(this, this.Client.SettingsFastSnapshot.CookieEncryptPassword);

        if (this._IsPostBack())
        {
            if (profile.Pcid._IsFilled())
            {
                // 現在のプロファイルの保存
                this._EasySaveCookie("thin_current_profile", profile.CloneAsDefault(), GetCookieOption(), true, this.Client.SettingsFastSnapshot.CookieEncryptPassword);

                // ヒストリへの追加
                history.Add(profile);
                history.SaveToCookie(this, GetCookieOption(), this.Client.SettingsFastSnapshot.CookieEncryptPassword);

                // thin_last_pcid の保存
                this._EasySaveCookie("thin_last_pcid", profile.Pcid, GetCookieOption());

                var    clientIp   = Request.HttpContext.Connection.RemoteIpAddress._UnmapIPv4() !;
                var    clientPort = Request.HttpContext.Connection.RemotePort;
                string clientFqdn = await Client.DnsResolver.GetHostNameSingleOrIpAsync(clientIp);

                // Rate limit
                if (this.Client.RateLimit.TryInput(clientIp.ToString(), out _) == false)
                {
                    throw new CoresException(this.Page.Stb["THINWEB_RATELIMIT_EXCEEDED"]);
                }

                var tc = this.Client.CreateThinClient(this.StrTable);

                if (button_wol._ToBool() == false)
                {
                    // 普通の接続
                    WideTunnelClientOptions wideOptions = new WideTunnelClientOptions(WideTunnelClientFlags.None, clientIp.ToString(), clientFqdn, clientPort);

                    // セッションの開始
                    var session = tc.StartConnect(new ThinClientConnectOptions(profile.Pcid, clientIp, clientFqdn, this.Client.SettingsFastSnapshot.Debug_EnableGuacdMode, wideOptions, form.IsWebpSupported, profile.Preference, profile._CloneWithJson()),
                                                  this.Client.SettingsFastSnapshot.MaxConcurrentSessionsPerClientIp);
                    string sessionId = session.SessionId;

                    // セッション ID をもとにした URL にリダイレクト
                    return(Redirect($"/ThinWebClient/Session/{sessionId}/?pcid={profile.Pcid._MakeVerySafeAsciiOnlyNonSpaceString()}"));
                }
                else
                {
                    try
                    {
                        // WoL 信号の発射
                        WideTunnelClientOptions wideOptions = new WideTunnelClientOptions(WideTunnelClientFlags.WoL, clientIp.ToString(), clientFqdn, clientPort);

                        await tc.ExecuteWoLAsync(new ThinClientConnectOptions(profile.Preference.WoLTriggerPcid, clientIp, clientFqdn, false, wideOptions, form.IsWebpSupported, profile.Preference, profile._CloneWithJson()),
                                                 profile.Pcid, this._GetRequestCancellationToken());

                        // WoL OK メッセージ
                        form.WolOkMessage = this.Page.Stb["DU_WOL_MSG"]._FormatC(profile.Pcid, profile.Preference.WoLTriggerPcid);
                    }
                    catch (Exception ex)
                    {
                        // WoL エラーメッセージの文字列化
                        string msg = ThinWebClientErrorUtil.GetFriendlyErrorMessage(ex, this.Page);

                        form.WolErrorMessage = msg;

                        form.JumpToWol = true;
                    }
                }
            }
        }
        else
        {
            if (pcid._IsEmpty())
            {
                // Query String の pcid が空の場合、Cookie から読み出す
                pcid = this._EasyLoadCookie <string>("thin_last_pcid")._NonNullTrim();
            }

            if (deleteAll._ToBool())
            {
                // History をすべて消去するよう指示された
                // Cookie の History をすべて消去する
                history.Clear();
                history.SaveToCookie(this, GetCookieOption(), this.Client.SettingsFastSnapshot.CookieEncryptPassword);
                this._EasySaveCookie("thin_last_pcid", "", GetCookieOption());

                // トップページにリダイレクトする
                return(Redirect("/"));
            }
            else if (pcid._IsFilled())
            {
                // History から履歴を指定された。id を元に履歴からプロファイルを読み出す
                historySelectedProfile = history.Items.Where(h => h.Pcid._IsSamei(pcid)).FirstOrDefault();
            }

            if (historySelectedProfile == null)
            {
                // デフォルト値
                GuaKeyboardLayout defaultKeyboardLayout = GuaKeyboardLayout.Japanese;

                if (Page.CurrentLanguage.Key._IsSamei("ja") == false)
                {
                    // 日本語以外の環境では英語キーボードをデフォルトで選択する
                    defaultKeyboardLayout = GuaKeyboardLayout.EnglishUs;
                }

                profile = this._EasyLoadCookie <ThinWebClientProfile>("thin_current_profile", true, this.Client.SettingsFastSnapshot.CookieEncryptPassword) ?? new ThinWebClientProfile(defaultKeyboardLayout);
            }
            else
            {
                // History で選択された値
                profile = historySelectedProfile;
            }

            profile.Normalize();
            form.CurrentProfile = profile;

            // GET の場合は必ず PCID 入力ボックスをフォーカスする
            form.FocusToPcid = true;
        }

        form.FillHistory(history);

        if (historySelectedProfile != null)
        {
            form.SelectedHistory = form.HistoryItems.Where(x => x.Text._IsSamei(historySelectedProfile.Pcid)).FirstOrDefault()?.Value ?? "";
        }

        return(View(form));
    }
Пример #3
0
    } = new GuaPreference();                                             // 接続設定

    public ThinWebClientProfile(GuaKeyboardLayout keyboardLayout = GuaKeyboardLayout.Japanese)
    {
        this.Preference.KeyboardLayout = keyboardLayout;
    }