| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# User Management tool |
| 4 |
# |
| 5 |
|
| 6 |
KISSHOME=/usr/share/kiss |
| 7 |
|
| 8 |
if [ ! -r ${KISSHOME}/kiss.conf ]; then |
| 9 |
echo "$0: error: unable to continue, kiss.conf not found." |
| 10 |
exit 1 |
| 11 |
else |
| 12 |
source ${KISSHOME}/kiss.conf |
| 13 |
fi |
| 14 |
|
| 15 |
if [ ! -f ${KISSHOME}/kisslib ]; then |
| 16 |
echo "$0: error: unable to continue, kisslib not found." |
| 17 |
exit 1 |
| 18 |
else |
| 19 |
source ${KISSHOME}/kisslib |
| 20 |
fi |
| 21 |
|
| 22 |
adduser() |
| 23 |
{ |
| 24 |
|
| 25 |
local user name qshell shell defgroup defgroups passwd1 passwd2 |
| 26 |
defgroup=${DEFGROUP} |
| 27 |
defgroups=${DEFGROUPS} |
| 28 |
user=""; name=""; shell=""; passwd1="bad"; passwd2="dab"; |
| 29 |
|
| 30 |
while [ "x${user}" == "x" ]; do |
| 31 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 32 |
--caption "KISS: User Management" \ |
| 33 |
--title "KISS: User Management" \ |
| 34 |
--inputbox "Enter the user name (do not use special characters or space):" 1>${Q} 2>/dev/null |
| 35 |
user=$(cat ${Q}) |
| 36 |
rm -f ${Q} |
| 37 |
if ! valid_user ${user}; then |
| 38 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 39 |
--caption "KISS: User Management" \ |
| 40 |
--title "KISS: User Management" \ |
| 41 |
--error "Invalid username. Please don't use special characters or space character when typing the username." |
| 42 |
user="" |
| 43 |
fi |
| 44 |
done |
| 45 |
|
| 46 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 47 |
--caption "KISS: User Management" \ |
| 48 |
--title "KISS: User Management" \ |
| 49 |
--inputbox "Enter the real name (geos) for the new user:" 1>${Q} 2>/dev/null |
| 50 |
name=$(cat ${Q}) |
| 51 |
rm -f ${Q} |
| 52 |
if [ "x${name}" == "x" ]; then |
| 53 |
name=${user} |
| 54 |
fi |
| 55 |
|
| 56 |
qshell=$(cat /etc/shells|grep -v ^#|tr '\n' ' ') |
| 57 |
while [ "x${shell}" == "x" ]; do |
| 58 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 59 |
--caption "KISS: User Management" \ |
| 60 |
--title "KISS: User Management" \ |
| 61 |
--combobox "Select a login shell from the list for the new user:" ${qshell} 1>${Q} 2>/dev/null |
| 62 |
shell=$(cat ${Q}) |
| 63 |
rm -f ${Q} |
| 64 |
done |
| 65 |
|
| 66 |
${ADDUSER} -c "${name}" -m -s ${shell} -g ${defgroup} -G ${defgroups} ${user} >/dev/null 2>&1; ERR=$? |
| 67 |
if [ ${ERR} -eq 0 ]; then |
| 68 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 69 |
--caption "KISS: User Management" \ |
| 70 |
--title "KISS: User Management" \ |
| 71 |
--msgbox "User ${user} has been created successfully." |
| 72 |
while [ ! "${passwd1}" == "${passwd2}" ]; do |
| 73 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 74 |
--caption "KISS: User Management" \ |
| 75 |
--title "KISS: User Management" \ |
| 76 |
--password "Enter a password for the new user ${user}:" 1>${Q} 2>/dev/null |
| 77 |
passwd1=$(cat ${Q}) |
| 78 |
rm -f ${Q} |
| 79 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 80 |
--caption "KISS: User Management" \ |
| 81 |
--title "KISS: User Management" \ |
| 82 |
--password "Re-enter the password for the new user ${user}:" 1>${Q} 2>/dev/null |
| 83 |
passwd2=$(cat ${Q}) |
| 84 |
rm -f ${Q} |
| 85 |
|
| 86 |
if [ "x${passwd1}" == "x" ]; then |
| 87 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 88 |
--caption "KISS: User Management" \ |
| 89 |
--title "KISS: User Management" \ |
| 90 |
--sorry "Empty passwords are not allowed. Please re-type the password with minimum 6 characters." |
| 91 |
passwd1="bad"; passwd2="dab" |
| 92 |
elif [ ${#passwd1} -lt 6 ]; then |
| 93 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 94 |
--caption "KISS: User Management" \ |
| 95 |
--title "KISS: User Management" \ |
| 96 |
--sorry "Password too short. Please use a password with minimum 6 characters." |
| 97 |
passwd1="bad"; passwd2="dab" |
| 98 |
elif [ ! "${passwd1}" == "${passwd2}" ]; then |
| 99 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 100 |
--caption "KISS: User Management" \ |
| 101 |
--title "KISS: User Management" \ |
| 102 |
--sorry "Passwords don't match. Please re-type your password correctly." |
| 103 |
passwd1="bad"; passwd2="dab" |
| 104 |
fi |
| 105 |
done |
| 106 |
|
| 107 |
echo "${user}:${passwd1}"| ${CHPASSWD} >/dev/null 2>&1; ERR=$? |
| 108 |
if [ ${ERR} -eq 0 ]; then |
| 109 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 110 |
--caption "KISS: User Management" \ |
| 111 |
--title "KISS: User Management" \ |
| 112 |
--msgbox "Password for the new user ${user} has been set successfully.\nDon't forget the password for this new user,\notherwise you wont be able to login with this user." |
| 113 |
else |
| 114 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 115 |
--caption "KISS: User Management" \ |
| 116 |
--title "KISS: User Management" \ |
| 117 |
--error "Unable to change password for the new user ${user}.\nMake sure you have rights to change this user's password." |
| 118 |
fi |
| 119 |
|
| 120 |
else |
| 121 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 122 |
--caption "KISS: User Management" \ |
| 123 |
--title "KISS: User Management" \ |
| 124 |
--error "Something bad happened while trying to create user ${user}.\nMake sure you have rights to create this user." |
| 125 |
fi |
| 126 |
} |
| 127 |
|
| 128 |
deluser() |
| 129 |
{ |
| 130 |
local listuser delhome user opt |
| 131 |
user=""; opt=""; |
| 132 |
delhome="YES" |
| 133 |
listuser=$(cat /etc/passwd|awk -F":" '$4 == 100 {print $1}'|grep -v games|tr '\n' ' ') |
| 134 |
listuser="${listuser} root" |
| 135 |
|
| 136 |
if [ ! "x${listuser}" == "x" ]; then |
| 137 |
while [ "x${user}" == "x" ]; do |
| 138 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 139 |
--caption "KISS: User Management" \ |
| 140 |
--title "KISS: User Management" \ |
| 141 |
--combobox "Select a user from the list to delete:" ${listuser} 1>${Q} 2>/dev/null |
| 142 |
user=$(cat ${Q}) |
| 143 |
rm -f ${Q} |
| 144 |
done |
| 145 |
rm -f ${Q} |
| 146 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 147 |
--caption "KISS: User Management" \ |
| 148 |
--title "KISS: User Management" \ |
| 149 |
--warningyesno "Would you like to remove also the user data (home directory, mail spool, etc.) ?" >/dev/null 2>&1; echo $? > ${Q} |
| 150 |
|
| 151 |
ERR=$(cat ${Q}) |
| 152 |
if [ ${ERR} -eq 1 ]; then |
| 153 |
delhome="NO" |
| 154 |
else |
| 155 |
delhome="YES" |
| 156 |
fi |
| 157 |
|
| 158 |
if [ "${delhome}" == "YES" ]; then |
| 159 |
opt="${opt} -r" |
| 160 |
else |
| 161 |
opt="${opt}" |
| 162 |
fi |
| 163 |
|
| 164 |
${DELUSER} ${opt} ${user} >/dev/null 2>&1; ERR=$? |
| 165 |
if [ ${ERR} -eq 0 ]; then |
| 166 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 167 |
--caption "KISS: User Management" \ |
| 168 |
--title "KISS: User Management" \ |
| 169 |
--msgbox "User ${user} deleted successfully." |
| 170 |
else |
| 171 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 172 |
--caption "KISS: User Management" \ |
| 173 |
--title "KISS: User Management" \ |
| 174 |
--error "Something bad happened while trying to delete user ${user}.\nMake sure you have rights to delete this user." |
| 175 |
fi |
| 176 |
else |
| 177 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 178 |
--caption "KISS: User Management" \ |
| 179 |
--title "KISS: User Management" \ |
| 180 |
--sorry "No users found.\nThis means that you might need to create first a user, then try to delete it." |
| 181 |
fi |
| 182 |
} |
| 183 |
|
| 184 |
chpasswd() |
| 185 |
{ |
| 186 |
local passwd1 passwd2 listuser user |
| 187 |
passwd1="bad"; passwd2="dab"; user=""; |
| 188 |
listuser=$(cat /etc/passwd|awk -F":" '$4 == 100 {print $1}'|grep -v games|tr '\n' ' ') |
| 189 |
listuser="${listuser} root" |
| 190 |
|
| 191 |
if [ ! "x${listuser}" == "x" ]; then |
| 192 |
while [ "x${user}" == "x" ]; do |
| 193 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 194 |
--caption "KISS: User Management" \ |
| 195 |
--title "KISS: User Management" \ |
| 196 |
--combobox "Select the user for which you want to change the password:" ${listuser} 1>${Q} 2>/dev/null |
| 197 |
user=$(cat ${Q}) |
| 198 |
rm -f ${Q} |
| 199 |
done |
| 200 |
while [ ! "${passwd1}" == "${passwd2}" ]; do |
| 201 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 202 |
--caption "KISS: User Management" \ |
| 203 |
--title "KISS: User Management" \ |
| 204 |
--password "Enter the new password for user ${user}:" 1>${Q} 2>/dev/null |
| 205 |
passwd1=$(cat ${Q}) |
| 206 |
rm -f ${Q} |
| 207 |
|
| 208 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 209 |
--caption "KISS: User Management" \ |
| 210 |
--title "KISS: User Management" \ |
| 211 |
--password "Re-enter the new password for user ${user}:" 1>${Q} 2>/dev/null |
| 212 |
passwd2=$(cat ${Q}) |
| 213 |
rm -f ${Q} |
| 214 |
|
| 215 |
if [ "x${passwd1}" == "x" ]; then |
| 216 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 217 |
--caption "KISS: User Management" \ |
| 218 |
--title "KISS: User Management" \ |
| 219 |
--sorry "Empty passwords are not allowed. Please re-type the password with minimum 6 characters." |
| 220 |
passwd1="bad"; passwd2="dab" |
| 221 |
elif [ ${#passwd1} -lt 6 ]; then |
| 222 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 223 |
--caption "KISS: User Management" \ |
| 224 |
--title "KISS: User Management" \ |
| 225 |
--sorry "Password too short. Please use a password with minimum 6 characters." |
| 226 |
passwd1="bad"; passwd2="dab" |
| 227 |
elif [ ! "${passwd1}" == "${passwd2}" ]; then |
| 228 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 229 |
--caption "KISS: User Management" \ |
| 230 |
--title "KISS: User Management" \ |
| 231 |
--sorry "Passwords don't match. Please re-type your password correctly." |
| 232 |
passwd1="bad"; passwd2="dab" |
| 233 |
fi |
| 234 |
done |
| 235 |
|
| 236 |
echo "${user}:${passwd1}"| ${CHPASSWD} >/dev/null 2>&1; ERR=$? |
| 237 |
if [ ${ERR} -eq 0 ]; then |
| 238 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 239 |
--caption "KISS: User Management" \ |
| 240 |
--title "KISS: User Management" \ |
| 241 |
--msgbox "Password for user ${user} has been changed successfully.\nDon't forget to use the new password when logging in with this user." |
| 242 |
else |
| 243 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 244 |
--caption "KISS: User Management" \ |
| 245 |
--title "KISS: User Management" \ |
| 246 |
--error "Unable to change password for user ${user}.\nMake sure you have rights to change this user's password." |
| 247 |
fi |
| 248 |
|
| 249 |
else |
| 250 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 251 |
--caption "KISS: User Management" \ |
| 252 |
--title "KISS: User Management" \ |
| 253 |
--sorry "No users found.\nThis means that you might need to create first a user, then try to change it's password." |
| 254 |
fi |
| 255 |
} |
| 256 |
chname() |
| 257 |
{ |
| 258 |
local listuser newname user oldname |
| 259 |
user=""; newname=""; oldname=""; |
| 260 |
listuser=$(cat /etc/passwd|awk -F":" '$4 == 100 {print $1}'|grep -v games|tr '\n' ' ') |
| 261 |
listuser="${listuser} root" |
| 262 |
|
| 263 |
if [ ! "x${listuser}" == "x" ]; then |
| 264 |
while [ "x${user}" == "x" ]; do |
| 265 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 266 |
--caption "KISS: User Management" \ |
| 267 |
--title "KISS: User Management" \ |
| 268 |
--combobox "Select the user for which you want to change the geos information:" ${listuser} 1>${Q} 2>/dev/null |
| 269 |
user=$(cat ${Q}) |
| 270 |
rm -f ${Q} |
| 271 |
done |
| 272 |
|
| 273 |
oldname=$(cat /etc/passwd|grep -w ${user}|awk -F":" '{print $5}') |
| 274 |
|
| 275 |
while [ "x${newname}" == "x" ]; do |
| 276 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 277 |
--caption "KISS: User Management" \ |
| 278 |
--title "KISS: User Management" \ |
| 279 |
--inputbox "Enter the new geos information (real name) for the user ${user}:" "${oldname}" 1>${Q} 2>/dev/null |
| 280 |
newname=$(cat ${Q}) |
| 281 |
rm -f ${Q} |
| 282 |
done |
| 283 |
|
| 284 |
${MODUSER} -c "${newname}" ${user} >/dev/null 2>&1; ERR=$? |
| 285 |
if [ ${ERR} -eq 0 ]; then |
| 286 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 287 |
--caption "KISS: User Management" \ |
| 288 |
--title "KISS: User Management" \ |
| 289 |
--msgbox "Geos information (real name) for user ${user} changed successfully." |
| 290 |
else |
| 291 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 292 |
--caption "KISS: User Management" \ |
| 293 |
--title "KISS: User Management" \ |
| 294 |
--error "Something bad happened while trying to change geos information for user ${user}.\nMake sure you have rights to delete this user." |
| 295 |
fi |
| 296 |
|
| 297 |
else |
| 298 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 299 |
--caption "KISS: User Management" \ |
| 300 |
--title "KISS: User Management" \ |
| 301 |
--sorry "No users found.\nThis means that you might need to create first a user, then try to change its real name." |
| 302 |
fi |
| 303 |
} |
| 304 |
|
| 305 |
chshell() |
| 306 |
{ |
| 307 |
local listuser newshell user oldshell |
| 308 |
user=""; newshell=""; oldshell=""; |
| 309 |
listuser=$(cat /etc/passwd|awk -F":" '$4 == 100 {print $1}'|grep -v games|tr '\n' ' ') |
| 310 |
listuser="${listuser} root" |
| 311 |
|
| 312 |
if [ ! "x${listuser}" == "x" ]; then |
| 313 |
while [ "x${user}" == "x" ]; do |
| 314 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 315 |
--caption "KISS: User Management" \ |
| 316 |
--title "KISS: User Management" \ |
| 317 |
--combobox "Select a user from the list to modify login shell:" ${listuser} 1>${Q} 2>/dev/null |
| 318 |
user=$(cat ${Q}) |
| 319 |
rm -f ${Q} |
| 320 |
done |
| 321 |
|
| 322 |
oldshell=$(cat /etc/passwd|grep -w ^${user}|awk -F":" '{print $7}') |
| 323 |
listshell=$(cat /etc/shells|grep -v ^#|tr '\n' ' ') |
| 324 |
|
| 325 |
while [ "x${newshell}" == "x" ]; do |
| 326 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 327 |
--caption "KISS: User Management" \ |
| 328 |
--title "KISS: User Management" \ |
| 329 |
--combobox "Select a new login shell for the user ${user} (old login shell is ${oldshell}):" ${listshell} 1>${Q} 2>/dev/null |
| 330 |
newshell=$(cat ${Q}) |
| 331 |
rm -f ${Q} |
| 332 |
done |
| 333 |
|
| 334 |
${MODUSER} -s "${newshell}" ${user} >/dev/null 2>&1; ERR=$? |
| 335 |
if [ ${ERR} -eq 0 ]; then |
| 336 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 337 |
--caption "KISS: User Management" \ |
| 338 |
--title "KISS: User Management" \ |
| 339 |
--msgbox "Login shell for user ${user} has been changed successfully." |
| 340 |
else |
| 341 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 342 |
--caption "KISS: User Management" \ |
| 343 |
--title "KISS: User Management" \ |
| 344 |
--error "Something bad happened while trying to change the login shell for user ${user}.\nMake sure you have rights to delete this user." |
| 345 |
fi |
| 346 |
else |
| 347 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 348 |
--caption "KISS: User Management" \ |
| 349 |
--title "KISS: User Management" \ |
| 350 |
--sorry "No users found.\nThis means that you might need to create first a user, then try to change its login shell." |
| 351 |
fi |
| 352 |
} |
| 353 |
|
| 354 |
SWITCH="" |
| 355 |
while [ "x${SWITCH}" == "x" -o "x{SWITCH}" == "x" ]; do |
| 356 |
/usr/bin/kdialog --icon ${KISSICON} \ |
| 357 |
--caption "KISS: User Management" \ |
| 358 |
--title "KISS: User Management" \ |
| 359 |
--menu "Please chose one of the options" \ |
| 360 |
a 'Add user' \ |
| 361 |
b 'Delete user' \ |
| 362 |
c 'Change user password' \ |
| 363 |
d 'Change user geos information' \ |
| 364 |
e 'Change user login shell' \ |
| 365 |
x 'Exit' 1>${Q} 2>/dev/null |
| 366 |
SWITCH=$(cat ${Q}) |
| 367 |
rm -f ${Q} |
| 368 |
done |
| 369 |
|
| 370 |
case "${SWITCH}" in |
| 371 |
a) |
| 372 |
adduser |
| 373 |
${KISSHOME}/kissmgr/usermgr |
| 374 |
;; |
| 375 |
|
| 376 |
b) |
| 377 |
deluser |
| 378 |
${KISSHOME}/kissmgr/usermgr |
| 379 |
;; |
| 380 |
|
| 381 |
c) |
| 382 |
chpasswd |
| 383 |
${KISSHOME}/kissmgr/usermgr |
| 384 |
;; |
| 385 |
|
| 386 |
d) |
| 387 |
chname |
| 388 |
${KISSHOME}/kissmgr/usermgr |
| 389 |
;; |
| 390 |
|
| 391 |
e) |
| 392 |
chshell |
| 393 |
${KISSHOME}/kissmgr/usermgr |
| 394 |
;; |
| 395 |
|
| 396 |
x) |
| 397 |
${KISSHOME}/kissmgr/kissmgr |
| 398 |
;; |
| 399 |
|
| 400 |
esac |