= $maxnumber) { $input_errors[] = sprintf(gettext("Roll number must be numeric and less than %s"), $maxnumber); } if (!is_numeric($_POST['count']) || $_POST['count'] < 1 || $_POST['count'] > $maxcount) { $input_errors[] = sprintf(gettext("A roll has at least one voucher and less than %s."), $maxcount); } if (!is_numeric($_POST['minutes']) || $_POST['minutes'] < 1) { $input_errors[] = gettext("Each voucher must be good for at least 1 minute."); } if (!$input_errors) { if (isset($id) && $a_roll[$id]) { $rollent = $a_roll[$id]; } $rollent['zone'] = $_POST['zone']; $rollent['number'] = $_POST['number']; $rollent['minutes'] = $_POST['minutes']; $rollent['descr'] = $_POST['descr']; /* New Roll or modified voucher count: create bitmask */ $voucherlck = lock("voucher{$cpzone}"); if ($_POST['count'] != $rollent['count']) { $rollent['count'] = $_POST['count']; $len = ($rollent['count']>>3) + 1; // count / 8 +1 $rollent['used'] = base64_encode(str_repeat("\000",$len)); // 4 bitmask $rollent['active'] = array(); voucher_write_used_db($rollent['number'], $rollent['used']); voucher_write_active_db($rollent['number'], array()); // create empty DB voucher_log(LOG_INFO,sprintf(gettext('All %1$s vouchers from Roll %2$s marked unused'), $rollent['count'], $rollent['number'])); } else { // existing roll has been modified but without changing the count // read active and used DB from ramdisk and store it in XML config $rollent['used'] = base64_encode(voucher_read_used_db($rollent['number'])); $activent = array(); $db = array(); $active_vouchers = voucher_read_active_db($rollent['number'], $rollent['minutes']); foreach($active_vouchers as $voucher => $line) { list($timestamp, $minutes) = explode(",", $line); $activent['voucher'] = $voucher; $activent['timestamp'] = $timestamp; $activent['minutes'] = $minutes; $db[] = $activent; } $rollent['active'] = $db; } unlock($voucherlck); if (isset($id) && $a_roll[$id]) $a_roll[$id] = $rollent; else $a_roll[] = $rollent; write_config(); header("Location: services_captiveportal_vouchers.php?zone={$cpzone}"); exit; } } include("head.inc"); if ($input_errors) print_input_errors($input_errors); if ($savemsg) print_info_box($savemsg, 'success'); require_once('classes/Form.class.php'); $form = new Form(); $section = new Form_Section('Voucher rolls'); $section->addInput(new Form_Input( 'number', 'Roll #', 'text', $pconfig['number'] ))->setHelp('Enter the Roll# (0..%d) found on top of the generated/printed vouchers', [$maxnumber]); $section->addInput(new Form_Input( 'minutes', 'Minutes per ticket', 'text', $pconfig['minutes'] ))->setHelp('Defines the time in minutes that a user is allowed access. The clock starts ticking the first time a voucher is used for authentication.'); $section->addInput(new Form_Input( 'count', 'Count', 'text', $pconfig['count'] ))->setHelp('Enter the number of vouchers (1..%d) found on top of the generated/printed vouchers. WARNING: Changing this number for an existing Roll will mark all vouchers as unused again', [$maxcount]); $section->addInput(new Form_Input( 'descr', 'Comment', 'text', $pconfig['descr'] ))->setHelp('Can be used to further identify this roll. Ignored by the system.'); $section->addInput(new Form_Input( 'zone', null, 'hidden', $cpzone )); if (isset($id) && $a_roll[$id]) { $section->addInput(new Form_Input( 'id', null, 'hidden', $pconfig['id'] )); } $form->add($section); print($form); include("foot.inc");