[英]How to using phpseclib on laravel 5 php
I'm making an application based laravel that allows it to communicate with a linux server via SSH, I usually use phpseclib to communicate with servers such as rebooting and others, but when I build the application with laravel I could not or would rather not see the way how to integrate with laravel I tried to include manual of php but still could not error Class 'phpseclib\\Net\\ Net_SSH2' not found, my current code 我正在制作一个基于应用程序的laravel,该应用程序允许它通过SSH与linux服务器通信,我通常使用phpseclib与服务器通信,例如重新启动和其他服务器,但是当我使用laravel构建应用程序时,我无法或宁愿看不到如何与laravel集成的方式我尝试包括php手册,但仍然无法出错未找到类'phpseclib \\ Net \\ Net_SSH2',我当前的代码
public function store(Request $request)
{
// create ssh account and inserted into database here
if(Auth::check()) // make sure user has been logging on
{
if($dump = DB::table('servers')->where('key', $request->_key)->get())
{
if($prices = DB::table('app_data')->get())
{
$price = $prices[0]->prices;
if(DB::table('ssh_users')->where('name', $request->sshname)->where('on_server', $dump[0]->ip)->count() > 0 )
{
return view('create')->with('userexist', $request->sshname);
}
else
{
include(app_path() . "/lib/phpseclib/phpseclib/phpseclib/Net/SSH2.php");
$command = new \phpseclib\Net\Net_SSH2($dump[0]->ip);
$valid = array(
'sshuser' => $request->sshname,
'sshpass' => $request->sshpass,
'sshcreated' => date('d/m/Y'),
'sshexpired' => $request->sshexpired,
'onserver' => $dump[0]->name,
'serveruser' => $dump[0]->user,
'serverpass' => $dump[0]->password,
'sshprice' => $price,
'command' => $command
);
if(DB::table('ssh_users')->insert([
'name' => $request->sshname,
'password' => $request->sshpass,
'created_at' => date('d/m/Y'),
'expired_on' => $request->sshexpired,
'on_server' => $dump[0]->ip,
'reseller' => Auth::user()->name
])) {
return view('create')->with('valid', $valid);
}
}
}
else
{
return view('create')->with('error', $request->sshname);
}
}
else
{
return view('create')->with('serverabort', $request->sshname);
}
}
}
Solution 1: 解决方案1:
Check /lib/phpseclib/phpseclib/phpseclib/Net/SSH2.php
and note what class name is used, it may be SSH2
, and not Net_SSH2
(pre PSR-4 namespacing). 检查
/lib/phpseclib/phpseclib/phpseclib/Net/SSH2.php
并注意使用了什么类名,它可能是SSH2
,而不是Net_SSH2
(PSR-4命名Net_SSH2
之前)。
Then update the line, eg to: 然后更新该行,例如:
$command = new \\phpseclib\\Net\\SSH2($dump[0]->ip); $ command = new \\ phpseclib \\ Net \\ SSH2($ dump [0]-> ip);
Solution 2: 解决方案2:
Install phpseclib as a composer package 将phpseclib安装为作曲家软件包
composer require phpseclib/phpseclib
Then it will be autoloaded and you won't need the include()
然后它将自动加载,您将不需要
include()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.