mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-04 05:00:25 +08:00
节点SSH密码和私钥均以掩码方式显示
This commit is contained in:
@@ -31,7 +31,14 @@ func (this *GrantAction) RunGet(params struct {
|
|||||||
|
|
||||||
// TODO 处理节点专用的认证
|
// TODO 处理节点专用的认证
|
||||||
|
|
||||||
grant := grantResp.NodeGrant
|
var grant = grantResp.NodeGrant
|
||||||
|
|
||||||
|
var privateKey = grant.PrivateKey
|
||||||
|
const maskLength = 64
|
||||||
|
if len(privateKey) > maskLength+32 {
|
||||||
|
privateKey = privateKey[:maskLength] + strings.Repeat("*", len(privateKey)-maskLength)
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["grant"] = maps.Map{
|
this.Data["grant"] = maps.Map{
|
||||||
"id": grant.Id,
|
"id": grant.Id,
|
||||||
"name": grant.Name,
|
"name": grant.Name,
|
||||||
@@ -39,7 +46,7 @@ func (this *GrantAction) RunGet(params struct {
|
|||||||
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
|
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
|
||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": strings.Repeat("*", len(grant.Password)),
|
"password": strings.Repeat("*", len(grant.Password)),
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": privateKey,
|
||||||
"passphrase": strings.Repeat("*", len(grant.Passphrase)),
|
"passphrase": strings.Repeat("*", len(grant.Passphrase)),
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
page := this.NewPage(countResp.Count)
|
var page = this.NewPage(countResp.Count)
|
||||||
this.Data["page"] = page.AsHTML()
|
this.Data["page"] = page.AsHTML()
|
||||||
|
|
||||||
grantsResp, err := this.RPC().NodeGrantRPC().ListEnabledNodeGrants(this.AdminContext(), &pb.ListEnabledNodeGrantsRequest{
|
grantsResp, err := this.RPC().NodeGrantRPC().ListEnabledNodeGrants(this.AdminContext(), &pb.ListEnabledNodeGrantsRequest{
|
||||||
@@ -39,7 +39,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
grantMaps := []maps.Map{}
|
var grantMaps = []maps.Map{}
|
||||||
for _, grant := range grantsResp.NodeGrants {
|
for _, grant := range grantsResp.NodeGrants {
|
||||||
// 集群数
|
// 集群数
|
||||||
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithNodeGrantIdRequest{NodeGrantId: grant.Id})
|
countClustersResp, err := this.RPC().NodeClusterRPC().CountAllEnabledNodeClustersWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodeClustersWithNodeGrantIdRequest{NodeGrantId: grant.Id})
|
||||||
@@ -47,7 +47,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countClusters := countClustersResp.Count
|
var countClusters = countClustersResp.Count
|
||||||
|
|
||||||
// 节点数
|
// 节点数
|
||||||
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGrantIdRequest{NodeGrantId: grant.Id})
|
countNodesResp, err := this.RPC().NodeRPC().CountAllEnabledNodesWithNodeGrantId(this.AdminContext(), &pb.CountAllEnabledNodesWithNodeGrantIdRequest{NodeGrantId: grant.Id})
|
||||||
@@ -55,7 +55,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
countNodes := countNodesResp.Count
|
var countNodes = countNodesResp.Count
|
||||||
|
|
||||||
grantMaps = append(grantMaps, maps.Map{
|
grantMaps = append(grantMaps, maps.Map{
|
||||||
"id": grant.Id,
|
"id": grant.Id,
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package grants
|
package grants
|
||||||
|
|
||||||
import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants/grantutils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UpdateAction struct {
|
type UpdateAction struct {
|
||||||
@@ -34,15 +36,23 @@ func (this *UpdateAction) RunGet(params struct {
|
|||||||
|
|
||||||
// TODO 处理节点专用的认证
|
// TODO 处理节点专用的认证
|
||||||
|
|
||||||
grant := grantResp.NodeGrant
|
var grant = grantResp.NodeGrant
|
||||||
|
|
||||||
|
// private key
|
||||||
|
var privateKey = grant.PrivateKey
|
||||||
|
const maskLength = 64
|
||||||
|
if len(privateKey) > maskLength+32 {
|
||||||
|
privateKey = privateKey[:maskLength] + strings.Repeat("*", len(privateKey)-maskLength)
|
||||||
|
}
|
||||||
|
|
||||||
this.Data["grant"] = maps.Map{
|
this.Data["grant"] = maps.Map{
|
||||||
"id": grant.Id,
|
"id": grant.Id,
|
||||||
"name": grant.Name,
|
"name": grant.Name,
|
||||||
"method": grant.Method,
|
"method": grant.Method,
|
||||||
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
|
"methodName": grantutils.FindGrantMethodName(grant.Method, this.LangCode()),
|
||||||
"username": grant.Username,
|
"username": grant.Username,
|
||||||
"password": grant.Password,
|
"password": strings.Repeat("*", len(grant.Password)),
|
||||||
"privateKey": grant.PrivateKey,
|
"privateKey": privateKey,
|
||||||
"passphrase": grant.Passphrase,
|
"passphrase": grant.Passphrase,
|
||||||
"description": grant.Description,
|
"description": grant.Description,
|
||||||
"su": grant.Su,
|
"su": grant.Su,
|
||||||
@@ -85,6 +95,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 验证私钥
|
// 验证私钥
|
||||||
|
if !strings.HasSuffix(params.PrivateKey, "******") /* 非掩码 */ {
|
||||||
var err error
|
var err error
|
||||||
if len(params.Passphrase) > 0 {
|
if len(params.Passphrase) > 0 {
|
||||||
_, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase))
|
_, err = ssh.ParsePrivateKeyWithPassphrase([]byte(params.PrivateKey), []byte(params.Passphrase))
|
||||||
@@ -95,6 +106,7 @@ func (this *UpdateAction) RunPost(params struct {
|
|||||||
this.Fail("私钥验证失败,请检查格式:" + err.Error())
|
this.Fail("私钥验证失败,请检查格式:" + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
this.Fail("请选择正确的认证方式")
|
this.Fail("请选择正确的认证方式")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>SSH密码</td>
|
<td>SSH密码</td>
|
||||||
<td><input type="password" name="password" maxlength="100"/>
|
<td><input type="password" name="password" maxlength="100"/>
|
||||||
<p class="comment">SSH登录用户密码。</p> </td>
|
<p class="comment">SSH登录用户密码。<mask-warning></mask-warning></p> </td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
<td>RSA私钥 *</td>
|
<td>RSA私钥 *</td>
|
||||||
<td>
|
<td>
|
||||||
<file-textarea name="privateKey" spellcheck="false" placeholder="填入RSA私钥内容或者拖动私钥文件到当前框中"></file-textarea>
|
<file-textarea name="privateKey" spellcheck="false" placeholder="填入RSA私钥内容或者拖动私钥文件到当前框中"></file-textarea>
|
||||||
<p class="comment">用来生成登录SSH公钥的私钥。</p>
|
<p class="comment">用来生成登录SSH公钥的私钥。<mask-warning></mask-warning></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
4
web/views/@default/clusters/grants/grant.css
Normal file
4
web/views/@default/clusters/grants/grant.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.CodeMirror-wrap pre {
|
||||||
|
word-break: break-all !important;
|
||||||
|
}
|
||||||
|
/*# sourceMappingURL=grant.css.map */
|
||||||
1
web/views/@default/clusters/grants/grant.css.map
Normal file
1
web/views/@default/clusters/grants/grant.css.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["grant.less"],"names":[],"mappings":"AAAA,gBAAiB;EAChB,qBAAA","file":"grant.css"}
|
||||||
3
web/views/@default/clusters/grants/grant.less
Normal file
3
web/views/@default/clusters/grants/grant.less
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.CodeMirror-wrap pre {
|
||||||
|
word-break: break-all !important;
|
||||||
|
}
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>SSH密码</td>
|
<td>SSH密码</td>
|
||||||
<td><input type="password" name="password" maxlength="100" v-model="grant.password"/>
|
<td><input type="password" name="password" maxlength="100" v-model="grant.password"/>
|
||||||
<p class="comment">SSH登录用户密码。</p> </td>
|
<p class="comment">SSH登录用户密码。<mask-warning></mask-warning></p> </td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<td>RSA私钥 *</td>
|
<td>RSA私钥 *</td>
|
||||||
<td>
|
<td>
|
||||||
<file-textarea name="privateKey" v-model="grant.privateKey" spellcheck="false" placeholder="填入RSA私钥内容或者拖动私钥文件到当前框中"></file-textarea>
|
<file-textarea name="privateKey" v-model="grant.privateKey" spellcheck="false" placeholder="填入RSA私钥内容或者拖动私钥文件到当前框中"></file-textarea>
|
||||||
<p class="comment">用来生成登录SSH公钥的私钥</p>
|
<p class="comment">用来生成登录SSH公钥的私钥。<mask-warning></mask-warning></p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user