From 119e55bddc155b8a34f8feef7db74d4cb683ba25 Mon Sep 17 00:00:00 2001 From: donny rolanda Date: Tue, 5 Jul 2022 09:14:12 +0800 Subject: [PATCH 1/6] Improvement - Add delay while init set source link file saved --- src/app/init/services/InitConfigService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/init/services/InitConfigService.ts b/src/app/init/services/InitConfigService.ts index e8d182f..686b425 100644 --- a/src/app/init/services/InitConfigService.ts +++ b/src/app/init/services/InitConfigService.ts @@ -46,6 +46,7 @@ const InitConfigService = BaseService.extend({ test = YAML.parse(readFileSync(upath.normalizeSafe(basePathFolder + '/example.yaml'), 'utf8')); test.sync_collection.src = sync_collection_src || upath.normalize(homedir() + "/sync_collections"); } + // console.log("test.sync_collection.src :: ",test.sync_collection.src); if (existsSync(path.resolve('sync-config.yaml')) == false) { writeFileSync(CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8'); if (silent == false) { @@ -59,6 +60,8 @@ const InitConfigService = BaseService.extend({ console.log('---------------------------------------------------') console.log(' Replace xxx_sync-config.yaml to sync-config.yaml'); console.log('---------------------------------------------------') + }else{ + writeFileSync(CONFIG_FILE_NAME, YAML.stringify(test, null), 'utf8'); } } if (existsSync('.sync_ignore') == false) { @@ -96,7 +99,7 @@ const InitConfigService = BaseService.extend({ this.generateTemplate(true, upath.normalize(answers.path)); setTimeout(() => { masterData.saveData('command.load_save.data', {}); - }, 1000); + }, 3000); }) return; } From 555f3fa303bc6fc56cdd8709936c3ba2ff71cbff Mon Sep 17 00:00:00 2001 From: donny Date: Sat, 9 Jul 2022 10:03:21 +0800 Subject: [PATCH 2/6] Improvement - Keep additional config still exist and not overrided --- src/app/init/compute/Config.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/init/compute/Config.ts b/src/app/init/compute/Config.ts index 61488ec..0a5c948 100644 --- a/src/app/init/compute/Config.ts +++ b/src/app/init/compute/Config.ts @@ -280,6 +280,10 @@ const Config = BaseModel.extend({ } }); + _overrideSyncConfig = { + ...this._config, + ..._overrideSyncConfig, + } // Override the sync-config if getting new and replace old version filendir.writeFileSync(path.resolve("", "sync-config.yaml"), YAML.stringify(_overrideSyncConfig, null), "utf8"); } catch (ex) { From 962dbc7ff386b2774cf8616cf837d3be4aa8cb1c Mon Sep 17 00:00:00 2001 From: donny Date: Mon, 11 Jul 2022 08:32:06 +0800 Subject: [PATCH 3/6] Improvement - [PrivateKey] : Add permission 400 - [ForceRsync] : Ignore privatekey path --- src/app/devsync/compute/Watcher.ts | 3 ++- src/app/devsync/services/DevSyncService.ts | 2 +- src/app/devsync2/services/DevSync2Service.ts | 2 +- src/app/forcersync/compute/SyncPush.ts | 4 +++- src/app/init/compute/Config.ts | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/devsync/compute/Watcher.ts b/src/app/devsync/compute/Watcher.ts index 7fbf1d9..b9b2b01 100644 --- a/src/app/devsync/compute/Watcher.ts +++ b/src/app/devsync/compute/Watcher.ts @@ -116,7 +116,8 @@ export default class Watcher { gitIgnore = [ ...gitIgnore, - ...defaultIgnores + ...defaultIgnores, + this.config.privateKey ] let resCHeckGItIgnores = (() => { diff --git a/src/app/devsync/services/DevSyncService.ts b/src/app/devsync/services/DevSyncService.ts index 7281385..8f635d1 100644 --- a/src/app/devsync/services/DevSyncService.ts +++ b/src/app/devsync/services/DevSyncService.ts @@ -635,7 +635,7 @@ const DevSyncService = BaseService.extend({ setTimeout(() => { this.construct(this._cli); - }, 1000); + }, 2000); } var closeRemote = () => { if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) { diff --git a/src/app/devsync2/services/DevSync2Service.ts b/src/app/devsync2/services/DevSync2Service.ts index f0edc79..7f0c69a 100644 --- a/src/app/devsync2/services/DevSync2Service.ts +++ b/src/app/devsync2/services/DevSync2Service.ts @@ -747,7 +747,7 @@ const DevRsyncService = BaseService.extend({ process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r'); setTimeout(() => { this.construct(this._cli); - }, 1000); + }, 2000); } var closeRemote = () => { if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) { diff --git a/src/app/forcersync/compute/SyncPush.ts b/src/app/forcersync/compute/SyncPush.ts index 5b8f10c..1ab51df 100644 --- a/src/app/forcersync/compute/SyncPush.ts +++ b/src/app/forcersync/compute/SyncPush.ts @@ -443,9 +443,11 @@ const SyncPush = BaseModel.extend>({ } } } + _filterPatternRules.ignores = [ ...newIgnores, - ..._filterPatternRules.ignores + ..._filterPatternRules.ignores, + this._config.privateKeyPath ]; let extraWatch: Array<{ diff --git a/src/app/init/compute/Config.ts b/src/app/init/compute/Config.ts index 0a5c948..1b7456a 100644 --- a/src/app/init/compute/Config.ts +++ b/src/app/init/compute/Config.ts @@ -1,7 +1,7 @@ import BaseModel, { BaseModelInterface } from "@root/base/BaseModel"; import { CliInterface, EXIT_CODE } from "../services/CliService"; import path, { join as pathJoin } from "path"; -import { readFileSync, existsSync, statSync, createReadStream } from "fs"; +import { readFileSync, existsSync, statSync, createReadStream, chmod, chmodSync } from "fs"; import { String, uniq } from "lodash"; import upath from 'upath'; const { parse } = require("jsonplus"); @@ -189,6 +189,8 @@ const Config = BaseModel.extend({ } /** @type {boolean} */ let hasPasspharse = await this._hasPassphrase(this._config.privateKey); + chmodSync(this._config.privateKey, 0o400); + // console.log(this._config.privateKey); if (hasPasspharse == true) { this.cli.read("Enter Passphrase to connect : ", true).then(answer => { this.password = this._config.password = answer; From 50b11804ebd52a030893f47b9582b1fab752f4e2 Mon Sep 17 00:00:00 2001 From: donny rolanda Date: Wed, 13 Jul 2022 11:34:51 +0800 Subject: [PATCH 4/6] Improvement - If the IdentityFile is a relative convert to absolute path --- src/app/directaccess/compute/DirectAccess.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/directaccess/compute/DirectAccess.ts b/src/app/directaccess/compute/DirectAccess.ts index 1aff069..81af7e8 100644 --- a/src/app/directaccess/compute/DirectAccess.ts +++ b/src/app/directaccess/compute/DirectAccess.ts @@ -1,7 +1,7 @@ import { ConfigInterface } from "@root/app/init/compute/Config"; import BaseModel, { BaseModelInterface } from "@root/base/BaseModel"; import SSHConfig, { SSHConfigInterface } from "@root/tool/ssh-config"; -import { readFileSync, writeFileSync } from "fs"; +import { existsSync, readFileSync, writeFileSync } from "fs"; import upath from 'upath'; import os from 'os'; import * as child_process from 'child_process'; @@ -33,6 +33,8 @@ const DirectAccess = BaseModel.extend>({ /* Manage the ssh_config from .ssh home dir */ this._ssh_config = SSHConfig.parse(readFileSync(_configFilePath).toString()); + + /* Loop every ssh_config collection from .ssh home dir */ for (var a = 0; a < _direct_access.ssh_configs.length; a++) { var sshSection = this._ssh_config.find({ Host: _direct_access.ssh_configs[a].Host }) @@ -44,6 +46,10 @@ const DirectAccess = BaseModel.extend>({ /* Insert the curent new config */ for (var a = 0; a < _direct_access.ssh_configs.length; a++) { + // If the IdentityFile is a relative convert to absolute path + if (existsSync(upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile)) == true) { + _direct_access.ssh_configs[a].IdentityFile = upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile); + } else { } this._ssh_config.append(_direct_access.ssh_configs[a]); } From cfc166441c5c1ce82df299f9fe4ccb5afa761e77 Mon Sep 17 00:00:00 2001 From: donny rolanda Date: Wed, 13 Jul 2022 12:13:35 +0800 Subject: [PATCH 5/6] Improvement - If the IdentityFile is a relative convert to absolute path --- src/app/directaccess/compute/DirectAccess.ts | 4 ++++ src/app/init/compute/Config.ts | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/directaccess/compute/DirectAccess.ts b/src/app/directaccess/compute/DirectAccess.ts index 81af7e8..f5649cf 100644 --- a/src/app/directaccess/compute/DirectAccess.ts +++ b/src/app/directaccess/compute/DirectAccess.ts @@ -50,6 +50,10 @@ const DirectAccess = BaseModel.extend>({ if (existsSync(upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile)) == true) { _direct_access.ssh_configs[a].IdentityFile = upath.normalize(process.cwd() + "/" + _direct_access.ssh_configs[a].IdentityFile); } else { } + if (os.platform() == "win32") { + child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Inheritance:r`) + child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Grant:r "%Username%":"(R)"`) + } this._ssh_config.append(_direct_access.ssh_configs[a]); } diff --git a/src/app/init/compute/Config.ts b/src/app/init/compute/Config.ts index 1b7456a..18744a2 100644 --- a/src/app/init/compute/Config.ts +++ b/src/app/init/compute/Config.ts @@ -9,6 +9,7 @@ import YAML from 'yaml' import os from 'os'; import { MasterDataInterface } from "@root/bootstrap/StartMasterData"; import filendir from 'filendir'; +import { execSync } from "child_process"; export const CONFIG_FILE_NAME = "sync-config.yaml"; export type trigger_permission = { @@ -189,7 +190,12 @@ const Config = BaseModel.extend({ } /** @type {boolean} */ let hasPasspharse = await this._hasPassphrase(this._config.privateKey); - chmodSync(this._config.privateKey, 0o400); + if (os.platform() == "win32") { + execSync(`Icacls "${this._config.privateKey}" /Inheritance:r`) + execSync(`Icacls "${this._config.privateKey}" /Grant:r "%Username%":"(R)"`) + }else{ + chmodSync(this._config.privateKey, 0o400); + } // console.log(this._config.privateKey); if (hasPasspharse == true) { this.cli.read("Enter Passphrase to connect : ", true).then(answer => { From ea503de2d145b1df1b7987daa4dea424951dc32f Mon Sep 17 00:00:00 2001 From: donny rolanda Date: Fri, 15 Jul 2022 10:21:27 +0800 Subject: [PATCH 6/6] Improvement - Add Full access for username of windows --- src/app/directaccess/compute/DirectAccess.ts | 3 ++- src/app/init/compute/Config.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app/directaccess/compute/DirectAccess.ts b/src/app/directaccess/compute/DirectAccess.ts index f5649cf..3b2c5e3 100644 --- a/src/app/directaccess/compute/DirectAccess.ts +++ b/src/app/directaccess/compute/DirectAccess.ts @@ -52,7 +52,8 @@ const DirectAccess = BaseModel.extend>({ } else { } if (os.platform() == "win32") { child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Inheritance:r`) - child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Grant:r "%Username%":"(R)"`) + child_process.execSync(`Icacls "${_direct_access.ssh_configs[a].IdentityFile}" /Grant:r "%username%":"(F)"`) + // Source : https://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows } this._ssh_config.append(_direct_access.ssh_configs[a]); } diff --git a/src/app/init/compute/Config.ts b/src/app/init/compute/Config.ts index 18744a2..0950cdb 100644 --- a/src/app/init/compute/Config.ts +++ b/src/app/init/compute/Config.ts @@ -192,7 +192,8 @@ const Config = BaseModel.extend({ let hasPasspharse = await this._hasPassphrase(this._config.privateKey); if (os.platform() == "win32") { execSync(`Icacls "${this._config.privateKey}" /Inheritance:r`) - execSync(`Icacls "${this._config.privateKey}" /Grant:r "%Username%":"(R)"`) + execSync(`Icacls "${this._config.privateKey}" /Grant:r "%username%":"(F)"`) + // Source :: https://stackoverflow.com/questions/2928738/how-to-grant-permission-to-users-for-a-directory-using-command-line-in-windows }else{ chmodSync(this._config.privateKey, 0o400); }