Skip to content

Commit 965fe56

Browse files
committed
Implement 2FA v-Scripts, 2FA libary and control scripts.
1 parent b4f8742 commit 965fe56

28 files changed

+1158
-0
lines changed

bin/v-add-user-2fa

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# info: add 2fa to existing user
3+
# options: USER
4+
#
5+
# The function creates a new 2fa token for user.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'USER'
25+
is_format_valid 'user' 'system'
26+
is_object_valid 'user' 'USER' "$user"
27+
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
# Reading user values
34+
source $USER_DATA/user.conf
35+
36+
# Check if 2FA is already enabled
37+
if [ ! -z "$TWOFA" ]; then
38+
echo "Error: 2FA already enabled"
39+
exit $E_EXIST
40+
fi
41+
42+
# Get secret and qr code from 2fa libary
43+
data=$($HESTIA/php/bin/php $HESTIA/web/inc/2fa/secret.php)
44+
45+
# Split to secret and qrcode using delimiter
46+
IFS='-' read -r -a array <<< "$data"
47+
secret=${array[0]}
48+
qrcode=${array[1]}
49+
50+
# Save the secret in user config (needs encryption?)
51+
sed -i "/RKEY/a TWOFA='$secret'" $USER_DATA/user.conf
52+
sed -i "/TWOFA/a QRCODE='$qrcode'" $USER_DATA/user.conf
53+
54+
#----------------------------------------------------------#
55+
# Hestia #
56+
#----------------------------------------------------------#
57+
58+
exit

bin/v-check-user-2fa

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# info: check user token
3+
# options: USER TOKEN
4+
#
5+
# The function verifies user 2fa token.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
token=$2
15+
16+
# Includes
17+
source $HESTIA/func/main.sh
18+
source $HESTIA/conf/hestia.conf
19+
20+
21+
#----------------------------------------------------------#
22+
# Verifications #
23+
#----------------------------------------------------------#
24+
25+
check_args '2' "$#" 'USER TOKEN'
26+
is_format_valid 'user' 'system'
27+
is_object_valid 'user' 'USER' "$user"
28+
29+
30+
#----------------------------------------------------------#
31+
# Action #
32+
#----------------------------------------------------------#
33+
34+
# Reading user values
35+
source $USER_DATA/user.conf
36+
37+
# Check if 2FA is enabled
38+
if [ -z "$TWOFA" ]; then
39+
echo "Error: 2FA is not enabled"
40+
exit $E_NOTEXIST
41+
fi
42+
43+
# Check if token is valid
44+
result=$($HESTIA/php/bin/php $HESTIA/web/inc/2fa/secret.php)
45+
if [ "$result" != "ok" ]; then
46+
echo "Error: Token missmatch"
47+
exit 9
48+
fi
49+
50+
#----------------------------------------------------------#
51+
# Hestia #
52+
#----------------------------------------------------------#
53+
54+
exit

bin/v-delete-user-2fa

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# info: delete 2fa of existing user
3+
# options: USER
4+
#
5+
# The function deletes 2fa token of a user.
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
# Argument definition
13+
user=$1
14+
15+
# Includes
16+
source $HESTIA/func/main.sh
17+
source $HESTIA/conf/hestia.conf
18+
19+
20+
#----------------------------------------------------------#
21+
# Verifications #
22+
#----------------------------------------------------------#
23+
24+
check_args '1' "$#" 'USER'
25+
is_format_valid 'user' 'system'
26+
is_object_valid 'user' 'USER' "$user"
27+
28+
29+
#----------------------------------------------------------#
30+
# Action #
31+
#----------------------------------------------------------#
32+
33+
# Reading user values
34+
source $USER_DATA/user.conf
35+
36+
# Check if 2FA is enabled
37+
if [ -z "$TWOFA" ]; then
38+
echo "Error: 2FA is not enabled"
39+
exit $E_NOTEXIST
40+
fi
41+
42+
# Remove 2FA from user config
43+
sed -i '/TWOFA=/d' $USER_DATA/user.conf
44+
sed -i '/QRCODE=/d' $USER_DATA/user.conf
45+
46+
#----------------------------------------------------------#
47+
# Hestia #
48+
#----------------------------------------------------------#
49+
50+
exit

