Exemplo n.º 1
0
function checkSubnet() {
    /* Check that the given subnet is not contained into an existing subnet */
    $subnet = $_POST["subnet"];
    $netmask = $_POST["netmask"];
    foreach(getSubnets("") as $dn => $entry) {
        $sub = $entry[1]["cn"][0];
        $mask = $entry[1]["dhcpNetMask"][0];
        if (ipInNetwork($subnet, $sub, $mask, True)) {
            $error = sprintf(_T("The given network address belongs to the already existing DHCP subnet %s / %s."), $sub, $mask);
            setFormError("subnet");
            setFormError("netmask");
            break;
        }
    }
    if (isset($error)) {
        $_POST["subnet"] = "";
        $_POST["netmask"] = "";
    }
    return array(isset($error), $error);
}
Exemplo n.º 2
0
function checkPools(&$poolsRanges)
{
    /* Check that the given pool range is valid */
    $subnet = $_POST["subnet"];
    $netmask = $_POST["netmask"];
    if (isset($_POST["hassubnetpools"])) {
        foreach ($_POST as $key => $value) {
            if (preg_match('/^subnetpool_[0-9]*$/', $key)) {
                list($ipStart, $ipEnd) = preg_split("/\\s+/", $value);
                if (isset($ipStart) && isset($ipEnd)) {
                    if (!(ipLowerThan($ipStart, $ipEnd) && ipInNetwork($ipStart, $subnet, $netmask) && ipInNetwork($ipEnd, $subnet, $netmask))) {
                        $error .= sprintf(_T("The specified dynamic pool IP range from %s to %s is not valid."), $ipStart, $ipEnd);
                        setFormError("subnetpools");
                    }
                    $poolsRanges[] = $ipStart . " " . $ipEnd;
                }
            }
        }
    }
    return array(isset($error), $error);
}
Exemplo n.º 3
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _base_verifInfo($FH, $mode)
{
    global $error;
    global $conf;
    $base_errors = "";
    $uid = $FH->getPostValue("uid");
    $pass = $FH->getPostValue("pass");
    $confpass = $FH->getPostValue("confpass");
    $homedir = $FH->getPostValue("homeDirectory");
    $primary = $FH->getPostValue("primary");
    $firstname = $FH->getPostValue("givenName");
    $lastname = $FH->getPostValue("sn");
    $durete = $FH->testpassword($pass);
    if (!preg_match("/^[a-zA-Z0-9][A-Za-z0-9_.-]*\$/", $uid)) {
        $base_errors .= _("User's name invalid !") . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $uid && userExists($uid)) {
        $base_errors .= sprintf(_("The user %s already exists."), $uid) . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $pass == '') {
        $base_errors .= _("Password is empty.") . "<br/>";
        setFormError("pass");
    } else {
        if (strlen($pass) < intval($conf["global"]["minsizepassword"])) {
            $base_errors .= _("Minimum") . " " . $conf["global"]["minsizepassword"] . " " . _("characters for the password") . "<br/>";
            setFormError("pass");
        } else {
            if ($FH->testpassword($pass) < intval($conf["global"]["weakPassword"])) {
                if ($durete < 5) {
                    $msgval = _("very weak");
                } else {
                    if ($durete < 15) {
                        $msgval = _("weak");
                    } else {
                        if ($durete < 40) {
                            $msgval = _("medium");
                        } else {
                            $msgval = _("good");
                        }
                    }
                }
                $base_errors .= _("Password") . " : " . $msgval . "<br/>";
                setFormError("pass");
            }
        }
    }
    if ($mode == "add" && $lastname == '') {
        $base_errors .= _("Last name is empty.") . "<br/>";
        setFormError("sn");
    }
    if ($mode == "add" && $firstname == '') {
        $base_errors .= _("First name is empty.") . "<br/>";
        setFormError("givenName");
    }
    if ($pass != $confpass) {
        $base_errors .= _("The confirmation password does not match the new password.") . " <br/>";
        setFormError("pass");
        setFormError("confpass");
    }
    /* Check that the primary group name exists */
    if (!strlen($primary)) {
        $base_errors .= _("The primary group field can't be empty.") . "<br />";
        setFormError("primary");
    } else {
        if (!existGroup($primary)) {
            $base_errors .= sprintf(_("The group %s does not exist, and so can't be set as primary group."), $primary) . "<br />";
            setFormError("primary");
        }
    }
    /* Check that the homeDir does not exists */
    if ($mode == "add") {
        if ($FH->getPostValue("createHomeDir") == "on" && $FH->getPostValue("ownHomeDir") != "on" && $uid) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    } else {
        /* If we want to move the userdir check the destination */
        if ($FH->isUpdated("homeDirectory")) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    }
    $error .= $base_errors;
    return $base_errors ? 1 : 0;
}
Exemplo n.º 4
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _mail_verifInfo($FH, $mode)
{
    global $error;
    $mail_errors = "";
    $attrs = getMailAttributes();
    if ($FH->isUpdated($attrs['mailalias'])) {
        $ereg = '/^([A-Za-z0-9._+@-])*$/';
        $mails = $FH->getValue($attrs['mailalias']);
        foreach ($mails as $key => $value) {
            if ($value && !preg_match($ereg, $mails[$key])) {
                $mail_errors .= sprintf(_T("%s is not a valid mail alias.", "mail"), $mails[$key]) . "<br />";
                setFormError($attrs['mailalias'] . "[" . $key . "]");
            }
        }
    }
    if ($FH->isUpdated($attrs['maildrop']) && count($FH->getValue($attrs['maildrop'])) == 0 && !hasVDomainSupport()) {
        $mail_errors .= _T("You must specify at least one mail drop. Usually it has the same name as the user.", "mail") . "<br />";
    }
    if ($FH->getPostValue("mailaccess") == "on") {
        $mailreg = '/^([A-Za-z0-9._+-]+@[A-Za-z0-9.-]+)$/';
        if (!preg_match($mailreg, $FH->getPostValue('mail'), $matches)) {
            $mail_errors .= _T("You must specify a valid mail address to enable mail delivery.", "mail") . "<br />";
            setFormError("mail");
        }
    }
    $error .= $mail_errors;
    return $mail_errors ? 1 : 0;
}
Exemplo n.º 5
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _base_verifInfo($FH, $mode)
{
    global $error;
    $base_errors = "";
    $uid = $FH->getPostValue("uid");
    $pass = $FH->getPostValue("pass");
    $confpass = $FH->getPostValue("confpass");
    $homedir = $FH->getPostValue("homeDirectory");
    $primary = $FH->getPostValue("primary");
    if (!preg_match("/^[a-zA-Z0-9][A-Za-z0-9_.-]*\$/", $uid)) {
        $base_errors .= _("User's name invalid !") . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $uid && userExists($uid)) {
        $base_errors .= sprintf(_("The user %s already exists."), $uid) . "<br/>";
        setFormError("uid");
    }
    if ($mode == "add" && $pass == '') {
        $base_errors .= _("Password is empty.") . "<br/>";
        setFormError("pass");
    }
    if ($pass != $confpass) {
        $base_errors .= _("The confirmation password does not match the new password.") . " <br/>";
        setFormError("pass");
        setFormError("confpass");
    }
    /* Check that the primary group name exists */
    if (!strlen($primary)) {
        $base_errors .= _("The primary group field can't be empty.") . "<br />";
        setFormError("primary");
    } else {
        if (!existGroup($primary)) {
            $base_errors .= sprintf(_("The group %s does not exist, and so can't be set as primary group."), $primary) . "<br />";
            setFormError("primary");
        }
    }
    /* Check that the homeDir does not exists */
    if ($mode == "add") {
        if ($FH->getPostValue("createHomeDir") == "on" && $FH->getPostValue("ownHomeDir") != "on" && $uid) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    } else {
        /* If we want to move the userdir check the destination */
        if ($FH->isUpdated("homeDirectory")) {
            getHomeDir($uid, $FH->getValue("homeDirectory"));
        }
    }
    $error .= $base_errors;
    return $base_errors ? 1 : 0;
}
Exemplo n.º 6
0
$p->setSideMenu($sidemenu);
$p->display();
global $error;
/* Adding a new record */
if (isset($_POST["badd"])) {
    $hostname = $_POST["hostname"];
    $ipaddress = $_POST["ipaddress"];
    /* Basic checks */
    if (hostExists($zone, $hostname)) {
        $error = _T("The specified hostname has been already recorded in this zone.") . " ";
        setFormError("hostname");
        $hostname = "";
    }
    if (ipExists($zone, $ipaddress)) {
        $error .= _T("The specified IP address has been already recorded in this zone.");
        setFormError("address");
    } else {
        $keepaddress = True;
    }
    if (!isset($error)) {
        $ret = addRecordA($zone, $hostname, $ipaddress);
        if (!isXMLRPCError()) {
            if ($ret === 1) {
                $msg = _T("Host successfully added to DNS zone.");
            } else {
                $msg = _T("Host successfully added to DNS zone and corresponding reverse zone.");
            }
            new NotifyWidgetSuccess($msg);
            if (isset($_GET["gobackto"])) {
                header("Location: " . $_SERVER["PHP_SELF"] . "?" . rawurldecode($_GET["gobackto"]));
            } else {
Exemplo n.º 7
0
         if (!$nsName) {
             setFormError('nameservers0');
         } else {
             $nameservers[] = $ns;
         }
     }
 }
 $mxservers = array();
 foreach ($mxserverstmp as $mx) {
     if (!empty($mx)) {
         $mxInfo = explode(' ', $mx);
         $mxPriority = $mxInfo[0];
         $mxName = $mxInfo[1];
         $mxName = hasARecord($zonename, $mxName);
         if (!$mxName) {
             setFormError('mxservers0');
         } else {
             $mxservers[] = $mxPriority . ' ' . $mxName;
         }
     }
 }
 if (!isset($error)) {
     setSOANSRecord($zonename, $nameserver);
     setNSRecords($zonename, $nameservers);
     setMXRecords($zonename, $mxservers);
     setSOAARecord($zonename, $zoneaddress);
     setZoneDescription($zonename, $description);
     if (!isXMLRPCError()) {
         new NotifyWidgetSuccess(_T("DNS zone successfully modified."));
         header("Location: " . urlStrRedirect("network/network/index"));
         exit;
Exemplo n.º 8
0
/**
 * Function called before changing user attributes
 * @param $FH FormHandler of the page
 * @param $mode add or edit mode
 */
function _samba_verifInfo($FH, $mode)
{
    global $error;
    $samba_errors = "";
    if ($FH->getPostValue("uid") && $FH->getPostValue("isSamba")) {
        if (!hasSmbAttr($FH->getPostValue("uid"))) {
            if (!$FH->getValue("pass")) {
                // if we not precise password
                $samba_errors .= _T("You must reenter your password.", "samba") . "<br />\n";
                setFormError("pass");
            }
        }
        $drive = $FH->getValue("sambaHomeDrive");
        if ($drive != "") {
            // Check that the SAMBA home drive is a correct drive letter
            // "X:", "U:", etc.
            $err = False;
            if (!preg_match("/^[C-Z]:\$/", $drive)) {
                $samba_errors .= _T("Invalid network drive.", "samba") . "<br />\n";
                setFormError("sambaHomeDrive");
            }
        }
    }
    $error .= $samba_errors;
    return $samba_errors ? 1 : 0;
}
Exemplo n.º 9
0
} else {
    $mode = "edit";
    $title = _T("Edit virtual alias", "mail");
    $sidemenu->forceActiveItem("index");
    $alias = $_GET['alias'];
    $FH->setArr(getVAlias($alias));
}
if ($_POST) {
    if ($mode == "add") {
        if ($FH->isUpdated("mailalias")) {
            addVAlias($FH->getValue("mailalias"));
            $alias = $FH->getValue("mailalias");
            $result .= _T("The virtual alias has been created.", "mail") . "<br />";
        } else {
            $error .= _T("The alias name is required.", "mail");
            setFormError("mailalias");
        }
    } else {
        if ($FH->isUpdated("mailalias")) {
            changeVAliasName($alias, $FH->getValue("mailalias"));
            $alias = $FH->getValue("mailalias");
            $result .= _T("Virtual alias name updated.", "mail") . "<br />";
        }
    }
    if (!$error && !isXMLRPCError()) {
        if ($FH->isUpdated("users")) {
            if ($mode == "edit") {
                $old = getVAliasUsers($alias);
            } else {
                $old = array();
            }
Exemplo n.º 10
0
    $mode = "edit";
    $title = _T("Edit password policy", "ppolicy");
    $sidemenu->forceActiveItem("indexppolicy");
    $ppolicy = $_GET['ppolicy'];
    $FH->setArr(getAllPPolicyAttributes($ppolicy));
}
if ($_POST) {
    $name = $FH->getPostValue("cn");
    $desc = $FH->getPostValue("description");
    // Some sanity checks...
    if ($FH->isUpdated("pwdMaxAge") or $FH->isUpdated("pwdMinAge")) {
        $max = $FH->getPostValue("pwdMaxAge");
        $min = $FH->getPostValue("pwdMinAge");
        if ($min && $max && $min > $max) {
            $error .= _T('"Maximum age" must be greater than "Minimum age".', 'ppolicy') . "<br />";
            setFormError("pwdMinAge");
        }
    }
    if ($mode == "add") {
        if (!checkPPolicy($name)) {
            addPPolicy($name, $desc);
            if (!isXMLRPCError()) {
                $result .= _T(sprintf("Password policy %s created.", $name), "ppolicy") . "<br />";
            } else {
                $error .= _T(sprintf("Failed to create %s password policy.", $name), "ppolicy") . "<br />";
            }
        } else {
            $error .= _T(sprintf("Password policy %s already exists.", $name), "ppolicy") . "<br />";
        }
    }
    if (!$error && !isXMLRPCError()) {
Exemplo n.º 11
0
             if (ipExistsInSubnet($subnet, $ipaddress)) {
                 $error .= _T("The specified IP address has been already registered in this DHCP subnet.") . " ";
                 setFormError("ipaddress");
             }
             $options = getSubnetOptions(getSubnet($subnet));
             if ($domainexist) {
                 /* If a DNS record exists for this machine, we need to update it too */
                 $zone = $options["primarydomainname"];
                 if (hostExists($zone, $hostname) && ipExists($zone, $oldip)) {
                     /* a record exists, can we update it ? */
                     if (ipExists($zone, $ipaddress)) {
                         /* The new IP already exists */
                         /* If the current hostname doesn't resolve to this already existing IP, we can't register it */
                         if (resolve($zone, $hostname) != $ipaddress) {
                             $error .= sprintf(_T("The IP address %s is already registered in DNS zone %s"), $ipaddress, $zone);
                             setFormError("ipaddress");
                         }
                         /* else there is no need to update the DNS record, it is already set to the good value */
                     } else {
                         $updatednsrecord = True;
                     }
                 }
             }
         }
     }
 }
 if (!isset($error)) {
     if (isset($_POST["badd"])) {
         addHostToSubnet($subnet, $hostname);
         setHostOption($subnet, $hostname, "host-name", $hostname);
         if (isset($_POST["dnsrecord"])) {
Exemplo n.º 12
0
function _checkPassword($FH, $mode)
{
    if (_enablingSamba4ToUser($FH, $mode)) {
        if (!$FH->isUpdated("pass")) {
            setFormError("pass");
            /* Mark the field password to be filled */
            setFormError("confpass");
            return _T("You must reenter your password.", "samba4") . "<br />\n";
        }
    }
    return "";
}