<?php

/*
 * postLDAPadmin
 *
 * Copyright (C) 2006,2007 DesigNET, INC.
 *
 * 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; either version 2 of the License, or
 * (at your option) any later version.

 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

define("MAX_DOMAIN_LENGTH", 128);

/*********************************************************
 * check_path()
 *
 * եͥå
 *
 * []
 *      $path       եΥѥޥ
 * [֤]
 *      TRUE         
 *      FALSE        ۾
 **********************************************************/
function check_path($path)
{
    /* ʸå */
    /* pathͤ뤫Ĵ٤ */
    if (isset($path) && $path != "") {
        $letters = strlen($path);
        if ($letters < 1) {
            return FALSE;
        }

        /* Ⱦѱ羮ʸ국Τߵ */
        $num = "0123456789";
        $sl = "abcdefghijklmnopqrstuvwxyz";
        $ll = strtoupper($sl);
        $sym = "/.-_ ";
        $allow_letter = $num . $sl . $ll . $sym;
        if (strspn($path, $allow_letter) != $letters) {
            return FALSE;
        }
    }
    /*ͤʤäTRUE*/
    return TRUE;
}

/*********************************************************
 * check_defdomain()
 *
 * եDefDoaminͥå
 *
 * []
 *      $defdomain       ֥ͥåȾ˼ưŪϤɥᥤ̾
 * [֤]
 *      TRUE         
 *      FALSE        ۾
 **********************************************************/
function check_defdomain($defdomain)
{
    /* ʸå */
    /* defdomainͤ뤫Ĵ٤ */
    if (isset($defdomain) && $defdomain != "") {
        $letters = strlen($defdomain);
        if ($letters < 1 || $letters > MAX_DOMAIN_LENGTH) {
            return FALSE;
        }

        /* Ⱦѱ羮ʸ국Τߵ */
        $num = "0123456789";
        $sl = "abcdefghijklmnopqrstuvwxyz";
        $ll = strtoupper($sl);
        $sym = "-.";
        $allow_letter = $num . $sl . $ll . $sym;
        $head = substr($defdomain, 0, 1);
        $end = mb_substr($defdomain, -1);
        if (strspn($defdomain, $allow_letter) != $letters ||
            strspn($head, $sym) == 1 || strspn($end, $sym) == 1) {
            return FALSE;
        }
    }
    /*ͤʤäTRUE*/
    return TRUE;
}

/* ե */
$conf_keys["dhcpadmin"] = array(
                    "dhcpdconfpath"     => "check_path",
                    "dhcpd6confpath"    => "check_path",
                    "dhcpdleasespath"   => "check_path",
                    "dhcpd6leasespath"  => "check_path",
                    "locktime"          => "is_positive_number",
                    "defdomain"         => "check_defdomain",
                    "defleasetime"      => "is_positive_number",
                    "defmaxleasetime"   => "is_positive_number",
                    "dhcpdrestartcom"   => "check_path",
                    "dhcpd6restartcom"  => "check_path",
                    "dhcpdcheckcom"     => "check_path",
                    "dhcpd6checkcom"    => "check_path",
                    "dhcpdconftestcom"  => "check_path",
                    "dhcpd6conftestcom"  => "check_path",
                    "leaseslistnum"     => "is_positive_number");


/* Υǥե */
$conf_def["dhcpadmin"] = array(
                    "dhcpdconfpath"     => "/etc/dhcp/dhcpd.conf",
                    "dhcpd6confpath"    => "/etc/dhcp/dhcpd6.conf",
                    "dhcpdleasespath"   => "/var/lib/dhcpd/dhcpd.leases",
                    "dhcpd6leasespath"  => "/var/lib/dhcpd/dhcpd6.leases",
                    "dhcpdrestartcom"  => "/usr/bin/sudo /usr/bin/systemctl restart dhcpd",
                    "dhcpd6restartcom"  => "/usr/bin/sudo /usr/bin/systemctl restart dhcpd6",
                    "dhcpdcheckcom"  => "/usr/bin/sudo /usr/bin/systemctl status dhcpd",
                    "dhcpd6checkcom"  => "/usr/bin/sudo /usr/bin/systemctl status dhcpd6",
                    "dhcpdconftestcom"  => "/usr/bin/sudo /usr/sbin/dhcpd -cf /etc/dhcp/dhcpd.conf -t",
                    "dhcpd6conftestcom"  => "/usr/bin/sudo /usr/sbin/dhcpd -6 -cf /etc/dhcp/dhcpd6.conf -t",
                    "locktime"          => "600",
                    "leaseslistnum"     => "20");

?>
