Skip to content

Commit

Permalink
#4104 Add ability to run from the webui and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-developer committed Dec 27, 2024
1 parent 087d492 commit 5e97ab6
Show file tree
Hide file tree
Showing 4 changed files with 322 additions and 75 deletions.
13 changes: 11 additions & 2 deletions html/includes/support.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
border: 1px solid transparent !important;
border-radius: 4px !important;
}

#as-support-files th {
font-size: 1.3em;
}

#as-support-files td {
padding-bottom: 10px;
font-size: 1.2em;
}

table tbody tr:first-child {
color: green;
}

.mr-10 {
Expand Down Expand Up @@ -41,11 +50,11 @@

<div class="panel panel-default">
<div class="panel-heading">
<h3>Support Logs <small>previously generated log files</small></h3>
<h3>Support Logs <small>previously generated log files</small><div class="pull-right"><button type="button" class="btn btn-danger" id="as-support-generate">Generate</button></div></h3>
</div>
<div class="panel-body">
<div class="alert alert-warning" role="alert">
<p>When requesting support please generate a log file by logging into your pi as the SAME user you installed Allsky as and from the Allsky home directory run</p>
<p>When requesting support please generate a log file by either clicking the 'Generate' button on the right or logging into your pi as the SAME user you installed Allsky as and from the Allsky home directory run</p>
<p>./support.sh</p>
<p>Once complete return to this page and refresh it. The generated log will be available below to download.</p>
</div>
Expand Down
10 changes: 9 additions & 1 deletion html/includes/supportutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function __construct() {

public function run()
{
// $this->checkXHRRequest();
$this->checkXHRRequest();
$this->sanitizeRequest();
$this->runRequest();
}
Expand Down Expand Up @@ -155,6 +155,14 @@ public function getSupportFilesList() {
}
$this->sendResponse(json_encode($data));
}

public function getGenerateLog() {
$command = 'export ALLSKY_HOME=' . ALLSKY_HOME . '; export SUDO_OK="true"; ' . ALLSKY_HOME . '/support.sh --auto';
$output = shell_exec($command);

$this->sendResponse(json_encode("ok"));
}

}


Expand Down
191 changes: 191 additions & 0 deletions html/js/allsky-support/allsky-support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
"use strict";

class ALLSKYSUPPORT {
#supportFilesTable = null

constructor() {

$(document).on('click', '.as-support-log-delete', (event) => {
var logId = $(event.currentTarget).data('logid')
var logTable = this.#supportFilesTable
bootbox.confirm({
message: 'Are you sure you wish to delete this log entry?',
centerVertical: true,
callback: function(result) {
if (result) {
$('.as-support-loading').LoadingOverlay('show', {
background: 'rgba(0, 0, 0, 0.5)',
imageColor: '#a94442'
});
$.ajax({
type: 'POST',
url: 'includes/supportutils.php?request=DeleteLog',
data: {
logId: logId
},
dataType: 'json',
cache: false
}).done(() => {
logTable.ajax.reload()
}).always(() => {
$('.as-support-loading').LoadingOverlay('hide')
})
}
}
})
})

$(document).on('click', '.as-support-log-github', (event) => {
var logId = $(event.currentTarget).data('logid')
var logTable = this.#supportFilesTable
bootbox.prompt({
title: 'Enter the id of the Github discussion',
centerVertical: true,
inputType: 'number',
callback: function(githubid){
if (githubid !== null && githubid !== '') {
$('.as-support-loading').LoadingOverlay('show', {
background: 'rgba(0, 0, 0, 0.5)',
imageColor: '#a94442'
});
$.ajax({
type: 'POST',
url: 'includes/supportutils.php?request=ChangeGithubId',
data: {
logId: logId,
githubid: githubid
},
dataType: 'json',
cache: false
}).done(() => {
logTable.ajax.reload();
}).always(() => {
$('.as-support-loading').LoadingOverlay('hide')
})
}
}
});
})

$(document).on('click', '.as-support-log-download', (event) => {
var logId = $(event.currentTarget).data('logid')
$('.as-support-loading').LoadingOverlay('show', {
background: 'rgba(0, 0, 0, 0.5)',
imageColor: '#a94442'
});

$.ajax({
url: 'includes/supportutils.php?request=DownloadLog',
type: 'POST',
data: {
logId: logId
},
xhrFields: {
responseType: 'blob'
}
}).done((blob) => {
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = logId
document.body.appendChild(a)
a.click()
a.remove()
window.URL.revokeObjectURL(url)
}).always(() => {
$('.as-support-loading').LoadingOverlay('hide')
})
})

$(document).on('click', '#as-support-generate', (event) => {
var logTable = this.#supportFilesTable

let message="This script will collect data from your Raspberry Pi to assist in supporting any issues.<br>\
No personal information is collected by this script. The following data is collected<br><br>\
- Basic system information\<br>\
- Filesystem/Memory/Network Information (IPV4/6/MAC details are obfuscated)<br>\
- Installed system and python packages<br>\
- Allsky/lighttpd logs and error logs<br>\
- Connected camera details<br>\
- i2c bus details<br>\
- Running processes<br>\
- Allsky config files (obfuscated where required to hide any credentials)<br><br>\
Select 'Ok' to agree or 'Cancel' to cncel"

bootbox.confirm(message, function(result){
if (result) {
$('body').LoadingOverlay('show', {
background: 'rgba(0, 0, 0, 0.5)',
imageColor: '#a94442',
textColor: '#a94442',
text: 'Generating Support Information'
});

$.ajax({
url: 'includes/supportutils.php?request=GenerateLog',
type: 'GET',
dataType: 'json',
cache: false
}).done(() => {
logTable.ajax.reload()
}).always(() => {
$('body').LoadingOverlay('hide')
})
}
});


})


this.#supportFilesTable = $('#as-support-files').DataTable({
ajax: {
url: 'includes/supportutils.php?request=SupportFilesList',
type: 'GET',
dataSrc: ''
},
dom: 'rtip',
order: [[1, 'desc']],
columnDefs: [
{
targets: [0,1],
visible: false
}
],
columns: [
{
data: 'filename'
},{
data: 'sortfield'
},{
data: 'date'
},{
data: 'issue',
render: function (item, type, row, meta) {
let result = 'No LInked Issue'
if (item !== 'none') {
let issue = 'https://github.com/AllskyTeam/allsky/discussions/' + item
result = '<a external="true" href="' + issue + '" target="_blank">Issue ' + item + '</a>'
}

return result
}
},{
data: 'size'
},{
data: null,
width: '120px',
render: function (item, type, row, meta) {
let buttonGithub = '<button type="button" title="Edit Guthib Discussion Number" class="btn btn-primary as-support-log-github mr-10" data-logid="' + item.filename + '"><i class="fa-brands fa-github"></i></button>'
let buttonDownload = '<button type="button" title="Download log" class="btn btn-primary as-support-log-download mr-10" data-logid="' + item.filename + '"><i class="fa-solid fa-download"></i></button>'
let buttonDelete = '<button type="button" title="Delete Log" class="btn btn-danger as-support-log-delete" data-logid="' + item.filename + '"><i class="fa-solid fa-trash"></i></button>'

let buttons = '<div>' + buttonDownload + buttonGithub + buttonDelete + '</div>'
return buttons
}
}
]
});
}

}
Loading

0 comments on commit 5e97ab6

Please sign in to comment.