Example #1
0
/**
 * Copyright (C) 2012 Ulteo SAS
 * http://www.ulteo.com
 * Author Julien LANGLOIS <*****@*****.**>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 **/
function webservices_load_server($addr_)
{
    $server = null;
    // First, try to detect the server using the reverse DNS resolution
    $reverse = @gethostbyaddr($addr_);
    if ($reverse !== false && $reverse != $addr_) {
        $server = Abstract_Server::load_by_fqdn($reverse);
    }
    if (is_null($server)) {
        // Then, try to detect the server using the source IP address
        $server = Abstract_Server::load_by_fqdn($addr_);
    }
    return $server;
}
Example #2
0
 public function server_set_fqdn($server_id_, $fqdn_)
 {
     $this->check_authorized('manageServers');
     $server = Abstract_Server::load($server_id_);
     if (!is_object($server)) {
         Logger::error('api', sprintf('Unknown server "%s"', $server_id_));
         return false;
     }
     if (!validate_ip($fqdn_) && !validate_fqdn($fqdn_)) {
         Logger::error('api', sprintf('Internal name "%s" is invalid', $fqdn_));
         return false;
     }
     $fqdn_old = $server->fqdn;
     if ($fqdn_old == $fqdn_) {
         return true;
     }
     $server2 = Abstract_Server::load_by_fqdn($fqdn_);
     if ($server2 != null && $server->id != $server_id_) {
         Logger::error('api', sprintf('Internal name "%s" is already used for another server', $fqdn_));
         return false;
     }
     $server->fqdn = $fqdn_;
     Abstract_Server::save($server);
     $this->log_action('server_set_fqdn', array('id' => $server->id, 'name' => $server->getDisplayName(), 'value' => array('old' => $fqdn_old, 'new' => $fqdn_)));
     return true;
 }