mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 22:18:07 +08:00
feat: sftp 备份账号支持密钥添加 (#6677)
This commit is contained in:
parent
b6aac773ea
commit
d027a9a2ba
@ -25,11 +25,28 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
|||||||
if len(port) == 0 {
|
if len(port) == 0 {
|
||||||
global.LOG.Errorf("load param port from vars failed, err: not exist!")
|
global.LOG.Errorf("load param port from vars failed, err: not exist!")
|
||||||
}
|
}
|
||||||
password := loadParamFromVars("password", vars)
|
authMode := loadParamFromVars("authMode", vars)
|
||||||
|
passPhrase := loadParamFromVars("passPhrase", vars)
|
||||||
username := loadParamFromVars("username", vars)
|
username := loadParamFromVars("username", vars)
|
||||||
|
password := loadParamFromVars("password", vars)
|
||||||
bucket := loadParamFromVars("bucket", vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
|
|
||||||
auth := []ssh.AuthMethod{ssh.Password(password)}
|
var auth []ssh.AuthMethod
|
||||||
|
if authMode == "key" {
|
||||||
|
var signer ssh.Signer
|
||||||
|
var err error
|
||||||
|
if len(passPhrase) != 0 {
|
||||||
|
signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(password), []byte(passPhrase))
|
||||||
|
} else {
|
||||||
|
signer, err = ssh.ParsePrivateKey([]byte(password))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
|
||||||
|
} else {
|
||||||
|
auth = []ssh.AuthMethod{ssh.Password(password)}
|
||||||
|
}
|
||||||
clientConfig := &ssh.ClientConfig{
|
clientConfig := &ssh.ClientConfig{
|
||||||
User: username,
|
User: username,
|
||||||
Auth: auth,
|
Auth: auth,
|
||||||
|
@ -142,6 +142,15 @@ func (u *BackupService) SearchWithPage(req dto.SearchPageWithType) (int64, inter
|
|||||||
if !item.RememberAuth {
|
if !item.RememberAuth {
|
||||||
item.AccessKey = ""
|
item.AccessKey = ""
|
||||||
item.Credential = ""
|
item.Credential = ""
|
||||||
|
if account.Type == constant.Sftp {
|
||||||
|
varMap := make(map[string]interface{})
|
||||||
|
if err := json.Unmarshal([]byte(item.Vars), &varMap); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
delete(varMap, "passPhrase")
|
||||||
|
itemVars, _ := json.Marshal(varMap)
|
||||||
|
item.Vars = string(itemVars)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
item.AccessKey = base64.StdEncoding.EncodeToString([]byte(item.AccessKey))
|
item.AccessKey = base64.StdEncoding.EncodeToString([]byte(item.AccessKey))
|
||||||
item.Credential = base64.StdEncoding.EncodeToString([]byte(item.Credential))
|
item.Credential = base64.StdEncoding.EncodeToString([]byte(item.Credential))
|
||||||
|
@ -26,17 +26,23 @@ func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
|||||||
global.LOG.Errorf("load param port from vars failed, err: not exist!")
|
global.LOG.Errorf("load param port from vars failed, err: not exist!")
|
||||||
}
|
}
|
||||||
authMode := loadParamFromVars("authMode", vars)
|
authMode := loadParamFromVars("authMode", vars)
|
||||||
privateKey := loadParamFromVars("privateKey", vars)
|
passPhrase := loadParamFromVars("passPhrase", vars)
|
||||||
password := loadParamFromVars("password", vars)
|
password := loadParamFromVars("password", vars)
|
||||||
bucket := loadParamFromVars("bucket", vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
|
|
||||||
var auth []ssh.AuthMethod
|
var auth []ssh.AuthMethod
|
||||||
if authMode == "key" {
|
if authMode == "key" {
|
||||||
itemPrivateKey, err := ssh.ParsePrivateKey([]byte(privateKey))
|
var signer ssh.Signer
|
||||||
|
var err error
|
||||||
|
if len(passPhrase) != 0 {
|
||||||
|
signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(password), []byte(passPhrase))
|
||||||
|
} else {
|
||||||
|
signer, err = ssh.ParsePrivateKey([]byte(password))
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
auth = []ssh.AuthMethod{ssh.PublicKeys(itemPrivateKey)}
|
auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
|
||||||
} else {
|
} else {
|
||||||
auth = []ssh.AuthMethod{ssh.Password(password)}
|
auth = []ssh.AuthMethod{ssh.Password(password)}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,34 @@
|
|||||||
<el-form-item :label="$t('commons.login.username')" prop="accessKey" :rules="[Rules.requiredInput]">
|
<el-form-item :label="$t('commons.login.username')" prop="accessKey" :rules="[Rules.requiredInput]">
|
||||||
<el-input v-model.trim="dialogData.rowData!.accessKey" />
|
<el-input v-model.trim="dialogData.rowData!.accessKey" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('commons.login.password')" prop="credential" :rules="[Rules.requiredInput]">
|
|
||||||
|
<div v-if="dialogData.rowData!.type === 'SFTP'">
|
||||||
|
<el-form-item :label="$t('terminal.authMode')" prop="varsJson.authMode">
|
||||||
|
<el-radio-group v-model="dialogData.rowData!.varsJson['authMode']">
|
||||||
|
<el-radio value="password">{{ $t('terminal.passwordMode') }}</el-radio>
|
||||||
|
<el-radio value="key">{{ $t('terminal.keyMode') }}</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
<div v-if="dialogData.rowData!.type === 'SFTP' && dialogData.rowData!.varsJson['authMode'] === 'key'">
|
||||||
|
<el-form-item :label="$t('terminal.key')" prop="credential" :rules="[Rules.requiredInput]">
|
||||||
|
<el-input type="textarea" v-model="dialogData.rowData!.credential" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item :label="$t('terminal.keyPassword')" prop="varsJson.passPhrase">
|
||||||
|
<el-input
|
||||||
|
type="password"
|
||||||
|
show-password
|
||||||
|
clearable
|
||||||
|
v-model="dialogData.rowData!.varsJson['passPhrase']"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</div>
|
||||||
|
<el-form-item
|
||||||
|
v-else
|
||||||
|
:label="$t('commons.login.password')"
|
||||||
|
prop="credential"
|
||||||
|
:rules="[Rules.requiredInput]"
|
||||||
|
>
|
||||||
<el-input type="password" clearable show-password v-model.trim="dialogData.rowData!.credential" />
|
<el-input type="password" clearable show-password v-model.trim="dialogData.rowData!.credential" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</div>
|
</div>
|
||||||
@ -437,6 +464,7 @@ const changeType = async () => {
|
|||||||
}
|
}
|
||||||
case 'SFTP':
|
case 'SFTP':
|
||||||
dialogData.value.rowData.varsJson['port'] = 22;
|
dialogData.value.rowData.varsJson['port'] = 22;
|
||||||
|
dialogData.value.rowData.varsJson['authMode'] = 'password';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const changeFrom = () => {
|
const changeFrom = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user