1
|
|
2
|
domReady(function() {
|
3
|
|
4
|
/*
|
5
|
Jeroen's Chmod Calculator- By Jeroen Vermeulen of Alphamega Hosting <jeroen@alphamegahosting.com>
|
6
|
Visit http://www.javascriptkit.com for this script and more
|
7
|
This notice must stay intact
|
8
|
modified by Dietmar W?llbrink for WebsiteBaker CMS
|
9
|
*/
|
10
|
|
11
|
function octalFilechange( ) {
|
12
|
console.error(document.Settings.chmodFile);
|
13
|
if (document.Settings.chmodFile==='undefined'){return false;}
|
14
|
var val = document.Settings.chmodFile.value;
|
15
|
var userbin = parseInt(val.charAt(1)).toString(2);
|
16
|
while (userbin.length<3) { userbin="0"+userbin; };
|
17
|
//console.info( userbin );
|
18
|
var groupbin = parseInt(val.charAt(2)).toString(2);
|
19
|
while (groupbin.length<3) { groupbin="0"+groupbin; };
|
20
|
//console.info( groupbin );
|
21
|
var otherbin = parseInt(val.charAt(3)).toString(2);
|
22
|
while (otherbin.length<3) { otherbin="0"+otherbin; };
|
23
|
|
24
|
document.Settings.file_u_r.checked = parseInt(userbin.charAt(0));
|
25
|
document.Settings.file_u_w.checked = parseInt(userbin.charAt(1));
|
26
|
document.Settings.file_u_e.checked = parseInt(userbin.charAt(2));
|
27
|
|
28
|
document.Settings.file_g_r.checked = parseInt(groupbin.charAt(0));
|
29
|
document.Settings.file_g_w.checked = parseInt(groupbin.charAt(1));
|
30
|
document.Settings.file_g_e.checked = parseInt(groupbin.charAt(2));
|
31
|
|
32
|
document.Settings.file_o_r.checked = parseInt(otherbin.charAt(0));
|
33
|
document.Settings.file_o_w.checked = parseInt(otherbin.charAt(1));
|
34
|
document.Settings.file_o_e.checked = parseInt(otherbin.charAt(2));
|
35
|
console.info('file : ' + userbin+' '+groupbin+' '+otherbin );
|
36
|
calcFilechmod(1);
|
37
|
}
|
38
|
|
39
|
function octalDirchange( ) {
|
40
|
if (document.Settings.chmodDir==='undefined'){return false;}
|
41
|
var val = document.Settings.chmodDir.value;
|
42
|
|
43
|
var userbin = parseInt(val.charAt(1)).toString(2);
|
44
|
while (userbin.length<3) { userbin="0"+userbin; };
|
45
|
//console.info( userbin );
|
46
|
var groupbin = parseInt(val.charAt(2)).toString(2);
|
47
|
while (groupbin.length<3) { groupbin="0"+groupbin; };
|
48
|
//console.info( groupbin );
|
49
|
var otherbin = parseInt(val.charAt(3)).toString(2);
|
50
|
while (otherbin.length<3) { otherbin="0"+otherbin; };
|
51
|
|
52
|
document.Settings.dir_u_r.checked = parseInt(userbin.charAt(0));
|
53
|
document.Settings.dir_u_w.checked = parseInt(userbin.charAt(1));
|
54
|
document.Settings.dir_u_e.checked = parseInt(userbin.charAt(2));
|
55
|
|
56
|
document.Settings.dir_g_r.checked = parseInt(groupbin.charAt(0));
|
57
|
document.Settings.dir_g_w.checked = parseInt(groupbin.charAt(1));
|
58
|
document.Settings.dir_g_e.checked = parseInt(groupbin.charAt(2));
|
59
|
|
60
|
document.Settings.dir_o_r.checked = parseInt(otherbin.charAt(0));
|
61
|
document.Settings.dir_o_w.checked = parseInt(otherbin.charAt(1));
|
62
|
document.Settings.dir_o_e.checked = parseInt(otherbin.charAt(2));
|
63
|
console.info('dir : ' + userbin+' '+groupbin+' '+otherbin );
|
64
|
calcDirchmod(1);
|
65
|
}
|
66
|
|
67
|
function calcFilechmod(noTotals) {
|
68
|
var users = new Array("file_u_", "file_g_", "file_o_");
|
69
|
calc_chmod( users, noTotals, 'chmodFile' );
|
70
|
}
|
71
|
function calcDirchmod(noTotals) {
|
72
|
var users = new Array("dir_u_", "dir_g_", "dir_o_");
|
73
|
calc_chmod( users, noTotals, 'chmodDir' );
|
74
|
}
|
75
|
|
76
|
function calc_chmod( users, noTotals, Mode ) {
|
77
|
|
78
|
var totals = new Array("","","");
|
79
|
var syms = new Array("","","");
|
80
|
|
81
|
for (var i=0; i<users.length; i++) {
|
82
|
var user=users[i];
|
83
|
var field1 = user + "r";
|
84
|
var field2 = user + "w";
|
85
|
var field4 = user + "e";
|
86
|
//var total = "t_" + user;
|
87
|
var symbolic = "sym_" + user;
|
88
|
var number = 0;
|
89
|
var sym_string = "";
|
90
|
|
91
|
if (document.Settings[field1].checked == true) { number += 4; }
|
92
|
if (document.Settings[field2].checked == true) { number += 2; }
|
93
|
if (document.Settings[field4].checked == true) { number += 1; }
|
94
|
|
95
|
if (document.Settings[field1].checked == true) {
|
96
|
sym_string += "r";
|
97
|
} else {
|
98
|
sym_string += "-";
|
99
|
}
|
100
|
if (document.Settings[field2].checked == true) {
|
101
|
sym_string += "w";
|
102
|
} else {
|
103
|
sym_string += "-";
|
104
|
}
|
105
|
if (document.Settings[field4].checked == true) {
|
106
|
sym_string += "x";
|
107
|
} else {
|
108
|
sym_string += "-";
|
109
|
}
|
110
|
//if (number == 0) { number = ""; }
|
111
|
//document.Settings[total].value =
|
112
|
totals[i] = totals[i]+number;
|
113
|
syms[i] = syms[i]+sym_string;
|
114
|
};
|
115
|
if ( Mode === 'chmodDir' ) {
|
116
|
if (!noTotals) {document.Settings.chmodDir.value = totals[0] + totals[1] + totals[2];}
|
117
|
document.Settings.sym_chmodDir.value = "" + syms[0] + syms[1] + syms[2];
|
118
|
console.info(totals[0] + totals[1] + totals[2]);
|
119
|
console.info("" + syms[0] + syms[1] + syms[2]);
|
120
|
}
|
121
|
if ( Mode === 'chmodFile' ) {
|
122
|
if (!noTotals) {document.Settings.chmodFile.value = totals[0] + totals[1] + totals[2];}
|
123
|
document.Settings.sym_chmodFile.value = "" + syms[0] + syms[1] + syms[2];
|
124
|
console.info("" + syms[0] + syms[1] + syms[2]);
|
125
|
}
|
126
|
}
|
127
|
|
128
|
function addEvent ( elm ) {
|
129
|
if ( elm ){
|
130
|
//console.info( elm );
|
131
|
elm.addEventListener("click", function() {
|
132
|
calcFilechmod();
|
133
|
calcDirchmod();
|
134
|
}, false);
|
135
|
}
|
136
|
}
|
137
|
|
138
|
window.onload = function () {
|
139
|
var types = new Array( "file_u_", "file_g_", "file_o_", "dir_u_", "dir_g_", "dir_o_" ),
|
140
|
action = new Array( "r", "w", "e" );
|
141
|
for (i=0; i < types.length ; i++ ) {
|
142
|
addEvent( document.getElementById( types[i]+'r' ) );
|
143
|
addEvent( document.getElementById( types[i]+'w' ) );
|
144
|
addEvent( document.getElementById( types[i]+'e' ) );
|
145
|
}
|
146
|
octalFilechange();
|
147
|
octalDirchange();
|
148
|
}
|
149
|
|
150
|
|
151
|
});
|