node-7z enoent error 7zip-bin when using password - javascript

I'm trying to use node-7z in my Electron app to decrypt password protected zip files, but whenever I pass a password, I get an enoent error. I'm including 7zip-bin and the .7za file is present at the location and when I console.log 7zip-bin.path7za I'm getting a valid exe.
If I extract a zip that does not have any password, there is no issues and I have ran npm install in both my project root and the node modules folder, is there anything else I am missing?
Thank you for your help.
const { extractFull } = require('node-7z')
const zipbin = require('7zip-bin')
let testFile = zipLocation + "/zip.zip";
const pathTo7zip = zipbin.path7za;
console.log(pathTo7zip); -->Returns .z7a file path
const myStream = extractFull(testFile, installLocation, { password: 'password' }, {
$bin: pathTo7zip,
$progress: true
})
myStream.on('error', (err) => handleError(err));
}
If I add a password using either p: or password: then I get the below error:
Error: spawn 7z ENOENT
at notFoundError (***app\node_modules\cross-spawn\lib\enoent.js:6)
at verifyENOENT (****app\node_modules\cross-spawn\lib\enoent.js:40)
at ChildProcess.cp.emit (*****app\node_modules\cross-spawn\lib\enoent.js:27)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272)
Without a password, I have no issues, but the whole reason I'm using node-7z is for zip/.7z encryption.

This may be a little late, but in case somebody stumbles upon this post, like I did, here's the solution.
As mentioned in the answer here: electron-packager spawn ENOENT
npm install fix-path (https://www.npmjs.com/package/fix-path)
Import/require and run it inside your electron-main.js
const fixPath = require('fix-path');
// or
import fixPath from 'fix-path';
fixPath();
Reason why this happens kinda explained in the description of the package:
GUI apps on macOS don't inherit the $PATH defined in your dotfiles.

Related

Need to check the size of root directory from remote server

I am not able to find the size of root directory of remote ftp/sftp server
I have tried ls -l and du -sh commands, nothing worked
vars.filepath = "sftp://username:password#abc.server.com/root/";
cmd = "ls -l "+vars.filepath;
vars.res = execCommand(cmd, true);
logInfo("size : "+ vars.res);
It should give me the size of the root directory in MB excluding the sub directories size.
With ls and du commands it gave me
-53,cannot access
sftp://username:password#abc.server.com/root/ No such file or directory
But when I try to connect to FTP/SFTP through winscp/filezilla it works.
You can only run commands on the local system using SFTP. Run help to see what commands are available:
sftp> help
I don't think du is available with sftp from command line, you would need to us ssh instead
You could just use SSH but if JS is a must ssh-exec should work
Not tested but should be pretty close
Run
npm i ssh-exec
create file ssh.js
paste : 👇
var exec = require('ssh-exec')
//option 1 requires id_rsa as private key
exec('ls -lh', 'ubuntu#my-remote.com').pipe(process.stdout)
// option 2
//USE ENV VAR LIKE $MY_PWORD DONT HARDCODE PW
exec('du -sh /PATH/TO/DIIR', {
user: '"userName",
host: 'my-remote.com',
key: myKeyFileOrBuffer,
password: '$MY_PWORD'
}).pipe(process.stdout)
/// option 3 what you are trying to do with sftp
exec('ls -lh', 'ubuntu#my-remote.com', function (err, stdout, stderr) {
console.log(err, stdout, stderr)
})

How to use credentials to work with nodegit.push on Windows

Edit: I'm changing the question to suit my current understanding of the problem which has changed significantly.
Original Title: Nodegit seems to be asking for wrong credentials on push
When trying to push using nodegit nothing seems to work on Windows (while they work fine on Linux).
Using SSH
sshKeyFromAgent - error authenticating: failed connecting agent
sshKeyNew - credentials callback is repeatedly (looks like an infinite loop
but I can't be sure)
sshKeyMemoryNew: credentials is called twice and then node exits with no diagnostic (the exit and beforeExit events on process aren't signalled)
Using HTTPS
userpassPlaintextNew: [Error: unknown certificate check failure] errno: -17
Original question follows.
I'm trying to get nodegit to push and the following question seems to address this situation. However I'm not able to get it to work.
I've cloned a repository using SSH and when I try to push, my credentials callback is being called with user git and not motti (which is the actual git user).
try {
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => {
console.log(`Push asked for credentials for '${user}' on ${url}`);
return git.Cred.sshKeyFromAgent(user);
}
}
});
}
catch(err) {
console.log("Error:", err);
}
I get the following output:
Push asked for credentials for 'git' on git#github.[redacted].net:motti/tmp.git
Error: { Error: error authenticating: failed connecting agent errno: -1, errorFunction: 'Remote.push' }
If I try to hardcode motti to the sshKeyFromAgent function the error changes to:
Error: { Error: username does not match previous request errno: -1, errorFunction: 'Remote.push' }
This my first time trying to programmatically use git so I may be missing something basic...
Answer for some questions from comments:
I'm running on windows 10
node v8.9.4
git version 2.15.0.windows.1
nodegit version 0.24.1
the user running node is my primary user which when I use for git in command line works correctly
Instead of using git.Cred.sshKeyFromAgent - you could use git.Cred.sshKeyNew and pass your username / keys along.
const fs = require('fs');
// ...
const username = "git";
const publickey = fs.readFileSync("PATH TO PUBLIC KEY").toString();
const privatekey = fs.readFileSync("PATH TO PRIVATE KEY").toString();
const passphrase = "YOUR PASSPHRASE IF THE KEY HAS ONE";
const cred = await Git.Cred.sshKeyMemoryNew(username, publickey, privatekey, passphrase);
const remote = await repository.getRemote("origin");
await remote.push(["refs/head/master:refs/heads/master"], {
callbacks: {
credentials: (url, user) => cred
}
});
You need to run an ssh agent locally and save your password there. Follow these steps to make it work:
Enable the ssh agent locally (automatically runs on OS X): https://code.visualstudio.com/docs/remote/troubleshooting#_setting-up-the-ssh-agent
Run 'ssh-add' in the same CLI as you're running your nodegit actions and enter your passphrase
I hope this helps because I also struggled a lot with it and it can be very frustrating.

