1 ////////////////////////////////////////////////////////////////////////////////
3 // File: $RCSfile: clearadm.js,v $
4 // Revision: $Revision: 1.8 $
5 // Description: Javascript routines for Clearadm
6 // Author: Andrew@ClearSCM.com
7 // Created: Wed Dec 29 12:36:47 EST 2010
8 // Modified: $Date: 2011/01/21 01:00:09 $
9 // Language: JavaScript
11 // (c) Copyright 2010, ClearSCM, Inc., all rights reserved.
13 ////////////////////////////////////////////////////////////////////////////////
14 function getXMLHTTP () {
16 return new XMLHttpRequest ();
19 return new ActiveXObject ('Microsoft.XMLHTTP');
22 return new ActiveXObject ('Msxml2.XMLHTTP');
30 function updateTimestamp (system, elementID, filesystem) {
31 var request = getXMLHTTP ();
32 var script = 'getTimestamp.cgi?system=' + system + '&elementID=' + elementID;
34 var scaling = document.getElementById ('scalingFactor').value;
37 script += '&scaling=' + scaling;
41 script += '&filesystem=' + filesystem;
45 request.onreadystatechange = function () {
46 if (request.readyState == 4) {
47 if (request.status == 200) {
48 document.getElementById (elementID).innerHTML
49 = request.responseText;
54 request.open ('get', script, true);
57 alert ('Unable to create XMLHTTP Request object');
61 function updateSystem (system) {
62 updateTimestamp (system, 'startTimestamp');
63 updateTimestamp (system, 'endTimestamp');
66 function updateSystemLink (system) {
67 document.getElementById ('systemLink').innerHTML
68 = '<a href="systemdetails.cgi?system=' + system + '">System</a>';
70 updateTimestamp (system, 'startTimestamp');
71 updateTimestamp (system, 'endTimestamp');
74 function updateFilesystems (system) {
75 var request = getXMLHTTP ();
78 request.onreadystatechange = function () {
79 if (request.readyState == 4) {
80 if (request.status == 200) {
81 document.getElementById ('filesystems').innerHTML
82 = request.responseText;
87 request.open ('GET', 'getFilesystems.cgi?system=' + system, true);
90 alert ('Unable to create XMLHTTP Request object');
92 } // updateFilesystems
94 function updateFilesystem (system, filesystem) {
95 updateTimestamp (system, 'startTimestamp', filesystem);
96 updateTimestamp (system, 'endTimestamp', filesystem);
99 function trimSpaces (str) {
100 return str.replace (/^\s+|\s+$/g, '');
103 function validEmailAddress (email) {
104 var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
106 return emailPattern.test (email);
107 } // validEmailAddress
109 function validateAlert (alertrec) {
111 if (name.value == '') {
112 alert ("You must specify the alert's name");
118 if (!validEmailAddress (alertrec.who.value)) {
119 alert ('That email address is invalid!\n'
120 + 'Must be <username>@<domainname>\n'
121 + 'For example: Andrew@ClearSCM.com');
128 function validateNotification (notification) {
129 with (notification) {
130 if (name.value == '') {
131 alert ("You must specify the notification's name");
136 if (cond.value == '') {
137 alert ('You must specify a condition');
142 } // validateNotification
144 function validateSchedule (schedule) {
146 if (name.value == '') {
147 alert ("You must specify the schedule's name");
152 if (isNaN (nbr.value)) {
153 alert ('Frequency is not a number');
156 } else if (nbr.value < 1 || nbr.value > 999) {
157 alert ('Frequency must be a positive number between 1-999');
162 } // validateSchedule
164 function validateTask (task) {
166 if (name.value == '') {
167 alert ("You must specify the task's name");
174 function validateSystem (system) {
176 name.value = trimSpaces (name.value);
178 if (name.value == '') {
179 alert ("You must specify the system's name");
184 admin.value = trimSpaces (admin.value);
186 if (admin.value == '') {
187 alert ("You must specify the admin's name");
192 if (isNaN (port.value)) {
193 alert ('Port is not a number');
196 } else if (port.value < 1 || port.value > 65535) {
197 alert ('Port must be a positive number between 1-65535');
202 if (isNaN (loadavgThreshold.value)) {
203 alert ('Loadavg Threshold is not a number');
204 loadavgThreshold.focus;
206 } else if (loadavgThreshold.value < 0 || loadavgThreshold.value > 99.99) {
207 alert ('Loadavg Threshold must be a positive number between 0 - 99.99');
208 loadavgThreshold.focus;
212 email.value = trimSpaces (email.value);
214 if (email.value == '') {
215 alert ("You must specify the admin's email");
219 if (!validEmailAddress (email.value)) {
220 alert ('That email address is invalid!\n'
221 + 'Must be <username>@<domainname>\n'
222 + 'For example: Andrew@ClearSCM.com');
229 function AreYouSure (message) {
230 return window.confirm (message);