Skip to content
Snippets Groups Projects
Commit c20a8165 authored by Cristian Rocha's avatar Cristian Rocha
Browse files

changes added

parent fc98cc35
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,6 @@ usb_drives=`ls -lt 2>/dev/null /dev/disk/by-id/usb* | rev | cut -f 3 -d ' ' | r ...@@ -64,7 +64,6 @@ usb_drives=`ls -lt 2>/dev/null /dev/disk/by-id/usb* | rev | cut -f 3 -d ' ' | r
shadow=`eval echo $user_info | cut -f 2 -d '='` shadow=`eval echo $user_info | cut -f 2 -d '='`
elif [[ $type == "SLX_USB_GROUP" ]] elif [[ $type == "SLX_USB_GROUP" ]]
then then
group=`eval echo $user_info | cut -f 2 -d '='` group=`eval echo $user_info | cut -f 2 -d '='`
......
...@@ -23,7 +23,8 @@ function find_path { ...@@ -23,7 +23,8 @@ function find_path {
done done
fi fi
# temp_file=$(mktemp)
# temp_file_name=$(mktemp)
name=`echo $mount_path | rev | cut -f 1 -d '/'| rev` name=`echo $mount_path | rev | cut -f 1 -d '/'| rev`
eval echo $mount_path >> /tmp/mount_openslx eval echo $mount_path >> /tmp/mount_openslx
eval echo $name >> /tmp/name_openslx eval echo $name >> /tmp/name_openslx
...@@ -54,6 +55,7 @@ function create_dir { ...@@ -54,6 +55,7 @@ function create_dir {
# crete the dir /Openslx/home # crete the dir /Openslx/home
if [ ! -d "$mount_path$DIR_OPENSLX" ]; then if [ ! -d "$mount_path$DIR_OPENSLX" ]; then
mkdir "$mount_path"/Openslx/ mkdir "$mount_path"/Openslx/
mkdir "$mount_path"/Openslx/.config/
mkdir "$mount_path"/Openslx/home mkdir "$mount_path"/Openslx/home
mkdir "$mount_path"/Openslx/home/Destkop mkdir "$mount_path"/Openslx/home/Destkop
mkdir "$mount_path"/Openslx/home/Documents mkdir "$mount_path"/Openslx/home/Documents
...@@ -63,16 +65,35 @@ function create_dir { ...@@ -63,16 +65,35 @@ function create_dir {
mkdir "$mount_path"/Openslx/home/Public mkdir "$mount_path"/Openslx/home/Public
mkdir "$mount_path"/Openslx/home/Templates mkdir "$mount_path"/Openslx/home/Templates
mkdir "$mount_path"/Openslx/home/Videos mkdir "$mount_path"/Openslx/home/Videos
touch "$mount_path"/Openslx/config touch "$mount_path"/Openslx/.config/config
touch "$mount_path"/Openslx/log touch "$mount_path"/Openslx/log
fi fi
} }
function read_user_pass {
function get_user {
#get the username and the password #get the username and the password
new_user=$( dialog --stdout --inputbox 'Digite o nome de usuário:' 0 0 ) new_user=$( dialog --stdout --inputbox 'Digite o nome de usuário:' 0 0 )
#username should be at linux standards
while [[ ! $new_user =~ ^[a-z][-a-z0-9]*$ ]]
do
new_user=$( dialog --stdout --inputbox 'O nome de usuário consiste apenas de letras, números, hífens(-). E o nome de usuário deve começar apenas com letras. Tente novamente :' 0 0 )
done
check_user_name=` cat "$mount_path"/Openslx/log | grep -w "$new_user"`
#check if user_name already exists
while [[ -n $check_user_name ]];
do
#get the username and the password
new_user=$( dialog --stdout --inputbox 'Usuário já existente. Tente novamente:' 0 0 )
#username should be at linux standards
while [[ ! $new_user =~ ^[a-z][-a-z0-9]*$ ]]
do
new_user=$( dialog --stdout --inputbox 'O nome de usuário consiste apenas de letras, números, hífens(-). E o nome de usuário deve começar apenas com letras. Tente novamente :' 0 0 )
done
check_user_name=`cat "$mount_path"/Openslx/log | grep -w "$new_user"`
done
pass=$( dialog --stdout --passwordbox 'Por favor, digite a senha:' 0 0 ) pass=$( dialog --stdout --passwordbox 'Por favor, digite a senha:' 0 0 )
check_pass=$( dialog --stdout --passwordbox 'Por favor, confirme a senha:' 0 0 ) check_pass=$( dialog --stdout --passwordbox 'Por favor, confirme a senha:' 0 0 )
...@@ -87,33 +108,56 @@ function get_user { ...@@ -87,33 +108,56 @@ function get_user {
check_pass=$( dialog --stdout --passwordbox 'Por favor, confirme a senha:' 0 0 ) check_pass=$( dialog --stdout --passwordbox 'Por favor, confirme a senha:' 0 0 )
done done
}
function get_user {
#get the username and the password
read_user_pass
#start the log with a default id #start the log with a default id
user_id=$((10000+$(((RANDOM%10000)+1)))) user_id=$((10000+$(((RANDOM%10000)))))
check_user_name=` cat "$mount_path"/Openslx/log | grep -w "$new_user"`
check_user_id=`cat "$mount_path"/Openslx/config | grep "SLX_USB_PASSWD" | cut -f 3 -d ':' | grep -w "$user_id"`
#check if user_name already exists check_user_id=`cat "$mount_path"/Openslx/.config/config | grep "SLX_USB_PASSWD" | cut -f 3 -d ':' | grep -w "$user_id"`
while [[ -n $check_user_name ]];
do
new_user=$( dialog --stdout --inputbox 'Nome de usuário já existente. Digite outro nome de usuário:' 0 0 )
check_user_name=`cat "$mount_path"/Openslx/log | grep -w "$new_user"`
done
#get the last id
last_id=`cat "$mount_path"/Openslx/log | cut -f 1 -d ' ' | tail -n1`
#check if user_id already exists #check if user_id already exists
while [[ -n $check_user_id ]]; while [[ -n $check_user_id ]];
do do
#get the last id
user_id=`cat "$mount_path"/Openslx/log | cut -f 1 -d ' ' | tail -n1`
#user_id will be last id plus one, if it does not exists already #user_id will be last id plus one, if it does not exists already
user_id=$((10000+$(((RANDOM%10000)+1)))) last_id=$(($last_id+1))
check_user_id=`cat "$mount_path"/Openslx/config | grep "SLX_USB_PASSWD" | cut -f 3 -d ':' | grep -w "$user_id"` #check if the last_id already exists in the config file
check_user_id=`cat "$mount_path"/Openslx/.config/config | grep "SLX_USB_PASSWD" | cut -f 3 -d ':' | grep -w "$last_id"`
#if is the last_id in the USB DRIVE range, go back to the start of the range
if [[ ($last_id -ge 19999) && (-n $check_user_id) ]]; then
last_id=9999
#otherwise, set user_id
else
user_id=$last_id
fi
done done
#create dir of the user
if [ ! -d "$mount_path"/Openslx/$new_user ]; then
mkdir "$mount_path"/Openslx/$new_user
fi
} }
function create_config { function success_message {
#show the confirmation message
dialog \
--title 'Cadastro:' \
--msgbox 'Cadastro realizado com sucesso.' \
6 40
}
function calculate_days_and_pass {
#get days since Linux Epoch (January 1, 1970) #get days since Linux Epoch (January 1, 1970)
seconds=`date +%s` seconds=`date +%s`
minutes=$(($seconds/60)) minutes=$(($seconds/60))
...@@ -121,23 +165,39 @@ function create_config { ...@@ -121,23 +165,39 @@ function create_config {
days=$(($hours/24)) days=$(($hours/24))
#encrypt password #encrypt password
encry_pass=`echo "$pass" | openssl passwd -1 -stdin` encry_pass=`echo "$pass" | openssl passwd -1 -stdin`
echo $encry_pass #echo $encry_pass
}
function create_config {
#get days since Linux Epoch (January 1, 1970)
calculate_days_and_pass
#insert data in the log file #insert data in the log file
echo "$user_id $new_user active $date" >> "$mount_path"/Openslx/log echo "$user_id $new_user active $date" >> "$mount_path"/Openslx/log
#insert data in the config file #insert data in the config file
echo "SLX_USB_PASSWD=$new_user:x:$user_id:$user_id::/home/$new_user:/bin/bash" >> "$mount_path"/Openslx/config echo "SLX_USB_PASSWD=$new_user:x:$user_id:$user_id::/home/$new_user:/bin/bash" >> "$mount_path"/Openslx/.config/config
echo "SLX_USB_SHADOW=$new_user:$encry_pass:$days:0:99999:7:::" >> "$mount_path"/Openslx/config echo "SLX_USB_SHADOW=$new_user:$encry_pass:$days:0:99999:7:::" >> "$mount_path"/Openslx/.config/config
echo "SLX_USB_GROUP=$new_user:x:$user_id;" >> "$mount_path"/Openslx/config echo "SLX_USB_GROUP=$new_user:x:$user_id;" >> "$mount_path"/Openslx/.config/config
success_message
}
#show the confirmation message function create_config_hd {
dialog \
--title 'Cadastro:' \ calculate_days_and_pass
--msgbox 'Cadastro realizado com sucesso.' \
6 40 #insert data in the log file
echo "$user_id $new_user active $date" >> "$mount_path"/openslx/log
#insert data in the config file
echo "SLX_PASSWD=$new_user:x:$user_id:$user_id::/home/$new_user:/bin/bash" >> "$mount_path"/openslx/config
echo "SLX_SHADOW=$new_user:$encry_pass:$days:0:99999:7:::" >> "$mount_path"/openslx/config
echo "SLX_GROUP=$new_user:x:$user_id;" >> "$mount_path"/openslx/config
success_message
} }
function show_menu { function show_menu {
...@@ -187,14 +247,64 @@ function usb_drive { ...@@ -187,14 +247,64 @@ function usb_drive {
fim_setup fim_setup
} }
function hd_drive {
# crete the dir /home/openslx and config files
if [ ! -d "/home/openslx" ]; then
mkdir -p /home/openslx/
fi
if [ ! -e "/home/openslx/config" ]; then
touch /home/openslx/config
fi
if [ ! -e "/home/openslx/log" ]; then
touch /home/openslx/log
fi
read_user_pass
user_id=cat /etc/passwd | cut -d: -f3 | grep -e 2....$ | sort -h | tail -n 1
if [ -z "$user_id" ]; then
user_id=20000
else
user_id=$(( $user_id+1 ))
if [ user_id -ge 30000 ]; then
echo $0": Provavelmente acabou os id's valido, procurando sequencialmente" >> /home/openslx/log
#Da para tentar fazer algum código usando diff e {20000..29999}
#Ai nao precisa desse loop
for i in $(echo {20000..29999}); do
user_id=cat /etc/passwd | cut -d: -f3 | grep -e $i$
if [ -z "$user_id" ]; then
user_id=$i
break;
fi
done
if [ -z "$user_id" ]; then
echo $0": Acabou os id's validos" >> /home/openslx/log
dialog \
--title 'Erro:' \
--msgbox 'Estorou o limite de ususario locais nessa maquina, impossivel criar mais' \
6 40
exit 255
fi
fi
fi
mount_path="/home"
create_config_hd
}
id_user=`id -r -u` id_user=`id -r -u`
if [ $id_user -eq 0 ]; then if [ $id_user -eq 0 ]; then
FILE=$(dialog --menu "Que tipo de cadastro você deseja fazer?" 10 50 2 1 "Cadastrar por Pen Drive" 2 "Cadastrar por HD" 3>&2 2>&1 1>&3) FILE=$(dialog --menu "Que tipo de cadastro você deseja fazer?" 10 50 2 1 "Cadastrar por Pen Drive" 2 "Cadastrar por HD" 3>&2 2>&1 1>&3)
if [ $FILE -eq 1 ]; then if [ $FILE -eq 1 ] &> /dev/null; then
usb_drive usb_drive
else elif [ $FILE -eq 2 ] &> /dev/null; then
echo "parte do HD" hd_drive
fi fi
else else
usb_drive usb_drive
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment