Browse Source

fix:开源版文件加密修改

master
prr 6 months ago
parent
commit
d6d78eca0e
  1. 4
      frontend/src/components/builtin/FileList.vue
  2. 75
      frontend/src/components/oa/FilePwd.vue
  3. 58
      frontend/src/components/setting/SetFilePwd.vue
  4. 14
      frontend/src/components/window/IframeFile.vue
  5. 20
      frontend/src/hook/useContextMenu.ts
  6. 1
      frontend/src/i18n/lang/zh.json
  7. 5
      frontend/src/system/config.ts
  8. 45
      frontend/src/system/core/FileOs.ts
  9. 10
      frontend/src/system/index.ts
  10. 2
      frontend/src/system/window/Dialog.ts

4
frontend/src/components/builtin/FileList.vue

@ -111,6 +111,7 @@
import { throttle } from "@/util/debounce";
import { dealSize } from "@/util/file";
import { markRaw, onMounted, ref } from "vue";
const { openPropsWindow, copyFile, createLink, deleteFile } =
useContextMenu();
const sys = useSystem();
@ -495,8 +496,7 @@
// win.show();
// },
// });
}
// eslint-disable-next-line prefer-spread
}
menuArr.push.apply(menuArr, fileMenus);
}
const sysEndMenu = [

75
frontend/src/components/oa/FilePwd.vue

@ -21,33 +21,54 @@
</template>
<script lang="ts" setup>
import { BrowserWindow, useSystem } from "@/system";
import { notifyError, notifySuccess } from "@/util/msg";
import { ref } from "vue";
const window: BrowserWindow | undefined = inject("browserWindow");
const filePwd = ref("");
const sys = useSystem();
async function setFilePwd() {
if (
filePwd.value !== "" &&
filePwd.value.length >= 6 &&
filePwd.value.length <= 10
) {
const path = window?.config.path || "";
const header = {
pwd: filePwd.value,
};
const file = await sys.fs.readFile(path);
if (file === false) return;
const res = await sys.fs.writeFile(path, file, header);
if (res && res.success) {
notifySuccess("文件密码设置成功");
} else {
notifyError("文件密码设置失败");
}
//console.log("", res, path);
}
}
import { BrowserWindow, useSystem } from "@/system";
import { notifyError, notifySuccess } from "@/util/msg";
import { md5 } from "js-md5";
import { ref } from "vue";
import { getSystemConfig, setSystemKey } from "@/system/config";
const window: BrowserWindow | undefined = inject("browserWindow");
const filePwd = ref("");
const sys = useSystem();
async function setFilePwd() {
if (
filePwd.value !== "" &&
filePwd.value.length >= 6 &&
filePwd.value.length <= 10
) {
const path = window?.config.path || "";
const header = {
pwd: getSystemConfig().userType == 'person' ? md5(filePwd.value) : filePwd.value
};
const file = await sys.fs.readFile(path);
if (file === false) return;
const res = await sys.fs.writeFile(path, file, header);
//console.log('res:', res);
if (res && res.code == 0) {
notifySuccess("文件密码设置成功");
localStorageFilePwd(path, filePwd.value)
} else {
notifyError("文件密码设置失败");
}
//console.log("", res, path);
}
}
//
function localStorageFilePwd (path:string, pwd: string) {
if (getSystemConfig().file.isPwd && getSystemConfig().userType == 'person') {
let fileInputPwd = getSystemConfig().fileInputPwd
const pos = fileInputPwd.findIndex((item: any) => item.path == path)
if (pos !== -1) {
fileInputPwd[pos].pwd = pwd
} else {
fileInputPwd.push({
path: path,
pwd: pwd
})
}
setSystemKey('fileInputPwd', fileInputPwd)
}
}
</script>
<style scoped>
.btn-group {

58
frontend/src/components/setting/SetFilePwd.vue

@ -1,6 +1,6 @@
<template>
<div class="file-pwd-box">
<div v-if="setPwd">
<!-- <div v-if="setPwd">
<div class="setting-item">
<label>文件密码</label>
<el-input
@ -23,16 +23,15 @@
>取消文件加密</el-button
>
</div>
</div>
</div> -->
<div
v-else
class="setting-item"
>
<label></label>
<el-button
@click="setPwd = true"
@click="setFilePwd"
type="primary"
>设置文件密码</el-button
>{{ isSetPwd ? t("cancleFilePwd") : t("setFilePwd") }}</el-button
>
</div>
</div>
@ -46,51 +45,20 @@
getSystemConfig,
setSystemKey,
} from "@/system/config";
import { notifyError, notifySuccess } from "@/util/msg";
import { md5 } from "js-md5";
import { onMounted, ref } from "vue";
const filePwd = ref("");
const setPwd = ref(false);
const config = getSystemConfig();
const params = {
isPwd: 1,
pwd: "",
salt: getSystemConfig().file.salt,
};
//
async function toSetFilePwd() {
if (filePwd.value.length < 6 || filePwd.value.length > 10) {
notifyError("密码长度应该在6-10位之间");
return;
}
params.pwd = md5(filePwd.value);
params.isPwd = filePwd.value === "" ? 0 : 1;
const url = getApiUrl() + "/file/setfilepwd";
const header = {
salt: params.salt ? params.salt : "vIf_wIUedciAd0nTm6qjJA==",
pwd: params.pwd,
};
const isSetPwd = ref(false);
async function setFilePwd() {
isSetPwd.value = !isSetPwd.value
const params = {
isPwd: isSetPwd.value ? 1 : 0
}
await fetchGet(`${getApiUrl()}/file/changeispwd?ispwd=${params.isPwd}`);
const res = await fetchGet(url, header);
if (res.ok) {
notifySuccess("设置文件密码成功");
} else {
params.isPwd = 0;
params.pwd = "";
notifyError("设置文件密码失败");
}
setSystemKey("file", params);
}
async function clearPwd() {
setPwd.value = false;
filePwd.value = "";
params.isPwd = 0;
await fetchGet(`${getApiUrl()}/file/changeispwd?ispwd=0`);
setSystemKey("file", params);
}
}
onMounted(() => {
params.isPwd = config.file.isPwd;
setPwd.value = params.isPwd ? true : false;
isSetPwd.value = config.file.isPwd ? true : false;
});
</script>

14
frontend/src/components/window/IframeFile.vue

@ -9,6 +9,7 @@ import { base64ToBuffer, isBase64 } from "@/util/file";
import { isShareFile } from "@/util/sharePath.ts";
import { inject, onMounted, onUnmounted, ref, toRaw } from "vue";
import { askAi } from "@/hook/useAi";
import { md5 } from "js-md5";
const SP = getSplit();
const sys: any = inject<System>("system");
@ -131,11 +132,16 @@ const eventHandler = async (e: MessageEvent) => {
title = title.split(SP).pop();
if (!content && win?.config.path) {
const file = getSystemConfig().file;
const header = {
salt: file.salt,
pwd: file.pwd,
pwd: ''
};
const filePwd = getSystemConfig().fileInputPwd
const pos = filePwd.findIndex((item: any) => item.path == win?.config.path)
//console.log('', win?.config.path, pos, filePwd);
const userType = getSystemConfig().userType
if (pos !== -1) {
header.pwd = userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
}
content = await sys?.fs.readFile(win?.config.path, header);
}
content = toRaw(content);
@ -188,7 +194,7 @@ const eventHandler = async (e: MessageEvent) => {
}
else if (eventData.type == 'aiCreater') {
// console.log(eventData)
console.log('传递内容: ',eventData)
let postData:any = {}
if(eventData.data){
postData.content = eventData.data

20
frontend/src/hook/useContextMenu.ts

@ -7,6 +7,7 @@ import { Dialog } from '../system/window/Dialog';
import { Menu } from '../system/menu/Menu';
import { uniqBy } from '../util/modash';
import { UnwrapNestedRefs } from 'vue';
import { getSystemConfig } from "@/system/config";
export function createTaskbarIconContextMenu(e: MouseEvent, windowNode: UnwrapNestedRefs<BrowserWindow>) {
Menu.buildFromTemplate([
@ -159,8 +160,27 @@ function useContextMenu() {
}
const content = '';
initPwd(newFilePath)
return await system.fs.writeFile(newFilePath, content);
}
// 开源版新建文件初始化密码
function initPwd(path: string) {
//console.log('新建路径:',path);
if (getSystemConfig().userType == 'person' && getSystemConfig().file.isPwd == 1) {
const win = new BrowserWindow({
title: "初始化文件密码",
content: "FilePwd",
config: {
path: path,
},
width: 400,
height: 200,
center: true,
});
win.show()
}
}
async function createNewDir(path: string) {
const system = useSystem();
if (!system) return;

1
frontend/src/i18n/lang/zh.json

@ -11,6 +11,7 @@
"myshare": "我的分享",
"othershare": "接收的分享",
"setFilePwd": "设置文件密码",
"cancleFilePwd": "取消文件密码",
"favorite": "我的收藏",
"desktop": "桌面",
"personalization": "个性化",

5
frontend/src/system/config.ts

@ -33,7 +33,7 @@ export const getSystemConfig = (ifset = false) => {
config.file = {
isPwd: 0,
pwd: '',
salt: 'vIf_wIUedciAd0nTm6qjJA=='
// salt: 'vIf_wIUedciAd0nTm6qjJA=='
}
}
if (!config.fileInputPwd) {
@ -255,7 +255,8 @@ export function fetchPost(url: string, data: any, headerConfig?: { [key: string]
if (config.userType == 'person') {
return fetch(url, {
method: 'POST',
body: data
body: data,
headers: headerConfig
})
} else {
return fetch(url, {

45
frontend/src/system/core/FileOs.ts

@ -115,18 +115,16 @@ export async function handleExists(path: string): Promise<any> {
export async function handleReadFile(path: string, header?: { [key: string]: string }): Promise<any> {
const userType = getSystemConfig().userType
//console.log('请求头:', header);
// let head = userType === 'member' ? { pwd: header?.pwd || '' } : { ...header }
let head = {}
if (userType === 'member') {
//console.log('read header:', header);
if (userType == 'member') {
head = {
pwd: header?.pwd || ''
}
// } else if (getSystemConfig().file.isPwd === 1) {
} else if (header) {
head = {
pwd: header?.pwd === '' ? '' : md5(header?.pwd),
salt: header?.salt || ''
}
}
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, head);
@ -308,19 +306,6 @@ export const useOsFile = () => {
return response.data
}
return []
// const response = await handleShareDir(id, file.path);
// useShareFile().setCurrentFile(file)
// if (response && response.data) {
// const result = response.data.map((item: {[key: string]: OsFile}) => {
// item.fi.isShare = true
// item.fi.parentPath = turnLocalPath(item.fi.parentPath ,file.path,1)
// item.fi.path = turnLocalPath(item.fi.path ,file.path,1)
// // item.fi.titleName = turnLocalPath(item.fi.titleName, file.path, 1)
// return item.fi
// })
// return result
// }
// return [];
},
async getShareInfo(path: string) {
const response = await handleShareDetail(path);
@ -416,21 +401,21 @@ export const useOsFile = () => {
},
async writeFile(path: string, content: string | Blob, header?: { [key: string]: any }) {
let head = {}
if (getSystemConfig().userType == 'member') {
if (header) {
head = { ...header }
} else {
const filePwd = getSystemConfig().fileInputPwd
const pos = filePwd.findIndex((item: any) => item.path == path)
if (pos !== -1) {
head = {
pwd: filePwd[pos].pwd
}
if (header) {
head = { ...header }
} else {
const filePwd = getSystemConfig().fileInputPwd
const pos = filePwd.findIndex((item: any) => item.path == path)
//console.log('路径:', path, pos, filePwd);
const userType = getSystemConfig().userType
if (pos !== -1) {
head = {
pwd: userType == 'person' ? md5(filePwd[pos].pwd) : filePwd[pos].pwd
}
}
} else {
head = { ...header }
}
console.log('请求头:', head);
const response = await handleWriteFile(path, content, head);
if (response) {

10
frontend/src/system/index.ts

@ -455,9 +455,7 @@ export class System {
this._flieOpenerMap.get('dir')?.func.call(this, path, '');
return;
} else {
const filePwd = getSystemConfig()
const header = {
salt: '',
pwd: ''
}
//判断文件是否需要输入密码
@ -466,19 +464,17 @@ export class System {
if (temp.response !== 1) {
return
}
header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
// header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
header.pwd = temp?.inputPwd || ''
}
// 读取文件内容
const fileContent = await this.fs.readFile(path, header);
// console.log('文件:', fileContent);
if (fileContent === false && fileStat.isPwd) {
notifyError('密码错误')
return
}
//企业用户文件加密密码存储
if (fileStat.isPwd && getSystemConfig().userType === 'member') {
//用户文件加密密码存储
if (fileStat.isPwd) {
let fileInputPwd = getSystemConfig().fileInputPwd
const pos = fileInputPwd.findIndex((item: any) => item.path == path)
if (pos !== -1) {

2
frontend/src/system/window/Dialog.ts

@ -1,7 +1,5 @@
import { ElMessageBox } from 'element-plus'
import { BrowserWindow } from "./BrowserWindow"
// import { setSystemKey } from "@/system/config"
// import { md5 } from "js-md5"
class Dialog {
constructor() {
// static class

Loading…
Cancel
Save