Browse Source

fix(gui): SSL certificate selection error

read certificate file data

related #215

Signed-off-by: Pranav C Balan <pranavxc@gmail.com>
pull/240/head
Pranav C Balan 4 years ago
parent
commit
26404ee15f
  1. 21
      packages/nc-gui/components/createOrEditProject.vue
  2. 42
      packages/nc-gui/helpers/fileReader.js

21
packages/nc-gui/components/createOrEditProject.vue

@ -438,7 +438,10 @@
</v-select> </v-select>
<v-row class="pa-0 ma-0"> <v-row class="pa-0 ma-0">
<input type="file" ref="certFilePath" class="d-none"/>
<input type="file" ref="certFilePath" class="d-none"
@change="readFileContent(db,'ssl','cert',dbIndex)"
/>
<x-btn tooltip="Select .cert file" <x-btn tooltip="Select .cert file"
small small
color="primary" color="primary"
@ -449,7 +452,8 @@
>{{ db.ui.ssl.cert }} >{{ db.ui.ssl.cert }}
</x-btn> </x-btn>
<input type="file" ref="keyFilePath" class="d-none"/> <input type="file" ref="keyFilePath" class="d-none"
@change="readFileContent(db,'ssl','key',dbIndex)"/>
<x-btn tooltip="Select .key file" <x-btn tooltip="Select .key file"
small small
color="primary" color="primary"
@ -460,7 +464,8 @@
>{{ db.ui.ssl.key }} >{{ db.ui.ssl.key }}
</x-btn> </x-btn>
<input type="file" ref="caFilePath" class="d-none"/> <input type="file" ref="caFilePath" class="d-none"
@change="readFileContent(db,'ssl','ca',dbIndex)"/>
<x-btn tooltip="Select CA file" <x-btn tooltip="Select CA file"
small small
color="primary" color="primary"
@ -769,7 +774,7 @@ import MonacoJsonEditor from "@/components/monaco/MonacoJsonEditor";
import JSON5 from 'json5'; import JSON5 from 'json5';
const {uniqueNamesGenerator, starWars, adjectives, animals} = require('unique-names-generator'); const {uniqueNamesGenerator, starWars, adjectives, animals} = require('unique-names-generator');
import readFile from "@/helpers/fileReader";
import {mapGetters, mapActions, mapState, mapMutations} from "vuex"; import {mapGetters, mapActions, mapState, mapMutations} from "vuex";
import Vue from 'vue'; import Vue from 'vue';
@ -1209,9 +1214,13 @@ export default {
openJsonInSystemEditor() { openJsonInSystemEditor() {
// shell.openItem(path.join(this.project.folder, 'config.xc.json')); // shell.openItem(path.join(this.project.folder, 'config.xc.json'));
}, },
readFileContent(db, obj, key, index) {
readFile(this.$refs[`${key}FilePath`][index], (data) => {
Vue.set(db.connection[obj], key, data)
})
},
selectFile(db, obj, key, index) { selectFile(db, obj, key, index) {
// this.$refs[key][index].click() this.$refs[key][index].click()
// console.log(obj, key); // console.log(obj, key);
// const file = dialog.showOpenDialog({ // const file = dialog.showOpenDialog({

42
packages/nc-gui/helpers/fileReader.js

@ -0,0 +1,42 @@
// Ref : https://stackoverflow.com/a/12002275
//Tested in Mozilla Firefox browser, Chrome
function ReadFileAllBrowsers(FileElement, CallBackFunction) {
try {
if (!FileElement.files || !FileElement.files.length) return CallBackFunction();
const file = FileElement.files[0];
if (file) {
const reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = function (evt) {
CallBackFunction(evt.target.result);
}
reader.onerror = function (evt) {
CallBackFunction()
}
}
} catch (Exception) {
const fall_back = ieReadFile(FileElement.value);
if (fall_back != false) {
CallBackFunction(fall_back);
}
}
}
///Reading files with Internet Explorer
function ieReadFile(filename) {
try {
const fso = new ActiveXObject("Scripting.FileSystemObject");
const fh = fso.OpenTextFile(filename, 1);
const contents = fh.ReadAll();
fh.Close();
return contents;
} catch (Exception) {
return false;
}
}
export default ReadFileAllBrowsers;
Loading…
Cancel
Save