Trigger ISPConfig vhost folders creation - php

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

Related

how to send message remotely to kafka

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.

Status call back not working in twilio

Iam using twilio Programmable voice while trying to Tracking the call status of an outbound call and save it log whether the user answer or cut the call ,but the problem i didn't get any log and while checking in twilio debugger it showing error:15003
Here my Code:
<?php
require_once "vendor/autoload.php";
use Twilio\Rest\Client;
$AccountSid= 'AC04421826f5ffaa58eaefa1ba6984dac2';
$AuthToken= 'token';
$client = new Client($AccountSid, $AuthToken);
try {
$call = $client->account->calls->create(
// to call.
"+9120000000",
"+1209000001",
array(
"url" => "http://demo.twilio.com/docs/voice.xml",
"method" => "GET",
"statusCallbackMethod" => "POST",
"statusCallback" => "localhost/twilio/log.txt",
"statusCallbackEvent" => array(
"initiated", "ringing", "answered", "completed"
)
)
);
echo "Started call: " . $call->sid;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
Twilio evangelist here.
Looks like you have set the statuscallback property to point to localhost.
localhost is a domain that is only reachable from your own local machine so Twilio does not how to reach the localhost running on your local machine.
I'd suggest checking out ngrok which is a simple tool that lets you expose the web server running on your local machine via a publicly addressable domain.
Hope that helps
The issue here is a GET or POST request cannot be written directly to log.txt file and the file should be hosted on a http domain.
change the following code
"statusCallback" => "localhost/twilio/log.txt",
to
"statusCallback" => "http://yourdomain.com/twilio/log.php",
as you rather need an additional file log.php which can write to log.txt
<?php
$status = implode(',',$_REQUEST) ;
$handle = fopen('log.txt','a');
fwrite($handle, $status);
?>

aws php sdk - function works on local host and in console, but not on browser when on server

I'm having an issue where my php function works when I call it from the server's command line, but not on the web page. It also works on the web page when I have it hosted locally through WAMP.
Any ideas what might be the issue?
function getCFTemplateSummary($CFUrl){
//init client
$client = new CloudFormationClient(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2010-05-15',
'http' => [ 'verify' => false ]
));
try {
$result = $client->getTemplateSummary(['TemplateURL' => $CFUrl]);
}catch(\Aws\CloudFormation\Exception\CloudFormationException $e){
echo $e->getMessage();
}catch(\Aws\Exception\AwsException $e){
echo $e->getMessage();
}
echo "<pre>";
print_r($result);
echo "inside the function";
echo "</pre>";
return $result;
}
I was able to trace down the issue to this by trial and error commenting ...but not sure how to proceed debugging as I don't see any error messages.
$result = $client->getTemplateSummary(['TemplateURL' => $CFUrl]);
Try catching Exception instead of \Aws\CloudFormation\CloudFormationException, it's possible that a different Exception (e.g., incorrectly configured AWS credentials) is being thrown from your server that you aren't explicitly catching in your current code.

yii-node-socket is not working for me

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?

ssh2_auth_pubkey_file authentication always fails

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>";

Categories