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 { type FileWget struct {
Url string `json:"url" validate:"required"` Url string `json:"url" validate:"required"`
Path string `json:"path" validate:"required"` Path string `json:"path" validate:"required"`
Name string `json:"name" validate:"required"` Name string `json:"name" validate:"required"`
IgnoreCertificate bool `json:"ignoreCertificate"`
} }
type FileMove struct { 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) { func (f *FileService) Wget(w request.FileWget) (string, error) {
fo := files.NewFileOp() fo := files.NewFileOp()
key := "file-wget-" + common.GetUuid() 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 { 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 { func (f FileOp) DownloadFileWithProcess(url, dst, key string, ignoreCertificate bool) error {
client := &http.Client{ client := &http.Client{}
Transport: &http.Transport{ if ignoreCertificate {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}, }
} }
request, err := http.NewRequest("GET", url, nil) request, err := http.NewRequest("GET", url, nil)
if err != nil { if err != nil {

View File

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

View File

@ -1105,6 +1105,9 @@ const message = {
wordWrap: 'Automatically wrap', wordWrap: 'Automatically wrap',
deleteHelper2: deleteHelper2:
'Are you sure you want to delete the selected file? The deletion operation cannot be rolled back', '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: { ssh: {
autoStart: 'Auto Start', autoStart: 'Auto Start',

View File

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

View File

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

View File

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