Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFS Gluon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
firmware
FFS Gluon
Commits
e7b434ef
Unverified
Commit
e7b434ef
authored
8 years ago
by
Matthias Schiffer
Browse files
Options
Downloads
Patches
Plain Diff
gluon-luci-admin: fix password setting
parent
70b116fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
package/gluon-luci-admin/luasrc/usr/lib/lua/luci/model/cbi/admin/remote.lua
+57
-73
57 additions, 73 deletions
...-admin/luasrc/usr/lib/lua/luci/model/cbi/admin/remote.lua
with
57 additions
and
73 deletions
package/gluon-luci-admin/luasrc/usr/lib/lua/luci/model/cbi/admin/remote.lua
+
57
−
73
View file @
e7b434ef
...
...
@@ -16,90 +16,74 @@ $Id$
local
fs
=
require
"nixio.fs"
local
m
=
Map
(
"system"
,
translate
(
"SSH keys"
))
m
.
pageaction
=
false
m
.
template
=
"cbi/simpleform"
if
fs
.
access
(
"/etc/config/dropbear"
)
then
local
s
=
m
:
section
(
TypedSection
,
"_dummy1"
,
nil
,
translate
(
"You can provide your SSH keys here (one per line):"
))
s
.
addremove
=
false
s
.
anonymous
=
true
function
s
.
cfgsections
()
return
{
"_keys"
}
end
local
keys
keys
=
s
:
option
(
TextValue
,
"_data"
,
""
)
keys
.
wrap
=
"off"
keys
.
rows
=
5
keys
.
rmempty
=
true
function
keys
.
cfgvalue
()
return
fs
.
readfile
(
"/etc/dropbear/authorized_keys"
)
or
""
end
function
keys
.
write
(
self
,
section
,
value
)
if
value
then
fs
.
writefile
(
"/etc/dropbear/authorized_keys"
,
value
:
gsub
(
"
\r\n
"
,
"
\n
"
):
trim
()
..
"
\n
"
)
end
end
function
keys
.
remove
(
self
,
section
)
if
keys
:
formvalue
(
"_keys"
)
then
fs
.
remove
(
"/etc/dropbear/authorized_keys"
)
end
end
local
f_keys
=
SimpleForm
(
'keys'
,
translate
(
"SSH keys"
),
translate
(
"You can provide your SSH keys here (one per line):"
))
f_keys
.
hidden
=
{
submit_keys
=
'1'
}
local
keys
keys
=
f_keys
:
field
(
TextValue
,
"keys"
,
""
)
keys
.
wrap
=
"off"
keys
.
rows
=
5
keys
.
rmempty
=
true
function
keys
.
cfgvalue
()
return
fs
.
readfile
(
"/etc/dropbear/authorized_keys"
)
or
""
end
local
m2
=
Map
(
"system"
,
translate
(
"Password"
))
m2
.
reset
=
false
m2
.
pageaction
=
false
m2
.
template
=
"cbi/simpleform"
function
keys
.
write
(
self
,
section
,
value
)
if
not
f_keys
:
formvalue
(
'submit_keys'
)
then
return
end
local
s
=
m2
:
section
(
TypedSection
,
"_dummy2"
,
nil
,
translate
(
"Alternatively, you can set a password to access you node. Please choose a secure password you don't use anywhere else.<br /><br />"
..
"If you set an empty password, login via password will be disabled. This is the default."
))
fs
.
writefile
(
"/etc/dropbear/authorized_keys"
,
value
:
gsub
(
"
\r\n
"
,
"
\n
"
):
trim
()
..
"
\n
"
)
end
s
.
addremove
=
false
s
.
anonymous
=
true
function
keys
.
remove
(
self
,
section
)
if
not
f_keys
:
formvalue
(
'submit_keys'
)
then
return
end
local
pw1
=
s
:
option
(
Value
,
"pw1"
,
translate
(
"Password"
))
fs
.
remove
(
"/etc/dropbear/authorized_keys"
)
end
local
f_password
=
SimpleForm
(
'password'
,
translate
(
"Password"
),
translate
(
"Alternatively, you can set a password to access you node. Please choose a secure password you don't use anywhere else.<br /><br />"
..
"If you set an empty password, login via password will be disabled. This is the default."
)
)
f_password
.
hidden
=
{
submit_password
=
'1'
}
f_password
.
reset
=
false
local
pw1
=
f_password
:
field
(
Value
,
"pw1"
,
translate
(
"Password"
))
pw1
.
password
=
true
function
pw1
.
cfgvalue
()
return
''
end
local
pw2
=
s
:
option
(
Value
,
"pw2"
,
translate
(
"Confirmation"
))
local
pw2
=
f_password
:
field
(
Value
,
"pw2"
,
translate
(
"Confirmation"
))
pw2
.
password
=
true
function
s
.
cfgsections
()
return
{
"_pass"
}
function
pw2
.
cfgvalue
()
return
''
end
function
m2
.
on_commit
(
map
)
local
v1
=
pw1
:
formvalue
(
"_pass"
)
local
v2
=
pw2
:
formvalue
(
"_pass"
)
if
v1
and
v2
then
if
v1
==
v2
then
if
#
v1
>
0
then
if
luci
.
sys
.
user
.
setpasswd
(
'root'
,
v1
)
==
0
then
m2
.
message
=
translate
(
"Password changed."
)
else
m2
.
errmessage
=
translate
(
"Unable to change the password."
)
end
else
-- We don't check the return code here as the error 'password for root is already locked' is normal...
os.execute
(
'passwd -l root >/dev/null'
)
m2
.
message
=
translate
(
"Password removed."
)
end
else
m2
.
errmessage
=
translate
(
"The password and the confirmation differ."
)
end
end
function
f_password
:
handle
(
state
,
data
)
if
not
f_password
:
formvalue
(
'submit_password'
)
then
return
end
if
data
.
pw1
~=
data
.
pw2
then
f_password
.
errmessage
=
translate
(
"The password and the confirmation differ."
)
return
end
if
data
.
pw1
and
#
data
.
pw1
>
0
then
if
luci
.
sys
.
user
.
setpasswd
(
'root'
,
data
.
pw1
)
==
0
then
f_password
.
message
=
translate
(
"Password changed."
)
else
f_password
.
errmessage
=
translate
(
"Unable to change the password."
)
end
else
-- We don't check the return code here as the error 'password for root is already locked' is normal...
os.execute
(
'passwd -l root >/dev/null'
)
f_password
.
message
=
translate
(
"Password removed."
)
end
end
local
c
=
Compound
(
m
,
m2
)
local
c
=
Compound
(
f_keys
,
f_password
)
c
.
pageaction
=
false
return
c
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment