NTP Analyzer  0.8.2
Analyze the operation of time servers
DefaultHostPageRender.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using System.Linq;
24 using System.Text;
26 using Ntp.Common.Web;
27 
28 namespace Ntp.Analyzer.Render.Host
29 {
31  {
32  public DefaultHostPageRender(HostPageConfiguration config, string ip, int refresh)
33  : base(config.WebPath)
34  {
35  this.config = config;
36  this.ip = ip;
37  this.refresh = refresh;
38  }
39 
40  private readonly HostPageConfiguration config;
41  private readonly string ip;
42  private readonly int refresh;
43 
44  public override string Render()
45  {
46  return "<body>";
47  }
48 
49  public override string RenderFooter()
50  {
51  var builder = new StringBuilder();
52  builder.AppendLine(string.Empty);
53 
54  DateTime now = DateTime.Now;
55 
56  builder.AppendLine("<br>");
57 
58  if (config.ShowUtc == DateTimeKind.Utc)
59  {
60  builder.Append("Time is ");
61  builder.Append(now.ToLongDateString() + " ");
62  builder.Append(TimeZoneInfo.Utc.StandardName);
63  }
64  else
65  {
66  builder.Append("Local time is ");
67  builder.Append(now.ToLongDateString() + " ");
68  builder.Append(TimeZoneInfo.Local.IsDaylightSavingTime(now)
69  ? TimeZoneInfo.Local.DaylightName
70  : TimeZoneInfo.Local.StandardName);
71  }
72  builder.Append(" " + now.ToShortTimeString() + ". ");
73 
74  builder.AppendLine("<br><br>");
75  if (config.PoolMember)
76  {
77  string poolLink = "http://www.pool.ntp.org/scores/" + ip;
78  string poolText = $@"<a href=""{poolLink}"">pool.ntp.org</a>";
79  builder.Append("Server is pool member on ");
80  builder.Append(poolText);
81  }
82 
83  if (config.PeerSummaries.Pages.Count() != 0)
84  {
85  builder.AppendLine("<br><br>");
86  builder.Append("Peer graphs are available with ");
87  builder.Append(@"<a href=""");
88  builder.Append(config.PeerSummaries.Pages.First().Link.ToHtmlString());
89  builder.Append(@""">");
90  builder.Append(config.PeerSummaries.Pages.First().Title);
91  builder.Append(@"</a> and ");
92  builder.Append(@"<a href=""");
93  builder.Append(config.PeerSummaries.Pages.ToList()[1].Link.ToHtmlString());
94  builder.Append(@""">");
95  builder.Append(config.PeerSummaries.Pages.ToList()[1].Title);
96  builder.Append(@"</a>.");
97  }
98 
99  builder.AppendLine("<br><br>");
100  builder.AppendLine("Page refreshes every 5 minutes.");
101 
102  builder.AppendLine("</body>");
103  builder.AppendLine("</html>");
104 
105  return builder.ToString();
106  }
107 
108  public override string RenderHead()
109  {
110  var builder = new StringBuilder();
111 
112  builder.AppendLine("<!DOCTYPE html>");
113  builder.AppendLine("<html><head>");
114  builder.AppendLine(@"<meta charset=""UTF-8"">");
115  builder.AppendLine(@"<style type=""text/css"" media=""screen"">");
116  builder.AppendLine("body {font-family: monospace; line-height:100%; }");
117  builder.AppendLine("table { border-collapse:collapse; border-spacing: 0; width: 940px; }");
118  builder.AppendLine(
119  "th { text-align: left; font-weight: bold; border-bottom: 2px solid; padding: 0px; padding-top: 5px; padding-bottom: 3px;}");
120  builder.AppendLine(
121  "td { padding: 0px; padding-right: 7px; padding-left: 2px; padding-top: 2px; padding-bottom: 2px; }");
122  builder.AppendLine("td.aright { text-align: right; padding-right: 17px;}");
123  builder.AppendLine("td.spc { padding: 0px; line-height: 5px; }");
124  builder.AppendLine("td.but { border-top: 2px solid; padding: 0px; padding-top: 2px; line-height: 7px; }");
125  builder.AppendLine("a:link { color:#33348e; text-decoration: none; }");
126  builder.AppendLine("a:visited { color:#33348e; text-decoration: none; }");
127  builder.AppendLine("a:hover { color:#33348e; text-decoration: underline;; }");
128  builder.AppendLine("a:active { color:#7476b4; text-decoration: underline; }");
129  builder.AppendLine("</style>");
130  builder.AppendLine("<title>");
131  builder.AppendLine(config.ServerName);
132  builder.AppendLine("</title>");
133  builder.AppendLine($@"<meta http-equiv=""refresh"" content=""{refresh}"">");
134  builder.AppendLine("</head>");
135  return builder.ToString();
136  }
137  }
138 }
DefaultHostPageRender(HostPageConfiguration config, string ip, int refresh)
Configuration for a HTML page showing status and graphs for a hosted NTP server.