2004-09-14 11:09:35 +00:00
|
|
|
;;; dns-mode.el --- a mode for viewing/editing Domain Name System master files
|
2005-08-06 17:48:15 +00:00
|
|
|
|
2009-01-05 03:18:22 +00:00
|
|
|
;; Copyright (C) 2000, 2001, 2004, 2005, 2006, 2007, 2008, 2009
|
2008-01-07 02:23:04 +00:00
|
|
|
;; Free Software Foundation, Inc.
|
2004-09-14 11:09:35 +00:00
|
|
|
|
|
|
|
;; Author: Simon Josefsson <simon@josefsson.org>
|
|
|
|
;; Keywords: DNS master zone file SOA
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 04:34:22 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2004-09-14 11:09:35 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:34:22 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2004-09-14 11:09:35 +00:00
|
|
|
|
|
|
|
;; GNU Emacs 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
|
2008-05-06 04:34:22 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2004-09-14 11:09:35 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Use M-x dns-mode RET to invoke in master files.
|
|
|
|
;;
|
|
|
|
;; C-c C-s Increment SOA serial.
|
|
|
|
;; Understands YYYYMMDDNN, Unix time, and serial number formats,
|
|
|
|
;; and complains if it fail to find SOA serial.
|
|
|
|
;;
|
|
|
|
;; Put something similar to the following in your ~/.emacs to use this file:
|
|
|
|
;;
|
|
|
|
;; (load "~/path/to/dns-mode.el")
|
|
|
|
;; (setq auto-mode-alist (cons '("\\.soa\\'" . dns-mode) auto-mode-alist))
|
|
|
|
|
|
|
|
;;; References:
|
|
|
|
|
|
|
|
;; RFC 1034, "DOMAIN NAMES - CONCEPTS AND FACILITIES", P. Mockapetris.
|
|
|
|
;; RFC 1035, "DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION", P. Mockapetris.
|
|
|
|
|
|
|
|
;;; Release history:
|
|
|
|
|
|
|
|
;; 2004-09-11 Posted on gnu.emacs.sources.
|
|
|
|
;; 2004-09-13 Ported to XEmacs.
|
|
|
|
;; 2004-09-14 Installed in Emacs CVS.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(defgroup dns-mode nil
|
2005-05-27 12:32:51 +00:00
|
|
|
"DNS master file mode configuration."
|
|
|
|
:group 'data)
|
2004-09-14 11:09:35 +00:00
|
|
|
|
|
|
|
(defconst dns-mode-classes '("IN" "CS" "CH" "HS")
|
|
|
|
"List of strings with known DNS classes.")
|
|
|
|
|
|
|
|
(defconst dns-mode-types '("A" "NS" "MD" "MF" "CNAME" "SOA" "MB" "MG" "MR"
|
|
|
|
"NULL" "WKS" "PTR" "HINFO" "MINFO" "MX" "TXT"
|
|
|
|
"RP" "AFSDB" "X25" "ISDN" "RT" "NSAP" "NSAP"
|
|
|
|
"SIG" "KEY" "PX" "GPOS" "AAAA" "LOC" "NXT"
|
|
|
|
"EID" "NIMLOC" "SRV" "ATMA" "NAPTR" "KX" "CERT"
|
|
|
|
"A6" "DNAME" "SINK" "OPT" "APL" "DS" "SSHFP"
|
|
|
|
"RRSIG" "NSEC" "DNSKEY" "UINFO" "UID" "GID"
|
|
|
|
"UNSPEC" "TKEY" "TSIG" "IXFR" "AXFR" "MAILB"
|
|
|
|
"MAILA")
|
|
|
|
"List of strings with known DNS types.")
|
|
|
|
|
|
|
|
;; Font lock.
|
|
|
|
|
|
|
|
(defvar dns-mode-control-entity-face 'font-lock-keyword-face
|
|
|
|
"Name of face used for control entities, e.g. $ORIGIN.")
|
|
|
|
|
|
|
|
(defvar dns-mode-bad-control-entity-face 'font-lock-warning-face
|
|
|
|
"Name of face used for non-standard control entities, e.g. $FOO.")
|
|
|
|
|
|
|
|
(defvar dns-mode-type-face 'font-lock-type-face
|
|
|
|
"Name of face used for DNS types, e.g., SOA.")
|
|
|
|
|
|
|
|
(defvar dns-mode-class-face 'font-lock-constant-face
|
|
|
|
"Name of face used for DNS classes, e.g., IN.")
|
|
|
|
|
|
|
|
(defcustom dns-mode-font-lock-keywords
|
|
|
|
`(("^$ORIGIN" 0 ,dns-mode-control-entity-face)
|
|
|
|
("^$INCLUDE" 0 ,dns-mode-control-entity-face)
|
|
|
|
("^$[a-z0-9A-Z]+" 0 ,dns-mode-bad-control-entity-face)
|
|
|
|
(,(regexp-opt dns-mode-classes) 0 ,dns-mode-class-face)
|
|
|
|
(,(regexp-opt dns-mode-types) 0 ,dns-mode-type-face))
|
|
|
|
"Font lock keywords used to highlight text in DNS master file mode."
|
|
|
|
:type 'sexp
|
|
|
|
:group 'dns-mode)
|
|
|
|
|
2006-08-10 20:06:19 +00:00
|
|
|
(defcustom dns-mode-soa-auto-increment-serial t
|
|
|
|
"Whether to increment the SOA serial number automatically.
|
|
|
|
|
|
|
|
If this variable is t, the serial number is incremented upon each save of
|
|
|
|
the file. If it is `ask', Emacs asks for confirmation whether it should
|
|
|
|
increment the serial upon saving. If nil, serials must be incremented
|
|
|
|
manually with \\[dns-mode-soa-increment-serial]."
|
|
|
|
:type '(choice (const :tag "Always" t)
|
|
|
|
(const :tag "Ask" ask)
|
|
|
|
(const :tag "Never" nil))
|
|
|
|
:group 'dns-mode)
|
|
|
|
|
2004-09-14 11:09:35 +00:00
|
|
|
;; Syntax table.
|
|
|
|
|
|
|
|
(defvar dns-mode-syntax-table
|
|
|
|
(let ((table (make-syntax-table)))
|
|
|
|
(modify-syntax-entry ?\; "< " table)
|
|
|
|
(modify-syntax-entry ?\n "> " table)
|
|
|
|
table)
|
|
|
|
"Syntax table in use in DNS master file buffers.")
|
|
|
|
|
|
|
|
;; Keymap.
|
|
|
|
|
|
|
|
(defvar dns-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map "\C-c\C-s" 'dns-mode-soa-increment-serial)
|
|
|
|
map)
|
|
|
|
"Keymap for DNS master file mode.")
|
|
|
|
|
|
|
|
;; Menu.
|
|
|
|
|
|
|
|
(defvar dns-mode-menu nil
|
|
|
|
"Menubar used in DNS master file mode.")
|
|
|
|
|
|
|
|
(easy-menu-define dns-mode-menu dns-mode-map
|
|
|
|
"DNS Menu."
|
|
|
|
'("DNS"
|
|
|
|
["Increment SOA serial" dns-mode-soa-increment-serial t]))
|
|
|
|
|
|
|
|
;; Mode.
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(define-derived-mode dns-mode text-mode "DNS"
|
|
|
|
"Major mode for viewing and editing DNS master files.
|
|
|
|
This mode is inherited from text mode. It add syntax
|
|
|
|
highlighting, and some commands for handling DNS master files.
|
|
|
|
Its keymap inherits from `text-mode' and it has the same
|
|
|
|
variables for customizing indentation. It has its own abbrev
|
|
|
|
table and its own syntax table.
|
|
|
|
|
|
|
|
Turning on DNS mode runs `dns-mode-hook'."
|
|
|
|
(set (make-local-variable 'comment-start) ";")
|
|
|
|
(set (make-local-variable 'comment-end) "")
|
|
|
|
(set (make-local-variable 'comment-start-skip) ";+ *")
|
|
|
|
(unless (featurep 'xemacs)
|
|
|
|
(set (make-local-variable 'font-lock-defaults)
|
|
|
|
'(dns-mode-font-lock-keywords nil nil ((?_ . "w")))))
|
2006-08-11 13:56:50 +00:00
|
|
|
(add-hook 'before-save-hook 'dns-mode-soa-maybe-increment-serial
|
2006-08-10 20:06:19 +00:00
|
|
|
nil t)
|
2004-09-14 11:09:35 +00:00
|
|
|
(easy-menu-add dns-mode-menu dns-mode-map))
|
|
|
|
|
2006-08-10 20:06:19 +00:00
|
|
|
;;;###autoload (defalias 'zone-mode 'dns-mode)
|
|
|
|
|
2004-09-14 11:09:35 +00:00
|
|
|
;; Tools.
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun dns-mode-soa-increment-serial ()
|
|
|
|
"Locate SOA record and increment the serial field."
|
|
|
|
(interactive)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
|
|
|
(unless (re-search-forward
|
|
|
|
(concat "^\\(\\(\\([^ \t]+[ \t]+\\)?[^ \t]+"
|
|
|
|
"[ \t]+\\)?[^ \t]+[ \t]+\\)?SOA") nil t)
|
|
|
|
(error "Cannot locate SOA record"))
|
|
|
|
(if (re-search-forward (concat "\\<\\("
|
|
|
|
;; year
|
|
|
|
"\\(198\\|199\\|20[0-9]\\)[0-9]"
|
|
|
|
;; month
|
|
|
|
"\\(0[0-9]\\|10\\|11\\|12\\)"
|
|
|
|
;; day
|
|
|
|
"\\([012][0-9]\\|30\\|31\\)"
|
|
|
|
;; counter
|
|
|
|
"\\([0-9]\\{1,3\\}\\)"
|
|
|
|
"\\)\\>")
|
|
|
|
nil t)
|
|
|
|
;; YYYYMMDDIII format, one to three I's.
|
|
|
|
(let* ((serial (match-string 1))
|
|
|
|
(counterstr (match-string 5))
|
|
|
|
(counter (string-to-number counterstr))
|
|
|
|
(now (format-time-string "%Y%m%d"))
|
|
|
|
(nowandoldserial (concat now counterstr)))
|
|
|
|
(if (string< serial nowandoldserial)
|
|
|
|
(let ((new (format "%s00" now)))
|
|
|
|
(replace-match new nil nil nil 1)
|
|
|
|
(message "Replaced old serial %s with %s" serial new))
|
|
|
|
(if (string= serial nowandoldserial)
|
|
|
|
(let ((new (format (format "%%s%%0%dd" (length counterstr))
|
|
|
|
now (1+ counter))))
|
|
|
|
(replace-match new nil nil nil 1)
|
|
|
|
(message "Replaced old serial %s with %s" serial new))
|
|
|
|
(error "Current SOA serial is in the future"))))
|
|
|
|
(if (re-search-forward "\\<\\([0-9]\\{9,10\\}\\)\\>" nil t)
|
|
|
|
;; Unix time
|
|
|
|
(let* ((serial (match-string 1))
|
|
|
|
(new (format-time-string "%s")))
|
|
|
|
(if (not (string< serial new))
|
|
|
|
(error "Current SOA serial is in the future")
|
|
|
|
(replace-match new nil nil nil 1)
|
|
|
|
(message "Replaced old serial %s with %s" serial new)))
|
|
|
|
(if (re-search-forward "\\<\\([0-9]+\\)\\>" nil t)
|
|
|
|
;; Just any serial number.
|
|
|
|
(let* ((serial (match-string 1))
|
|
|
|
(new (format "%d" (1+ (string-to-number serial)))))
|
|
|
|
(replace-match new nil nil nil 1)
|
|
|
|
(message "Replaced old serial %s with %s" serial new))
|
|
|
|
(error "Cannot locate serial number in SOA record"))))))
|
|
|
|
|
2006-08-10 20:06:19 +00:00
|
|
|
(defun dns-mode-soa-maybe-increment-serial ()
|
|
|
|
"Increment SOA serial if needed.
|
|
|
|
|
2006-08-11 13:56:50 +00:00
|
|
|
This function is run from `before-save-hook'."
|
2006-08-10 20:06:19 +00:00
|
|
|
(when (and (buffer-modified-p)
|
|
|
|
dns-mode-soa-auto-increment-serial
|
|
|
|
(or (eq dns-mode-soa-auto-increment-serial t)
|
|
|
|
(y-or-n-p "Increment SOA serial? ")))
|
2006-08-11 14:11:24 +00:00
|
|
|
;; If `dns-mode-soa-increment-serial' signals an error saving will
|
|
|
|
;; fail but that probably means that the serial should be fixed to
|
|
|
|
;; comply with the RFC anyway! -rfr
|
2006-08-11 13:56:50 +00:00
|
|
|
(progn (dns-mode-soa-increment-serial)
|
2006-08-11 14:11:24 +00:00
|
|
|
;; We return nil in case this is used in write-contents-functions.
|
|
|
|
nil)))
|
2006-08-10 20:06:19 +00:00
|
|
|
|
* textmodes/tex-mode.el (tex-alt-dvi-print-command)
(tex-dvi-print-command, tex-bibtex-command, tex-start-commands)
(tex-start-options, slitex-run-command, latex-run-command)
(tex-run-command, tex-directory):
* textmodes/ispell.el (ispell-html-skip-alists)
(ispell-tex-skip-alists, ispell-tex-skip-alists):
* textmodes/fill.el (adaptive-fill-first-line-regexp):
(adaptive-fill-regexp):
* textmodes/dns-mode.el (auto-mode-alist):
* progmodes/python.el (interpreter-mode-alist):
* progmodes/etags.el (tags-compression-info-list):
* progmodes/etags.el (tags-file-name):
* net/browse-url.el (browse-url-galeon-program)
(browse-url-firefox-program):
* mail/sendmail.el (mail-signature-file)
(mail-citation-prefix-regexp):
* international/mule-conf.el (eight-bit):
* international/latexenc.el (latex-inputenc-coding-alist):
* international/fontset.el (x-pixel-size-width-font-regexp):
* emacs-lisp/warnings.el (warning-type-format):
* emacs-lisp/trace.el (trace-buffer):
* emacs-lisp/lisp-mode.el (lisp-interaction-mode-map)
(emacs-lisp-mode-map):
* calendar/holidays.el (holiday-solar-holidays)
(holiday-bahai-holidays, holiday-islamic-holidays)
(holiday-christian-holidays, holiday-hebrew-holidays)
(hebrew-holidays-4, hebrew-holidays-3, hebrew-holidays-2)
(hebrew-holidays-1, holiday-oriental-holidays)
(holiday-general-holidays):
* x-dnd.el (x-dnd-known-types):
* tool-bar.el (tool-bar):
* startup.el (site-run-file):
* shell.el (shell-dumb-shell-regexp):
* rfn-eshadow.el (file-name-shadow-tty-properties)
(file-name-shadow-properties):
* paths.el (remote-shell-program, news-directory):
* mouse.el ([C-down-mouse-3]):
* menu-bar.el (menu-bar-tools-menu):
* jka-cmpr-hook.el (jka-compr-load-suffixes)
(jka-compr-mode-alist-additions, jka-compr-compression-info-list)
(jka-compr-compression-info-list):
* isearch.el (search-whitespace-regexp):
* image-file.el (image-file-name-extensions):
* find-dired.el (find-ls-option):
* files.el (directory-listing-before-filename-regexp)
(directory-free-space-args, insert-directory-program)
(list-directory-brief-switches, magic-fallback-mode-alist)
(magic-fallback-mode-alist, auto-mode-interpreter-regexp)
(automount-dir-prefix):
* faces.el (face-x-resources, x-font-regexp, x-font-regexp-head)
(x-font-regexp-slant, x-font-regexp-weight, face-x-resources)
(face-font-registry-alternatives, face-font-registry-alternatives)
(face-font-family-alternatives):
* facemenu.el (facemenu-add-new-face, facemenu-background-menu)
(facemenu-foreground-menu, facemenu-face-menu):
* epa-hook.el (epa-file-name-regexp):
* dnd.el (dnd-protocol-alist):
* textmodes/rst.el (auto-mode-alist):
* button.el (default-button): Purecopy strings.
2009-11-06 05:16:23 +00:00
|
|
|
;;;###autoload(add-to-list 'auto-mode-alist (purecopy '("\\.soa\\'" . dns-mode)))
|
2004-09-14 11:09:35 +00:00
|
|
|
|
|
|
|
(provide 'dns-mode)
|
|
|
|
|
|
|
|
;; arch-tag: 6a179f0a-072f-49db-8b01-37b8f23998c0
|
|
|
|
;;; dns-mode.el ends here
|