public IActionResult Settings() { SettingsViewModel model = null; if (IOFile.Exists("synosettings.json")) { model = JsonConvert.DeserializeObject <SettingsViewModel>(IOFile.ReadAllText("synosettings.json")); } return(View(model)); }
public IActionResult Index() { if (!IOFile.Exists("synosettings.json")) { return(RedirectToAction(nameof(Settings))); } var settings = JsonConvert.DeserializeObject <SettingsViewModel>(IOFile.ReadAllText("synosettings.json")); return(View()); }
public IActionResult GetYamlFile() { if (!OptionsSnapshot.Value.RemoteConfiguration) { return(Forbid()); } var yaml = IOFile.ReadAllText(Program.ConfigurationFile); return(Ok(yaml)); }
public async Task <int> OnExecuteAsync() { var sess = _main.GetSession(); using var client = sess.GetClient(); var vault = Vault == null ? null : _main.GetVault(client, Vault !); if (vault == null && Vault != null) { return(1); } var record = _main.GetRecord(client, ref vault, Record !); if (record == null || vault == null) { return(1); } if (!IOFile.Exists(File)) { _console.WriteError("could not find input file."); return(1); } var fileContent = IOFile.ReadAllText(File); var fileInput = JsonSerializer.Deserialize <SetRecordInput>(fileContent, MainCommand.JsonInputOpts); if (fileInput == null) { _console.WriteError("could not read or parse input file."); return(1); } client.UnlockVault(vault); client.UnlockRecord(vault, record); if (record.Summary == null) { record.Summary = new(); } if (record.Content == null) { record.Content = new(); } SetProp(v => record.Summary.Label = v, fileInput.Label, fileInput.RemoveLabel); SetProp(v => record.Summary.Type = v, fileInput.Type, fileInput.RemoveType); SetProp(v => record.Summary.Username = v, fileInput.Username, fileInput.RemoveUsername); SetProp(v => record.Summary.Address = v, fileInput.Address, fileInput.RemoveAddress); SetProp(v => record.Content.Password = v, fileInput.Password, fileInput.RemovePassword); SetProp(v => record.Content.Memo = v, fileInput.Memo, fileInput.RemoveMemo); if (fileInput.Fields?.Length > 0 && record.Content.Fields == null) { record.Content.Fields = new(); } if (record.Content.Fields != null) { if (fileInput.RemoveFields?.Length > 0) { var toDel = record.Content.Fields.Where(x => fileInput.RemoveFields.Contains(x.Name) && (fileInput.Fields == null || !fileInput.Fields.Any(y => object.Equals(y.Name, x.Name)))); foreach (var f in toDel) { record.Content.Fields.Remove(f); } } if (fileInput.Fields?.Length > 0) { foreach (var f in fileInput.Fields) { var rcf = record.Content.Fields.FirstOrDefault(x => object.Equals(x.Name, f.Name)); if (rcf == null) { rcf = new(); record.Content.Fields.Add(rcf); } rcf.Name = f.Name; rcf.Type = f.Type; rcf.Value = f.Value; } } } var id = await client.SaveRecordAsync(vault, record); sess.Save(client); _console.WriteLine(id); return(0); }
public int OnExecute() { if (!IOFile.Exists(File)) { _console.WriteError("input file not found"); return(-1); } var inputBody = IOFile.ReadAllText(File); var input = JsonSerializer.Deserialize <PasswordGeneratorInput>(inputBody, MainCommand.JsonInputOpts); // Validate the inputs if (input?.Classes?.Count == 0) { _console.WriteError("no Character Classes defined"); return(1); } if (input !.Length <= 1) { _console.WriteError("missing or invalid length"); return(1); } var totalMin = 0; var totalMax = 0; foreach (var cc in input.Classes !) { var ccChars = cc.Value.Chars; if (string.IsNullOrEmpty(ccChars)) { _console.WriteError($"missing characters for Character Class [{cc.Key}]"); return(1); } if (cc.Value.Min is int ccMin) { if (cc.Value.Max is int ccMinMax && ccMin > ccMinMax) { _console.WriteError($"invalid min/max specified for Character Class [{cc.Key}]"); return(1); } totalMin += ccMin; } if (cc.Value.Max is int ccMax) { totalMax += ccMax; } else { totalMax = short.MaxValue; } } if (totalMin > input.Length) { _console.WriteError("specified minimums for Character Classes exceed total length"); return(1); } if (totalMax < input.Length) { _console.WriteError("specified maximums for Character Classes are insufficient for total length"); return(1); } foreach (var cc in input.Classes) { var ccChars = cc.Value.Chars !; while (CharsRange.Match(ccChars) is { Success: true, Groups: var g })
public async Task <int> OnExecuteAsync() { var sess = _main.GetSession(); using var client = sess.GetClient(); var vault = _main.GetVault(client, Vault !); if (vault == null) { return(1); } if (!IOFile.Exists(File)) { _console.WriteError("could not find input file."); return(1); } var fileContent = IOFile.ReadAllText(File); var fileInput = JsonSerializer.Deserialize <NewRecordInput>(fileContent, MainCommand.JsonInputOpts); if (fileInput == null) { _console.WriteError("could not read or parse input file."); return(1); } var record = new Record(); record.Summary = new(); record.Summary.Label = fileInput.Label; record.Summary.Type = fileInput.Type; record.Summary.Username = fileInput.Username; record.Summary.Address = fileInput.Address; record.Summary.Tags = fileInput.Tags; record.Content = new(); record.Content.Password = fileInput.Password; record.Content.Memo = fileInput.Memo; record.Content.Fields = fileInput.Fields?.Select(x => new RecordField { Name = x.Name, Type = x.Type, Value = x.Value, }).ToList(); var id = await client.SaveRecordAsync(vault, record); sess.Save(client); _console.WriteLine(id); if (Delete) { IOFile.Delete(File); } return(0); }