bin/v-list-user

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ json_list() {
4444
"CONTACT": "'$CONTACT'",
4545
"CRON_REPORTS": "'$CRON_REPORTS'",
4646
"RKEY": "'$RKEY'",
47+
"TWOFA": "'$TWOFA'",
48+
"QRCODE": "'$QRCODE'",
4749
"SUSPENDED": "'$SUSPENDED'",
4850
"SUSPENDED_USERS": "'$SUSPENDED_USERS'",
4951
"SUSPENDED_WEB": "'$SUSPENDED_WEB'",

web/inc/2fa/.gitignore

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
## Ignore Visual Studio temporary files, build results, and
2+
## files generated by popular Visual Studio add-ons.
3+
4+
# User-specific files
5+
*.suo
6+
*.user
7+
*.sln.docstates
8+
9+
# Build results
10+
[Dd]ebug/
11+
[Dd]ebugPublic/
12+
[Rr]elease/
13+
[Rr]eleases/
14+
x64/
15+
x86/
16+
build/
17+
bld/
18+
[Bb]in/
19+
[Oo]bj/
20+
21+
# Roslyn cache directories
22+
*.ide/
23+
24+
# MSTest test Results
25+
[Tt]est[Rr]esult*/
26+
[Bb]uild[Ll]og.*
27+
28+
#NUNIT
29+
*.VisualState.xml
30+
TestResult.xml
31+
32+
# Build Results of an ATL Project
33+
[Dd]ebugPS/
34+
[Rr]eleasePS/
35+
dlldata.c
36+
37+
*_i.c
38+
*_p.c
39+
*_i.h
40+
*.ilk
41+
*.meta
42+
*.obj
43+
*.pch
44+
*.pdb
45+
*.pgc
46+
*.pgd
47+
*.rsp
48+
*.sbr
49+
*.tlb
50+
*.tli
51+
*.tlh
52+
*.tmp
53+
*.tmp_proj
54+
*.log
55+
*.vspscc
56+
*.vssscc
57+
.builds
58+
*.pidb
59+
*.svclog
60+
*.scc
61+
62+
# Chutzpah Test files
63+
_Chutzpah*
64+
65+
# Visual C++ cache files
66+
ipch/
67+
*.aps
68+
*.ncb
69+
*.opensdf
70+
*.sdf
71+
*.cachefile
72+
73+
# Visual Studio profiler
74+
*.psess
75+
*.vsp
76+
*.vspx
77+
78+
# TFS 2012 Local Workspace
79+
$tf/
80+
81+
# Guidance Automation Toolkit
82+
*.gpState
83+
84+
# ReSharper is a .NET coding add-in
85+
_ReSharper*/
86+
*.[Rr]e[Ss]harper
87+
*.DotSettings.user
88+
89+
# JustCode is a .NET coding addin-in
90+
.JustCode
91+
92+
# TeamCity is a build add-in
93+
_TeamCity*
94+
95+
# DotCover is a Code Coverage Tool
96+
*.dotCover
97+
98+
# NCrunch
99+
_NCrunch_*
100+
.*crunch*.local.xml
101+
102+
# MightyMoose
103+
*.mm.*
104+
AutoTest.Net/
105+
106+
# Web workbench (sass)
107+
.sass-cache/
108+
109+
# Installshield output folder
110+
[Ee]xpress/
111+
112+
# DocProject is a documentation generator add-in
113+
DocProject/buildhelp/
114+
DocProject/Help/*.HxT
115+
DocProject/Help/*.HxC
116+
DocProject/Help/*.hhc
117+
DocProject/Help/*.hhk
118+
DocProject/Help/*.hhp
119+
DocProject/Help/Html2
120+
DocProject/Help/html
121+
122+
# Click-Once directory
123+
publish/
124+
125+
# Publish Web Output
126+
*.[Pp]ublish.xml
127+
*.azurePubxml
128+
# TODO: Comment the next line if you want to checkin your web deploy settings
129+
# but database connection strings (with potential passwords) will be unencrypted
130+
*.pubxml
131+
*.publishproj
132+
133+
# NuGet Packages
134+
*.nupkg
135+
# The packages folder can be ignored because of Package Restore
136+
**/packages/*
137+
# except build/, which is used as an MSBuild target.
138+
!**/packages/build/
139+
# If using the old MSBuild-Integrated Package Restore, uncomment this:
140+
#!**/packages/repositories.config
141+
142+
# Windows Azure Build Output
143+
csx/
144+
*.build.csdef
145+
146+
# Windows Store app package directory
147+
AppPackages/
148+
149+
# Others
150+
sql/
151+
*.Cache
152+
ClientBin/
153+
[Ss]tyle[Cc]op.*
154+
~$*
155+
*~
156+
*.dbmdl
157+
*.dbproj.schemaview
158+
*.pfx
159+
*.publishsettings
160+
node_modules/
161+
162+
# RIA/Silverlight projects
163+
Generated_Code/
164+
165+
# Backup & report files from converting an old project file
166+
# to a newer Visual Studio version. Backup files are not needed,
167+
# because we have git ;-)
168+
_UpgradeReport_Files/
169+
Backup*/
170+
UpgradeLog*.XML
171+
UpgradeLog*.htm
172+
173+
# SQL Server files
174+
*.mdf
175+
*.ldf
176+
177+
# Business Intelligence projects
178+
*.rdl.data
179+
*.bim.layout
180+
*.bim_*.settings
181+
182+
# Microsoft Fakes
183+
FakesAssemblies/
184+
185+
# Composer
186+
/vendor
187+
188+
# .vs
189+
.vs/

web/inc/2fa/.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: php
2+
3+
php:
4+
- 5.4
5+
- 5.5
6+
- 5.6
7+
- 7.0
8+
- 7.1
9+
- 7.2
10+
11+
before_script:
12+
- composer install
13+
14+
script:
15+
- vendor/bin/phpunit --coverage-text tests

0 commit comments

Comments
 (0)