public async Task <IActionResult> Registracija(RegisterRequest model) { var response = await _authApi.RegisterAsync(model); if (response.StatusCode == HttpStatusCode.OK) { return(Redirect("/Prijava")); } else { TempData["error_message"] = ErrorParser.Parse(response.Error.Content); return(View(nameof(Index), model)); } }
protected override void HandleCommon(Session session, PacketReader packet) { packet.ReadByte(); byte function = packet.ReadByte(); if (function == 1) { // Some random data that isn't text... // Example: 56 00 00 01 03 03 00 66 70 73 9B D2 6A 42 29 73 07 44 A3 45 00 00 00 00 00 00 00 00 70 42 03 00 6D 65 6D BC 2E 01 45 B4 FA B3 43 A3 45 00 00 00 A0 FE 44 00 80 01 45 03 00 6C 61 74 00 00 00 00 00 00 00 00 A3 45 00 00 00 00 00 00 00 00 00 00 return; } try { StringBuilder builder = new(); while (packet.Available > 2) { string message = packet.ReadUnicodeString(); if (message.Contains("exception")) { // Read remaining string string debug = packet.ReadUnicodeString(); SockExceptionInfo exceptionInfo = ErrorParser.Parse(debug); Logger.Error("[{message}] [SendOp: {sendOp}] [Offset: {offset}] [Hint: {hint}]", message, exceptionInfo.SendOp, exceptionInfo.Offset, exceptionInfo.Hint); session.OnError?.Invoke(session, debug); return; } builder.Append(message); } Logger.Warning("Client Log: {builder}", builder); } catch (Exception ex) { Logger.Error("Error parsing DEBUG_MSG packet:{packet} f({function}), {ex}", packet, function, ex); } }
public static async Task <string> GetVerifyString(this S1WebClient client) { string verify = ""; //use DownloadString will just return cached data, which is not what i want //post dummy data to disable cache var privacyPage = await client.PostDataTaskAsync(new Uri(UserAction.PrivacyUrl)); var root = new HtmlDoc(privacyPage).RootElement; var input = root.FindFirst("input", (e) => e.Attributes["name"] == "verify"); if (input != null) { verify = input.Attributes["value"]; } else { throw new S1UserException(ErrorParser.Parse(root)); } return(verify); }
public async Task <IActionResult> Prijava(LoginRequest model) { var response = await _authApi.LoginAsync(model); if (response.StatusCode == HttpStatusCode.OK) { HttpContext.SetJwt(response.Content.Token); var jwt = response.Content.Token; var handler = new JwtSecurityTokenHandler(); var token = handler.ReadJwtToken(jwt); var role = token.Claims.First(claim => claim.Type == "role").Value; switch (role) { case "Administrator": return(Redirect("/Administrator/Home/Index")); case "Uposlenik": return(Redirect("/Uposlenik/Home/Index")); case "Korisnik": return(Redirect("/Korisnik/Home/Index")); default: return(Redirect("/Home/Index")); } } else { TempData["error_message"] = ErrorParser.Parse(response.Error.Content); return(View(nameof(Index), model)); } }
private async void RequestData(DisplayRootRegistry displayRootRegistry, DataUpdaterViewModel dataUpdater) { var net = new Net(); var dataLauncher = new LauncherInfoSerializer(); var proc = new ProcessHelper(); var settingHelp = new SettingHelper(); LauncherSettingLastSerializer lastSettingLauncher = null; try { lastSettingLauncher = settingHelp.Read <LauncherSettingLastSerializer>(CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); dataLauncher.version = lastSettingLauncher.Info.Version; } catch (Exception ex) { if (ex is DirectoryNotFoundException || ex is FileNotFoundException) { MessageBox.Show(CommonConstant.NotFoundFileSettings); } else { MessageBox.Show(CommonConstant.ErrorReadOrWriteSettings); } proc.CloseProcess(Constant.PidLauncher); Application.Current.Shutdown(); return; } var programLauncher = await net.RequestAsync(Constant.UrlUpdaterLauncherCheckVersion, Net.Post, dataLauncher); if (programLauncher.detail != null) { MessageBox.Show(ErrorParser.Parse(programLauncher.detail)); return; } if (!programLauncher.is_updated) { var message = MessageBox.Show(Constant.DescriptionMessBoxUpdate, "Обновление", MessageBoxButton.OKCancel); if (message == MessageBoxResult.Cancel) { return; } _dataMainViewModel.TimerUpdater.Stop(); displayRootRegistry.ShowPresentation(dataUpdater); programLauncher = await net.RequestAsync <LauncherInfoSerializer>( Constant.UrlUpdaterLauncherInfo, Net.Post, null, null, null, (s, e) => { dataUpdater.ProgressValue = (e.BytesReceived * 100 / e.TotalBytesToReceive); }); if (programLauncher.detail != null) { displayRootRegistry.HidePresentation(dataUpdater); MessageBox.Show(ErrorParser.Parse(programLauncher.detail)); return; } var cryptBytesLauncher = Convert.FromBase64String(programLauncher.data); if (Hash.Sha256Bytes(cryptBytesLauncher) == programLauncher.hash) { var crypt = new Crypt(Encoding.UTF8.GetBytes(CommonConstant.Key)); crypt.RemoveAndSetIv(ref cryptBytesLauncher); var bytesLauncher = crypt.Decode(cryptBytesLauncher); proc.CloseProcess(Constant.PidLauncher); var zip = new ArchiveHelper(); var bytesLauncherSetting = zip.Extract(bytesLauncher, programLauncher.hash, Path.GetTempPath()); settingHelp.RemoveProgram(@".\", false); settingHelp.RemoveDumps <SettingLastSerializer, IRemoveData>(lastSettingLauncher.Info); settingHelp.CopyFilesProgram(Path.GetTempPath() + programLauncher.hash, ".\\"); var getLauncherSetting = settingHelp.Read <LauncherSettingSerializer>(bytesLauncherSetting, CommonConstant.KeySettings); settingHelp.RewriteLastToNewSettingsLauncher(getLauncherSetting, lastSettingLauncher, CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); displayRootRegistry.HidePresentation(dataUpdater); try { proc.StartProcess(getLauncherSetting.Info.StartApp, new string[1] { programLauncher.hash }); } catch (System.ComponentModel.Win32Exception) { MessageBox.Show(Constant.NotFoundStartAppLauncher); } Application.Current.Shutdown(); return; } else { MessageBox.Show(Constant.NoHashEqual); } displayRootRegistry.HidePresentation(dataUpdater); _dataMainViewModel.TimerUpdater.Start(); } }
private async void UpdateProgram() { var programInfo = new ProgramInfoSerializer(); _mainWindowVeiwModel.CheckProgramTimer.Stop(); _mainWindowVeiwModel.IsEnabledTable = false; var net = new Net(); var setHelp = new SettingHelper(); SettingSerializer selectProgram = null; LauncherSettingSerializer launcherSet = null; try { launcherSet = setHelp.Read <LauncherSettingSerializer>(CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); selectProgram = launcherSet.InfoInstallPrograms?.FirstOrDefault(p => p.Dep == _mainWindowVeiwModel.SelectedRow.Dep); if (selectProgram == null) { MessageBox.Show(Constant.NotFoundInstallProgram); _mainWindowVeiwModel.IsEnabledTable = true; return; } } catch (Exception ex) { if (ex is DirectoryNotFoundException || ex is FileNotFoundException) { MessageBox.Show(CommonConstant.NotFoundFileSettings); } else { MessageBox.Show(CommonConstant.ErrorReadOrWriteSettings); } Application.Current.Shutdown(); return; } programInfo.dep = _mainWindowVeiwModel.SelectedRow.Dep; var request = await net.RequestAsync( Constant.UrlGetProgram, Net.Post, programInfo, _mainWindowVeiwModel.Auth, null, (s, e) => { _mainWindowVeiwModel.ProgressValue = e.BytesReceived * 100 / e.TotalBytesToReceive; }); if (request.detail != null) { _mainWindowVeiwModel.CheckProgramTimer.Start(); MessageBox.Show(ErrorParser.Parse(request.detail)); _mainWindowVeiwModel.IsEnabledTable = true; return; } var cryptBytesProgram = Convert.FromBase64String(request.data); if (Hash.Sha256Bytes(cryptBytesProgram) == request.hash) { var crypt = new Crypt(Encoding.UTF8.GetBytes(CommonConstant.Key)); crypt.RemoveAndSetIv(ref cryptBytesProgram); var bytesLauncher = crypt.Decode(cryptBytesProgram); try { setHelp.RemoveProgram(selectProgram.Path, true); setHelp.RemoveDumps <SettingSerializer, IRemoveData>(selectProgram); } catch (DirectoryNotFoundException) { MessageBox.Show(Constant.NotFoundFileOrDirectoryWithProgram); } catch (FileNotFoundException) { MessageBox.Show(Constant.NotFoundFileOrDirectoryWithProgram); } var zip = new ArchiveHelper(); var bytesProgramSetting = zip.Extract(bytesLauncher, request.hash); var getProgramSetting = setHelp.Read <SettingSerializer>(bytesProgramSetting, CommonConstant.KeySettings); getProgramSetting.Path = request.hash; var instalProgs = launcherSet.InfoInstallPrograms.ToList(); for (int i = 0; i < instalProgs.Count; i++) { if (instalProgs[i].Dep == getProgramSetting.Dep) { instalProgs[i] = getProgramSetting; break; } } setHelp.Write(launcherSet, CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); _mainWindowVeiwModel.SelectedRow.SetStateAfterUpdate(); _mainWindowVeiwModel.SelectedRow.Status = StatusHelper.InstallAndUpdated; _mainWindowVeiwModel.SelectedRow.Version = getProgramSetting.Version; _mainWindowVeiwModel.ProgressValue = 0; } else { MessageBox.Show(Constant.NoHashEqual); } _mainWindowVeiwModel.IsEnabledTable = true; _mainWindowVeiwModel.CheckProgramTimer.Start(); }
private async void DownloadInstallProgram() { _mainWindowVeiwModel.IsEnabledTable = false; _mainWindowVeiwModel.CheckProgramTimer.Stop(); var selectedRow = _mainWindowVeiwModel.SelectedRow; var programInfo = new ProgramInfoSerializer(); var net = new Net(); var setHelp = new SettingHelper(); LauncherSettingSerializer launcherSet = null; try { launcherSet = setHelp.Read <LauncherSettingSerializer>(CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); } catch (Exception ex) { if (ex is DirectoryNotFoundException || ex is FileNotFoundException) { MessageBox.Show(CommonConstant.NotFoundFileSettings); } else { MessageBox.Show(CommonConstant.ErrorReadOrWriteSettings); } Application.Current.Shutdown(); return; } programInfo.dep = selectedRow.Dep; var request = await net.RequestAsync( Constant.UrlGetProgram, Net.Post, programInfo, _mainWindowVeiwModel.Auth, null, (s, e) => { _mainWindowVeiwModel.ProgressValue = e.BytesReceived * 100 / e.TotalBytesToReceive; }); if (request.detail != null) { _mainWindowVeiwModel.CheckProgramTimer.Start(); MessageBox.Show(ErrorParser.Parse(request.detail)); _mainWindowVeiwModel.IsEnabledTable = true; return; } var cryptBytesProgram = Convert.FromBase64String(request.data); if (Hash.Sha256Bytes(cryptBytesProgram) == request.hash) { var crypt = new Crypt(Encoding.UTF8.GetBytes(CommonConstant.Key)); crypt.RemoveAndSetIv(ref cryptBytesProgram); var bytesProgram = crypt.Decode(cryptBytesProgram); var zip = new ArchiveHelper(); var bytesProgramSetting = zip.Extract(bytesProgram, request.hash); var getProgramSetting = setHelp.Read <SettingSerializer>(bytesProgramSetting, CommonConstant.KeySettings); getProgramSetting.Path = request.hash; if (launcherSet.InfoInstallPrograms == null || launcherSet.InfoInstallPrograms?.Count() == 0) { launcherSet.InfoInstallPrograms = new List <SettingSerializer>() { getProgramSetting }; } else { (launcherSet.InfoInstallPrograms as List <SettingSerializer>).Add(getProgramSetting); } setHelp.Write(launcherSet, CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); _mainWindowVeiwModel.SelectedRow.SetStateAfterDownloadAndInstall(); _mainWindowVeiwModel.SelectedRow.Status = StatusHelper.InstallAndUpdated; _mainWindowVeiwModel.ProgressValue = 0; } else { MessageBox.Show(Constant.NoHashEqual); } _mainWindowVeiwModel.IsEnabledTable = true; _mainWindowVeiwModel.CheckProgramTimer.Start(); }
public void Execute(object parameter) { var programsInfo = new ProgramsInfoSerializer(); var setHelper = new SettingHelper(); var net = new Net(); try { var launcherSet = setHelper.Read <LauncherSettingSerializer>(CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); var request = net.Request(Constant.UrlCheckVersionPrograms, Net.Post, programsInfo, _mainWindowVeiwModel.Auth); if (request.detail != null) { MessageBox.Show(ErrorParser.Parse(request.detail)); return; } _mainWindowVeiwModel.DataTable.Clear(); if (launcherSet.InfoInstallPrograms == null || launcherSet.InfoInstallPrograms?.Count() == 0) { request.programs_info?.ToList().ForEach(p => { var prog = new DataProgramInfo { Name = p.name, Version = p.version, NewVersion = p.version, Dep = p.dep }; prog.SetStateAfterRequestNoDownloadAndInstall(); prog.Status = StatusHelper.NoInstall; _mainWindowVeiwModel.DataTable.Add(prog); }); } else { request.programs_info?.ToList().ForEach(p => { var installProg = launcherSet.InfoInstallPrograms?.FirstOrDefault(ip => ip.Dep == p.dep); if (installProg == null) { var prog = new DataProgramInfo { Name = p.name, Version = p.version, NewVersion = p.version, Dep = p.dep }; prog.SetStateAfterRequestNoDownloadAndInstall(); prog.Status = StatusHelper.NoInstall; _mainWindowVeiwModel.DataTable.Add(prog); } else { var prog = new DataProgramInfo { Name = p.name, Version = installProg.Version, NewVersion = p.version, Dep = p.dep }; if (prog.Version != prog.NewVersion) { prog.SetStateToUpdate(); prog.Status = StatusHelper.ThereIsUpdate; } else { prog.SetStateAfterDownloadAndInstall(); prog.Status = StatusHelper.InstallAndUpdated; } _mainWindowVeiwModel.DataTable.Add(prog); } }); } if ((launcherSet.InfoInstallPrograms != null || launcherSet.InfoInstallPrograms?.Count() > 0) && request.programs_info != null) { var installProgs = launcherSet.InfoInstallPrograms.ToList(); for (int i = 0; i < installProgs.Count; i++) { if (!request.programs_info.Any(p => p.dep == installProgs[i].Dep)) { try { setHelper.RemoveProgram(installProgs[i].Path, true); setHelper.RemoveDumps <SettingSerializer, IRemoveData>(installProgs[i]); } catch (DirectoryNotFoundException) { } catch (FileNotFoundException) { } installProgs.Remove(installProgs[i]); } } launcherSet.InfoInstallPrograms = installProgs; setHelper.Write(launcherSet, CommonConstant.KeySettings, CommonConstant.FileSettingsLauncher); } } catch (Exception ex) { if (ex is DirectoryNotFoundException || ex is FileNotFoundException) { MessageBox.Show(CommonConstant.NotFoundFileSettings); } else { MessageBox.Show(CommonConstant.ErrorReadOrWriteSettings); } Application.Current.Shutdown(); } }