function get_next_serial($curr_serial, $today = '')
{
    // Zone transfer to zone slave(s) will occur only if the serial number
    // of the SOA RR is arithmetically greater that the previous one
    // (as defined by RFC-1982).
    // The serial should be updated, unless:
    //  - the serial is set to "0", see http://doc.powerdns.com/types.html#id482176
    //
    //  - set a fresh serial ONLY if the existing serial is lower than the current date
    //
    //	- update date in serial if it reaches limit of revisions for today or do you
    //	think that ritual suicide is better in such case?
    //
    // "This works unless you will require to make more than 99 changes until the new
    // date is reached - in which case perhaps ritual suicide is the best option."
    // http://www.zytrax.com/books/dns/ch9/serial.html
    if ($today == '') {
        set_timezone();
        $today = date('Ymd');
    }
    $revision = (int) substr($curr_serial, -2);
    $ser_date = substr($curr_serial, 0, 8);
    if ($curr_serial == '0') {
        $serial = $curr_serial;
    } elseif ($curr_serial == $today . '99') {
        $serial = get_next_date($today) . '00';
    } else {
        if (strcmp($today, $ser_date) === 0) {
            // Current serial starts with date of today, so we need to update the revision only.
            ++$revision;
        } elseif (strncmp($today, $curr_serial, 8) === -1) {
            // Reuse existing serial date if it's in the future
            $today = substr($curr_serial, 0, 8);
            // Get next date if revision reaches maximum per day (99) limit otherwise increment the counter
            if ($revision == 99) {
                $today = get_next_date($today);
                $revision = "00";
            } else {
                ++$revision;
            }
        } else {
            // Current serial did not start of today, so it's either an older
            // serial, therefore set a fresh serial
            $revision = "00";
        }
        // Create new serial out of existing/updated date and revision
        $serial = $today . str_pad($revision, 2, "0", STR_PAD_LEFT);
    }
    return $serial;
}
예제 #2
0
/** Get Next Serial
 *
 * Zone transfer to zone slave(s) will occur only if the serial number
 * of the SOA RR is arithmetically greater that the previous one
 * (as defined by RFC-1982).
 *
 * The serial should be updated, unless:
 *
 * - the serial is set to "0", see http://doc.powerdns.com/types.html#id482176
 *
 * - set a fresh serial ONLY if the existing serial is lower than the current date
 *
 * - update date in serial if it reaches limit of revisions for today or do you
 * think that ritual suicide is better in such case?
 *
 * "This works unless you will require to make more than 99 changes until the new
 * date is reached - in which case perhaps ritual suicide is the best option."
 * http://www.zytrax.com/books/dns/ch9/serial.html
 *
 * @param string $curr_serial Current Serial No
 * @param string $today Optional date for "today"
 *
 * @return string Next serial number
 */
function get_next_serial($curr_serial, $today = '')
{
    // Autoserial
    if ($curr_serial == 0) {
        return 0;
    }
    // Serial number could be a not date based
    if ($curr_serial < 1979999999) {
        return $curr_serial + 1;
    }
    // Reset the serial number, Bind was written in the early 1980s
    if ($curr_serial == 1979999999) {
        return 1;
    }
    if ($today == '') {
        set_timezone();
        $today = date('Ymd');
    }
    $revision = (int) substr($curr_serial, -2);
    $ser_date = substr($curr_serial, 0, 8);
    if ($curr_serial == '0') {
        $serial = $curr_serial;
    } elseif ($curr_serial == $today . '99') {
        $serial = get_next_date($today) . '00';
    } else {
        if (strcmp($today, $ser_date) === 0) {
            // Current serial starts with date of today, so we need to update the revision only.
            ++$revision;
        } elseif (strncmp($today, $curr_serial, 8) === -1) {
            // Reuse existing serial date if it's in the future
            $today = substr($curr_serial, 0, 8);
            // Get next date if revision reaches maximum per day (99) limit otherwise increment the counter
            if ($revision == 99) {
                $today = get_next_date($today);
                $revision = "00";
            } else {
                ++$revision;
            }
        } else {
            // Current serial did not start of today, so it's either an older
            // serial, therefore set a fresh serial
            $revision = "00";
        }
        // Create new serial out of existing/updated date and revision
        $serial = $today . str_pad($revision, 2, "0", STR_PAD_LEFT);
    }
    return $serial;
}
예제 #3
0
$events_next_month = array();
$insert = false;
while ($row = mysql_fetch_object($result)) {
    switch ($row->repeat) {
        case -1:
            $string = $row->repeat_special . " " . date("Y");
            //$string = str_replace("of ","",$string); // PHP 5.2 doesn't deal with 'of' in the relative date format
            $date_this_year = date("Y-m-d H:i:s", strtotime($string));
            $insert = true;
            break;
        case 0:
            $date_this_year = $row->when;
            $insert = true;
            break;
        case 1:
            $date_this_year = get_next_date($row->when);
            $insert = true;
            break;
        case 2:
            // no need right now
            break;
        case 3:
            // no need right now
            break;
    }
    if ($insert) {
        list($date, $time) = explode(" ", $date_this_year);
        list($year, $month, $day) = explode("-", $date);
        if (strtotime("{$year}-{$month}") == strtotime(date("Y-m"))) {
            $events_this_month[] = array(date("Y") . "-{$month}-{$day}", $row->id);
        }