Changeset 2570
- Timestamp:
- 10/04/09 17:38:04 (4 years ago)
- Location:
- alternc-jabber/bureau/class
- Files:
-
- 2 edited
-
XMPPHP/XMPP.php (modified) (1 diff)
-
m_jabber.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
alternc-jabber/bureau/class/XMPPHP/XMPP.php
r2569 r2570 236 236 237 237 } 238 /** 239 * Send XMPP Query 240 * 241 * @param string $to 242 * @param string $body 243 * @param string $type 244 * @param string $subject 245 */ 246 public function query($to, $queryns, $payload = null) { 247 $to = htmlspecialchars($to); 248 $command = htmlspecialchars($command); 249 $id = $this->getID(); 250 $this->addIdHandler($id, 'query_iq_handler'); 251 $out = "<iq type=\"set\" to=\"$to\" id=\"$id\">"; 252 $out.= "<query xmlns=\"$queryns\">"; 253 $out.= $payload; 254 $out.= "</query></iq>"; 255 $this->send($out); 256 } 238 257 239 258 -
alternc-jabber/bureau/class/m_jabber.php
r2569 r2570 52 52 var $domains; 53 53 54 /** Configuration variables are 55 * server port login domain pass (for the jabber server driven mode) 56 */ 57 var $conf; 58 59 /** Share handle for the connection to the jabber server 60 */ 61 var $conn; 54 62 55 63 /* ----------------------------------------------------------------- */ … … 58 66 */ 59 67 function m_jabber() { 68 // We read the configuration file 69 $config_file = @fopen('/etc/alternc/jabber.conf', 'r'); 70 if ($config_file) { 71 while (FALSE !== ($line = fgets($config_file))) { 72 if (preg_match('/^([A-Za-z0-9_]*) *= *"?(.*?)"?$/', trim($line), $regs)) { 73 $this->conf[$regs[1]] = $regs[2]; 74 } 75 } 76 fclose($config_file); 77 } 60 78 } 61 79 … … 139 157 // FIXME 140 158 } 159 if ($mode==JABBER_MODE_NO && $oldmode!=JABBER_MODE_NO) { 160 // Deleting a vhost 161 $this->_deletevhost($dom); 162 } 163 if ($mode!=JABBER_MODE_NO && $oldmode==JABBER_MODE_NO) { 164 // Creating a vhost 165 $this->_createvhost($dom); 166 } 141 167 $db->query("UPDATE jabber_dom SET mode='$mode' WHERE dom='$dom' AND user='$cuid';"); 142 168 return true; … … 360 386 return false; 361 387 } 362 echo "A:$account:D:$domain:$cuid:";363 388 $db->query("SELECT id FROM jabber_account WHERE account='$account' AND domain='$domain' AND user='$cuid';"); 364 389 if (!$db->next_record()) { … … 399 424 400 425 function _createaccount($account,$domain,$pass) { 401 echo "<pre>\n"; 402 require_once("/var/alternc/bureau/class/XMPPHP/XMPP.php"); 403 $conn = new XMPPHP_XMPP('elga.lautre.net', 5222, 'root', 'poipoi', 'xmpphp', 'elga.lautre.net', $printlog=true, $loglevel=XMPPHP_Log::LEVEL_VERBOSE); 404 $conn->connect(); 405 $conn->processUntil('session_start'); 406 // $conn->message('benjamin@mailfr.com', 'This is a test message!'); 407 $conn->command('vhost-man@elga.lautre.net', 'VHOSTS_UPDATE', '<x xmlns="jabber:x:data" type="submit" ><field type="text-single" var="VHost" ><value>root.lautre.net</value></field><field type="list-single" var="Enabled" ><value>true</value></field></x>'); 408 $payloads = $conn->processUntil(array('command_result'),3); 426 require_once(dirname(__FILE__)."/XMPPHP/XMPP.php"); 427 $this->conn = new XMPPHP_XMPP($this->conf['server'], $this->conf['port'], $this->conf['login'], $this->conf['passwod'], 'xmpphp', $this->conf['domain'], $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); 428 $this->conn->connect(); 429 $this->conn->processUntil('session_start'); 430 // $this->conn->message('benjamin@mailfr.com', 'This is a test message!'); 431 $this->conn->command($this->conf['server'], 'http://jabber.org/protocol/admin#add-user', '<x xmlns="jabber:x:data" type="submit" ><field type="hidden" var="FORM_TYPE" > <value>http://jabber.org/protocol/admin</value></field><field type="jid-single" var="accountjid" ><value>".$account."@".$domain."</value></field><field type="text-private" var="password" ><value>".$pass."</value></field><field type="text-private" var="password-verify" ><value>".$pass."</value></field><field type="text-single" var="email" ><value>".$account."@".$domain."</value></field></x>'); 432 $payloads = $this->conn->processUntil(array('command_result'),5); 409 433 if (is_array($payloads)) { 410 434 foreach($payloads as $event) { … … 412 436 switch($event[0]) { 413 437 case 'command_result': 414 echo "<pre><b>PAYLOAD:</b>\n";415 print_r($event[1]);416 438 if ($event[1]->attrs['status']=="completed") { 439 $this->conn->disconnect(); 417 440 return true; 418 441 } 419 echo "\n</pre>\n";420 442 break; 421 443 } 422 444 } 423 } else { 424 echo "No Payload..."; 425 } 426 $conn->disconnect(); 427 echo "</pre>\n"; 445 } 446 $this->conn->disconnect(); 447 return false; 448 } 449 450 451 function _deleteaccount($account,$domain) { 452 // Delete a user account. For now there is no way other than in the DB ... 453 $db->query("SELECT uid FROM system_tigase.tig_users WHERE user_id='".$account."@".$domain."';"); 454 if ($db->next_record()) { 455 $uid=$db->Record["uid"]; 456 $db->query("SELECT pval FROM tig_pairs WHERE uid='$uid' AND pkey='password';"); 457 if ($db->next_record()) { 458 $pass=$db->Record["pval"]; 459 460 require_once(dirname(__FILE__)."/XMPPHP/XMPP.php"); 461 $this->conn = new XMPPHP_XMPP($this->conf['server'], $this->conf['port'], $account, $pass, 'xmpphp', $domain, $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); 462 $this->conn->connect(); 463 $this->conn->processUntil('session_start',5); // FIXME : check the result ? 464 $this->conn->query($domain, 'jabber:iq:register', '<remove/>'); 465 $this->conn->disconnect(); 466 return true; 467 468 } else { 469 return false; 470 } 471 } else { 472 return false; 473 } 428 474 return true; 429 475 } 430 476 431 function _deleteaccount($account,$domain) { 477 478 function _updateaccount($account,$domain,$pass) { 479 // Change a user's password. For now there is no way other than in the DB ... 480 $db->query("SELECT uid FROM system_tigase.tig_users WHERE user_id='".$account."@".$domain."';"); 481 if ($db->next_record()) { 482 $uid=$db->Record["uid"]; 483 $db->query("UPDATE tig_pairs SET pval='$pass' WHERE uid='$uid' AND pkey='password';"); 484 return true; 485 } else { 486 return false; 487 } 432 488 return true; 433 489 } 434 function _updateaccount($account,$domain,$pass) { 490 491 492 493 function _createvhost($domain) { 494 require_once(dirname(__FILE__)."/XMPPHP/XMPP.php"); 495 $this->conn = new XMPPHP_XMPP($this->conf['server'], $this->conf['port'], $this->conf['login'], $this->conf['passwod'], 'xmpphp', $this->conf['domain'], $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); 496 $this->conn->connect(); 497 $this->conn->processUntil('session_start'); 498 $this->conn->command('vhost-man@'.$this->conf['server'], 'VHOSTS_UPDATE', '<x xmlns="jabber:x:data" type="submit" ><field type="text-single" var="VHost" ><value>".$domain."</value></field><field type="list-single" var="Enabled" ><value>true</value></field></x>'); 499 $payloads = $this->conn->processUntil(array('command_result'),5); 500 if (is_array($payloads)) { 501 foreach($payloads as $event) { 502 $pl = $event[1]; 503 switch($event[0]) { 504 case 'command_result': 505 if ($event[1]->attrs['status']=="completed") { 506 $this->conn->disconnect(); 507 return true; 508 } 509 break; 510 } 511 } 512 } 513 $this->conn->disconnect(); 514 return false; 515 } 516 517 518 function _deletevhost($domain) { 519 require_once(dirname(__FILE__)."/XMPPHP/XMPP.php"); 520 $this->conn = new XMPPHP_XMPP($this->conf['server'], $this->conf['port'], $this->conf['login'], $this->conf['passwod'], 'xmpphp', $this->conf['domain'], $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO); 521 $this->conn->connect(); 522 $this->conn->processUntil('session_start'); 523 // $this->conn->message('benjamin@mailfr.com', 'This is a test message!'); 524 $this->conn->command('vhost-man@'.$this->conf['server'], 'VHOSTS_REMOVE', '<x xmlns="jabber:x:data" type="submit" ><field type="text-single" var="VHost" ><value>".$domain."</value></field></x>'); 525 $payloads = $this->conn->processUntil(array('command_result'),5); 526 if (is_array($payloads)) { 527 foreach($payloads as $event) { 528 $pl = $event[1]; 529 switch($event[0]) { 530 case 'command_result': 531 if ($event[1]->attrs['status']=="completed") { 532 $this->conn->disconnect(); 533 return true; 534 } 535 break; 536 } 537 } 538 } 539 $this->conn->disconnect(); 540 return false; 541 } 542 543 544 /* ----------------------------------------------------------------- */ 545 /** This function is magically called by the m_mail class when an email 546 * is created. It may be an email or an alias or both. 547 * The parameters are the same as in mail->add_mail 548 * @access private 549 */ 550 function alternc_add_mail($dom,$mail,$pop,$pass,$alias) { 551 global $err,$db,$cuid; 552 $err->error=0; 553 $err->log("jabber","alternc_add_mail",$mail."@".$dom); 554 555 return true; 556 } 557 558 559 /* ----------------------------------------------------------------- */ 560 /** This function is magically called by the m_mail class when an email 561 * is deleted. It may be an email or an alias or both. 562 * The parameters are the same as in mail->del_mail 563 * @access private 564 */ 565 function alternc_del_mail($mail) { 566 global $err,$db,$cuid; 567 $err->error=0; 568 $err->log("jabber","alternc_del_mail",$mail); 435 569 return true; 436 570 } … … 448 582 $err->error=0; 449 583 $err->log("jabber","alternc_del_mx_domain",$dom); 450 451 return true;452 453 584 /* Effacement de tous les mails de ce domaine : */ 454 585 $a=$this->enum_doms_jabber($dom); … … 464 595 /* Effacement du domaine himself */ 465 596 $db->query("DELETE FROM jabber_domain WHERE domain='$dom';"); 597 $this->_deletevhost($dom); 466 598 return true; 467 599 } 600 468 601 469 602
Note: See TracChangeset
for help on using the changeset viewer.
