Move html and template files to /opt/mailstats

This commit is contained in:
2024-06-04 10:12:01 +01:00
parent 1dd11f04f1
commit 4a0c17e1c0
5 changed files with 10 additions and 6 deletions

View File

@@ -0,0 +1,59 @@
table {
border:2px solid;
border-collapse:collapse;
}
tr,td,th {
border:1px solid;
}
.mailstats-detail-1stcol{
width:174px;
}
thead tr {
border-bottom :2px solid;
color:black;
background-color:darkgrey;
}
tfoot tr {
border-top:2px solid;
color:black;
font-weight: bold;
background-color:darkgrey;
}
tbody tr:nth-child(odd) {background-color: #dfdfdf}
a.prevlink {
float: left;
width:33.33333%;
text-align:left;
}
div.divseeinbrowser {
float: left;
width:33.33333%;
text-align:center;
}
a.nextlink {
float: left;
width:33.33333%;
text-align:right;
}
.cssclass1 {background-color:#ffff99;}
.cssclass2 {background-color:lightcoral;}
.cssclass3 {background-color:lightcyan;}
.cssclass4 {background-color:lightgoldenrodyellow;}
.cssclass5 {background-color:lightgray;}
.cssclass6 {background-color:lightgreen;}
.cssclass7 {background-color:lightpink;}
.cssclass8 {background-color:lightsalmon;}
.cssclass9 {background-color:lightseagreen;}
.cssclass10 {background-color:lightskyblue;}
.cssclass11 {background-color:lightslategray;}
.cssclass12 {background-color:lightsteelblue;}
p.cssvalid,p.htmlvalid {float:left;margin-right:20px)

0
root/opt/mailstats/logs/.gitignore vendored Normal file
View File

View File

@@ -0,0 +1,15 @@
<h2>${title}</h2>
<table border="1">
<thead>
<tr>
<th tal:repeat="header column_headers">${header}</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="item array_2d.items()">
<td>${item[0]}</td>
<td>${item[1]}</td>
</tr>
</tbody>
</table>

View File

@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html><head><meta charset="utf-8">
<title>SMEServer Mailstats</title>
<link rel='stylesheet' type='text/css' href='mailstats.css' />
<!-- Check links -->
<script>
function LinkCheck(url){
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status!=404;
}
function doNavs() {
var aTags = document.getElementsByTagName('a'),
atl = aTags.length,i;
for (i = 0; i < atl; i++) {
if (aTags[i].innerText == "Previous") {
if (!LinkCheck(aTags[i].href)) {
aTags[i].style.visibility = "hidden";
} else {
aTags[i].style.visibility = "visible";
}
} else if (aTags[i].innerText == "Next") {
if (!LinkCheck(aTags[i].href)) {
aTags[i].style.visibility = "hidden";
} else {
aTags[i].style.visibility = "visible";
}
}
}
}
</script>
</head>
<body>
<!---Navigation here-->
<h1>${title}</h1>
<br />
<table border="1">
<thead>
<tr>
<th>Date/Time</th>
<th tal:repeat="header column_headers" tal:content="header">Header</th>
</tr>
</thead>
<tbody>
<tr tal:repeat="row array_2d">
<td tal:condition="repeat.row.index == 24" tal:content="'TOTALS'">Totals</td>
<td tal:condition="repeat.row.index == 25" tal:content="'PERCENT'">Percent</td>
<td tal:condition="repeat.row.index < 24" tal:content="string:${reporting_date}, ${repeat.row.index}">Hour</td>
<td tal:repeat="cell row" tal:content="cell">Cell</td>
</tr>
</tbody>
</table>
<!---Add in sub tables here -->
<br />
<footer>${version}</footer>
<script>window.onload = function(){doNavs();} </script>
<p class="cssvalid">
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px"
src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" />
</a>
</p>
<p class="htmlvalid">
<a href="https://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>

View File

@@ -28,10 +28,14 @@ from collections import defaultdict
Mailstats_version = '1.2'
script_dir = os.path.dirname(os.path.abspath(__file__))
data_file_path = script_dir+'/../../../'
data_file_path = script_dir+'/../..' #back to the top
now = datetime.now()
yesterday = now - timedelta(days=1)
formatted_yesterday = yesterday.strftime("%Y-%m-%d")
#html_page_path = data_file_path+"/home/e-smith/files/ibays/mesdb/html/mailstats/"
html_page_dir = data_file_path+"/opt/mailstats/html/"
template_dir = data_file_path+"/opt/mailstats/templates/"
logs_dir = data_file_path+"/opt/mailstats/logs/"
# Column numbering
Hour = 0
@@ -360,7 +364,7 @@ def split_timestamp_and_data(log_entry: str) -> list:
def render_sub_table(table_title,table_headers,found_values):
# NeedNOTE: also need to compute the percentages here.
template_path = data_file_path+'mailstats-sub-table.html.pt'
template_path = template_dir+'mailstats-sub-table.html.pt'
# Load the template
with open(template_path, 'r') as template_file:
template_content = template_file.read()
@@ -409,8 +413,8 @@ if __name__ == "__main__":
num_hours = 25 # Represents hours from 0 to 23 - adds extra one for column totals and another for percentages
data_file = data_file_path+'current.log'
log_entries,skip_count = read_in_yesterday_log_file(data_file)
log_file = logs_dir+'current.log'
log_entries,skip_count = read_in_yesterday_log_file(log_file)
if len(log_entries) == 0:
print(f"No records found in {data_file}")
quit()
@@ -613,7 +617,7 @@ if __name__ == "__main__":
print(f"J:{j} I:{i}")
#Now apply the results to the chameleon template - main table
# Path to the template file
template_path = data_file_path+'mailstats.html.pt'
template_path = template_dir+'mailstats.html.pt'
# Load the template
with open(template_path, 'r') as template_file:
template_content = template_file.read()
@@ -660,7 +664,7 @@ if __name__ == "__main__":
total_html = insert_string_after(total_html,Nav_str, "<!---Navigation here-->")
# Write the rendered HTML to a file
output_path = data_file_path+'mailstats_for_'+formatted_yesterday
output_path = html_page_dir+'mailstats_for_'+formatted_yesterday
output_path = output_path.replace(' ','_')
with open(output_path+'.html', 'w') as output_file:
output_file.write(total_html)