Guest User

Untitled

a guest
May 22nd, 2017
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: User
  5. * Date: 3/05/2017
  6. * Time: 14:39
  7. */
  8.  
  9. require_once __DIR__ . '/vendor/autoload.php';
  10. use PhpAmqpLib\Connection\AMQPStreamConnection;
  11.  
  12. use PhpAmqpLib\Message\AMQPMessage;
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. // Check connection
  23.  
  24. $servername = "localhost";
  25. $username = "root";
  26. $password = "";
  27. $db = "UUID";
  28.  
  29.  
  30. echo "Connected successfully";
  31. $connection = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
  32. $channel = $connection->channel();
  33. $connection2 = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
  34. $channel2 = $connection2->channel();
  35. $channel2->queue_bind('cloud','Cloud','monitoring.logs');
  36. $data2 = implode(' ', array_slice($argv, 1));
  37.  
  38. //$channel->queue_declare('frontend2', false, true, false, false);
  39. $channel->queue_bind('cloud','Cloud','cloud.emp');
  40. echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
  41. $callback = function($msg){
  42.  
  43. $bytes = openssl_random_pseudo_bytes(32);
  44. $hash = base64_encode($bytes);
  45.  
  46. $test = simplexml_load_string($msg->body);
  47. $usernameget = $test->email;
  48. $passwordget = $hash;
  49. echo $test->email;
  50. echo " [x] Received ", "\n" . "username: " . $usernameget . "\n" . "password: " . $passwordget , "\n";
  51. echo "Begun processing credentials , first it will be stored in local variables" . "<br/>";
  52.  
  53. // Loading into local variables
  54. echo $$test->username;
  55. echo "Hello " . $usernameget . "<br/>";
  56. echo "Your password is " . $passwordget . "<br/>";
  57. $ownAdminname = 'admin';
  58. $ownAdminpassword = 'integrationcloud';
  59.  
  60.  
  61. $url = 'http://' . $ownAdminname . ':' . $ownAdminpassword . '@10.3.51.18/owncloud/ocs/v1.php/cloud/users';
  62.  
  63. echo "Created URL is " . $url . "<br/>";
  64.  
  65. $ownCloudPOSTArray = array('userid' => $usernameget, 'password' => $passwordget );
  66.  
  67. $ch = curl_init($url);
  68. curl_setopt($ch, CURLOPT_POST, 1);
  69. curl_setopt($ch, CURLOPT_POSTFIELDS, $ownCloudPOSTArray);
  70. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  71. $response = curl_exec($ch);
  72. curl_close($ch);
  73. echo "Response from curl :" . $response;
  74. echo "<br/>Created a new user in owncloud<br/>";
  75.  
  76.  
  77. $email = $test->email;
  78. $UUID = $test->UUID;
  79. echo $UUID;
  80. $name = $test->username;
  81. echo $email;
  82. $servername = "localhost";
  83. $username = "root";
  84. $password = "";
  85. $db = "owncloud";
  86. $conn2 = new mysqli($servername, $username, $password,$db);
  87. $sql = "UPDATE oc_accounts SET email='$email' WHERE user_id ='$name'";
  88.  
  89. if ($conn2->query($sql) === TRUE) {
  90. $t2=time();
  91. $data2 = <<<XML
  92. <xml>
  93. <sender>Cloud</sender>
  94. <status>200</status>
  95. <message>User aangemaakt : $usernameget</message>
  96. <time>$t2</time>
  97. </xml>
  98. XML;
  99.  
  100. echo "Record updated successfully";
  101. } else {
  102. echo "Error updating record: " . $conn2->error;
  103. }
  104.  
  105.  
  106. $servername = "localhost";
  107. $username = "root";
  108. $password = "";
  109. $db = "UUID";
  110. // Create connection
  111. $conn=new mysqli($servername,$username,$password,$db);
  112.  
  113. $stmt = $conn->prepare("INSERT INTO owncloud (UUID,UserName) VALUES (?,?)");
  114. $stmt->bind_param("ss", $UUID,$name);
  115. // set parameters and execute
  116. $stmt->execute();
  117. echo " [x] Done", "\n";
  118. $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
  119. };
  120.  
  121.  
  122.  
  123. $t2=time();
  124. $data2 = <<<XML
  125. <xml>
  126. <sender>Cloud</sender>
  127. <status>200</status>
  128. <message>User aangemaakt : $usernameget</message>
  129. <time>$t2</time>
  130. </xml>
  131. XML;
  132.  
  133.  
  134. $msg = new AMQPMessage($data2,
  135. array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
  136. );
  137.  
  138. $channel2->basic_publish($msg, 'Cloud', 'monitoring.log');
  139. echo " [x] Sent ", $data2, "\n";
  140. $channel2->close();
  141. $connection2->close();
  142. $channel->basic_qos(null, 1, null);
  143. $channel->basic_consume('cloud', '', false, false, false, false, $callback);
  144. while(count($channel->callbacks)) {
  145. $channel->wait();
  146. }
  147. $channel->close();
  148. $connection->close();
  149. ?>
Add Comment
Please, Sign In to add comment