mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Device copy server side #276 work
This commit is contained in:
@@ -348,6 +348,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -464,9 +466,33 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h4 class="bottom-border-aqua"><?= lang('DevDetail_Copy_Device_Title');?></h4>
|
||||||
|
<div class="box-body form-horizontal">
|
||||||
|
<label class="col-sm-3 control-label">
|
||||||
|
<?= lang('Navigation_Devices');?>
|
||||||
|
</label>
|
||||||
|
<div class="col-sm-9">
|
||||||
|
<div class="input-group">
|
||||||
|
<input class="form-control" title="<?= lang('DevDetail_Copy_Device_Tooltip');?>" id="txtFromDevice" type="text" value="--">
|
||||||
|
<span class="input-group-addon" title='<?= lang('Gen_Copy');?>'><i class="fa fa-copy pointer" onclick="askCopyFromDevice();"></i></span>
|
||||||
|
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||||
|
<span class="fa fa-caret-down"></span>
|
||||||
|
</button>
|
||||||
|
<ul id="dropdownDevices" class="dropdown-menu dropdown-menu-right">
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Buttons -->
|
<!-- Buttons -->
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
@@ -949,6 +975,7 @@ function initializeCombos () {
|
|||||||
initializeCombo ( '#dropdownNetworkNodeMac', 'getNetworkNodes', 'txtNetworkNodeMac', false);
|
initializeCombo ( '#dropdownNetworkNodeMac', 'getNetworkNodes', 'txtNetworkNodeMac', false);
|
||||||
initializeCombo ( '#dropdownIcon', 'getIcons', 'txtIcon', false);
|
initializeCombo ( '#dropdownIcon', 'getIcons', 'txtIcon', false);
|
||||||
initializeCombo ( '#dropdownAction', 'getActions', 'txtAction', false);
|
initializeCombo ( '#dropdownAction', 'getActions', 'txtAction', false);
|
||||||
|
initializeCombo ( '#dropdownDevices', 'getDevices', 'txtFromDevice', false);
|
||||||
|
|
||||||
// Initialize static combos
|
// Initialize static combos
|
||||||
initializeComboSkipRepeated ();
|
initializeComboSkipRepeated ();
|
||||||
@@ -1623,6 +1650,29 @@ function deleteDeviceEvents () {
|
|||||||
$('#panDetails :input').attr('disabled', true);
|
$('#panDetails :input').attr('disabled', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
function askCopyFromDevice() {
|
||||||
|
// Ask
|
||||||
|
showModalWarning('<?= lang('BackDevDetail_Copy_Title');?>', '<?= lang('BackDevDetail_Copy_Ask');?>',
|
||||||
|
'<?= lang('Gen_Cancel');?>', '<?= lang('Gen_Run');?>', 'copyFromDevice');
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyFromDevice() {
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
$.get('php/server/devices.php?action=copyFromDevice&'
|
||||||
|
+ '&macTo=' + $('#txtMAC').val()
|
||||||
|
+ '&macFrom=' + $('#txtFromDevice').val()
|
||||||
|
, function(msg) {
|
||||||
|
showMessage (msg);
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
window.location.reload();
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
function askRunAction() {
|
function askRunAction() {
|
||||||
// Ask
|
// Ask
|
||||||
|
|||||||
@@ -58,6 +58,8 @@
|
|||||||
case 'overwriteIconType': overwriteIconType(); break;
|
case 'overwriteIconType': overwriteIconType(); break;
|
||||||
case 'getIcons': getIcons(); break;
|
case 'getIcons': getIcons(); break;
|
||||||
case 'getActions': getActions(); break;
|
case 'getActions': getActions(); break;
|
||||||
|
case 'getDevices': getDevices(); break;
|
||||||
|
case 'copyFromDevice': copyFromDevice(); break;
|
||||||
case 'wakeonlan': wakeonlan(); break;
|
case 'wakeonlan': wakeonlan(); break;
|
||||||
|
|
||||||
default: logServerConsole ('Action: '. $action); break;
|
default: logServerConsole ('Action: '. $action); break;
|
||||||
@@ -524,7 +526,7 @@ function ImportCSV() {
|
|||||||
if($error == "")
|
if($error == "")
|
||||||
{
|
{
|
||||||
// import succesful
|
// import succesful
|
||||||
echo lang('BackDevices_DBTools_ImportCSV') . "(Skipped lines: " .$skipped .")";
|
echo lang('BackDevices_DBTools_ImportCSV') . " (Skipped lines: " .$skipped .") ";
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -825,6 +827,36 @@ function getActions() {
|
|||||||
echo (json_encode ($tableData));
|
echo (json_encode ($tableData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
function getDevices() {
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
// Device Data
|
||||||
|
$sql = 'select dev_MAC, dev_Name from Devices';
|
||||||
|
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// arrays of rows
|
||||||
|
$tableData = array();
|
||||||
|
|
||||||
|
while ($row = $result -> fetchArray (SQLITE3_ASSOC)) {
|
||||||
|
$name = handleNull($row['dev_Name'], "(unknown)");
|
||||||
|
$mac = handleNull($row['dev_MAC'], "(unknown)");
|
||||||
|
// Push row data
|
||||||
|
$tableData[] = array('id' => $mac,
|
||||||
|
'name' => $name );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Control no rows
|
||||||
|
if (empty($tableData)) {
|
||||||
|
$tableData = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return json
|
||||||
|
echo (json_encode ($tableData));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Query the List of types
|
// Query the List of types
|
||||||
@@ -1176,6 +1208,56 @@ function wakeonlan() {
|
|||||||
echo lang('BackDevDetail_Tools_WOL_okay');
|
echo lang('BackDevDetail_Tools_WOL_okay');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Copy from device
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
function copyFromDevice() {
|
||||||
|
|
||||||
|
$MAC_FROM = $_REQUEST['macFrom'];
|
||||||
|
$MAC_TO = $_REQUEST['macTo'];
|
||||||
|
|
||||||
|
if ((false === filter_var($MAC_FROM , FILTER_VALIDATE_MAC) && $MAC_FROM != "Internet" && $MAC_FROM != "") ) {
|
||||||
|
throw new Exception('Invalid mac address');
|
||||||
|
}
|
||||||
|
if ((false === filter_var($MAC_TO , FILTER_VALIDATE_MAC) && $MAC_TO != "Internet" && $MAC_TO != "") ) {
|
||||||
|
throw new Exception('Invalid mac address');
|
||||||
|
}
|
||||||
|
|
||||||
|
global $db;
|
||||||
|
|
||||||
|
// clean-up temporary table
|
||||||
|
$sql = "DROP TABLE temp_devices ";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// create temporary table with the source data
|
||||||
|
$sql = "CREATE TABLE temp_devices AS SELECT * FROM Devices WHERE dev_MAC = '". $MAC_FROM . "';";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// update temporary table with the correct target MAC
|
||||||
|
$sql = "UPDATE temp_devices SET dev_MAC = '". $MAC_TO . "';";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// delete previous entry
|
||||||
|
$sql = "DELETE FROM Devices WHERE dev_MAC = '". $MAC_TO . "';";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// insert new entry with the correct target MAC from the temporary table
|
||||||
|
$sql = "INSERT INTO Devices SELECT * FROM temp_devices WHERE dev_MAC = '".$MAC_TO."'";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// clean-up temporary table
|
||||||
|
$sql = "DROP TABLE temp_devices ";
|
||||||
|
$result = $db->query($sql);
|
||||||
|
|
||||||
|
// check result
|
||||||
|
if ($result == TRUE) {
|
||||||
|
echo 'OK';
|
||||||
|
} else {
|
||||||
|
echo lang('BackDevices_Device_UpdDevError');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Status Where conditions
|
// Status Where conditions
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ $lang['en_us'] = array(
|
|||||||
'Gen_Save' => 'Save',
|
'Gen_Save' => 'Save',
|
||||||
'Gen_Saved' => 'Saved',
|
'Gen_Saved' => 'Saved',
|
||||||
'Gen_Run' => 'Run',
|
'Gen_Run' => 'Run',
|
||||||
|
'Gen_Copy' => 'Run',
|
||||||
'Gen_Action' => 'Action',
|
'Gen_Action' => 'Action',
|
||||||
'Gen_Purge' => 'Purge',
|
'Gen_Purge' => 'Purge',
|
||||||
'Gen_Backup' => 'Run Backup',
|
'Gen_Backup' => 'Run Backup',
|
||||||
@@ -245,6 +246,10 @@ $lang['en_us'] = array(
|
|||||||
'DevDetail_WOL_Title' => '<i class="fa fa-power-off"></i> Wake-on-LAN',
|
'DevDetail_WOL_Title' => '<i class="fa fa-power-off"></i> Wake-on-LAN',
|
||||||
'DevDetail_Run_Actions_Title' => '<i class="fa fa-play"></i> Run action on device',
|
'DevDetail_Run_Actions_Title' => '<i class="fa fa-play"></i> Run action on device',
|
||||||
'DevDetail_Run_Actions_Tooltip' => 'Run an action on the current device from the dropdown list.',
|
'DevDetail_Run_Actions_Tooltip' => 'Run an action on the current device from the dropdown list.',
|
||||||
|
'DevDetail_Copy_Device_Title' => '<i class="fa fa-copy"></i> Copy details from device',
|
||||||
|
'DevDetail_Copy_Device_Tooltip' => 'Copy details from device from the dropdown list. Everything on this page will be overwritten',
|
||||||
|
'BackDevDetail_Copy_Title' => 'Copy details',
|
||||||
|
'BackDevDetail_Copy_Ask' => 'Copy details from device from the dropdown list (Everything on this page will be overwritten)?',
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Maintenance Page
|
// Maintenance Page
|
||||||
@@ -368,7 +373,7 @@ $lang['en_us'] = array(
|
|||||||
'BackDevices_DBTools_ImportCSV' => 'The devices from the CSV file were imported successfully.',
|
'BackDevices_DBTools_ImportCSV' => 'The devices from the CSV file were imported successfully.',
|
||||||
'BackDevices_DBTools_ImportCSVError' => 'The CSV file couldn\'t be imported. Make sure the format is correct.',
|
'BackDevices_DBTools_ImportCSVError' => 'The CSV file couldn\'t be imported. Make sure the format is correct.',
|
||||||
'BackDevices_DBTools_ImportCSVMissing' => 'The CSV file couldn\'t be found under <b>/config/devices.csv.</b>',
|
'BackDevices_DBTools_ImportCSVMissing' => 'The CSV file couldn\'t be found under <b>/config/devices.csv.</b>',
|
||||||
'BackDevices_Device_UpdDevError' => 'Error updating devices, try later. The database is probable locked due to an ongoing task.',
|
'BackDevices_Device_UpdDevError' => 'Error updating devices, try later. The database is probably locked due to an ongoing task.',
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
Reference in New Issue
Block a user