From b841acef29826d192f7d2005e2f47bb52e7b2162 Mon Sep 17 00:00:00 2001 From: Azareal Date: Fri, 12 May 2017 14:25:12 +0100 Subject: [PATCH] Revamped the top navbar. Really large numbers are now formatted properly on the Control Panel Dashboard. --- last_version.txt | 1 + main.go | 3 + panel_routes.go | 10 +- templates/topic.html | 4 +- themes/cosmo-conflux/public/main.css | 5 +- themes/cosmo/public/main.css | 5 +- themes/tempra-conflux/public/main.css | 151 +++++++++++++------------- themes/tempra-cursive/public/main.css | 109 +++++++++++++------ themes/tempra-simple/public/main.css | 140 +++++++++++++----------- utils.go | 81 ++++++++------ websockets.go | 88 ++++++++------- 11 files changed, 338 insertions(+), 259 deletions(-) create mode 100644 last_version.txt diff --git a/last_version.txt b/last_version.txt new file mode 100644 index 00000000..0d4d1249 --- /dev/null +++ b/last_version.txt @@ -0,0 +1 @@ +0.1.0-dev diff --git a/main.go b/main.go index 7e4eb621..a457ce4a 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,9 @@ const kilobyte int = 1024 const megabyte int = kilobyte * 1024 const gigabyte int = megabyte * 1024 const terabyte int = gigabyte * 1024 +//const thousand int = 1000 +//const million int = 1_000_000 +//const billion int = 1_000_000_000 const saltLength int = 32 const sessionLength int = 80 var enable_websockets bool = false // Don't change this, the value is overwritten by an initialiser diff --git a/panel_routes.go b/panel_routes.go index 61a4cd49..8dd7ad41 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -168,9 +168,13 @@ func route_panel(w http.ResponseWriter, r *http.Request){ onlineUsersColour = "stat_red" } - gridElements = append(gridElements, GridElement{"dash-totonline",strconv.Itoa(totonline) + " online",3,"grid_stat " + onlineColour,"","","The number of people who are currently online"}) - gridElements = append(gridElements, GridElement{"dash-gonline",strconv.Itoa(gonline) + " guests online",4,"grid_stat " + onlineGuestsColour,"","","The number of guests who are currently online"}) - gridElements = append(gridElements, GridElement{"dash-uonline",strconv.Itoa(uonline) + " users online",5,"grid_stat " + onlineUsersColour,"","","The number of logged-in users who are currently online"}) + totonline, totunit := convert_friendly_unit(totonline) + uonline, uunit := convert_friendly_unit(uonline) + gonline, gunit := convert_friendly_unit(gonline) + + gridElements = append(gridElements, GridElement{"dash-totonline",strconv.Itoa(totonline) + totunit + " online",3,"grid_stat " + onlineColour,"","","The number of people who are currently online"}) + gridElements = append(gridElements, GridElement{"dash-gonline",strconv.Itoa(gonline) + gunit + " guests online",4,"grid_stat " + onlineGuestsColour,"","","The number of guests who are currently online"}) + gridElements = append(gridElements, GridElement{"dash-uonline",strconv.Itoa(uonline) + uunit + " users online",5,"grid_stat " + onlineUsersColour,"","","The number of logged-in users who are currently online"}) } gridElements = append(gridElements, GridElement{"dash-postsperday",strconv.Itoa(postCount) + " posts / " + postInterval,6,"grid_stat " + postColour,"","","The number of new posts over the last 24 hours"}) diff --git a/templates/topic.html b/templates/topic.html index dccd92ae..c8f84fb1 100644 --- a/templates/topic.html +++ b/templates/topic.html @@ -18,7 +18,7 @@ -
+

{{.Topic.Content}}

@@ -31,7 +31,7 @@ {{if .Topic.LikeCount}}{{.Topic.LikeCount}}😀{{end}} {{if .Topic.Tag}}{{.Topic.Tag}}{{else}}{{.Topic.Level}}👑{{end}}
-

