Skip to content

Commit

Permalink
add logrotate function
Browse files Browse the repository at this point in the history
  • Loading branch information
lancard committed Dec 5, 2023
1 parent da8c7bb commit eb84fd7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
14 changes: 14 additions & 0 deletions admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,20 @@ app.get('/api/getSystemInformation', (req, res) => {
});
});

app.get('/api/getLogrotate', (req, res) => {
if (isUnauthroizedRequest(req, res)) return;

res.send(fs.readFileSync('/etc/logrotate.d/nginx').toString());
});

app.post('/api/saveLogrotate', (req, res) => {
if (isUnauthroizedRequest(req, res)) return;

fs.writeFileSync('/etc/logrotate.d/nginx', req.body.logrotate);

res.send("OK");
});

app.get('/api/getConfig', (req, res) => {
if (isUnauthroizedRequest(req, res)) return;

Expand Down
41 changes: 36 additions & 5 deletions admin/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@
<!-- Divider -->
<hr class="sidebar-divider">

<!-- Heading -->
<div class="sidebar-heading">
Logrotate
</div>

<!-- Nav Item - Pages Collapse Menu -->
<li class="nav-item">
<a class="nav-link" href="javascript:void(0)" onclick="showPanel('configLogrotate')">
<i class="fas fa-fw fa-cog"></i>
<span>Config</span>
</a>
</li>

<!-- Divider -->
<hr class="sidebar-divider">

<!-- Heading -->
<div class="sidebar-heading">
Document
Expand All @@ -137,11 +153,6 @@
<!-- Divider -->
<hr class="sidebar-divider d-none d-md-block">

<!-- Sidebar Toggler (Sidebar) -->
<div class="text-center d-none d-md-inline">
<button class="rounded-circle border-0" id="sidebarToggle"></button>
</div>

</ul>
<!-- End of Sidebar -->

Expand Down Expand Up @@ -209,6 +220,25 @@
</nav>
<!-- End of Topbar -->

<div class="container-fluid collapse" id="configLogrotate">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Config logrotate</h1>
<a href="javascript: void(0)" onclick="saveLogrotate()"
class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm">
<i class="fas fa-upload fa-sm text-white-50"></i> Save
</a>
</div>

<div class="mb-2">
<strong class="text-danger">
will save to '/etc/logrotate.d/nginx' and will be overwritten if exist.
</strong>
</div>

<textarea class="form-control" rows="20" id="logrotate"></textarea>
</div>

<div class="container-fluid collapse" id="uploadCert">
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
Expand Down Expand Up @@ -715,6 +745,7 @@ <h5 class="modal-title" id="closeModalLabel">Ready to Leave?</h5>

<script>
$(function () {
loadLogrotate();
loadConfig();
createChart();
});
Expand Down
17 changes: 17 additions & 0 deletions admin/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,23 @@ function configToUpstreamDOM() {

}

function loadLogrotate() {
$.get('/api/getLogrotate', (ret) => {
$("#logrotate").val(ret);
});
}

function saveLogrotate() {
$.ajax({
type: "POST",
url: '/api/saveLogrotate',
data: { logrotate: $("#logrotate").val() },
success: (ret) => {
alert(ret);
}
});
}

function saveConfig() {
// write to back config
upstreamDomToConfig();
Expand Down

0 comments on commit eb84fd7

Please sign in to comment.