diff --git a/index.html b/index.html
index 0fde83b0..58e12adf 100755
--- a/index.html
+++ b/index.html
@@ -292,12 +292,14 @@
if (arrayLength > 0 ) {
$('#templateEditorSave').prop('disabled', false);
+ $('#templateEditorDeleteDialog').prop('disabled', false);
$('#templateSelector').html(htmlContent);
$('#templateSelector').selectpicker('refresh');
$('#templateSelector').trigger('change');
} else {
$('#templateEditorSave').prop('disabled', true);
+ $('#templateEditorDeleteDialog').prop('disabled', true);
}
$('#templateEditor').modal('show');
@@ -511,6 +513,10 @@
$('#templateDialogSaveAs').modal('show');
});
+ $('#templateEditorDeleteDialog').click(function(event) {
+ $('#templateDialogDelete').modal('show');
+ });
+
$('#templateEditorSaveAs').click(function(event) {
var templateId = $('#templateName').val();
var template = $('#template').val();
@@ -520,6 +526,12 @@
$('#templateEditor').modal('hide');
});
+ $('#templateEditorDelete').click(function(event) {
+ var templateId = $('#templateSelector').val();
+
+ deleteTemplateConfig(templateId, template);
+ });
+
$('#clientStatusList tbody').on( 'click', 'button#LOG', function () {
var data = table.row( $(this).parents('tr') ).data();
var clientId = data['client_status']['client_id'];
@@ -856,6 +868,20 @@
}
});
}
+
+ function deleteTemplateConfig(templateId) {
+ $.ajax({
+ url: "/admin/deleteClientConfig?clientId=template_" + templateId,
+ type: 'POST',
+ dataType: "text",
+ success: function(data){
+ setSuccess('Successfully deleted template: ' + templateId + '');
+ },
+ error: function (data) {
+ setError('Failed to delete template: ' + templateId + ' \nError: ' + JSON.stringify(data,undefined, 2));
+ }
+ });
+ }
@@ -982,7 +1008,8 @@
@@ -1003,7 +1030,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1034,7 +1081,7 @@
diff --git a/src/cc/Service.cpp b/src/cc/Service.cpp
index 3bf47457..6520a3b0 100644
--- a/src/cc/Service.cpp
+++ b/src/cc/Service.cpp
@@ -155,6 +155,8 @@ unsigned Service::handlePOST(const Options* options, const std::string& url, con
resultCode = setClientConfig(options, clientId, data, resp);
} else if (url.rfind("/admin/setClientCommand", 0) == 0) {
resultCode = setClientCommand(clientId, data, resp);
+ } else if (url.rfind("/admin/deleteClientConfig", 0) == 0) {
+ resultCode = deleteClientConfig(options, clientId, resp);
} else {
LOG_WARN("[%s] 400 BAD REQUEST - Request does not contain clientId (%s)", clientIp.c_str(), url.c_str());
}
@@ -482,6 +484,20 @@ void Service::setClientLog(size_t maxRows, const std::string& clientId, const st
}
}
+unsigned Service::deleteClientConfig(const Options* options, const std::string& clientId, std::string& resp)
+{
+ if (!clientId.empty()) {
+ std::string clientConfigFileName = getClientConfigFileName(options, clientId);
+ if (!clientConfigFileName.empty() && remove(clientConfigFileName.c_str()) == 0) {
+ return MHD_HTTP_OK;
+ } else {
+ return MHD_HTTP_NOT_FOUND;
+ }
+ } else {
+ return MHD_HTTP_BAD_REQUEST;
+ }
+}
+
unsigned Service::resetClientStatusList(const std::string& data, std::string& resp)
{
m_clientStatus.clear();
diff --git a/src/cc/Service.h b/src/cc/Service.h
index 7c755ee4..88f5fecf 100644
--- a/src/cc/Service.h
+++ b/src/cc/Service.h
@@ -60,6 +60,7 @@ private:
static unsigned setClientStatus(const Options* options, const std::string& clientIp, const std::string& clientId, const std::string& data, std::string& resp);
static unsigned setClientCommand(const std::string& clientId, const std::string& data, std::string& resp);
static unsigned setClientConfig(const Options* options, const std::string &clientId, const std::string &data, std::string &resp);
+ static unsigned deleteClientConfig(const Options* options, const std::string& clientId, std::string& resp);
static unsigned resetClientStatusList(const std::string& data, std::string& resp);
static void setClientLog(size_t maxRows, const std::string& clientId, const std::string& log);