我正在尝试使用mscdex/ssh2以root身份登录远程linux机器,我试图实现的步骤是:
但我在第二部分失败了,我无法正确设置密码,这是我的代码.
conn.on('ready', function() {
conn.exec('sudo -s ls /', { pty: true }, (err, stream) => {
if (err) {
res.send(err);
}
stream.on('exit', (code, signal) => {
console.log(`Stream :: close :: code: ${code}, signal: ${signal}`);
});
stream.on('data', data => {
// here it's where supposedly the password should be given
stream.write('r00tpa$$word' + '\n');
console.log(data);
});
});
}).connect({
host: '192.168.100.100',
username: 'fakeAdmin',
password: 'fakePassword'
});
Run Code Online (Sandbox Code Playgroud)
我已经将pty选项设置为true,但我只是在promt上收到错误消息.
更新:
这是我的新代码片段:
const Client = require('ssh2').Client;
const conn = new Client(); …Run Code Online (Sandbox Code Playgroud) 我有这个问题,我不知道为什么。在 for 循环中,我尝试为对象数组中的每个对象分配一个新的键值对,这是来自猫鼬查询的响应。例如
obj = {
value1: "someValue",
value2: [],
value3: {}
value4: {
id: "someId"
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试做一个 obj.value4.newKey = "newValue" 似乎什么也没有发生,但问题是当我做
console.log(obj.value4.newKey) // prints "newValue"
Run Code Online (Sandbox Code Playgroud)
但是当我这样做的时候
console.log(obj)
Run Code Online (Sandbox Code Playgroud)
或者
console.log(obj.value4)
Run Code Online (Sandbox Code Playgroud)
之前添加的新密钥似乎不存在
我已经按照w3c的说明使用javascript设置了元素的css属性,但是我无法弄清楚如何使用json对象。
我的代码是这样的:
var style = {
position:'fixed',
top:0,
right:0,
bottom:0,
left:0,
background:'red'
}
var el = document.getElementById( 'some_id' );
for( var key in style ){
el.style.key = style[key]
}
Run Code Online (Sandbox Code Playgroud)
但是当运行我的脚本时,我得到“ Uncaught TypeError:无法读取null的属性'style'
目前我有一个标准的 Laravel 5 项目,例如:
Laravel Directory
app Directory
bootstrap Directory
config Directory
database Directory
public Directory
resources Directory
routes Directory
storage Directory
tests Directory
vendor Directory
Run Code Online (Sandbox Code Playgroud)
我想要做的是从应用程序中取出 public 和 resources 文件夹并将它们放在不同的项目中,这样我将仅将 laravel 部分用于后端目的,而前端部分我将在外部项目上管理它。例如:
Laravel Directory
app Directory
bootstrap Directory
config Directory
database Directory
routes Directory
storage Directory
tests Directory
vendor Directory
Frontend project
index.html
app folder
css folder
assets
Run Code Online (Sandbox Code Playgroud)
有什么建议或想法可以做到吗?