+
{{range .ItemList}}{{if .ActionType}}
{{.ActionIcon}} diff --git a/themes/cosmo-conflux/public/main.css b/themes/cosmo-conflux/public/main.css index f2f621d8..c6d66e66 100644 --- a/themes/cosmo-conflux/public/main.css +++ b/themes/cosmo-conflux/public/main.css @@ -1,5 +1,5 @@ /* AtomBB Cosmo Port. Copyright Azareal 2017 - 2018 */ -/* I'm currently converting the CSS over. Don't use this yet! */ +/* I'm currently converting the CSS over from one of my previous projects. Don't use this yet! */ * { box-sizing: border-box; @@ -280,8 +280,7 @@ hr { color: silver; border: 1px solid silver; } { padding: 0px; padding-top: 0px; - width: 100%; - margin-bottom: 8px; + margin-bottom: 16px; overflow: hidden; word-wrap: break-word; } diff --git a/themes/cosmo/public/main.css b/themes/cosmo/public/main.css index c7971cc3..e9ac5148 100644 --- a/themes/cosmo/public/main.css +++ b/themes/cosmo/public/main.css @@ -1,5 +1,5 @@ /* AtomBB Cosmo Port. Copyright Azareal 2017 */ -/* I'm currently converting the CSS over. Don't use this yet! */ +/* I'm currently converting the CSS over from one of my previous projects. Don't use this yet! */ * { box-sizing: border-box; @@ -269,8 +269,7 @@ hr { color: silver; border: 1px solid silver; } { padding: 0px; padding-top: 0px; - width: 100%; - margin-bottom: 8px; + margin-bottom: 16px; overflow: hidden; word-wrap: break-word; } diff --git a/themes/tempra-conflux/public/main.css b/themes/tempra-conflux/public/main.css index ab0f1916..e4f96f4b 100644 --- a/themes/tempra-conflux/public/main.css +++ b/themes/tempra-conflux/public/main.css @@ -12,7 +12,7 @@ body background-size: cover; } -/* Patch for Edge */ +/* Patch for Edge, until they fix emojis in arial x.x */ @supports (-ms-ime-align:auto) { .user_content { font-family: Segoe UI Emoji, arial; } } @@ -23,27 +23,27 @@ ul { padding-left: 0px; padding-right: 0px; - height: 28px; + height: 36px; list-style-type: none; border: 1px solid #ccc; background-color: white; + margin-bottom: 12px; } li { - height: 26px; + height: 35px; padding-left: 10px; - padding-top: 5px; - padding-bottom: 5px; - font-weight: bold; - text-transform: uppercase; + padding-top: 8px; + padding-bottom: 8px; } li:hover { background: rgb(250,250,250); } li a { text-decoration: none; - color: #515151; + /*color: #515151;*/ + color: black; + font-size: 17px; } -/*li a:hover { color: #7a7a7a; }*/ .menu_left { float: left; @@ -58,25 +58,24 @@ li a } .menu_alerts { - padding-left: 7px; + /*padding-left: 7px;*/ + font-size: 20px; padding-top: 2px; color: rgb(80,80,80); } .menu_alerts .alert_counter { - position:relative; - font-size: 9px; - top: -24px; - background-color: rgb(140,0,0); + position: relative; + font-size: 8px; + top: -25px; + background-color: rgb(190,0,0); color: white; - padding: 3px; width: 14px; left: 10px; line-height: 8px; - border-radius: 20px; padding-top: 2.5px; height: 14px; - opacity: 0.8; text-align: center; + border: white solid 1px; } .menu_alerts .alert_counter:empty { display: none; @@ -100,7 +99,7 @@ li a } .selectedAlert .alertList { position: absolute; - top: 43px; + top: 51px; display: block; background: white; font-size: 10px; @@ -135,6 +134,8 @@ li a height: 30px; width: 100%; color: black; + font-size: 10px; + font-weight: bold; } .alertItem .text.smaller { font-size: 9px; @@ -197,7 +198,7 @@ li a padding: 0px; padding-top: 0px; width: 100%; - margin-bottom: 8px; + margin-bottom: 12px; overflow: hidden; word-wrap: break-word; } @@ -208,7 +209,6 @@ li a .colstack_grid { display: grid; grid-template-columns: repeat(3, 1fr); - /*grid-gap: 15px;*/ grid-gap: 12px; margin-left: 5px; } @@ -220,16 +220,12 @@ li a overflow: hidden; } .grid_stat, .grid_istat { - /*padding-top: 15px;*/ text-align: center; - /*padding-bottom: 15px; - font-size: 20px;*/ padding-top: 12px; padding-bottom: 12px; font-size: 16px; } .grid_istat { - /*margin-bottom: 10px;*/ margin-bottom: 5px; } @@ -302,16 +298,14 @@ li a width: 100%; background-color: white; } + /* Clearfix */ .formrow:before, .formrow:after { content: " "; display: table; } .formrow:after { clear: both; } -.formrow:not(:last-child) -{ - border-bottom: 1px dotted #ccc; -} +.formrow:not(:last-child) { border-bottom: 1px dotted #ccc; } .formitem { @@ -322,18 +316,10 @@ li a padding-bottom: 8px; font-weight: bold; } -.formitem:first-child -{ - font-weight: bold; -} -.formitem:not(:last-child) -{ - border-right: 1px dotted #ccc; -} -.formitem.invisible_border -{ - border: none; -} +.formitem:first-child { font-weight: bold; } +.formitem:not(:last-child) { border-right: 1px dotted #ccc; } +.formitem.invisible_border { border: none; } + /* Mostly for textareas */ .formitem:only-child { width: 100%; } .formitem textarea @@ -414,10 +400,6 @@ button.username border-width: 1px; } -.mention { - font-weight: bold; -} - .tag-mini { text-transform: none; @@ -434,10 +416,8 @@ button.username font-size: 10px; } -.show_on_edit -{ - display: none; -} +.mention { font-weight: bold; } +.show_on_edit { display: none; } .alert { @@ -589,37 +569,54 @@ button.username /* Media Queries from Simple. Probably useless in Conflux */ @media (max-width: 880px) { - li { height: 25px; font-size: 15px; padding-left: 7px; } - ul { height: 26px; margin-top: 8px; } - .menu_left { padding-right: 7px; } - .menu_right { padding-right: 7px; } + li { + height: 29px; + font-size: 15px; + padding-left: 9px; + padding-top: 6px; + padding-bottom: 6px; + } + ul { + height: 30px; + margin-top: 8px; + } + .menu_left { padding-right: 9px; } + .menu_right { padding-right: 9px; } + .menu_alerts { + padding-left: 7px; + padding-right: 7px; + font-size: 18px; + } + body { padding-left: 4px; padding-right: 4px; margin: 0px !important; width: 100% !important; height: 100% !important; overflow-x: hidden; } .container { width: auto; } - .selectedAlert .alertList { top: 33px; right: 4px; } + .selectedAlert .alertList { top: 37px; right: 4px; } } @media (max-width: 810px) { - li - { - font-weight: normal; - text-transform: none; - } .rowitem { text-transform: none; } } -@media (max-width: 620px) { - li - { +@media (max-width: 680px) { + li { padding-left: 5px; - padding-top: 2px; + padding-top: 3px; padding-bottom: 2px; - height: 23px; + height: 25px; } - ul { height: 24px; } - .menu_left { padding-right: 5px; } - .menu_right { padding-right: 5px; } + li a { font-size: 14px; } + ul { height: 26px; } + .menu_left { padding-right: 7px; } + .menu_right { padding-right: 7px; } .menu_create_topic { display: none; } - .menu_alerts { padding-left: 4px; padding-right: 4px; } + + .menu_alerts { + padding-left: 4px; + padding-right: 4px; + font-size: 16px; + padding-top: 1px; + } + .selectedAlert .alertList { top: 33px; } .hide_on_mobile { display: none; } .prev_button, .next_button { top: auto;bottom: 5px; } @@ -628,12 +625,9 @@ button.username } @media (max-width: 470px) { - .menu_overview { display: none; } - .menu_profile { display: none; } - .hide_on_micro { display: none; } - .post_container { - overflow: visible !important; - } + .menu_overview, .menu_profile, .hide_on_micro { display: none; } + .post_container { overflow: visible !important; } + .post_item { background-position: 0px 2px !important; background-size: 64px 64px !important; @@ -661,9 +655,7 @@ button.username width: 60px; font-size: 15px; } - .userinfo { - width: 70px; - } + .userinfo { width: 70px; } .userinfo .avatar_item { background-size: 64px; width: 64px; @@ -679,4 +671,9 @@ button.username .post_tag { font-size: 12px; } .container { width: 100% !important; } -} \ No newline at end of file +} + +@media (max-width: 330px) { + li { padding-left: 6px; } + .menu_left { padding-right: 6px; } +} diff --git a/themes/tempra-cursive/public/main.css b/themes/tempra-cursive/public/main.css index 52131fd6..6154f23e 100644 --- a/themes/tempra-cursive/public/main.css +++ b/themes/tempra-cursive/public/main.css @@ -10,7 +10,7 @@ body padding-bottom: 8px; } -/* Patch for Edge */ +/* Patch for Edge, until they fix emojis in arial x.x */ @supports (-ms-ime-align:auto) { .user_content { font-family: Segoe UI Emoji, arial; } } @@ -19,34 +19,34 @@ ul { padding-left: 0px; padding-right: 0px; - height: 28px; + height: 36px; list-style-type: none; border: 1px solid #ccc; background-color: white; + margin-bottom: 12px; } li { - height: 26px; + height: 35px; padding-left: 10px; - padding-top: 5px; - padding-bottom: 5px; - font-weight: bold; - text-transform: uppercase; + padding-top: 8px; + padding-bottom: 8px; } li:hover { background: rgb(250,250,250); } li a { text-decoration: none; - color: #515151; + /*color: #515151;*/ + color: black; + font-size: 17px; } -/*li a:hover { color: #7a7a7a; }*/ .menu_left { float: left; border-right: 1px solid #ccc; padding-right: 10px; font-family: cursive; - padding-top: 2px; + padding-top: 4px; } .menu_right { @@ -56,25 +56,26 @@ li a } .menu_alerts { - padding-left: 7px; + /*padding-left: 7px;*/ + font-size: 20px; padding-top: 2px; color: rgb(80,80,80); } .menu_alerts .alert_counter { - position:relative; - font-size: 9px; - top: -24px; - background-color: rgb(140,0,0); + position: relative; + font-family: arial; + font-size: 8px; + top: -25px; + background-color: rgb(190,0,0); color: white; - padding: 3px; width: 14px; left: 10px; line-height: 8px; - border-radius: 20px; padding-top: 2.5px; height: 14px; - opacity: 0.8; text-align: center; + + border: white solid 1px; } .menu_alerts .alert_counter:empty { display: none; @@ -94,7 +95,7 @@ li a } .selectedAlert .alertList { position: absolute; - top: 43px; + top: 51px; display: block; background: white; font-size: 10px; @@ -128,6 +129,10 @@ li a width: calc(100% - 20px); height: 30px; } +.alertItem .text { + font-size: 10px; + font-weight: bold; +} .container { @@ -186,7 +191,7 @@ li a padding: 0px; padding-top: 0px; width: 100%; - margin-bottom: 8px; + margin-bottom: 12px; overflow: hidden; word-wrap: break-word; } @@ -233,7 +238,7 @@ li a width: 100%; padding-left: 8px; padding-right: 8px; - padding-top: 17px; + padding-top: 12px; padding-bottom: 12px; font-weight: bold; text-transform: uppercase; @@ -254,6 +259,7 @@ li a color: black; } .rowitem a:hover { color: silver; } +.top_post { margin-bottom: 16px; } .opthead { display: none; } .col_left @@ -484,17 +490,31 @@ button.username .next_button { right: 14px; } @media (max-width: 880px) { - li { height: 25px; font-size: 15px; padding-left: 7px; } - ul { height: 26px; margin-top: 8px; } - .menu_left { padding-right: 7px; } - .menu_right { padding-right: 7px; } + li { + height: 29px; + font-size: 15px; + padding-left: 9px; + padding-top: 2px; + padding-bottom: 6px; + } + ul { + height: 30px; + margin-top: 8px; + } + .menu_left { padding-right: 9px; padding-top: 2px; } + .menu_right { padding-right: 9px; } + .menu_alerts { + padding-left: 7px; + padding-right: 7px; + font-size: 18px; + } + body { padding-left: 4px; padding-right: 4px; margin: 0px !important; width: 100% !important; height: 100% !important; overflow-x: hidden; } .container { width: auto; } - .selectedAlert .alertList { top: 33px; right: 4px; } + .selectedAlert .alertList { top: 37px; right: 4px; } } @media (max-width: 810px) { - li { font-weight: normal; text-transform: none; } .rowitem { text-transform: none; } /*.rowhead { font-family: arial; } .menu_left { font-family: arial; }*/ @@ -502,19 +522,30 @@ button.username .level { font-size: 17px; } } -@media (max-width: 620px) { - li - { +@media (max-width: 700px) { + li { padding-left: 5px; - padding-top: 2px; + padding-top: 3px; padding-bottom: 2px; - height: 23px; + height: 25px; } - ul { height: 24px; } - .menu_left { padding-right: 5px; } + li a { font-size: 14px; } + ul { height: 26px; } + .menu_left { padding-right: 5px; padding-top: 1px; } .menu_right { padding-right: 5px; } .menu_create_topic { display: none;} - .menu_alerts { padding-left: 4px; padding-right: 4px; } + + .menu_alerts { + padding-left: 4px; + padding-right: 4px; + font-size: 16px; + padding-top: 1px; + } + .menu_alerts .alert_counter { + top: -23px; + left: 8px; + } + .selectedAlert .alertList { top: 33px; } .hide_on_mobile { display: none; } .prev_button, .next_button { top: auto; bottom: 5px; } @@ -561,4 +592,10 @@ button.username text-align: center; } .container { width: 100% !important; } -} \ No newline at end of file +} + +@media (max-width: 330px) { + li { padding-left: 6px; } + .menu_left { padding-right: 6px; } + .menu_alerts { border-left: none; } +} diff --git a/themes/tempra-simple/public/main.css b/themes/tempra-simple/public/main.css index fcf1283c..8fbe01f2 100644 --- a/themes/tempra-simple/public/main.css +++ b/themes/tempra-simple/public/main.css @@ -10,7 +10,7 @@ body padding-bottom: 8px; } -/* Patch for Edge */ +/* Patch for Edge, until they fix emojis in arial x.x */ @supports (-ms-ime-align:auto) { .user_content { font-family: Segoe UI Emoji, arial; } } @@ -21,27 +21,27 @@ ul { padding-left: 0px; padding-right: 0px; - height: 28px; + height: 36px; list-style-type: none; border: 1px solid #ccc; background-color: white; + margin-bottom: 12px; } li { - height: 26px; + height: 35px; padding-left: 10px; - padding-top: 5px; - padding-bottom: 5px; - font-weight: bold; - text-transform: uppercase; + padding-top: 8px; + padding-bottom: 8px; } li:hover { background: rgb(250,250,250); } li a { text-decoration: none; - color: #515151; + /*color: #515151;*/ + color: black; + font-size: 17px; } -/*li a:hover { color: #7a7a7a; }*/ .menu_left { float: left; @@ -56,25 +56,24 @@ li a } .menu_alerts { - padding-left: 7px; + /*padding-left: 7px;*/ + font-size: 20px; padding-top: 2px; color: rgb(80,80,80); } .menu_alerts .alert_counter { - position:relative; - font-size: 9px; - top: -24px; - background-color: rgb(140,0,0); + position: relative; + font-size: 8px; + top: -25px; + background-color: rgb(190,0,0); color: white; - padding: 3px; width: 14px; left: 10px; line-height: 8px; - border-radius: 20px; padding-top: 2.5px; height: 14px; - opacity: 0.8; text-align: center; + border: white solid 1px; } .menu_alerts .alert_counter:empty { display: none; @@ -94,7 +93,7 @@ li a } .selectedAlert .alertList { position: absolute; - top: 43px; + top: 51px; display: block; background: white; font-size: 10px; @@ -128,6 +127,10 @@ li a width: calc(100% - 20px); height: 30px; } +.alertItem .text { + font-size: 10px; + font-weight: bold; +} .container { @@ -186,7 +189,7 @@ li a padding: 0px; padding-top: 0px; width: 100%; - margin-bottom: 8px; + margin-bottom: 12px; overflow: hidden; word-wrap: break-word; } @@ -253,6 +256,7 @@ li a color: black; } .rowitem a:hover { color: silver; } +.top_post { margin-bottom: 12px; } .opthead { display: none; } .col_left @@ -274,16 +278,8 @@ li a font-weight: bold; text-transform: uppercase; } -.colitem.passive -{ - font-weight: normal; - text-transform: none; -} -.colitem a -{ - text-decoration: none; - color: black; -} +.colitem.passive { font-weight: normal; text-transform: none; } +.colitem a { text-decoration: none; color: black; } .colitem a:hover { color: silver; } .formrow @@ -298,11 +294,7 @@ li a display: table; } .formrow:after { clear: both; } - -.formrow:not(:last-child) -{ - border-bottom: 1px dotted #ccc; -} +.formrow:not(:last-child) { border-bottom: 1px dotted #ccc; } .formitem { @@ -368,11 +360,7 @@ button border-width: 1px; font-size: 15px; } -button.username -{ - position: relative; - top: -0.25px; -} +button.username { position: relative; top: -0.25px; } .username.level { color: #303030; } .username.real_username { color: #404040; font-size: 17px; } .username.real_username:hover { color: black; } @@ -480,33 +468,61 @@ button.username .next_button { right: 14px; } @media (max-width: 880px) { - li { height: 25px; font-size: 15px; padding-left: 7px; } - ul { height: 26px; margin-top: 8px; } - .menu_left { padding-right: 7px; } - .menu_right { padding-right: 7px; } - body { padding-left: 4px; padding-right: 4px; margin: 0px !important; width: 100% !important; height: 100% !important; overflow-x: hidden; } + li { + height: 29px; + font-size: 15px; + padding-left: 9px; + padding-top: 6px; + padding-bottom: 6px; + } + ul { + height: 30px; + margin-top: 8px; + } + .menu_left { padding-right: 9px; } + .menu_right { padding-right: 9px; } + .menu_alerts { + padding-left: 7px; + padding-right: 7px; + font-size: 18px; + } + + body { + padding-left: 4px; + padding-right: 4px; + margin: 0px !important; + width: 100% !important; + height: 100% !important; + overflow-x: hidden; + } .container { width: auto; } - .selectedAlert .alertList { top: 33px; right: 4px; } + .selectedAlert .alertList { top: 37px; right: 4px; } } @media (max-width: 810px) { - li { font-weight: normal; text-transform: none; } .rowitem { text-transform: none; } } -@media (max-width: 620px) { - li - { +@media (max-width: 680px) { + li { padding-left: 5px; - padding-top: 2px; + padding-top: 3px; padding-bottom: 2px; - height: 23px; + height: 25px; } - ul { height: 24px; } - .menu_left { padding-right: 5px; } - .menu_right { padding-right: 5px; } + li a { font-size: 14px; } + ul { height: 26px; } + .menu_left { padding-right: 7px; } + .menu_right { padding-right: 7px; } .menu_create_topic { display: none;} - .menu_alerts { padding-left: 4px; padding-right: 4px; } + + .menu_alerts { + padding-left: 4px; + padding-right: 4px; + font-size: 16px; + padding-top: 1px; + } + .selectedAlert .alertList { top: 33px; } .hide_on_mobile { display: none !important; } .prev_button, .next_button { top: auto; bottom: 5px; } @@ -515,12 +531,9 @@ button.username } @media (max-width: 470px) { - .menu_overview { display: none; } - .menu_profile { display: none; } + .menu_overview, .menu_profile { display: none; } .hide_on_micro { display: none !important; } - .post_container { - overflow: visible !important; - } + .post_container { overflow: visible !important; } .post_item { background-position: 0px 2px !important; background-size: 64px 64px !important; @@ -550,4 +563,9 @@ button.username text-align: center; } .container { width: 100% !important; } -} \ No newline at end of file +} + +@media (max-width: 330px) { + li { padding-left: 6px; } + .menu_left { padding-right: 6px; } +} diff --git a/utils.go b/utils.go index b2d83ef6..1f18fcb2 100644 --- a/utils.go +++ b/utils.go @@ -1,15 +1,17 @@ package main -import "fmt" -import "time" -import "os" -import "math" -import "strings" -import "unicode" -import "strconv" -import "encoding/base64" -import "crypto/rand" -import "net/smtp" +import ( + "fmt" + "time" + "os" + "math" + "strings" + "unicode" + "strconv" + "encoding/base64" + "crypto/rand" + "net/smtp" +) type Version struct { @@ -60,36 +62,23 @@ func relative_time(in string) (string, error) { case months > 11: //return t.Format("Mon Jan 2 2006"), err return t.Format("Jan 2 2006"), err - case months > 1: - return fmt.Sprintf("%d months ago", months), err - case months == 1: - return "a month ago", err - case weeks > 1: - return fmt.Sprintf("%d weeks ago", weeks), err - case int(hours / 24) == 7: - return "a week ago", err - case int(hours / 24) == 1: - return "1 day ago", err - case int(hours / 24) > 1: - return fmt.Sprintf("%d days ago", int(hours / 24)), err - case seconds <= 1: - return "a moment ago", err - case seconds < 60: - return fmt.Sprintf("%d seconds ago", int(seconds)), err - case seconds < 120: - return "a minute ago", err - case seconds < 3600: - return fmt.Sprintf("%d minutes ago", int(seconds / 60)), err - case seconds < 7200: - return "an hour ago", err - default: - return fmt.Sprintf("%d hours ago", int(seconds / 60 / 60)), err + case months > 1: return fmt.Sprintf("%d months ago", months), err + case months == 1: return "a month ago", err + case weeks > 1: return fmt.Sprintf("%d weeks ago", weeks), err + case int(hours / 24) == 7: return "a week ago", err + case int(hours / 24) == 1: return "1 day ago", err + case int(hours / 24) > 1: return fmt.Sprintf("%d days ago", int(hours / 24)), err + case seconds <= 1: return "a moment ago", err + case seconds < 60: return fmt.Sprintf("%d seconds ago", int(seconds)), err + case seconds < 120: return "a minute ago", err + case seconds < 3600: return fmt.Sprintf("%d minutes ago", int(seconds / 60)), err + case seconds < 7200: return "an hour ago", err + default: return fmt.Sprintf("%d hours ago", int(seconds / 60 / 60)), err } } func convert_byte_unit(bytes float64) (float64,string) { - switch - { + switch { case bytes >= float64(terabyte): return bytes / float64(terabyte), "TB" case bytes >= float64(gigabyte): return bytes / float64(gigabyte), "GB" case bytes >= float64(megabyte): return bytes / float64(megabyte), "MB" @@ -113,6 +102,26 @@ func convert_byte_in_unit(bytes float64,unit string) (count float64) { return } +func convert_unit(num int) (int,string) { + switch { + case num >= 1000000000000: return 0, "∞" + case num >= 1000000000: return num / 1000000000, "B" + case num >= 1000000: return num / 1000000, "M" + case num >= 1000: return num / 1000, "K" + default: return num, "" + } +} + +func convert_friendly_unit(num int) (int,string) { + switch { + case num >= 1000000000000: return 0, " zillion" + case num >= 1000000000: return num / 1000000000, " billion" + case num >= 1000000: return num / 1000000, " million" + case num >= 1000: return num / 1000, " thousand" + default: return num, "" + } +} + func SendEmail(email string, subject string, msg string) (res bool) { // This hook is useful for plugin_sendmail or for testing tools. Possibly to hook it into some sort of mail server? if vhooks["email_send_intercept"] != nil { diff --git a/websockets.go b/websockets.go index 1027b7aa..44585417 100644 --- a/websockets.go +++ b/websockets.go @@ -129,7 +129,7 @@ func ws_page_responses(ws_user *WS_User, page []byte) { switch(string(page)) { case "/panel/": //fmt.Println("/panel/ WS Route") - w, err := ws_user.conn.NextWriter(websocket.TextMessage) + /*w, err := ws_user.conn.NextWriter(websocket.TextMessage) if err != nil { //fmt.Println(err.Error()) return @@ -143,7 +143,7 @@ func ws_page_responses(ws_user *WS_User, page []byte) { w.Write([]byte("set #dash-totonline " + strconv.Itoa(totonline) + " online\r")) w.Write([]byte("set #dash-gonline " + strconv.Itoa(gonline) + " guests online\r")) w.Write([]byte("set #dash-uonline " + strconv.Itoa(uonline) + " users online\r")) - w.Close() + w.Close()*/ // Listen for changes and inform the admins... admin_stats_mutex.Lock() @@ -176,12 +176,15 @@ func admin_stats_ticker() { var last_cpu_perc int = -1 var last_available_ram int64 = -1 var no_stat_updates bool = false + var no_ram_updates bool = false var onlineColour, onlineGuestsColour, onlineUsersColour, cpustr, cpuColour, ramstr, ramColour string var cpuerr, ramerr error var memres *mem.VirtualMemoryStat var cpu_perc []float64 + var totunit, uunit, gunit string + AdminStatLoop: for { //fmt.Println("tick tock") @@ -200,7 +203,8 @@ AdminStatLoop: // It's far more likely that the CPU Usage will change than the other stats, so we'll optimise them seperately... no_stat_updates = (uonline == last_uonline && gonline == last_gonline && totonline == last_totonline) - if no_stat_updates && int(cpu_perc[0]) == last_cpu_perc && last_available_ram == int64(memres.Available) { + no_ram_updates = (last_available_ram == int64(memres.Available)) + if int(cpu_perc[0]) == last_cpu_perc && no_stat_updates && no_ram_updates { time.Sleep(time.Second) continue } @@ -229,6 +233,10 @@ AdminStatLoop: } else { onlineUsersColour = "stat_red" } + + totonline, totunit = convert_friendly_unit(totonline) + uonline, uunit = convert_friendly_unit(uonline) + gonline, gunit = convert_friendly_unit(gonline) } if cpuerr != nil { @@ -245,33 +253,35 @@ AdminStatLoop: } } - if ramerr != nil { - ramstr = "Unknown" - } else { - total_count, total_unit := convert_byte_unit(float64(memres.Total)) - used_count := convert_byte_in_unit(float64(memres.Total - memres.Available),total_unit) - - // Round totals with .9s up, it's how most people see it anyway. Floats are notoriously imprecise, so do it off 0.85 - var totstr string - if (total_count - float64(int(total_count))) > 0.85 { - used_count += 1.0 - (total_count - float64(int(total_count))) - totstr = strconv.Itoa(int(total_count) + 1) + if !no_ram_updates { + if ramerr != nil { + ramstr = "Unknown" } else { - totstr = fmt.Sprintf("%.1f",total_count) - } - - if used_count > total_count { - used_count = total_count - } - ramstr = fmt.Sprintf("%.1f",used_count) + " / " + totstr + total_unit - - ramperc := ((memres.Total - memres.Available) * 100) / memres.Total - if ramperc < 50 { - ramColour = "stat_green" - } else if ramperc < 75 { - ramColour = "stat_orange" - } else { - ramColour = "stat_red" + total_count, total_unit := convert_byte_unit(float64(memres.Total)) + used_count := convert_byte_in_unit(float64(memres.Total - memres.Available),total_unit) + + // Round totals with .9s up, it's how most people see it anyway. Floats are notoriously imprecise, so do it off 0.85 + var totstr string + if (total_count - float64(int(total_count))) > 0.85 { + used_count += 1.0 - (total_count - float64(int(total_count))) + totstr = strconv.Itoa(int(total_count) + 1) + } else { + totstr = fmt.Sprintf("%.1f",total_count) + } + + if used_count > total_count { + used_count = total_count + } + ramstr = fmt.Sprintf("%.1f",used_count) + " / " + totstr + total_unit + + ramperc := ((memres.Total - memres.Available) * 100) / memres.Total + if ramperc < 50 { + ramColour = "stat_green" + } else if ramperc < 75 { + ramColour = "stat_orange" + } else { + ramColour = "stat_red" + } } } @@ -290,20 +300,22 @@ AdminStatLoop: } if !no_stat_updates { - w.Write([]byte("set #dash-totonline " + strconv.Itoa(totonline) + " online\r")) - w.Write([]byte("set #dash-gonline " + strconv.Itoa(gonline) + " guests online\r")) - w.Write([]byte("set #dash-uonline " + strconv.Itoa(uonline) + " users online\r")) + w.Write([]byte("set #dash-totonline " + strconv.Itoa(totonline) + totunit + " online\r")) + w.Write([]byte("set #dash-gonline " + strconv.Itoa(gonline) + gunit + " guests online\r")) + w.Write([]byte("set #dash-uonline " + strconv.Itoa(uonline) + uunit + " users online\r")) - w.Write([]byte("set-class #dash-totonline grid_stat " + onlineColour + "\r")) - w.Write([]byte("set-class #dash-gonline grid_stat " + onlineGuestsColour + "\r")) - w.Write([]byte("set-class #dash-uonline grid_stat " + onlineUsersColour + "\r")) + w.Write([]byte("set-class #dash-totonline grid_item grid_stat " + onlineColour + "\r")) + w.Write([]byte("set-class #dash-gonline grid_item grid_stat " + onlineGuestsColour + "\r")) + w.Write([]byte("set-class #dash-uonline grid_item grid_stat " + onlineUsersColour + "\r")) } w.Write([]byte("set #dash-cpu CPU: " + cpustr + "%\r")) - w.Write([]byte("set-class #dash-cpu grid_istat " + cpuColour + "\r")) + w.Write([]byte("set-class #dash-cpu grid_item grid_istat " + cpuColour + "\r")) - w.Write([]byte("set #dash-ram RAM: " + ramstr + "\r")) - w.Write([]byte("set-class #dash-ram grid_istat " + ramColour + "\r")) + if !no_ram_updates { + w.Write([]byte("set #dash-ram RAM: " + ramstr + "\r")) + w.Write([]byte("set-class #dash-ram grid_item grid_istat " + ramColour + "\r")) + } w.Close() }