I'm trying to connect to another machine using PHP's ssh2 functions. I know the ssh keys have been created with no passwords and are distributed correctly, I can ssh user#host in the terminal on my machine to the server.
The PHP function tries to connect to a ip address using an ssh key file:-
function minnerConnect($miner_serial) {
$port = '7822';
$miner_ip = $this->getMinerIp($miner_serial);
$methods = array(
'kex' => 'diffie-hellman-group1-sha1',
'hostkey' => 'ssh-dss',
'client_to_server' => array(
'crypt' => '3des-cbc',
'mac' => 'hmac-md5',
'comp' => 'none'),
'server_to_client' => array(
'crypt' => '3des-cbc',
'mac' => 'hmac-md5',
'comp' => 'none'));
$connection = ssh2_connect($miner_ip, $port, $methods);
if (ssh2_auth_pubkey_file($connection, 'root',
'/root/.ssh/id_dsa.pub',
'/root/.ssh/id_dsa','')) {
echo "Public Key Authentication Successful\n";
} else {
echo "Public Key Authentication Failed";
}
but the error shown is:-
( ! ) Warning: ssh2_auth_pubkey_file(): Authentication failed for root using public key: Callback returned error in /var/www/application/models/miner_model.php on line 95
line 95 is '/root/.ssh/id_dsa','')) {.
Can anybody suggest a fix?
The error in this case was that the keys were generated by the root user, but they need to be accessible by the web server group/owner www-data.
I didn't like the idea of keeping ssh keys in a web folder open to www-data, so I moved the key files to a new user's home directory (/home/keyuser/) then made them accessible to www-data. Authentication was successful.
Even though the original error was saying it found the file, it couldn't read the file.
A better debug method is to try reading the file via php:
$prv_key = file_get_contents('/var/www/application/files/id_dsa');
print "<pre>";
var_export($prv_key);
print "</pre>";
Related
So I am trying to transfer a file via FTPS in Laravel. I am using this code to create a disk
public function disk(){
$protocol = $this->protocol;
if($this->protocol == "ftps"){
$protocol = "ftp";
}
$disk = Storage::build([
'driver' => $this->protocol,
'host' => $this->ip,
'username' => $this->username,
'password' => $this->password,
'ssl' => true,
'passive' => true
]);
return $disk;
}
And I am calling the function within this code-block and try to upload a file:
public function upload(ImportedImage $image){
$filepath = "path/to/file";
if($this->protocol == "ftp" || $this->protocol == "ftps"){
$this->disk()->putFileAs($this->folder, $filepath, $image->original_name);
return "ok";
}
}
But I get this error
ErrorException: ftp_fput(): SSL write failed in /var/www/html/zendee/vendor/league/flysystem/src/Adapter/Ftp.php:275
The object I am accessing has correct a username/password combination, I can access the server via cyberduck/filezilla, so that's not the issue. The protocol is "ftps", (so it gets changed to "ftp" in the "disk" function).
I have already looked into similar problems which where solved by the "passive" parameter. I tried every possible combination of the "ssl" and "passive" option - didn't help unfortunately.
It also said somewhere that I should configure my FTP-Server to allow ssl-only, so I also did that.
Thanks for every kind of help.
I am very new to kafka. I am trying to send a message from my local machine producer to kafka server. I am not able to figure out the issue or what am doing worng.
$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('localhost:9092');
$config->setBrokerVersion('1.0.0');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer(
function() {
return [
[
'topic' => 'test',
'value' => 'test....message.',
'key' => 'testkey',
],
];
}
);
// $producer->setLogger($logger);
$producer->success(function($result) {
print_r($result);
});
$producer->error(function($errorCode) {
var_dump($errorCode);
});
$producer->send(true);
Output:-
Fatal error: Uncaught exception 'Kafka\Exception' with message 'Not has broker can connection metadataBrokerList' in C:\xampp\htdocs\vendor\nmred\kafka-php\src\Kafka\Producer\Process.php on line 193
So you're trying to produce from your local machine to a different server? If that's the case you'll need to update the line
$config->setMetadataBrokerList('localhost:9092');
to point to that server's domain name and not localhost:9092
This is the library https://github.com/weiboad/kafka-php I was using in codeigniter for the producer.
This library works fine.
The issue was that on server port number was changed, it was 29092 actually by default the port is 9092 that why the connection was failing.
Recently I have been trying to integrate nodejs with my existing project to make sure of live updating of feeds. Thus, I used the following yii plugin and followed the instruction:
https://github.com/oncesk/yii-node-socket
The host and port are: bigcat,3001 respectively and I have configured them in the console.php and main.php as mentioned. I started the node server and the log indicated that it was listening to:
Listening bigcat:3001
Set origin: bigcat:*
At my client side I have the following codes (i created it as an external javascript):
// create object and connect to web socket server
var socket = new YiiNodeSocket();
socket.on('event.example', function () {
console.log('*****Trigger test.event, is a global event, for all clients*****');
});
socket.onConnect(function () {
socket.room('example').join(function (isConnected, numberOfRoomClients) {
if (isConnected) {
// catch test.event only for this rooom
console.log('***Joined into room example: members count [' + numberOfRoomClients + ']*****');
this.on('example.room.event', function (data) {
console.log('****WORKING****');
});
}
});
});
My console records that the client is successfully connected.An at homeController test method, I have the following code:
$event = Yii::app()->nodeSocket->getFrameFactory()->createEventFrame();
$event->setRoom('example');
$event->setEventName('example.room.event');
$event['type_string'] = 'hello world';
$event['type_array'] = array(1, 2, 3);
$event['type_object'] = array('one' => 1, 'two' => 2);
$event['type_bool'] = true;
$event['type_integer'] = 11;
$event->send();
When I invoke the homeController test method in another browser, my client should be able to listen to the event and the console should print "IT's WORKING". However, that is not happening. My log is showing the following error:
warn: handshake error INVALID SERVER: server host 127.0.0.1 not allowed for /server
debug: websocket writing 7::/server:undefined
The server side codes seems to not work at all. Could I get some advice on how to get it done. I feel I am close and yet far.
The server.config.js setting is:
module.exports = {
host : 'bigcat',
port : parseInt('3001'),
origin : 'bigcat:*',
allowedServers : ["127.0.1.1"],
dbOptions : {"driver":"dummy","config":[]},
checkClientOrigin : 1,
sessionVarName : 'PHPSESSID'
};
I think you need to add 127.0.0.1 in yii config file -> node socket configuration section -> parameter is allowedServerAddresses
Like this^
'nodeSocket' => array(
'class' => 'application.extensions.yii-node-socket.lib.php.NodeSocket',
'host' => 'localhost', // default is 127.0.0.1, can be ip or domain name, without http
'port' => 3001 // default is 3001, should be integer,
<b>'allowedServerAddresses' => array('127.0.0.1')</b>
)
And can you show node-socket/lib/js/server/server.config.js config file?
I'm making a call to retrieve a user's latest tracks using the last.fm PHP api library. It works perfectly when I run it on my local webserver (localhost), but when I run it on a remote server it sends back an error code of 99, saying that permission has been denied.
Here is my code:
static function readRecentTracks() {
$authVars['apiKey'] = '#########';
$auth = new lastfmApiAuth('setsession', $authVars);
$apiClass = new lastfmApi();
$packageClass = $apiClass->getPackage($auth, 'user');
$method_vars = array(
'user' => 'liquidus219',
'limit' => 25
);
if ($tracks = $packageClass->getRecentTracks($method_vars)) {
echo json_encode($tracks);
} else {
echo '<b>Error '.$packageClass->error['code'].' - </b><i>'.$packageClass->error['desc'].'</i>';
}
}
You can see the code in action at http://liquidus219.freehostia.com/api/?q=readRecentTracks
UPDATE: I have checked/changed the application URL to no effect.
UPDATE: I have gone through the code for the last.fm PHP api, no sign of an error 99 defined anywhere.
I found out in the end that my hosting provider was blocking the call.
I make an script that fill up all ISPConfig tables by itself and now i only need to raise some script to create the needed vhost and the rest of the symblink needed for apache to work.
My Script is working like a charm since i can view all the data correctly using the ISPConfig frontend.
Digging into the ISPConfig panel i see a RaiseEvent function triggered everytime a record is created but i can't trace where it ends and how it perform the creation of the symblink.
Maybe calling some function or cron it can work.
I'm using Apache 2 + PHP 5.3 + MySQL + ISPConfig 3 on Ubuntu Server 10.4
Ok I respond myself.
Since version 3 ISPConfig came with a simple API that let you performe some operation like Adding FTP Users, Websites and Databases.
I left here an example of how to create a database:
$params_db = array(
'server_id' => '1',
'system_user' => "web10",
'system_group' => 'client0',
'active' => 'y',
'type' => 'mysql',
'database_name' => $NAME,
'database_user' => $NAME,
'database_password' => '123456',
'database_charset' => 'utf8',
'remote_access' => 'n',
);
Next we have to create on the ISPConfig panel a "remote user" that allow to comunicate using the webservice.
$soap_username = 'whatever';
$soap_password = 'h4ck3m3';
$soap_location = 'http://localhost:8080/remote/index.php';
$soap_uri = 'http://localhost:8080/remote/';
$client = new SoapClient(null, array('location' => $soap_location, 'uri' => $soap_uri));
So, what's next?
Next we call the webserver function like this:
try
{
//* Login to the remote server
if( $session_id = $client->login($soap_username,$soap_password))
{
echo 'Logged into remote server sucessfully. The SessionID is '.$session_id. "\n";
$client->sites_database_add($session_id, $client_id, $params_db);
//* Logout
if($client->logout($session_id))
{
echo "DB Created\n";
}
}
}
catch (SoapFault $e)
{
die('SOAP Error: '.$e->getMessage());
}
For more information check out this link of howtogeek website: http://www.howtoforge.com/how-to-create-remote-api-scripts-for-ispconfig-3