-
Notifications
You must be signed in to change notification settings - Fork 1
/
clogin
123 lines (114 loc) · 4.8 KB
/
clogin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Author: Alirezarpi
# Should run as root
# Caution: You should edit the getty.target.wants/getty@tty1.service -> add " --autologin root " to ExecStart like this:
# ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
# When you're editing this don't forget to change the sizes
# Put the dialogrc file in /etc/ folder
if [[ "$USER" != "root" ]]; then
echo "Run as root"
exit 1
fi
checkdialog=$(ls /usr/bin/ | grep "^dialog$")
if [[ "$checkdialog" == "" ]]; then
echo "You should have <dialog> program, you can install it with apt or yum or ..."
exit 1
fi
emt=$(systemctl get-default)
if [[ "$emt" != "multi-user.target" ]]; then
echo "Setting the default runlevel to 3 ..."
systemctl set-default multi-user.target 2>/dev/null
sleep 0.5 # makes script cooler :))
fi
if [[ "$1" == "-c" ]]; then
echo "Changing password"
echo "Deleting /etc/ar-shadow ..."
rm /etc/ar-shadow
fi
passdd=$(ls /etc/ | grep ar-shadow)
if [[ "$passdd" == "" ]]; then
echo "Copying clogin to /usr/bin ..."
cp clogin /usr/bin 2>/dev/null
checkdialogrc=$(ls /etc/ | grep dialogrc)
if [[ "$checkdialogrc" == "" ]]; then
echo "Copying dialogrc to /etc/ ..."
cp dialogrc /etc/
fi
checkar=$(cat /root/.bashrc | grep "clogin")
if [[ "$checkar" == "" ]]; then
echo "Adding <clogin> in .bashrc ..."
sed -i '1 i\clogin' /root/.bashrc # adds to the first line of the .bashrc ( Root )
sed -i "1 i\stty susp '' ; trap '' INT " /root/.bashrc # disables Ctrl-C and Ctrl-Z
fi
sleep 0.1
echo -e " \033[32m+-------------------------+\033[00m"
echo -e " \033[32m-\033[00m \033[1;36mWelcome to Custom-Login\033[00m \033[32m-\033[00m"
echo -e " \033[32m+-------------------------+\033[00m"
sleep 1
echo -e "Please enter the password: \c"
read -s password1
echo
echo -e "Please confirm the password: \c"
read -s password2
echo
if [[ "$password1" == "$password2" ]]; then # Compare two given passwords
passwordhashed=$(echo $password1 | base64 ) # hash the password
echo "$passwordhashed" | openssl enc -aes-256-cbc -salt -k $passwordhashed > /etc/ar-shadow
echo "Password hashed and added to encrypted shadow file"
else
echo "Passwords does not match try again"
exit 1
fi
echo
echo -e "\033[32mOperation successfull\033[00m"
echo "---------------------"
echo -e "\033[33mRemember to edit the /etc/systemd/system/getty.target.wants/getty@tty1.service -> add '--autologin root' to ExecStart like this:\n \
\033[32mExecStart=-/sbin/agetty \033[1;35m--autologin root\033[00m \033[32m--noclear %I \$TERM\033[00m"
echo "---------------------"
echo -e "\033[34mYou can change the password by passing -c argument ->\033[00m \033[1;35msudo clogin -c\033[00m"
exit 0
fi
# Edit the boxes with your favorite color and name and title (( EDITS ))
# If you're using --colors arg
# 0 through 7 are the ANSI color numbers used in curses:
# black, red, green, yellow, blue, magenta, cyan and white re‐
# spectively.
# Bold is set by 'b', reset by 'B'.
# Reverse is set by 'r', reset by 'R'.
# Underline is set by 'u', reset by 'U'.
# The settings are cumulative, e.g., "\Zb\Z1" makes the fol‐
# lowing text bold (perhaps bright) red.
# Restore normal settings with "\Zn".
title='\Z1CAUTION: \Z3Title goes \Z6Here\Z3... \Z2(Change here to what you want) ^_^ ' # you can change the back title (EDIT)
try='0'
while true; do
gpassword=$(dialog --nocancel --insecure --colors --ok-label "Login" --backtitle "$title" \
--passwordbox "\Z6- Enter the \Zb\Z1password\ZB \Z6to login:\n\Z7" 9 50 3>&1 1>&2 2>&3) # get password (EDIT)
ggpassword=$(echo $gpassword | base64) # hash the password
ghashed=$(cat /etc/ar-shadow | openssl enc -aes-256-cbc -d -k $ggpassword) # real hashed password ;)
if [[ "$ggpassword" == "$ghashed" ]]; then # compare
dialog --sleep 1 --colors --nook --infobox "\Z2\ZbWelcome \Z6User" 3 19 # welcome box (EDIT)
break
fi
if [[ "$ggpassword" != "$ghashed" && "$gpassword" != "" ]]; then # Invalid password
(( try ++ ))
dialog --sleep 1 --colors --nook --backtitle "Make it three to \Z1shutdown\Zn baby ;)" --infobox "\Z1Invalid Password " 3 21 # Shutdown box (EDIT)
fi
if [[ "$gpassword" == "" ]]; then # Emty password
dialog --sleep 1 --colors --nook --infobox "\Z2Empty Password" 3 19 #Optional edit
fi
if [[ "$try" == "3" ]]; then # Shutdown after 3 invalid passwords
dialog --sleep 1 --colors --nook --infobox "\Z3Shutting down the system" 3 30 #Optional edit
systemctl poweroff
fi
sleep 0.01
done
checkgp=$(systemctl status graphical.target | grep " active")
if [[ "$checkgp" == "" ]]; then
trap INT # Ctrl-C Ctrl-V are disabled at run time so we are enabling it again
stty sane
systemctl start graphical.target # start the X server
fi
trap INT ; stty sane
tput clear
exit 0