Skip to content
This repository was archived by the owner on Jan 7, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions web_hosting_manager/app/lib/Downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import { getPath } from './temp';
import { shell } from 'electron';
import { safe, typetag, accessContainers } from './api';
import { safe, TAG_TYPE_WWW, accessContainers } from './api';

export default class Downloader {
constructor(networkPath, callback) {
Expand All @@ -21,7 +21,7 @@ export default class Downloader {

return safe.auth.getContainer(accessContainers.public)
.then((mdata) => mdata.encryptKey(containerPath.dir).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
.then((val) => safe.mutableData.newPublic(val, typetag))
.then((val) => safe.mutableData.newPublic(val, TAG_TYPE_WWW))
.then((mdata) => {
const nfs = mdata.emulateAs('NFS');
return nfs.fetch(containerPath.file)
Expand Down
24 changes: 13 additions & 11 deletions web_hosting_manager/app/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const accessContainers = {
publicNames: '_publicNames'
};

export const typetag = 15001;
export const TAG_TYPE_DNS = 15001;
export const TAG_TYPE_WWW = 15002;


let publicIds = {};
let uploader;
Expand Down Expand Up @@ -164,7 +166,7 @@ export const fetchServices = () => {
return safe.auth.getContainer(accessContainers.publicNames)
.then((mdata) => mdata.encryptKey(publicId).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
.then((decVal) => {
return safe.mutableData.newPublic(decVal, typetag)
return safe.mutableData.newPublic(decVal, TAG_TYPE_DNS)
})
.then((mut) => mut.getEntries()
.then((entries) => entries.forEach((key, val) => {
Expand Down Expand Up @@ -196,7 +198,7 @@ export const createPublicId = (publicId) => {
let publicIdName = null;

return safe.crypto.sha3Hash(publicId)
.then((hashVal) => safe.mutableData.newPublic(hashVal, typetag))
.then((hashVal) => safe.mutableData.newPublic(hashVal, TAG_TYPE_DNS))
.then((mdata) => {
let permissionSet = null;
let permissions = null;
Expand Down Expand Up @@ -243,7 +245,7 @@ export const createService = (publicId, service, container) => {
return mdata.encryptKey(publicId).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf));
})
.then((val) => {
return safe.mutableData.newPublic(val, typetag);
return safe.mutableData.newPublic(val, TAG_TYPE_DNS);
})
.then((publicIdMData) => {
return publicIdMData.getEntries()
Expand All @@ -259,7 +261,7 @@ export const createService = (publicId, service, container) => {

export const deleteService = (publicId, service) => {
return safe.crypto.sha3Hash(publicId)
.then((hashVal) => safe.mutableData.newPublic(hashVal, typetag))
.then((hashVal) => safe.mutableData.newPublic(hashVal, TAG_TYPE_DNS))
.then((mdata) => mdata.getEntries()
.then((entries) => entries.get(service)
.then((val) => entries.mutate()
Expand All @@ -268,7 +270,7 @@ export const deleteService = (publicId, service) => {
};

export const createContainer = (path) => {
return safe.mutableData.newRandomPublic(typetag)
return safe.mutableData.newRandomPublic(TAG_TYPE_WWW)
.then((mdata) => {
return mdata.quickSetup({})
.then(() => {
Expand Down Expand Up @@ -327,7 +329,7 @@ export const deleteItem = (nwPath) => {
if (fileName) {
return mdata.encryptKey(dirName).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf))
.then((val) => {
return safe.mutableData.newPublic(val, typetag)
return safe.mutableData.newPublic(val, TAG_TYPE_WWW)
.then((dirMdata) => dirMdata.getEntries()
.then(() => dirMdata.getEntries()
.then((dirEntries) => dirEntries.get(fileName)
Expand All @@ -338,7 +340,7 @@ export const deleteItem = (nwPath) => {
} else {
return mdata.encryptKey(nwPath.split('/').slice(0, -1).join('/')).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf))
.then((val) => {
return safe.mutableData.newPublic(val, typetag)
return safe.mutableData.newPublic(val, TAG_TYPE_WWW)
.then((tarMdata) => {
const targetKeys = [];
return tarMdata.getEntries()
Expand Down Expand Up @@ -372,7 +374,7 @@ export const remapService = (service, publicId, container) => {
.then(() => safe.auth.getContainer(accessContainers.publicNames))
.then((mdata) => mdata.encryptKey(publicId).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
// .then((entries) => entries.get(publicId))
.then((val) => safe.mutableData.newPublic(val, typetag))
.then((val) => safe.mutableData.newPublic(val, TAG_TYPE_DNS))
.then((publicIdMData) => publicIdMData.getEntries()
.then(() => publicIdMData.getEntries()
.then((entries) => entries.get(service)
Expand All @@ -387,7 +389,7 @@ export const getContainer = (path) => {
.then((mdata) => mdata.encryptKey(path.split('/').slice(0, 3).join('/'))
.then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
// .then((entries) => entries.get(path.split('/').slice(0, 3).join('/')))
.then((val) => safe.mutableData.newPublic(val, typetag))
.then((val) => safe.mutableData.newPublic(val, TAG_TYPE_WWW))
.then((mdata) => {
const files = [];
const nfs = mdata.emulateAs('NFS');
Expand Down Expand Up @@ -455,7 +457,7 @@ export const checkServiceExist = (publicId, service, path) => {
return safe.auth.getContainer(accessContainers.publicNames)
.then((mdata) => mdata.encryptKey(publicId).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
.then((decVal) => {
return safe.mutableData.newPublic(decVal, typetag)
return safe.mutableData.newPublic(decVal, TAG_TYPE_DNS)
})
.then((pubMut) => {
return pubMut.get(service)
Expand Down
6 changes: 3 additions & 3 deletions web_hosting_manager/app/lib/tasks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import fs from 'fs';
import { I18n } from 'react-redux-i18n';
import { safe, typetag, accessContainers } from './api';
import { safe, TAG_TYPE_WWW, accessContainers } from './api';

const parseContainerPath = (targetPath) => {
if (!targetPath) {
Expand Down Expand Up @@ -38,13 +38,13 @@ export class FileUploadTask extends Task {

return safe.auth.getContainer(accessContainers.public)
.then((mdata) => mdata.encryptKey(containerPath.target).then((encKey) => mdata.get(encKey)).then((value) => mdata.decrypt(value.buf)))
.then((val) => safe.mutableData.newPublic(val, typetag))
.then((val) => safe.mutableData.newPublic(val, TAG_TYPE_WWW))
.then((mdata) => {
const nfs = mdata.emulateAs('NFS');
return nfs.create(fs.readFileSync(this.localPath))
.then((file) => nfs.insert(containerPath.file, file)
.catch((err) => {
if (err.name !== 'ERR_ENTRY_EXISTS') {
if (err.code === -106) {
return Promise.reject(err);
}
return mdata.get(containerPath.file)
Expand Down
2 changes: 1 addition & 1 deletion web_hosting_manager/app/utils/app_utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const trimErrorMsg = (msg) => {
let index = msg.indexOf('->');
index = (index === -1) ? index : index + 2;
index = (index === -1) ? 0 : index + 2;
return msg.slice(index).trim()
};