Node.JS exec git command error: Permission denied (publickey)

Question: How can I run git push from node.js with passphrase.
I'm trying to build a small module where I need to run git push from node.js to a remote repo, but I'm getting an error when I with from node.js exec but not from the terminal.
My code.
./command.ts
import * as util from 'util';
const exec = util.promisify(require('child_process').exec);
export default function command(command: string): Promise<string> {
return exec(command, {cwd: process.cwd()}).then((resp) => {
const data = resp.stdout.toString().replace(/[\n\r]/g, '');
return Promise.resolve(data);
});
}
./index.ts
import command from './command';
async function init() {
try {
await command('git add .');
await command('git commit -m "my commit" ');
conat result = await command('git push');
} catch (e) {
console.log(e);
}
}
init();
and when I run ts-node ./index.ts I get the following error.
Error: Command failed: git push
git#hostname.org: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
But when I run git push from the terminal I get prompt with the passphrase and it works.
Any idea on how to solve this issue, is there a way to run git push with passphrase using node.js?
bear in mind that I will love to fix this without any external libs.
Thanks in advance.
As described here, check if the same program works when:
ssh-agent is launched
your key is ssh-add'ed
Not only the prompt should no longer query for your passphrase (now cached by the agent), but your script might benefit from that cache as well.
You may need to add env: process.env to your exec() options if your key is loaded into an ssh-agent process. There are some environment variables ssh-agent exports that other processes use to find ssh-agent to access its keys.

appium-uiautomator2-server-v0.1.8.apk' exited with code 1" while getting badging info

