SHARE
TWEET

Untitled

a guest May 22nd, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: User
  5.  * Date: 17/05/2017
  6.  * Time: 10:09
  7.  */
  8.  
  9.  
  10.  
  11. require_once __DIR__ . '/vendor/autoload.php';
  12. use PhpAmqpLib\Connection\AMQPStreamConnection;
  13. use PhpAmqpLib\Message\AMQPMessage;
  14.  
  15. $connection = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
  16. $channel = $connection->channel();
  17. //$channel->queue_declare('frontend2', false, true, false, false);
  18. $channel->queue_bind('cloud','Cloud','cloud.deleteemp');
  19. echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
  20. $callback = function($msg){
  21.  
  22.     $boolStatus = true;
  23.     $test = simplexml_load_string($msg->body);
  24.  
  25.     $uuidget = $test->UUID;
  26.     $usernameget = $test->username;
  27.  
  28.  
  29.     echo " [x] Received ", "\n" .    "username: " . $usernameget . "\n" . "UUID: " . $uuidget , "\n";
  30.     $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
  31.  
  32.  
  33.     $servername = "localhost";
  34.     $username = "root";
  35.     $password = "";
  36.     $dbname = "owncloud";
  37.  
  38. // Create connection
  39.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  40. // Check connection
  41.     if (!$conn) {
  42.         $boolStatus = false;
  43.         die("Connection failed: " . mysqli_connect_error());
  44.     }
  45.  
  46. // sql to delete a record
  47.     $sql = "DELETE FROM oc_users WHERE uid='".$usernameget."'";
  48.  
  49.     if (mysqli_query($conn, $sql)) {
  50.         echo "Record deleted successfully";
  51.     } else {
  52.         $boolStatus = false;
  53.         echo "Error deleting record: " . mysqli_error($conn);
  54.     }
  55.  
  56.  
  57.     // sql to delete a record
  58.     $sql = "DELETE FROM oc_accounts WHERE user_id='".$usernameget."'";
  59.  
  60.     if (mysqli_query($conn, $sql)) {
  61.         echo "Record deleted successfully";
  62.     } else {
  63.         $boolStatus = false;
  64.         echo "Error deleting record: " . mysqli_error($conn);
  65.     }
  66.  
  67.     mysqli_close($conn);
  68.  
  69.  
  70.  
  71.     $servername = "localhost";
  72.     $username = "root";
  73.     $password = "";
  74.     $dbname = "UUID";
  75.  
  76. // Create connection
  77.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  78. // Check connection
  79.     if (!$conn) {
  80.         $boolStatus = FALSE;
  81.         die("Connection failed: " . mysqli_connect_error());
  82.     }
  83.  
  84. // sql to delete a record
  85.     $sql = "DELETE FROM owncloud WHERE UUID='".$uuidget."'";
  86.  
  87.     if (mysqli_query($conn, $sql)) {
  88.         echo "Record deleted successfully";
  89.     } else {
  90.         $boolStatus = false;
  91.         echo "Error deleting record: " . mysqli_error($conn);
  92.     }
  93.  
  94.  
  95.     mysqli_close($conn);
  96.  
  97.  
  98.     //loggen naar monitoring
  99.     $connection2 = new AMQPStreamConnection('10.3.51.31', 5672, 'Cloud', 'integrationcloud');
  100.     $channel2 = $connection2->channel();
  101.     $channel2->queue_bind('monitoring','Cloud','monitoring.log');
  102.  
  103.  
  104.  
  105.     $t2=time();
  106. if ($boolStatus == true) {
  107.     if (empty($data)) $data = <<<XML
  108. <xml>
  109.     <sender>Cloud</sender>
  110.     <status>200</status>
  111.     <time>$t2</time>
  112.     <message>Deleted succesfully an employee.</message>
  113. </xml>
  114. XML;
  115. } else {
  116.  
  117.     if (empty($data)) $data = <<<XML
  118. <xml>
  119.     <sender>Cloud</sender>
  120.     <status>300</status>
  121.     <time>$t2</time>
  122.     <message>Could not delete an employee in owncloud.</message>
  123. </xml>
  124. XML;
  125. }
  126.     $msg = new AMQPMessage($data,
  127.         array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
  128.     );
  129.  
  130.     $channel2->basic_publish($msg, 'Cloud', 'monitoring.log');
  131.  
  132.     echo " [x] Sent ", $data, "\n";
  133.  
  134.     $channel2->close();
  135.     $connection2->close();
  136.  
  137.  
  138. };
  139. $channel->basic_qos(null, 1, null);
  140. $channel->basic_consume('cloud', '', false, false, false, false, $callback);
  141. while(count($channel->callbacks)) {
  142.     $channel->wait();
  143. }
  144. $channel->close();
  145. $connection->close();
  146. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top