Commit 37b3121b authored by Tristan A Spakes's avatar Tristan A Spakes

ver. 1.2.4 Remove user now allows more than just 3 character IDs to be...

ver. 1.2.4 Remove user now allows more than just 3 character IDs to be removed, remove user textbox changed to a dropdown with current users detected by checking /home
parent abcbda80
......@@ -6,7 +6,7 @@ if [[ ${CI_COMMIT_REF_NAME} == 'master' ]]; then
else
BRANCH="-${CI_COMMIT_REF_NAME}"
fi
VERSION_NUMBER='1.2.3'
VERSION_NUMBER='1.2.4'
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -ivh epel-release-latest-7.noarch.rpm
sudo yum -y install nodejs npm ruby-devel gcc make rpm-build rubygems
......
......@@ -310,7 +310,7 @@ function addWin(file, title, width, height) {
})
addWindow.setMenu(null)
//addWindow.openDevTools()
addWindow.openDevTools()
}
}
......
......@@ -51,10 +51,9 @@ input[type=submit] {
margin-left: 8px;
margin-right: 8px;
}
#removeUserTextbox {
width: 16vw;
height: 6.4vh;
}
#removeUserSelect {
margin-bottom: 22px;
}
#removeUserCheckbox1 {
margin-top: 3px;
}
......
......@@ -7,13 +7,14 @@
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<script src="./removeUser.js"></script>
</head>
<body>
<body onload="removeUserLoad()">
<form class="removeUserPage" onsubmit="return false">
<div class="removeUserLine">
<div id="removeUserText">
Enter a UID:
Select a user:
</div>
<input type="text" id="removeUserTextbox" maxlength="3">
<select id="removeUserSelect">
</select>
</div>
<div class="removeUserLine">
<div id="removeUserText">
......
......@@ -3,23 +3,24 @@ const ipcRenderer = require('electron').ipcRenderer
//Open a new terminal and start the process for removing a user
function removeUser() {
var uid = document.getElementById("removeUserTextbox").value //Retrieve UID
var dropdown = document.getElementById('removeUserSelect') //Retrieve dropdown
var user = dropdown.options[dropdown.selectedIndex].text //Retrieve user to be removed
var rhome = document.getElementById("removeUserCheckbox1").checked //Retrieve if user wants to remove the home directory
var confirm = document.getElementById("removeUserCheckbox2").checked //Retrieve if user is certain they wish to remove the user
ipcRenderer.send('log', 'ORNL Toolbox: Submitted Remove User request', 'info')
if(uid.length != 3 || /^[a-z0-9]+$/.test(uid) == false) { //Test for valid UID
ipcRenderer.send('log', `ORNL Toolbox: ${uid} is an invalid UID for Remove User - request aborted`, 'err')
alert('Please enter a valid 3 character UID')
if(user == "User") { //User didn't choose from the dropdown menu
ipcRenderer.send('log', 'ORNL Toolbox: No user selected - request aborted', 'info')
alert('No user selected')
return
}
if(rhome == true) { //Adding the remove home folder option if the user wanted
ipcRenderer.send('log', `ORNL Toolbox: Home folder of ${uid} set to be removed`, 'info')
ipcRenderer.send('log', `ORNL Toolbox: Home folder of ${user} set to be removed`, 'info')
rhome = "-r"
} else {
ipcRenderer.send('log', `ORNL Toolbox: Home folder of ${uid} set to be kept`, 'info')
ipcRenderer.send('log', `ORNL Toolbox: Home folder of ${user} set to be kept`, 'info')
rhome = ""
}
......@@ -30,12 +31,12 @@ function removeUser() {
}
try { //Launching command to remove the specified user
execSync(`pkexec /usr/sbin/userdel ${rhome} ${uid}`, (error, stdout, stderr) => {})
execSync(`pkexec /usr/sbin/userdel ${rhome} ${user}`, (error, stdout, stderr) => {})
} catch(error) {
error = error.toString()
if(error.includes('does not exist')) {
ipcRenderer.send('log', `ORNL Toolbox: Remove User request failed - ${uid} does not exist as a user`, 'err')
alert('User does not exist')
ipcRenderer.send('log', `ORNL Toolbox: Remove User request failed - ${user} does not exist as a user`, 'err')
alert('User does not exist - home folder may exist')
return
} else if(error.includes('Request dismissed')) {
ipcRenderer.send('log', 'ORNL Toolbox: Remove User request canceled', 'info')
......@@ -46,7 +47,28 @@ function removeUser() {
return
}
ipcRenderer.send('log', `ORNL Toolbox: ${uid} removed as a user`, 'info')
ipcRenderer.send('log', `ORNL Toolbox: ${user} removed as a user`, 'info')
alert('User removed')
ipcRenderer.send('close minor window')
}
function removeUserLoad() { //Loading the users
if(!execSync) var execSync = require('child_process').execSync
//Adding the options of the dropdown menu
var optionValue = 1
var dropdownString = '<option value="0" disabled selected>User</option>'
var users = execSync('ls /home', () => {})
users = users.toString()
userArray = users.split('\n')
for(i = 0; i < userArray.length; i++) {
if(userArray[i].trim() == "") continue
dropdownString = dropdownString + '\n' + `<option value="${optionValue}">${userArray[i]}</option>`
optionValue++
}
document.getElementById('removeUserSelect').innerHTML = dropdownString;
ipcRenderer.send('log', `ORNL Toolbox: List of users loaded`, 'info')
//Setting removal of home folder as the default
document.getElementById('removeUserCheckbox1').checked = true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment