Changeset 2570


Ignore:
Timestamp:
10/04/09 17:38:04 (4 years ago)
Author:
benjamin
Message:

mode batard pour l'instant, mais cela semble marcher ...

Location:
alternc-jabber/bureau/class
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • alternc-jabber/bureau/class/XMPPHP/XMPP.php

    r2569 r2570  
    236236 
    237237        } 
     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        } 
    238257 
    239258 
  • alternc-jabber/bureau/class/m_jabber.php

    r2569 r2570  
    5252  var $domains; 
    5353 
     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; 
    5462 
    5563  /* ----------------------------------------------------------------- */ 
     
    5866   */ 
    5967  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    } 
    6078  } 
    6179 
     
    139157      // FIXME 
    140158    } 
     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    } 
    141167    $db->query("UPDATE jabber_dom SET mode='$mode' WHERE dom='$dom' AND user='$cuid';"); 
    142168    return true; 
     
    360386      return false; 
    361387    } 
    362     echo "A:$account:D:$domain:$cuid:"; 
    363388    $db->query("SELECT id FROM jabber_account WHERE account='$account' AND domain='$domain' AND user='$cuid';"); 
    364389    if (!$db->next_record()) { 
     
    399424 
    400425  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); 
    409433    if (is_array($payloads)) { 
    410434      foreach($payloads as $event) { 
     
    412436        switch($event[0]) { 
    413437        case 'command_result': 
    414           echo "<pre><b>PAYLOAD:</b>\n"; 
    415           print_r($event[1]); 
    416438          if ($event[1]->attrs['status']=="completed") { 
     439            $this->conn->disconnect(); 
    417440            return true;  
    418441          } 
    419           echo "\n</pre>\n"; 
    420442          break; 
    421443        } 
    422444      } 
    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    } 
    428474    return true; 
    429475  } 
    430476 
    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    } 
    432488    return true; 
    433489  } 
    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); 
    435569    return true; 
    436570  } 
     
    448582    $err->error=0; 
    449583    $err->log("jabber","alternc_del_mx_domain",$dom); 
    450  
    451     return true; 
    452  
    453584    /* Effacement de tous les mails de ce domaine : */ 
    454585    $a=$this->enum_doms_jabber($dom); 
     
    464595    /* Effacement du domaine himself */ 
    465596    $db->query("DELETE FROM jabber_domain WHERE domain='$dom';");      
     597    $this->_deletevhost($dom); 
    466598    return true; 
    467599  } 
     600 
    468601 
    469602 
Note: See TracChangeset for help on using the changeset viewer.