Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: User
- * Date: 3/05/2017
- * Time: 14:39
- */
- require_once __DIR__ . '/vendor/autoload.php';
- use PhpAmqpLib\Connection\AMQPStreamConnection;
- use PhpAmqpLib\Message\AMQPMessage;
- // Check connection
- $servername = "localhost";
- $username = "root";
- $password = "";
- $db = "UUID";
- echo "Connected successfully";
- $connection = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
- $channel = $connection->channel();
- $connection2 = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
- $channel2 = $connection2->channel();
- $channel2->queue_bind('cloud','Cloud','monitoring.logs');
- $data2 = implode(' ', array_slice($argv, 1));
- //$channel->queue_declare('frontend2', false, true, false, false);
- $channel->queue_bind('cloud','Cloud','cloud.emp');
- echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
- $callback = function($msg){
- $bytes = openssl_random_pseudo_bytes(32);
- $hash = base64_encode($bytes);
- $test = simplexml_load_string($msg->body);
- $usernameget = $test->email;
- $passwordget = $hash;
- echo $test->email;
- echo " [x] Received ", "\n" . "username: " . $usernameget . "\n" . "password: " . $passwordget , "\n";
- echo "Begun processing credentials , first it will be stored in local variables" . "<br/>";
- // Loading into local variables
- echo $$test->username;
- echo "Hello " . $usernameget . "<br/>";
- echo "Your password is " . $passwordget . "<br/>";
- $ownAdminname = 'admin';
- $ownAdminpassword = 'integrationcloud';
- $url = 'http://' . $ownAdminname . ':' . $ownAdminpassword . '@10.3.51.18/owncloud/ocs/v1.php/cloud/users';
- echo "Created URL is " . $url . "<br/>";
- $ownCloudPOSTArray = array('userid' => $usernameget, 'password' => $passwordget );
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $response = curl_exec($ch);
- curl_close($ch);
- echo "Response from curl :" . $response;
- echo "<br/>Created a new user in owncloud<br/>";
- $email = $test->email;
- $UUID = $test->UUID;
- echo $UUID;
- $name = $test->username;
- echo $email;
- $servername = "localhost";
- $username = "root";
- $password = "";
- $db = "owncloud";
- $conn2 = new mysqli($servername, $username, $password,$db);
- $sql = "UPDATE oc_accounts SET email='$email' WHERE user_id ='$name'";
- if ($conn2->query($sql) === TRUE) {
- $t2=time();
- $data2 = <<<XML
- <xml>
- <sender>Cloud</sender>
- <status>200</status>
- <message>User aangemaakt : $usernameget</message>
- <time>$t2</time>
- </xml>
- XML;
- echo "Record updated successfully";
- } else {
- echo "Error updating record: " . $conn2->error;
- }
- $servername = "localhost";
- $username = "root";
- $password = "";
- $db = "UUID";
- // Create connection
- $conn=new mysqli($servername,$username,$password,$db);
- $stmt = $conn->prepare("INSERT INTO owncloud (UUID,UserName) VALUES (?,?)");
- $stmt->bind_param("ss", $UUID,$name);
- // set parameters and execute
- $stmt->execute();
- echo " [x] Done", "\n";
- $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
- };
- $t2=time();
- $data2 = <<<XML
- <xml>
- <sender>Cloud</sender>
- <status>200</status>
- <message>User aangemaakt : $usernameget</message>
- <time>$t2</time>
- </xml>
- XML;
- $msg = new AMQPMessage($data2,
- array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
- );
- $channel2->basic_publish($msg, 'Cloud', 'monitoring.log');
- echo " [x] Sent ", $data2, "\n";
- $channel2->close();
- $connection2->close();
- $channel->basic_qos(null, 1, null);
- $channel->basic_consume('cloud', '', false, false, false, false, $callback);
- while(count($channel->callbacks)) {
- $channel->wait();
- }
- $channel->close();
- $connection->close();
- ?>
Add Comment
Please, Sign In to add comment