feat: 远程下载文件增加是否忽略不可信证书选项 (#3324)

Refs **https://github.com/1Panel-dev/1Panel/issues/3307**
pull/3335/head
zhengkunwang 2023-12-14 14:42:11 +08:00 committed by GitHub
parent 18cbcb7f13
commit f91831a5ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 28 additions and 8 deletions

View File

@ -77,9 +77,10 @@ type FilePathCheck struct {
}
type FileWget struct {
Url string `json:"url" validate:"required"`
Path string `json:"path" validate:"required"`
Name string `json:"name" validate:"required"`
Url string `json:"url" validate:"required"`
Path string `json:"path" validate:"required"`
Name string `json:"name" validate:"required"`
IgnoreCertificate bool `json:"ignoreCertificate"`
}
type FileMove struct {

View File

@ -243,7 +243,7 @@ func (f *FileService) ChangeName(req request.FileRename) error {
func (f *FileService) Wget(w request.FileWget) (string, error) {
fo := files.NewFileOp()
key := "file-wget-" + common.GetUuid()
return key, fo.DownloadFileWithProcess(w.Url, filepath.Join(w.Path, w.Name), key)
return key, fo.DownloadFileWithProcess(w.Url, filepath.Join(w.Path, w.Name), key, w.IgnoreCertificate)
}
func (f *FileService) MvFile(m request.FileMove) error {

View File

@ -216,11 +216,12 @@ func (w *WriteCounter) SaveProcess() {
}
}
func (f FileOp) DownloadFileWithProcess(url, dst, key string) error {
client := &http.Client{
Transport: &http.Transport{
func (f FileOp) DownloadFileWithProcess(url, dst, key string, ignoreCertificate bool) error {
client := &http.Client{}
if ignoreCertificate {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
}
request, err := http.NewRequest("GET", url, nil)
if err != nil {

View File

@ -109,6 +109,7 @@ export namespace File {
path: string;
name: string;
url: string;
ignoreCertificate?: boolean;
}
export interface FileWgetRes {

View File

@ -1105,6 +1105,9 @@ const message = {
wordWrap: 'Automatically wrap',
deleteHelper2:
'Are you sure you want to delete the selected file? The deletion operation cannot be rolled back',
ignoreCertificate: 'Ignore Certificate',
ignoreCertificateHelper:
'Ignoring untrusted certificates during downloads may lead to data leakage or tampering. Please use this option with caution, only when trusting the download source.',
},
ssh: {
autoStart: 'Auto Start',

View File

@ -1051,6 +1051,9 @@ const message = {
fileRecycleBinMsg: '{0}',
wordWrap: '',
deleteHelper2: ' ',
ignoreCertificate: '',
ignoreCertificateHelper:
'使',
},
ssh: {
autoStart: '',

View File

@ -1052,6 +1052,9 @@ const message = {
fileRecycleBinMsg: '{0}',
wordWrap: '',
deleteHelper2: '',
ignoreCertificate: '',
ignoreCertificateHelper:
'使',
},
ssh: {
autoStart: '',

View File

@ -24,6 +24,12 @@
<el-form-item :label="$t('commons.table.name')" prop="name">
<el-input v-model="addForm.name"></el-input>
</el-form-item>
<el-form-item>
<el-checkbox v-model="addForm.ignoreCertificate">
{{ $t('file.ignoreCertificate') }}
</el-checkbox>
<span class="input-help">{{ $t('file.ignoreCertificateHelper') }}</span>
</el-form-item>
</el-form>
</el-col>
</el-row>
@ -67,6 +73,7 @@ const addForm = reactive({
url: '',
path: '',
name: '',
ignoreCertificate: false,
});
const em = defineEmits(['close']);
@ -111,6 +118,7 @@ const acceptParams = (props: WgetProps) => {
addForm.path = props.path;
open.value = true;
submitData.value = false;
addForm.ignoreCertificate = false;
};
defineExpose({ acceptParams });