Repository navigation
Expand file tree
/
Copy pathHomeController.cs
More file actions
156 lines (139 loc) · 5.26 KB
/
Copy pathHomeController.cs
File metadata and controls
156 lines (139 loc) · 5.26 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using Opserver.Views.Shared;
using Opserver.Data;
using Opserver.Helpers;
using Opserver.Models;
using Opserver.Views.Home;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using Opserver.Data.Dashboard;
using Opserver.Data.SQL;
using Opserver.Data.Redis;
using Opserver.Data.Exceptions;
using Opserver.Data.Elastic;
using Opserver.Data.HAProxy;
using System.Collections.Generic;
namespace Opserver.Controllers
{
[OnlyAllow(Roles.Authenticated)]
public class HomeController : StatusController
{
private PollingService Poller { get; }
private IEnumerable<StatusModule> Modules { get; }
private DashboardModule Dashboard { get; }
private SQLModule Sql { get; }
private RedisModule Redis { get; }
private ElasticModule Elastic { get; }
private ExceptionsModule Exceptions { get; }
private HAProxyModule HAProxy { get; }
public HomeController(
IOptions<OpserverSettings> _settings,
PollingService poller,
IEnumerable<StatusModule> modules,
DashboardModule dashboard,
SQLModule sql,
RedisModule redis,
ElasticModule elastic,
ExceptionsModule exceptions,
HAProxyModule haproxy
) : base(_settings)
{
Poller = poller;
Modules = modules;
Dashboard = dashboard;
Sql = sql;
Redis = redis;
Elastic = elastic;
Exceptions = exceptions;
HAProxy = haproxy;
}
[DefaultRoute("")]
public ActionResult Home()
{
// TODO: Order
foreach (var m in Modules)
{
//if (m.Enabled && m.SecuritySettings)
// return RedirectToAction()...
}
static bool AllowMeMaybe(StatusModule m) => m.Enabled && Current.User.HasAccess(m);
if (AllowMeMaybe(Dashboard))
return RedirectToAction(nameof(DashboardController.Dashboard), "Dashboard");
if (AllowMeMaybe(Sql))
return RedirectToAction(nameof(SQLController.Dashboard), "SQL");
if (AllowMeMaybe(Redis))
return RedirectToAction(nameof(RedisController.Dashboard), "Redis");
if (AllowMeMaybe(Elastic))
return RedirectToAction(nameof(ElasticController.Dashboard), "Elastic");
if (AllowMeMaybe(Exceptions))
return RedirectToAction(nameof(ExceptionsController.Exceptions), "Exceptions");
if (AllowMeMaybe(HAProxy))
return RedirectToAction(nameof(HAProxyController.Dashboard), "HAProxy");
return View("NoConfiguration");
}
[Route("ping"), HttpGet, HttpHead, AllowAnonymous, AlsoAllow(Roles.InternalRequest)]
public ActionResult Ping()
{
return Ok();
}
[Route("top-refresh")]
public ActionResult TopRefresh(string tab)
{
Current.NavTab = NavTab.GetByName(tab);
var vd = new TopRefreshModel
{
Tab = tab
};
return PartialView(vd);
}
[Route("issues")]
public ActionResult Issues() => PartialView();
[Route("about"), AlsoAllow(Roles.InternalRequest)]
public ActionResult About() => View();
[Route("about/caches"), AlsoAllow(Roles.InternalRequest)]
public ActionResult AboutCaches(string filter, bool refresh = true)
{
var vd = new AboutModel
{
AutoRefresh = refresh,
Filter = filter
};
return View("About.Caches", vd);
}
[Route("set-theme"), HttpPost]
public ActionResult SetTheme(string theme)
{
Theme.Set(theme, Response);
return RedirectToAction(nameof(About));
}
[Route("debug"), AllowAnonymous]
public ActionResult Debug()
{
var sb = StringBuilderCache.Get()
.AppendLine("Request Info")
.Append(" IP: ").AppendLine(Current.RequestIP)
.Append(" User: ").AppendLine(Current.User.AccountName)
.Append(" Roles: ").AppendLine(Current.User.Roles.ToString())
.AppendLine()
.AppendLine("Headers");
foreach (string k in Request.Headers.Keys)
{
sb.AppendFormat(" {0}: {1}\n", k, Request.Headers[k]);
}
var ps = Poller.GetPollingStatus();
sb.AppendLine()
.AppendLine("Polling Info")
.AppendLine(ps.GetPropertyNamesAndValues(prefix: " "));
return TextPlain(sb.ToStringRecycle());
}
[Route("error-test")]
public ActionResult ErrorTestPage()
{
Current.LogException(new Exception("Test Exception via GlobalApplication.LogException()"));
#pragma warning disable RCS1079 // Throwing of new NotImplementedException.
throw new NotImplementedException("I AM IMPLEMENTED, I WAS BORN TO THROW ERRORS!");
#pragma warning restore RCS1079 // Throwing of new NotImplementedException.
}
}
}