Ejemplo n.º 1
0
/**
 * Validate data settings
 * See also sumo_settings_data() in libs/lib.core.php
 */
function sumo_validate_data_settings($data = array(), $message = FALSE)
{
    $elements = count($data);
    $err = FALSE;
    if ($elements > 0) {
        for ($d = 0; $d < $elements; $d++) {
            if ($data[$d][2] == 1 || $data[$d][2] == 0 && $data[$d][1]) {
                switch ($data[$d][0]) {
                    case 'date_format':
                        if (!ereg("[BdDFjlLmMnrStTwWYyz:\\./\\-]+", $data[$d][1])) {
                            $err = 'W06011C';
                        }
                        break;
                    case 'time_format':
                        if (!ereg("[aABgGhHiIOrsTU.:-]+", $data[$d][1])) {
                            $err = 'W06010C';
                        }
                        break;
                    case 'admin_name':
                        if (!preg_match('/^[a-z0-9' . SUMO_REGEXP_ALLOWED_CHARS . '\'\\/\\\\_\\-\\ ]{0,50}$/i', $data[$d][1])) {
                            $err = 'W06012C';
                        }
                        break;
                    case 'accounts.life':
                        if ($data[$d][1] < 0) {
                            $err = 'W06001C';
                        }
                        break;
                    case 'accounts.registration.life':
                        if ($data[$d][1] < 1) {
                            $err = 'W06007C';
                        }
                        break;
                        // see also sumo_validate_data_accesspoint()
                    // see also sumo_validate_data_accesspoint()
                    case 'accesspoints.name':
                        $languages = sumo_get_available_languages();
                        for ($l = 0; $l < count($languages); $l++) {
                            if (!preg_match("/^[a-z0-9\\-\\_\\.\\=\\&\\/\\\\'\\ " . SUMO_REGEXP_ALLOWED_CHARS . "]{5,128}\$/i", $data[$d][1][$languages[$l]])) {
                                $err = 'W00031C';
                            }
                        }
                        break;
                        // see also sumo_validate_data_accesspoint()
                    // see also sumo_validate_data_accesspoint()
                    case 'accesspoints.group':
                        if (!sumo_validate_group($data[$d][1], FALSE)) {
                            $err = 'W07002C';
                        }
                        break;
                        // see also sumo_validate_data_accesspoint()
                    // see also sumo_validate_data_accesspoint()
                    case 'accesspoints.theme':
                        if (!in_array($data[$d][1], sumo_get_available_themes())) {
                            $err = 'W00033C';
                        }
                        break;
                    case 'security.banned_time':
                        if ($data[$d][1] < 5) {
                            $err = 'W06002C';
                        }
                        break;
                    case 'security.max_login_attempts':
                        if ($data[$d][1] < 3) {
                            $err = 'W06004C';
                        }
                        break;
                    case 'connections.timeout':
                        if ($data[$d][1] < 10) {
                            $err = 'W06005C';
                        }
                        break;
                    case 'sessions.timeout':
                        if ($data[$d][1] < 60) {
                            $err = 'W06006C';
                        }
                        break;
                    case 'database.optimize_hits':
                        if ($data[$d][1] < 100) {
                            $err = 'W06008C';
                        }
                        break;
                    case 'logs.life':
                        if ($data[$d][1] < 0) {
                            $err = 'W06003C';
                        }
                        break;
                    case 'logs.file.size':
                        if ($data[$d][1] < 32) {
                            $err = 'W06005C';
                        }
                        break;
                    case 'language':
                        if (!in_array($data[$d][1], sumo_get_available_languages())) {
                            $err = 'W00021C';
                        }
                        break;
                    case 'email':
                        if (!sumo_validate_email($data[$d][1])) {
                            $err = 'W00007C';
                        }
                        break;
                    case 'boolean':
                        if ($data[$d][1] != 0 && $data[$d][1] != 1) {
                            $err = 'W00032C';
                        }
                        break;
                    default:
                        $err = 'W00019C';
                        break;
                }
                if ($err) {
                    break;
                }
            }
        }
        if ($message) {
            if (!$err) {
                return array(TRUE, '');
            } else {
                return array(FALSE, sumo_get_message($err) . "<br>[expect:" . $data[$d][0] . "]");
            }
        } else {
            if (!$err) {
                return TRUE;
            } else {
                return FALSE;
            }
        }
    } else {
        return FALSE;
    }
}
Ejemplo n.º 2
0
/**
 * Create selection box of available themes
 */
function sumo_put_themes($default = '', $name = 'theme')
{
    $themes = sumo_get_available_themes();
    $num_themes = count($themes);
    $list = "<select name='{$name}'>\n";
    if ($default) {
        $list .= "<option value='{$default}'>" . ucwords($default) . "</option>\n";
    }
    for ($t = 0; $t < $num_themes; $t++) {
        if ($themes[$t] != $default) {
            $list .= "<option value='" . $themes[$t] . "'>" . ucwords($themes[$t]) . "</option>\n";
        }
    }
    $list .= "</select>";
    return $list;
}
Ejemplo n.º 3
0
/**
 * Validate data accesspoint
 * See also sumo_validate_data() in libs/lib.core.php
 * 
 * @author Alberto Basso
 */
function sumo_validate_accesspoint_data($data = array(), $message = FALSE)
{
    $elements = count($data);
    $err = FALSE;
    if ($elements > 0) {
        for ($d = 0; $d < $elements; $d++) {
            if ($data[$d][2] == 1 || $data[$d][2] == 0 && $data[$d][1]) {
                switch ($data[$d][0]) {
                    case 'id':
                        // INT = 256^4-1
                        if ($data[$d][1] < 1 || $data[$d][1] > 4294967296) {
                            $err = 'W00029C';
                        }
                        break;
                    case 'path':
                        if (!preg_match("/^(\\/)+[_\\.\\/a-z0-9-]{1,}(\\.){1}(php|php4|php5|html|htm|asp|pl|jsp){1}\$/i", $data[$d][1])) {
                            $err = 'W07003C';
                        }
                        break;
                    case 'node':
                        if ($data[$d][1] < 1 || $data[$d][1] > 4294967296) {
                            $err = 'W07004C';
                        }
                        break;
                    case 'name':
                        $languages = sumo_get_available_languages();
                        for ($l = 0; $l < count($languages); $l++) {
                            if (!preg_match("/^[-a-z0-9_\\.\\=\\&\\/\\'" . SUMO_REGEXP_ALLOWED_CHARS . " ]{5,128}\$/i", $data[$d][1][$languages[$l]])) {
                                $err = 'W00031C';
                            }
                        }
                        break;
                    case 'usergroup':
                        if (!sumo_validate_group($data[$d][1], FALSE)) {
                            $err = 'W07002C';
                        }
                        break;
                    case 'reg_group':
                        if (!sumo_validate_group($data[$d][1], FALSE)) {
                            $err = 'W07005C';
                        }
                        break;
                    case 'boolean':
                        if ($data[$d][1] != 0 && $data[$d][1] != 1) {
                            $err = 'W00032C';
                        }
                        break;
                    case 'theme':
                        if (!in_array($data[$d][1], sumo_get_available_themes())) {
                            $err = 'W00033C';
                        }
                        break;
                    default:
                        $err = 'W00019C';
                        break;
                }
                if ($err) {
                    break;
                }
            }
        }
        if ($message) {
            return !$err ? array(TRUE, '') : array(FALSE, sumo_get_message($err));
        } else {
            return !$err ? TRUE : FALSE;
        }
    } else {
        return FALSE;
    }
}