Esempio n. 1
0
 /**
  * Creates the domain
  * 
  * @global type $err
  * @param type $domainData
  * @param Console_CommandLine_Result $commandLineResult
  * @return int domain_id
  * @throws Exception
  */
 function createDomain($domainData, $commandLineResult)
 {
     global $err;
     global $cuid;
     // Retrieves command line options
     $options = $commandLineResult->options;
     // Retrieve forced uid if exists
     $force_uid = (int) $options["force_uid"];
     if ($force_uid) {
         $this->giveQuota(array("cuid" => $force_uid, "type" => "dom"));
     }
     // Retrieve domain
     $domain = $domainData["domaine"];
     $dns = $domainData["gesdns"];
     $dns_action = $domainData["dns_action"];
     $dns_result = $domainData["dns_result"];
     $mail = $domainData["gesmx"];
     $zonettl = $domainData["zonettl"];
     $noerase = $domainData['noerase'];
     $force = true;
     $isslave = false;
     $slavedom = "";
     // Attempts to insert domain
     $this->domain->lock();
     if (!$this->domain->add_domain($domain, $dns, $noerase, $force, $isslave, $slavedom)) {
         throw new Exception("Failed to create {$domain} : " . $err->errstr());
     }
     // Retrieve new domain id
     $query = "SELECT id FROM domaines WHERE domaine='{$domain}'";
     $result = current($this->query($query));
     $domain_id = (int) $result['id'];
     if (!$domain_id) {
         throw new Exception("Failed to retrieve domain_id for {$domain} ");
     }
     // Attempts to insert subdomains
     $subdomainsList = $domainData["sub_domains"];
     $subdomainsErrorList = array();
     foreach ($subdomainsList as $subdomainData) {
         $compte = $subdomainData["compte"];
         $domain = $subdomainData["domaine"];
         $sub = $subdomainData["sub"];
         $dest = $subdomainData["valeur"];
         $type = $subdomainData["type"];
         $web_action = $subdomainData["web_action"];
         $web_result = $subdomainData["web_result"];
         $enable = $subdomainData["enable"];
         if (!array_key_exists($type, $this->domainesTypeCache)) {
             $valid = $this->domain->domains_type_target_values($type);
             $this->domainesTypeCache[$type] = $valid;
         }
         if (!$this->domainesTypeCache[$type]) {
             $subdomainsErrorList[] = "Type '{$type}' is invalid ({$sub}.{$domain})";
             continue;
         }
         if (!$this->domain->set_sub_domain($domain, $sub, $type, $dest)) {
             $subdomainsErrorList[] = "Failed to create {$sub}.{$domain} : " . $err->errstr();
         }
     }
     if (count($subdomainsErrorList)) {
         return array("code" => 1, "message" => "Errors with subdomains : " . implode(" / ", $subdomainsErrorList));
     }
     return array("code" => 0, "message" => "ok", "domain_id" => $domain_id);
 }
