2010-03-12 21:16:15 +00:00
#!@PYTHON@
2010-03-15 16:29:45 +00:00
# Copyright (C) 2009 Internet Systems Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2010-03-16 12:39:09 +00:00
""" This is the main calling class for the bindctl configuration and
command tool . It sets up a command interpreter and runs that . """
2010-03-15 16:29:45 +00:00
2010-03-12 21:16:15 +00:00
import sys ; sys . path . append ( ' @@PYTHONPATH@@ ' )
2010-03-15 16:29:45 +00:00
from bindctl . moduleinfo import *
from bindctl . bindcmd import *
import pprint
from optparse import OptionParser , OptionValueError
2010-10-11 09:39:02 +00:00
import isc . util . process
2010-09-28 11:01:19 +00:00
2010-10-11 09:39:02 +00:00
isc . util . process . rename ( )
2010-03-15 16:29:45 +00:00
2010-12-01 20:32:13 +00:00
# This is the version that gets displayed to the user.
# The VERSION string consists of the module name, the module version
# number, and the overall BIND 10 version number (set in configure.ac).
2011-02-24 14:03:34 -06:00
VERSION = " bindctl 20110217 (BIND 10 @PACKAGE_VERSION@) "
2010-03-15 16:29:45 +00:00
2011-02-18 12:26:59 -06:00
DEFAULT_IDENTIFIER_DESC = " The identifier specifies the config item. Child elements are separated with the ' / ' character. List indices can be specified with ' [i] ' , where i is an integer specifying the index, starting with 0. Examples: ' Boss/start_auth ' , ' Recurse/listen_on[0]/address ' . If no identifier is given, shows the item at the current location. "
2011-01-04 11:16:39 +00:00
2010-03-15 16:29:45 +00:00
def prepare_config_commands ( tool ) :
2010-03-16 12:39:09 +00:00
''' Prepare fixed commands for local configuration editing '''
2011-02-18 12:48:07 -06:00
module = ModuleInfo ( name = CONFIG_MODULE_NAME , desc = " Configuration commands. " )
cmd = CommandInfo ( name = " show " , desc = " Show configuration. " )
param = ParamInfo ( name = " argument " , type = " string " , optional = True , desc = " If you specify the argument ' all ' (before the identifier), recursively show all child elements for the given identifier. " )
2010-12-22 14:38:47 +00:00
cmd . add_param ( param )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = True , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " show_json " , desc = " Show full configuration in JSON format. " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = True , desc = DEFAULT_IDENTIFIER_DESC )
2010-11-04 11:44:48 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-01-03 14:29:55 +00:00
cmd = CommandInfo ( name = " add " , desc = " Add an entry to configuration list. If no value is given, a default value is added. " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = True , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " value " , type = " string " , optional = True , desc = " Specifies a value to add to the list. It must be in correct JSON format and complete. " )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " remove " , desc = " Remove entry from configuration list. " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = True , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " value " , type = " string " , optional = True , desc = " Specifies a value to remove from the list. It must be in correct JSON format and complete. " )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " set " , desc = " Set a configuration value. " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = True , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " value " , type = " string " , optional = False , desc = " Specifies a value to set. It must be in correct JSON format and complete. " )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " unset " , desc = " Unset a configuration value (i.e. revert to the default, if any). " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = False , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " diff " , desc = " Show all local changes that have not been committed. " )
2010-03-15 16:29:45 +00:00
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " revert " , desc = " Revert all local changes. " )
2010-03-15 16:29:45 +00:00
module . add_command ( cmd )
2011-01-04 11:16:39 +00:00
cmd = CommandInfo ( name = " commit " , desc = " Commit all local changes. " )
2010-03-15 16:29:45 +00:00
module . add_command ( cmd )
2011-02-18 12:48:07 -06:00
cmd = CommandInfo ( name = " go " , desc = " Go to a specific configuration part. " )
2011-01-04 11:16:39 +00:00
param = ParamInfo ( name = " identifier " , type = " string " , optional = False , desc = DEFAULT_IDENTIFIER_DESC )
2010-03-15 16:29:45 +00:00
cmd . add_param ( param )
module . add_command ( cmd )
tool . add_module_info ( module )
def check_port ( option , opt_str , value , parser ) :
if ( value < 0 ) or ( value > 65535 ) :
raise OptionValueError ( ' %s requires a port number (0-65535) ' % opt_str )
parser . values . port = value
def check_addr ( option , opt_str , value , parser ) :
ipstr = value
ip_family = socket . AF_INET
if ( ipstr . find ( ' : ' ) != - 1 ) :
ip_family = socket . AF_INET6
try :
socket . inet_pton ( ip_family , ipstr )
except :
raise OptionValueError ( " %s invalid ip address " % ipstr )
parser . values . addr = value
def set_bindctl_options ( parser ) :
2011-03-08 14:58:07 -08:00
parser . add_option ( ' -p ' , ' --port ' , dest = ' port ' , type = ' int ' ,
action = ' callback ' , callback = check_port ,
default = ' 8080 ' , help = ' port for cmdctl of bind10 ' )
2010-03-15 16:29:45 +00:00
2011-03-08 14:58:07 -08:00
parser . add_option ( ' -a ' , ' --address ' , dest = ' addr ' , type = ' string ' ,
action = ' callback ' , callback = check_addr ,
default = ' 127.0.0.1 ' , help = ' IP address for cmdctl of bind10 ' )
2010-03-15 16:29:45 +00:00
2011-03-08 14:58:07 -08:00
parser . add_option ( ' -c ' , ' --certificate-chain ' , dest = ' cert_chain ' ,
type = ' string ' , action = ' store ' ,
help = ' PEM formatted server certificate validation chain file ' )
parser . add_option ( ' --csv-file-dir ' , dest = ' csv_file_dir ' , type = ' string ' ,
default = None , action = ' store ' ,
help = ' Directory to store the password CSV file ' )
2010-03-15 16:29:45 +00:00
if __name__ == ' __main__ ' :
2011-02-17 11:55:08 +01:00
parser = OptionParser ( version = VERSION )
set_bindctl_options ( parser )
( options , args ) = parser . parse_args ( )
server_addr = options . addr + ' : ' + str ( options . port )
2011-03-08 14:58:07 -08:00
tool = BindCmdInterpreter ( server_addr , pem_file = options . cert_chain ,
csv_file_dir = options . csv_file_dir )
2011-02-17 11:55:08 +01:00
prepare_config_commands ( tool )
tool . run ( )