forked from revenz/NextPvrWebConsole
/
SystemController.cs
84 lines (74 loc) · 3.17 KB
/
SystemController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Mvc;
namespace NextPvrWebConsole.Controllers
{
[Authorize(Roles="System")]
public class SystemController : Controller
{
private const string DummyPassword = "********";
public ActionResult Index()
{
var config = new Models.Configuration();
var SmtpModel = new Models.ConfigurationModels.SmtpConfiguration();
SmtpModel.Username = config.SmtpUsername;
SmtpModel.Password = !String.IsNullOrWhiteSpace(config.SmtpPassword) ? DummyPassword : "";
SmtpModel.Port = config.SmtpPort;
SmtpModel.Server = config.SmtpServer;
SmtpModel.UseSsl = config.SmtpUseSsl;
SmtpModel.Sender = config.SmtpSender;
ViewBag.SmtpModel = SmtpModel;
var GeneralModel = new Models.ConfigurationModels.GeneralSystem();
GeneralModel.WebsiteAddress = config.WebsiteAddress;
ViewBag.GeneralModel = GeneralModel;
return View();
}
public ActionResult UpdateSmtpSettings(Models.ConfigurationModels.SmtpConfiguration Model)
{
if (!ModelState.IsValid)
throw new ArgumentException();
var config = new Models.Configuration();
config.SmtpServer = Model.Server;
config.SmtpPort = Model.Port;
config.SmtpUsername = Model.Username;
if(Model.Password != DummyPassword) // only update it if its not the dummy
config.SmtpPassword = Helpers.Encrypter.Encrypt(Model.Password, Helpers.Encrypter.GetCpuId()); // TODO encrypt this
config.SmtpUseSsl = Model.UseSsl;
config.SmtpSender = Model.Sender;
config.Save();
return Json(new { success = true });
}
public ActionResult UpdateGeneralSettings(Models.ConfigurationModels.GeneralSystem GeneralModel)
{
try
{
if (!ModelState.IsValid)
throw new ArgumentException();
var config = new Models.Configuration();
config.WebsiteAddress = GeneralModel.WebsiteAddress;
config.Save();
return Json(new { success = true });
}
catch (Exception ex)
{
return Json(new { _error = true, message = ex.Message });
}
}
public ActionResult Log(string Oid, string Name)
{
// security, make sure the filename is in the list of log files
var log = new Api.LogsController().Get().Where(x => x.Oid == Oid || (Oid == "" && x.Name == Name)).FirstOrDefault();
if (log != null)
{
using (var stream = new System.IO.FileStream(log.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
return Content(reader.ReadToEnd());
}
}
return Content("Log file not found.");
}
}
}