Esempio n. 2
0
function sub_domains_edit($domain, $sub_domain_id = false)
{
    global $admin, $err, $oldid, $isedit;
    $dom = new m_dom();
    $dom->lock();
    if (!($r = $dom->get_domain_all($domain))) {
        $error = $err->errstr();
    }
    /*
    if (! empty($sub)) {
       if (!$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value)) {
         $error=$err->errstr();
       }
    }
    */
    $sd = $dom->get_sub_domain_all($sub_domain_id);
    $type = $sd['type'];
    $sub = $sd['name'];
    $dom->unlock();
    ?>

<form action="dom_subdoedit.php" method="post" name="main" id="main">
    <table border="0">
        <tr>
            <td>
            <input type="hidden" name="domain" value="<?php 
    ehe($domain);
    ?>
" />
            <input type="hidden" name="sub_domain_id" value="<?php 
    echo $sub_domain_id;
    ?>
" />
            <input type="hidden" name="action" value="add" />
  <?php 
    if ($isedit) {
        __("Edit a subdomain:");
    } else {
        __("Create a subdomain:");
    }
    ?>
</td><td>
<input type="text" class="int" name="sub" style="text-align:right" value="<?php 
    ehe($sub);
    ?>
" size="22" id="sub" /><span class="int" id="newsubname">.<?php 
    echo $domain;
    ?>
</span></td>
        </tr>
    <?php 
    $first_advanced = true;
    $lst_advanced = array();
    foreach ($dom->domains_type_lst() as $dt) {
        // If this type is disabled AND it's not the type in use here, continue
        if ($dt['enable'] == 'NONE' && strtoupper($type) != strtoupper($dt['name'])) {
            continue;
        }
        // If this type is only for ADMIN and i'm not an admin, continue (oldid is to check if we are an admin who take user identity)
        if ($dt['enable'] == 'ADMIN' && (!$admin->enabled and !intval($oldid))) {
            continue;
        }
        if (!$r['dns'] and $dt['need_dns']) {
            continue;
        }
        $targval = strtoupper($type) == strtoupper($dt['name']) ? $sd['dest'] : '';
        if ($dt['advanced']) {
            $lst_advanced[] = $dt['name'];
            if ($first_advanced) {
                $first_advanced = false;
                echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>";
                echo "<tr id='domtype_show' onClick=\"domtype_advanced_show();\"><td colspan='2'><a href=\"javascript:domtype_advanced_show();\"><b>+ ";
                __("Show advanced options");
                echo "</b></a></td></tr>";
                echo "<tr id='domtype_hide' onClick=\"domtype_advanced_hide();\" style='display:none'><td colspan='2'><a href=\"javascript:domtype_advanced_hide();\"><b>- ";
                __("Hide advanced options");
                echo "</b></a></td></tr>";
                echo "<tr><td colspan=\"2\" class=\"advdom\"></td></tr>";
            }
        }
        ?>
    <tr id="tr_<?php 
        echo $dt['name'];
        ?>
">
      <td>
        <input type="radio" id="r_<?php 
        echo $dt['name'];
        ?>
" class="inc" name="type" value="<?php 
        echo $dt['name'];
        ?>
" <?php 
        cbox(strtoupper($type) == strtoupper($dt['name']));
        ?>
 OnClick="getElementById('t_<?php 
        echo $dt['name'];
        ?>
').focus();"/>
        <label for="r_<?php 
        echo $dt['name'];
        ?>
"><?php 
        __($dt['description']);
        ?>
</label>
      </td>
      <td>
        <?php 
        switch ($dt['target']) {
            case "DIRECTORY":
                ?>
            <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
" value="<?php 
                ehe($targval);
                ?>
" size="28" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" />
            <?php 
                display_browser($targval, "main.t_" . $dt['name']);
                break;
            case "URL":
                ?>
              <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
" value="<?php 
                ehe(empty($targval) ? 'http://' : $targval);
                ?>
" size="50" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" />
              <small><?php 
                __("(enter an URL here)");
                ?>
</small><?php 
                break;
            case 'IP':
                ?>
              <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
"  value="<?php 
                ehe($targval);
                ?>
" size="16" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" />
            <small><?php 
                __("(enter an IPv4 address, for example 192.168.1.2)");
                ?>
</small><?php 
                break;
            case 'IPV6':
                ?>
            <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
" value="<?php 
                ehe($targval);
                ?>
" size="32" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" /> 
            <small><?php 
                __("(enter an IPv6 address, for example 2001:0910::0)");
                ?>
</small><?php 
                break;
            case 'TXT':
                ?>
              <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
" value="<?php 
                ehe($targval);
                ?>
" size="32" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" />
            <small><?php 
                __("(enter a TXT content for this domain)");
                ?>
</small><?php 
                break;
            case 'DOMAIN':
                ?>
              <input type="text" class="int" name="t_<?php 
                echo $dt['name'];
                ?>
" id="t_<?php 
                echo $dt['name'];
                ?>
" value="<?php 
                ehe($targval);
                ?>
" size="32" onKeyPress="getElementById('r_<?php 
                echo $dt['name'];
                ?>
').checked=true;" /> 
            <small><?php 
                __("(enter a domain name or subdomain)");
                ?>
</small><?php 
                break;
            case "NONE":
            default:
                break;
        }
        // switch
        ?>
      </td>
    </tr>
    <?php 
    }
    // foreach
    ?>

        <tr class="trbtn">
            <td colspan="2"><input type="submit" class="inb ok" name="add" onclick='return check_type_selected();' value="<?php 
    if ($isedit) {
        __("Edit this subdomain");
    } else {
        __("Add this subdomain");
    }
    ?>
" /></td>
        </tr>
    </table>
</form>

<script type="text/javascript">

function check_type_selected() {
  if ( $('input[name=type]:radio:checked').val() ) {
    // there is a value
    var ll = $('input[name=type]:radio:checked').val();
    var tt = $('#t_'+ll);
    if ( tt.length == 0 ) {
      // this element do not exist, so OK
      return true;
    }
    if ( tt.val() == '' ) {
      alert("<?php 
    __("Missing value for this sub-domain");
    ?>
");
      return false;
    }
  
    return true;
  }
  alert("<?php 
    __("Please select a type for this sub-domain");
    ?>
");
  return false;
}

function domtype_advanced_hide() { 
  <?php 
    foreach ($lst_advanced as $adv) {
        echo "\$(\"#tr_{$adv}\").hide();\n";
    }
    ?>
  $("#domtype_show").show();
  $("#domtype_hide").hide();
}
function domtype_advanced_show() { 
  <?php 
    foreach ($lst_advanced as $adv) {
        echo "\$(\"#tr_{$adv}\").show();\n";
    }
    ?>
  $("#domtype_show").hide();
  $("#domtype_hide").show();
}

<?php 
    if (isset($type) && in_array($type, $lst_advanced)) {
        // if it's an edit of an advanced option, we need to show the advanced options
        ?>
  domtype_advanced_show();
<?php 
    } else {
        ?>
  domtype_advanced_hide();
<?php 
    }
    // if advanced
    ?>

</script>
<?php 
}
Esempio n. 3
0
#!/usr/bin/php
<?php 
// test de la fonction whois :
include "../bureau/class/m_err.php";
include "../bureau/class/m_dom.php";
$err = new m_err();
$dom = new m_dom();
$doms = array("dns.be", "eurid.eu", "sonntag.name", "alternc.com", "alternc.org", "alternc.net", "sonntag.fr");
foreach ($doms as $d) {
    echo "\n";
    echo "Searching for whois for domain [{$d}]\n";
    $srv = $dom->whois($d);
    if (is_array($srv)) {
        foreach ($srv as $s) {
            echo "\tNameserver: {$s}\n";
        }
    } else {
        echo "\tNo nameserver found !\n";
    }
}
Esempio n. 4
0
 /**
  * Return the var for a specific environnement :
  *   * logged via $fqdn url
  *   * the user is $uid
  *   * $var if we want only 1 var instead of all of them
  * 
  * If $fqdn and $uid aren't specified, return the default value
  * 
  * @global m_mysql $db
  * @global m_err $err
  * @param string $fqdn
  * @param int $uid
  * @param string $var
  * @return array
  */
 function get_impersonated($fqdn = null, $uid = null, $var = null)
 {
     global $db, $err;
     $arr_var = $this->variables_list();
     // Get some vars we are going to need.
     if ($fqdn != NULL) {
         $sub_infos = m_dom::get_sub_domain_id_and_member_by_name(strtolower($fqdn));
     } else {
         $sub_infos = false;
     }
     if ($uid != NULL) {
         $creator = m_mem::get_creator_by_uid($uid);
     } else {
         $creator = false;
     }
     $variables = array();
     // Browse the array in the specific order of the strata
     foreach ($this->strata_order as $strata) {
         if (!isset($arr_var[$strata]) || !is_array($arr_var[$strata])) {
             continue;
         }
         switch ($strata) {
             case 'DEFAULT':
                 //          $variables = $this->variable_merge(array(),$arr_var['DEFAULT'][NULL]);
                 $variablesList = current($arr_var["DEFAULT"]);
                 $variables = $this->variable_merge(array(), $variablesList);
                 break;
             case 'GLOBAL':
                 $variables = $this->variable_merge($variables, $arr_var['GLOBAL'][NULL]);
                 break;
             case 'FQDN_CREATOR':
                 if (is_array($sub_infos) && isset($arr_var['FQDN_CREATOR'][$sub_infos['member_id']]) && is_array($arr_var['FQDN_CREATOR'][$sub_infos['member_id']])) {
                     $variables = $this->variable_merge($variables, $arr_var['FQDN_CREATOR'][$sub_infos['member_id']]);
                 }
                 break;
             case 'FQDN':
                 if (is_array($sub_infos) && isset($arr_var['FQDN'][$sub_infos['sub_id']]) && is_array($arr_var['FQDN'][$sub_infos['sub_id']])) {
                     $variables = $this->variable_merge($variables, $arr_var['FQDN'][$sub_infos['sub_id']]);
                 }
                 break;
             case 'CREATOR':
                 if ($creator && isset($arr_var['CREATOR'][$creator]) && is_array($arr_var['CREATOR'][$creator])) {
                     $variables = $this->variable_merge($variables, $arr_var['CREATOR'][$creator]);
                 }
                 break;
             case 'MEMBER':
                 if ($uid && isset($arr_var['MEMBER'][$uid]) && is_array($arr_var['MEMBER'][$uid])) {
                     $variables = $this->variable_merge($variables, $arr_var['MEMBER'][$uid]);
                 }
                 break;
             case 'DOMAIN':
                 //FIXME TODO
                 break;
         }
         //switch
     }
     //foreach
     // Replace needed vars
     foreach ($variables as $vv => $hh) {
         if (!isset($hh['value']) || empty($hh['value'])) {
             continue;
         }
         if (is_array($hh['value'])) {
             foreach ($hh["value"] as $key => $val) {
                 $variables[$vv]['value'][$key] = strtr($hh['value'][$key], $this->replace_array);
             }
         } else {
             $variables[$vv]['value'] = strtr($hh['value'], $this->replace_array);
         }
     }
     if ($var && isset($variables[$var])) {
         return $variables[$var];
     } else {
         return $variables;
     }
 }