I am trying to learn Appium, using the instructions given in the documentation:
http://appium.io/docs/en/about-appium/getting-started/?lang=en
I have put this code into a file called AppiumTest.js
const wdio = require('webdriverio');
const opts = {
port: 4723,
desiredCapabilities: {
platformName: "Android",
platformVersion: "8.0",
deviceName: "Pixel_API_26",
app: "C:/Users/SStaple/AppData/Local/Android/Sdk/ApiDemos-debug.apk",
automationName: "UiAutomator2"
}
};
const client = wdio.remote(opts);
client
.init()
.click("~App")
.click("~Alert Dialogs")
.back()
.back()
.end();
I am running it from the Node.js command prompt, using the command: node AppiumTest.js, after starting the Appium Server. It was also necessary to have an Android 8 emulator running.
(Appium Server v1.7.1)
I am getting an output in the Appium Server window. There are a number of errors. The first error shown is this:
Error "Command 'C\:\\Users\\SStaple\\AppData\\Local\\Android\\Sdk\\build-tools\\26.0.2\\aapt.exe d badging C\:\\Users\\SStaple\\AppData\\Local\\Programs\\appium-desktop\\resources\\app\\node_modules\\appium\\node_modules\\appium-uiautomator2-driver\\uiautomator2\\appium-uiautomator2-server-v0.1.8.apk' exited with code 1" while getting badging info
I have tried running this command on its own in the Command Prompt:
C:\Users\SStaple\AppData\Local\Android\Sdk\build-tools\26.0.2\aapt.exe d badging C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk
The result I get here is this:
W/zipro (13656): Error opening archive C:\Users\SStaple\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-uiautomator2-driver\uiautomator2\appium-uiautomator2-server-v0.1.8.apk: Invalid file
ERROR: dump failed because no AndroidManifest.xml found
Any ideas?
Update 28/12/2017 - I found the solution!
The file in question looked suspect. It was 0Kb in size!
I downloaded the apk file from https://github.com/appium/appium-uiautomator2-server/releases and used that instead.
This one is 1,518 KB in size.
(Apparently there is some problem with npm not putting that apk file into the right place while beta is installed.)
Having fixed that, I can move on to the next problem!
Its a known issue with apk signing.
You can start with trying to update dependencies:
npm install appium-uiautomator2-driver
npm install appium-adb
If it didn't help, there is more you can try (but that was for Linux):
modify
./node-v6.11.4-linux-armv7l/lib/node_modules/appium/node_modules/appium-adb/build/lib/tools/apk-signing.js so it would return a true even if it looks not signed.
case 20:
context$1$0.prev = 20;
context$1$0.t0 = context$1$0’catch’;
_loggerJs2[‘default’].debug(“App not signed with debug cert.”);
return context$1$0.abrupt(‘return’, true);

Error: write EPIPE on sendFile()?

I'm using the html-pdf module to generate pdfs, using the following code:
var ejs = require('ejs');
var fs = require('fs');
var pdf = require('html-pdf');
var build = function (template, data) {
var html = ejs.compile(fs.readFileSync(template, 'utf8'));
html = html(data);
return html;
}
pdf.create(build('views/print_templates/pm_export_pdf.ejs',
{rows:resolve(rows, user_rows, table_rows,
subproject_rows, milestone_rows, release_rows)}), pdfconfig)
.toFile(function (err, pdf) {
if (err)
return console.log(err);
res.sendFile(pdf.filename);
});
PDFconfig is the config variable for html-pdf. And resolve is my own db resolve function, which is not very relevant in this story.
When I run this locally on OSX 10.10 on my MacBook Pro this works like a charm. But when I run this on my server(centOS), I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)
Has this something to do with permissions maybe? I'm not really sure what I'm doing wrong..
I run the following versions:
Node: 0.10.31
Express: 4.10.7
html-pdf: 1.2.0
For future purposes:
I figured that I had to rebuild my node-modules. I think I accidentally copied the node-modules folder over to the test server on centOS, and phantomjs had build it's dependencies for OSX. I'm still not sure how the error that it threw correspondents with that, but it fixed it.
Also be sure that you have FreeType and fontconfiglib installed.

Categories

Resources