initial commit of file from CVS for smeserver-phpsysinfo on Sat Sep 7 20:53:46 AEST 2024
This commit is contained in:
225
root/opt/phpsysinfo/plugins/mdstatus/js/mdstatus.js
Normal file
225
root/opt/phpsysinfo/plugins/mdstatus/js/mdstatus.js
Normal file
@@ -0,0 +1,225 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2008 by phpSysInfo - A PHP System Information Script *
|
||||
* http://phpsysinfo.sourceforge.net/ *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
//
|
||||
// $Id: mdstatus.js 679 2012-09-04 10:10:11Z namiltd $
|
||||
//
|
||||
|
||||
/*global $, jQuery, buildBlock, genlang, createBar, plugin_translate, datetime */
|
||||
|
||||
"use strict";
|
||||
|
||||
//appendcss("./plugins/MDStatus/css/MDStatus.css");
|
||||
|
||||
var mdstatus_show = false;
|
||||
|
||||
/**
|
||||
* get the details of the raid
|
||||
* @param {jQuery} xml part of the plugin-XML
|
||||
* @param {number} id id of the device
|
||||
*/
|
||||
function mdstatus_buildinfos(xml, id) {
|
||||
var html = "", devstatus = "", devlevel = "", devchunk = 0, devsuper = 0, devalgo = 0, devactive = 0, devregis = 0, button = "";
|
||||
|
||||
devstatus = $(xml).attr("Disk_Status");
|
||||
devlevel = $(xml).attr("Level");
|
||||
devchunk = parseInt($(xml).attr("Chunk_Size"), 10);
|
||||
devsuper = parseInt($(xml).attr("Persistent_Superblock"), 10);
|
||||
devalgo = parseInt($(xml).attr("Algorithm"), 10);
|
||||
devactive = parseInt($(xml).attr("Disks_Active"), 10);
|
||||
devregis = parseInt($(xml).attr("Disks_Registered"), 10);
|
||||
html += "<tr><td>" + genlang(5, false, "MDStatus") + "</td><td>" + devstatus + "</td></tr>";
|
||||
html += "<tr><td>" + genlang(6, false, "MDStatus") + "</td><td>" + devlevel + "</td></tr>";
|
||||
if (devchunk !== -1) {
|
||||
html += "<tr><td>" + genlang(7, false, "MDStatus") + "</td><td>" + devchunk + "K</td></tr>";
|
||||
}
|
||||
if (devalgo !== -1) {
|
||||
html += "<tr><td>" + genlang(8, false, "MDStatus") + "</td><td>" + devalgo + "</td></tr>";
|
||||
}
|
||||
if (devsuper !== -1) {
|
||||
html += "<tr><td>" + genlang(9, false, "MDStatus") + "</td><td>" + genlang(10, false, "MDStatus") + "</td></tr>";
|
||||
}
|
||||
else {
|
||||
html += "<tr><td>" + genlang(9, false, "MDStatus") + "</td><td>" + genlang(11, false, "MDStatus") + "</td></tr>";
|
||||
}
|
||||
if (devactive !== -1 && devregis !== -1) {
|
||||
html += "<tr><td>" + genlang(12, false, "MDStatus") + "</td><td>" + devregis + "/" + devactive + "</td></tr>";
|
||||
}
|
||||
button += "<h3 style=\"cursor: pointer\" id=\"sPlugin_MDStatus_Info" + id + "\"><img src=\"./gfx/bullet_toggle_plus.png\" alt=\"plus\" style=\"vertical-align:middle;\" />" + genlang(4, false, "MDStatus") + "</h3>";
|
||||
button += "<h3 style=\"cursor: pointer; display: none;\" id=\"hPlugin_MDStatus_Info" + id + "\"><img src=\"./gfx/bullet_toggle_minus.png\" alt=\"minus\" style=\"vertical-align:middle;\" />" + genlang(4, false, "MDStatus") + "</h3>";
|
||||
button += "<table id=\"Plugin_MDStatus_InfoTable" + id + "\" style=\"border-spacing:0; display:none;\">" + html + "</table>";
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a html string with the current action on the disks
|
||||
* @param {jQuery} xml part of the plugin-XML
|
||||
*/
|
||||
function mdstatus_buildaction(xml) {
|
||||
var html = "", name = "", time = "", tunit = "", percent = 0;
|
||||
$("Action", xml).each(function mdstatus_getaction(id) {
|
||||
name = $(this).attr("Name");
|
||||
if (parseInt(name, 10) !== -1) {
|
||||
time = $(this).attr("Time_To_Finish");
|
||||
tunit = $(this).attr("Time_Unit");
|
||||
percent = parseFloat($(this).attr("Percent"));
|
||||
html += "<div style=\"padding-left:10px;\">";
|
||||
html += genlang(13, false, "MDStatus") + ": " + name + "<br/>";
|
||||
html += createBar(percent);
|
||||
html += "<br/>";
|
||||
html += genlang(14, false, "MDStatus") + " " + time + " " + tunit;
|
||||
html += "</div>";
|
||||
}
|
||||
});
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* choose the right diskdrive icon
|
||||
* @param {jQuery} xml part of the plugin-XML
|
||||
*/
|
||||
function mdstatus_diskicon(xml) {
|
||||
var html = "";
|
||||
$("Disks Disk", xml).each(function mdstatus_getdisk(id) {
|
||||
var diskstatus = "", diskname = "", img = "", alt = "";
|
||||
html += "<div class=\"plugin_mdstatus_biun\">";
|
||||
diskstatus = $(this).attr("Status");
|
||||
diskname = $(this).attr("Name");
|
||||
switch (diskstatus) {
|
||||
case " ":
|
||||
case "":
|
||||
img = "harddriveok.png";
|
||||
alt = "ok";
|
||||
break;
|
||||
case "F":
|
||||
img = "harddrivefail.png";
|
||||
alt = "fail";
|
||||
break;
|
||||
case "S":
|
||||
img = "harddrivespare.png";
|
||||
alt = "spare";
|
||||
break;
|
||||
default:
|
||||
alert("--" + diskstatus + "--");
|
||||
img = "error.png";
|
||||
alt = "error";
|
||||
break;
|
||||
}
|
||||
html += "<img class=\"plugin_mdstatus_biun\" src=\"./plugins/mdstatus/gfx/" + img + "\" alt=\"" + alt + "\" />";
|
||||
html += "<small>" + diskname + "</small>";
|
||||
html += "</div>";
|
||||
});
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* fill the plugin block
|
||||
* @param {jQuery} xml plugin-XML
|
||||
*/
|
||||
function mdstatus_populate(xml) {
|
||||
var htmltypes = "";
|
||||
|
||||
$("#Plugin_MDStatusTable").empty();
|
||||
|
||||
$("Plugins Plugin_MDStatus Supported_Types Type", xml).each(function mdstatus_getsupportedtypes(id) {
|
||||
// htmltypes += "<li>" + $(this).attr("Name") + "</li>";
|
||||
htmltypes += "<b>" + $(this).attr("Name") + " </b>";
|
||||
});
|
||||
if (htmltypes.length > 0) {
|
||||
htmltypes = "<ul>" + htmltypes + "</ul>";
|
||||
$("#Plugin_MDStatusTable").append("<tr><td style=\"width:160px;\">" + genlang(2, false, "MDStatus") + "</td><td>" + htmltypes + "</td></tr>");
|
||||
mdstatus_show = true;
|
||||
}
|
||||
|
||||
$("Plugins Plugin_MDStatus Raid", xml).each(function mdstatus_getdevice(id) {
|
||||
var htmldisks = "", htmldisklist = "", topic = "", name = "", buildedaction = "";
|
||||
name = $(this).attr("Device_Name");
|
||||
htmldisklist += mdstatus_diskicon(this);
|
||||
htmldisks += "<table style=\"width:100%;\">";
|
||||
htmldisks += "<tr><td>" + htmldisklist + "</td></tr>";
|
||||
buildedaction = mdstatus_buildaction($(this));
|
||||
if (buildedaction) {
|
||||
htmldisks += "<tr><td>" + buildedaction + "</td></tr>";
|
||||
}
|
||||
htmldisks += "<tr><td>" + mdstatus_buildinfos($(this), id) + "<td></tr>";
|
||||
htmldisks += "</table>";
|
||||
if (id) {
|
||||
topic = "";
|
||||
}
|
||||
else {
|
||||
topic = genlang(3, false, "MDStatus");
|
||||
}
|
||||
$("#Plugin_MDStatusTable").append("<tr><td>" + topic + "</td><td><div class=\"plugin_mdstatus_biun\" style=\"text-align:left;\"><b>" + name + "</b></div>" + htmldisks + "</td></tr>");
|
||||
$("#sPlugin_MDStatus_Info" + id).click(function mdstatus_showinfo() {
|
||||
$("#Plugin_MDStatus_InfoTable" + id).slideDown("slow");
|
||||
$("#sPlugin_MDStatus_Info" + id).hide();
|
||||
$("#hPlugin_MDStatus_Info" + id).show();
|
||||
});
|
||||
$("#hPlugin_MDStatus_Info" + id).click(function mdstatus_hideinfo() {
|
||||
$("#Plugin_MDStatus_InfoTable" + id).slideUp("slow");
|
||||
$("#hPlugin_MDStatus_Info" + id).hide();
|
||||
$("#sPlugin_MDStatus_Info" + id).show();
|
||||
});
|
||||
mdstatus_show = true;
|
||||
});
|
||||
|
||||
if ($("Plugins Plugin_MDStatus Unused_Devices", xml).length > 0) {
|
||||
$("#Plugin_MDStatusTable").append("<tr><td>" + genlang(15, false, "MDStatus") + "</td><td>" + $(this).attr("Devices") + "</td></tr>");
|
||||
mdstatus_show = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load the xml via ajax
|
||||
*/
|
||||
function mdstatus_request() {
|
||||
$.ajax({
|
||||
url: "xml.php?plugin=MDStatus",
|
||||
dataType: "xml",
|
||||
error: function mdstatus_error() {
|
||||
$.jGrowl("Error loading XML document for Plugin MDStatus");
|
||||
},
|
||||
success: function mdstatus_buildblock(xml) {
|
||||
populateErrors(xml);
|
||||
mdstatus_populate(xml);
|
||||
if (mdstatus_show) {
|
||||
plugin_translate("MDStatus");
|
||||
$("#Plugin_MDStatus").show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function mdstatus_buildpage() {
|
||||
var html = "";
|
||||
|
||||
$("#footer").before(buildBlock("MDStatus", 1, true));
|
||||
html += " <table id=\"Plugin_MDStatusTable\" style=\"border-spacing:0;\">\n";
|
||||
html += " </table>\n";
|
||||
$("#Plugin_MDStatus").append(html);
|
||||
|
||||
$("#Plugin_MDStatus").css("width", "915px");
|
||||
|
||||
mdstatus_request();
|
||||
|
||||
$("#Reload_MDStatusTable").click(function mdstatus_reload(id) {
|
||||
mdstatus_request();
|
||||
$("#Reload_MDStatusTable").attr("title",datetime());
|
||||
});
|
||||
});
|
146
root/opt/phpsysinfo/plugins/mdstatus/js/mdstatus_bootstrap.js
Normal file
146
root/opt/phpsysinfo/plugins/mdstatus/js/mdstatus_bootstrap.js
Normal file
@@ -0,0 +1,146 @@
|
||||
function renderPlugin_mdstatus(data) {
|
||||
|
||||
function raid_buildaction(data) {
|
||||
var html = "", name = "", percent = 0;
|
||||
if (data !== undefined) {
|
||||
name = data['Name'];
|
||||
if ((name !== undefined) && (parseInt(name) !== -1)) {
|
||||
percent = Math.round(parseFloat(data['Percent']));
|
||||
html += "<div>Current Action:" + String.fromCharCode(160) + name + "<br/>";
|
||||
html += '<table width=100%><tr><td width=50%><div class="progress">' +
|
||||
'<div class="progress-bar progress-bar-info" style="width: ' + percent + '%;"></div>' +
|
||||
'</div><div class="percent">' + percent + '%</div></td><td></td></tr></table>';
|
||||
html += "Finishing in:" + String.fromCharCode(160) + data['Time_To_Finish'] + String.fromCharCode(160) + data['Time_Unit'];
|
||||
html += "</div>";
|
||||
}
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
function raid_diskicon(data) {
|
||||
var html = "";
|
||||
var img = "", alt = "";
|
||||
|
||||
html += "<div style=\"text-align: center; float: left; margin-bottom: 5px; margin-right: 20px; width: 64px;\">";
|
||||
switch (data["Status"]) {
|
||||
case " ":
|
||||
case "":
|
||||
img = "harddriveok.png";
|
||||
alt = "ok";
|
||||
break;
|
||||
case "F":
|
||||
img = "harddrivefail.png";
|
||||
alt = "fail";
|
||||
break;
|
||||
case "S":
|
||||
img = "harddrivespare.png";
|
||||
alt = "spare";
|
||||
break;
|
||||
case "W":
|
||||
img = "harddrivewarn.png";
|
||||
alt = "warning";
|
||||
break;
|
||||
default:
|
||||
alert("--" + data["Status"] + "--");
|
||||
img = "error.png";
|
||||
alt = "error";
|
||||
break;
|
||||
}
|
||||
html += "<img src=\"./plugins/dmraid/gfx/" + img + "\" alt=\"" + alt + "\" />";
|
||||
html += "<small>" + data["Name"] + "</small>";
|
||||
html += "</div>";
|
||||
return html;
|
||||
}
|
||||
|
||||
if (data['Plugins']['Plugin_MDStatus'] !== undefined) {
|
||||
$('#mdstatus').empty();
|
||||
if (data['Plugins']['Plugin_MDStatus']['Supported_Types'] !== undefined) {
|
||||
var stitems = items(data['Plugins']['Plugin_MDStatus']['Supported_Types']['Type']);
|
||||
if (stitems.length > 0) {
|
||||
var htmltypes = "<tr><th>Supported RAID-Types</th><th>";
|
||||
for (i = 0; i < stitems.length ; i++) {
|
||||
htmltypes += stitems[i]["@attributes"]["Name"] + " ";
|
||||
}
|
||||
htmltypes += "</th><tr>";
|
||||
$('#mdstatus').append(htmltypes);
|
||||
$('#block_mdstatus').show();
|
||||
} else {
|
||||
$('#block_mdstatus').hide();
|
||||
}
|
||||
} else {
|
||||
$('#block_mdstatus').hide();
|
||||
}
|
||||
var mditems = items(data['Plugins']['Plugin_MDStatus']['Raid']);
|
||||
if (mditems.length > 0) {
|
||||
var html = '';
|
||||
for (i = 0; i < mditems.length ; i++) {
|
||||
if (i) {
|
||||
html += "<tr><td></td><td>";
|
||||
} else {
|
||||
html += "<tr><th>RAID-Devices</th><td>";
|
||||
}
|
||||
|
||||
if (mditems[i]['Disks'] !== undefined) {
|
||||
var devchunk = parseInt(mditems[i]["@attributes"]["Chunk_Size"]);
|
||||
var devsuper = parseInt(mditems[i]["@attributes"]["Persistent_Superblock"]);
|
||||
var devalgo = parseInt(mditems[i]["@attributes"]["Algorithm"]);
|
||||
var devactive = parseInt(mditems[i]["@attributes"]["Disks_Active"]);
|
||||
var devregis = parseInt(mditems[i]["@attributes"]["Disks_Registered"]);
|
||||
|
||||
html += "<table style=\"width:100%;\">";
|
||||
html += "<tr><td>";
|
||||
|
||||
var diskitems = items(mditems[i]['Disks']['Disk']);
|
||||
for (j = 0; j < diskitems.length ; j++) {
|
||||
html += raid_diskicon(diskitems[j]["@attributes"]);
|
||||
}
|
||||
|
||||
html += "</td></tr><tr><td>";
|
||||
if (mditems[i]['Action'] !== undefined) {
|
||||
var buildedaction = raid_buildaction(mditems[i]['Action']['@attributes']);
|
||||
if (buildedaction) {
|
||||
html += "<tr><td>" + buildedaction + "</td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
html += "<table id=\"mdstatus-" + i + "\"class=\"table table-hover table-condensed\">";
|
||||
html += "<tr class=\"treegrid-mdstatus-" + i + "\"><td><b>" + mditems[i]["@attributes"]["Device_Name"] + "</b></td><td></td></tr>";
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Status</th><td>" + mditems[i]["@attributes"]["Disk_Status"] + "</td></tr>";
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>RAID-Level</th><td>" + mditems[i]["@attributes"]["Level"] + "</td></tr>";
|
||||
if (devchunk !== -1) {
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Chunk Size</th><td>" + devchunk + "K</td></tr>";
|
||||
}
|
||||
if (devalgo !== -1) {
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Algorithm</th><td>" + devalgo + "</td></tr>";
|
||||
}
|
||||
if (devsuper !== -1) {
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Persistent Superblock</th><td>available</td></tr>";
|
||||
} else {
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Persistent Superblock</th><td>not available</td></tr>";
|
||||
}
|
||||
if (devactive !== -1 && devregis !== -1) {
|
||||
html += "<tr class=\"treegrid-parent-mdstatus-" + i + "\"><th>Registered/" + String.fromCharCode(8203) + "Active Disks</th><td>" + devregis + "/" + String.fromCharCode(8203) + devactive + "</td></tr>";
|
||||
}
|
||||
html += "</table>";
|
||||
html += "</td></tr>";
|
||||
html += "</table>";
|
||||
}
|
||||
|
||||
html +="</td></tr>";
|
||||
}
|
||||
$('#mdstatus').append(html);
|
||||
|
||||
for (i = 0; i < mditems.length ; i++) {
|
||||
if (mditems[i]['Disks'] !== undefined) {
|
||||
$('#mdstatus-'+i).treegrid({
|
||||
initialState: 'collapsed',
|
||||
expanderExpandedClass: 'normalicon normalicon-down',
|
||||
expanderCollapsedClass: 'normalicon normalicon-right'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$('#block_mdstatus').hide();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user