Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some additional adjustments and fixes. #17

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
93 changes: 60 additions & 33 deletions AutomateDiagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,73 @@
import getopt
import sys
import cgi
import html #Added to fix escape error in Python3

def system_call(command):
p = subprocess.Popen([command], stdout=subprocess.PIPE, shell=True)
return p.stdout.read()

# Read state file for info
with open("/usr/local/ltechagent/state","r") as read_file:
data = json.load(read_file)
if os.path.exists("/usr/local/ltechagent/state"):

lterrors = ""
try:
opts, args = getopt.getopt(sys.argv[1:],"e")
for opt, arg in opts:
if opt == '-e':
with open("/usr/local/ltechagent/agent.log","r") as log_file:
lterrors = cgi.escape(log_file.read())
except getopt.GetoptError:
pass
# Read state file for info
with open("/usr/local/ltechagent/state","r") as read_file:
data = json.load(read_file)

# Get last contact date
lc = data["last_contact"]
last_contact = "{0}/{1}/{2} {3}:{4:02d}:{5:02d}".format(lc["month"],lc["day_of_month"],lc["year"],lc["hour"],lc["min"],lc["sec"])

lterrors_bytes = lterrors.encode("ascii")
lterrors_b64_bytes = base64.b64encode(lterrors_bytes)
lterrors_str = lterrors_b64_bytes.decode("ascii")
old_version = data["version"]

# Get last contact date
lc = data["last_contact"]
last_contact = "{0}/{1}/{2} {3}:{4:02d}:{5:02d}".format(lc["month"],lc["day_of_month"],lc["year"],lc["hour"],lc["min"],lc["sec"])
system_call("/usr/local/ltechagent/ltupdate")

old_version = data["version"]
# Read state file for info
with open("/usr/local/ltechagent/state","r") as read_file:
data = json.load(read_file)

system_call("/usr/local/ltechagent/ltupdate")
if old_version != data["version"]:
update = "Updated from "+old_version+" to "+ data["version"]
else:
update = "Already updated to "+ data["version"]

server_addr = data["last_good_server_url"]
version = data["version"]
id = data['computer_id']
clientid = data['client_id']
online = data["is_signed_in"]

else:

server_addr = 'Not Found'
last_contact = ''
version = ''
update = ''
id = ''
clientid = ''
online = ''

# Read state file for info
with open("/usr/local/ltechagent/state","r") as read_file:
data = json.load(read_file)
if os.path.exists("/usr/local/ltechagent/agent.log"):

lterrors = ""

try:
opts, args = getopt.getopt(sys.argv[1:],"e")
for opt, arg in opts:
if opt == '-e':
with open("/usr/local/ltechagent/agent.log","r") as log_file:
lterrors = html.escape(log_file.read())
#Changed from cgi.escape to html.escape to resolve errors in Python3

except getopt.GetoptError:
pass

lterrors_bytes = lterrors.encode("ascii")
lterrors_b64_bytes = base64.b64encode(lterrors_bytes)
lterrors_str = lterrors_b64_bytes.decode("ascii")

if old_version != data["version"]:
update = "Updated from "+old_version+" to "+ data["version"]
else:
update = "Already updated to "+ data["version"]

lterrors_str = "Log file not found"

# Check services
if platform.system() == 'Darwin':
Expand Down Expand Up @@ -75,17 +102,17 @@ def system_call(command):
statusname = "Stopped"
svc_ltsvc = { "Status": statusname, "User": "ltechagent", "Start Mode": "Auto"}

diag_result = {
'server_addr': data["last_good_server_url"],
diag_result = {
'server_addr': server_addr,
'lastcontact': last_contact,
'update': update,
'version': data["version"],
'id': data['computer_id'],
'clientid': data['client_id'],
'online': data["is_signed_in"],
'version': version,
'id': id,
'clientid': clientid,
'online': online,
'svc_ltservice': svc_ltsvc,
'lterrors': lterrors_str
}

print("!---BEGIN JSON---!")
print(json.dumps(diag_result))
print(json.dumps(diag_result))
29 changes: 9 additions & 20 deletions DiagnosticsNewStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
margin-left: auto;
margin-right: auto;
table-layout: fixed;
margin: 0.4em 0em;
}

.Automate .Header {
Expand All @@ -19,6 +20,12 @@
display: none;
}

/* 2023.10.17 -- Joe McCall | So the Diagnostic Action in the context menu aligns correctly. */

.GetInfoPer {
text-align: left;
}

.success,
.failed {
font-weight: bold !important;
Expand All @@ -44,19 +51,6 @@
z-index: 5;
}

/*a.GetInfo.Automate.HasText {
display: inline-block;
width: 13em;
text-decoration: inherit;
color: #FFF !important;
border-radius: 0.2em;
padding: 0.4em 0.5em;
font-size: 1.0em;
font-weight: 500;
text-align: left;
background-color: #026CCF;
}*/

#dataTableHeader,
#dataTableData {
border: 0px;
Expand All @@ -76,7 +70,6 @@
}

#dataTable {
top: 10%;
width: 95%;
}

Expand Down Expand Up @@ -106,7 +99,6 @@
*/
font-size: 0.9em;
background-color: #252525;
color: #FFFFFF;
overflow: auto;
padding: 0.5em 0em 0em 0.5em;
height: 36em;
Expand Down Expand Up @@ -145,15 +137,13 @@
}

/* 2023.01.16 -- Joe McCall | Quality of life. */

.Automate a:hover {
background-color: #014e95 !important;
}

/* 2023.01.16 -- Joe McCall | Reduce wasted space */

#tableDetails,
#dataContainer {
width: 100%;
margin: 0em 0em 0.2em 0em !important;
}

Expand All @@ -174,7 +164,6 @@
.Automate hr,
.Automate dt,
.Automate dd,
.Automate table
.Automate pre {
margin: 0.2em 0em;
margin: 0.4em 0em;
}
Loading