JavascriptJavascript

  Main Menu

Home: Development: Javascript: Index
Unix style permissions generator:
This is a form to generate the values used for chmod in a unix type os (like Linux, FreeBSD, Solaris), for setting permissions on files, usually files in the cgi-bin directory.
This took me like forever to get a real handle on, so hopefully this will help someone else see it more quickly.
Chmod usage is like:
username@hostname$ >chmod 755 /home/httpd/cgi-bin/somefilename.cgi
Where somefilename.cgi is the file you want to adjust permissions on. It's usually most effective to set permissions as high as possible, then adjust them downward (for more security) as you test/debug your installation.


Shockingly this piece of javascript worked right away in IE, but broke in netscape. The last checkbox in the form didnt't think it was a number. Well...it didn't think it was a number for the longest time, then I changed the for loop to using a hard count of 9 instead of form.elemtents[i]. Whatever. Computers are dumb.

I'd like to have found a way to loop through the subtotals more elegantly-- meaning less typing, but wtf, it works.

  Owner Group All
Read (400) (40) (4)
Write (200) (20) (2)
Execute (100) (10) (1)
Subtotal


Here is the javascript code:

<script language="JavaScript">
<!-- hide from old browser//
function addUp() {
	var form = document.form
	var perms = 0
	var oPerms = 0
	var gPerms = 0
	var aPerms = 0
	
	for (var i = 0; i < 9; i++) {
		if (form.elements[i].checked)
		perms += parseInt(form.elements[i].value)
		}
	}
//////////////////////////////////

	if (form.oRead.checked){
		oPerms = 400
	}

	if (form.oWrite.checked){
		oPerms += 200
	}
	
	if (form.oExec.checked){
		oPerms += 100
	}
////////////////////////////////// RWX
	
	if (form.gRead.checked){
		gPerms = 40
	}

	if (form.gWrite.checked){
		gPerms += 20
	}
	
	if (form.gExec.checked){
		gPerms += 10
	}
//////////////////////////////////	OGA

	if (form.aRead.checked){
		aPerms = 4
	}

	if (form.aWrite.checked){
		aPerms += 2
	}
	
	if (form.aExec.checked){
		aPerms += 1
	}
	
	form.result.value = perms
	form.oResult.value = oPerms
	form.gResult.value = gPerms
	form.aResult.value = aPerms

}

//stop hiding-->
</script>