function match_ip_to_ip_or_cidr($ip, $ips_or_cidr_array) { if (isIPv4($ip)) { foreach ($ips_or_cidr_array as $ip_or_cidr) { if (isIPv4cidr($ip_or_cidr)) { if (ip_v4_cidr_match($ip, $ip_or_cidr)) { return true; } } elseif (isIPv4($ip_or_cidr)) { if ($ip == $ip_or_cidr) { return true; } } } } else { foreach ($ips_or_cidr_array as $ip_or_cidr) { if (isIPv6cidr($ip_or_cidr)) { if (ip_v6_cidr_match($ip, $ip_or_cidr)) { return true; } } elseif (isIPv6($ip_or_cidr)) { if ($ip == $ip_or_cidr) { return true; } } } } return false; }
AND user.id", $course_id); } echo json_encode($data); exit; } } load_js('tools.js'); // the exercise form has been submitted if (isset($_POST['submitExercise'])) { $v = new Valitron\Validator($_POST); $v->addRule('ipORcidr', function($field, $value, array $params) { //explode here and run a loop $IPs = explode(',', $value); //matches IPv4/6 and IPv4/6 CIDR ranges foreach ($IPs as $ip){ $valid = isIPv4($ip) || isIPv4cidr($ip) || isIPv6($ip) || isIPv6cidr($ip); if (!$valid) return false; } return true; }, $langIPInvalid); $v->rule('required', array('exerciseTitle')); $v->rule('numeric', array('exerciseTimeConstraint', 'exerciseAttemptsAllowed')); $v->rule('date', array('exerciseEndDate', 'exerciseStartDate')); $v->rule('ipORcidr', array('exerciseIPLock')); $v->labels(array( 'exerciseTitle' => "$langTheField $langExerciseName", 'exerciseTimeConstraint' => "$langTheField $langExerciseConstrain", 'exerciseAttemptsAllowed' => "$langTheField $langExerciseAttemptsAllowed", 'exerciseEndDate' => "$langTheField $langEnd", 'exerciseStartDate' => "$langTheField $langStart", 'exerciseIPLock' => "$langTheField IPs"