1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-31 22:18:07 +08:00

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

Refs **https://github.com/1Panel-dev/1Panel/issues/3307**
This commit is contained in:
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

@ -80,6 +80,7 @@ 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 });