F:/thesis_austausch/dissertation/code_docu_doxygen/Remote_Controller/admin_server.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''
00004 This module can be used to administer the server (daemon).
00005 
00006 Reading University
00007 MSc in Network Centered Computing
00008 a.weise - a.weise@reading.ac.uk - December 2005
00009 '''
00010 
00011 # config parsing
00012 import ConfigParser, string
00013 
00014 #misc
00015 import os, getopt, sys, re
00016 
00017 # connection issues
00018 from M2Crypto.m2xmlrpclib import Server, SSL_Transport
00019 from M2Crypto import SSL
00020 
00021 def LoadConfig(file, config={}):
00022     """
00023     This function returns a dictionary with key's of the form
00024     <section>.<option> and the corresponding values.
00025     
00026     source: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65334
00027     """
00028     config = config.copy()
00029     cp = ConfigParser.ConfigParser()
00030     cp.read(file)
00031     for sec in cp.sections():
00032         name = string.lower(sec)
00033         for opt in cp.options(sec):
00034             config[name + "." + string.lower(opt)] = string.strip(cp.get(sec, opt))
00035     return config
00036 
00037 
00038 class Colour:
00039     '''
00040     This class uses the ANSI escape sequences to color the output !
00041     '''
00042     color = {"reset":"\x1b[0m",
00043             "bold":"\x1b[01m",
00044             "teal":"\x1b[36;06m",
00045             "turquoise":"\x1b[36;01m",
00046             "fuscia":"\x1b[35;01m",
00047             "purple":"\x1b[35;06m",
00048             "blue":"\x1b[34;01m",
00049             "darkblue":"\x1b[34;06m",
00050             "green":"\x1b[32;01m",
00051             "darkgreen":"\x1b[32;06m",
00052             "yellow":"\x1b[33;01m",
00053             "brown":"\x1b[33;06m",
00054             "red":"\x1b[31;01m",
00055             "darkred":"\x1b[31;06m"}
00056     
00057     def __init__(self):
00058         '''
00059         Constructor 
00060         '''
00061         pass
00062     
00063     def green(self, text):
00064         '''
00065         dye green
00066         '''
00067         return self.color['green']+text+self.color['reset']
00068         
00069     def red(self, text):
00070         '''
00071         dye red
00072         '''
00073         return self.color['red']+text+self.color['reset']
00074     
00075     def bold(self, text):
00076         '''
00077         dye bold
00078         '''
00079         return self.color['bold']+text+self.color['reset']
00080     
00081     def teal(self, text):
00082         '''
00083         dye teal
00084         '''
00085         return self.color['teal']+text+self.color['reset']
00086     
00087     def turquoise(self, text):
00088         '''
00089         dye turquoise
00090         '''
00091         return self.color['turquoise']+text+self.color['reset']
00092     
00093     def fuscia(self, text):
00094         '''
00095         dye fuscia
00096         '''
00097         return self.color['fuscia']+text+self.color['reset']
00098     
00099     def purple(self, text):
00100         '''
00101         dye purple
00102         '''
00103         return self.color['purple']+text+self.color['reset']
00104     
00105     def darkred(self, text):
00106         '''
00107         dye darkred
00108         '''
00109         return self.color['darkred']+text+self.color['reset']    
00110     
00111     def darkblue(self, text):
00112         '''
00113         dye darkblue
00114         '''
00115         return self.color['darkblue']+text+self.color['reset']
00116 
00117     def blue(self, text):
00118         '''
00119         dye blue
00120         '''
00121         return self.color['blue']+text+self.color['reset']
00122     
00123     def darkgreen(self, text):
00124         '''
00125         dye darkgreen
00126         '''
00127         return self.color['darkgreen']+text+self.color['reset']
00128     
00129     def yellow(self, text):
00130         '''
00131         dye yellow
00132         '''
00133         return self.color['yellow']+text+self.color['reset']
00134     
00135     def brown(self, text):
00136         '''
00137         dye brown
00138         '''
00139         return self.color['brown']+text+self.color['reset']    
00140 
00141 
00142 class Admin:
00143     '''
00144     This is manager class for the Remote Controller application.
00145     '''
00146     
00147     def __init__(self, config):
00148         '''
00149         Constructor
00150         '''
00151         workingpath = os.getcwd()
00152         
00153         # varify user input
00154         self.__client_certificate = config.get("files.client_certificate")
00155         self.__client_certificate_path = config.get("path.path_client_certificate") 
00156         self.__client_certificate_path = self.__client_certificate_path.rstrip("/")        
00157         if(config.get("path.path_client_certificate") == '' or config.get("path.path_client_certificate") == None):
00158             self.__client_certificate_path = workingpath
00159         else:
00160             self.__client_certificate = self.__client_certificate.strip()
00161             if (-1 != self.__client_certificate_path.find("/", 0, 1)):
00162                 # first character "/"
00163                 pass
00164             else:
00165                 self.__client_certificate_path = workingpath+"/"+self.__client_certificate_path
00166                 
00167         self.__client_ca = config.get("files.client_ca")
00168         self.__client_ca_path = config.get("path.path_client_ca") 
00169         self.__client_ca_path = self.__client_ca_path.rstrip("/")        
00170         if(config.get("path.path_client_ca") == '' or config.get("path.path_client_ca") == None):
00171             self.__client_ca_path = workingpath
00172         else:
00173             self.__client_ca = self.__client_ca.strip()
00174             if (-1 != self.__client_ca_path.find("/", 0, 1)):
00175                 # first character "/"
00176                 pass
00177             else:
00178                 self.__client_ca_path = workingpath+"/"+self.__client_ca_path
00179                 
00180         # check if file are existing                
00181         if(0 == os.access((self.__client_ca_path+"/"+self.__client_ca), 4)):    # 4 R_OK
00182             print "\nCould not access client ca certificate under \"%s\" !\nMaybe change configuration file and try again!\n\n" % (self.__client_ca_path+"/"+self.__client_ca)
00183             os._exit(-1)
00184         
00185         if(0 == os.access((self.__client_certificate_path+"/"+self.__client_certificate), 4)):    # 4 R_OK
00186             print "\nCould not access client certificate under %s !\nMaybe change configuration file and try again!\n\n" % (self.__client_certificate_path+"/"+self.__client_certificate)
00187             os._exit(-1)          
00188 
00189     def connect_to_server(self, server, port):
00190         '''
00191         This function establishs the connection to the server.
00192         '''
00193         serverus = server
00194 
00195         ctx = self.create_ctx()
00196         # connect to server via SSL using the created context
00197         urladdress = "https://%s:%d" % (serverus, port)
00198         server = Server(urladdress, SSL_Transport(ctx))
00199         # return server object
00200         return server
00201 
00202     def create_ctx(self):
00203         '''
00204         This funciton creates the SSL context to establish an encrypted connetion by using certificates.
00205         '''
00206         ctx = SSL.Context(protocol='sslv3') # use SSLv3 only
00207         ctx.load_cert(self.__client_certificate_path+"/"+self.__client_certificate)         # load client certificate
00208         ctx.load_client_CA(self.__client_ca_path+"/"+self.__client_ca)        # load certificate authority private key
00209         # ctx.set_info_callback()             # tell me what you're doing --- debug ----
00210         ctx.set_session_id_ctx('server')     # session name
00211         return ctx    
00212 
00213 # ----------------- additional functions -------------------
00214 
00215 def usage_exit(progname, msg = None, color = 1):
00216     '''
00217     This function gives usage help and exits the module.
00218     '''
00219     if msg:
00220         if 1 == color and msg != None:
00221             color_obj = Colour()
00222             print color_obj.red(msg)
00223         else:
00224             print msg
00225         print # lf cr
00226     
00227     text = "usage: python %s -c config_file [optional commands] \n\n" % progname
00228     if 1 == color:
00229         print color_obj.red(text)
00230     else:
00231         print text
00232     os._exit(-1)
00233     
00234 def check_ip(ip):
00235     '''
00236     This function checks if a given IP is valid and returns -1 for an invalid IP address otherwise 0.
00237     '''
00238 
00239     try:
00240         ip = ip.split(".") # split in 4 number
00241     except AttributeError:
00242         return -1
00243     
00244     for i in range(len(ip)):
00245         check =  ip[i].find("0", 0, 1)
00246         if -1 != check and 1 < len(ip[i]):
00247             return -1
00248         try:
00249             ip[i] = int(ip[i])
00250         except ValueError:
00251             return -1
00252         if ip[i] >= 0 and ip[i] <= 255: # check if number is between 0 and 255
00253             pass
00254         else:
00255             return -1
00256         
00257     return 0
00258 
00259 def find_item(search, listus):
00260     '''
00261     This function finds an item within a list (1-3 dimensional) and returns the list index otherwise "None".
00262     '''
00263     for i in range(len(listus)):
00264         if 1 == len(listus[i]):
00265             if listus[i] == search:
00266                 return i
00267         elif 2 == len(listus[i]):
00268             if listus[i][0] == search:
00269                 return i
00270         elif 3 == len(listus[i]):
00271             if listus[i][0][0] == search:
00272                 return i
00273     return None
00274 
00275 def help_context(color):
00276     '''
00277     This function provides the help context.
00278     '''
00279     
00280     color_obj = Colour()
00281     msg = ''
00282     if color == 1:
00283         msg += color_obj.green("\n-----------   Help   ----------\n\n\n")
00284     else:
00285         msg += "\n-----------   Help   ----------\n\n\n"
00286         
00287     note = "PLEASE NOTE, if you give parameter values, please do not enter characters like \" \" (space) or \"!\", because this could be characters which are interpreted by the terminal. If you have to enter such characters, please escape them like \"\!\".\n\n"
00288     if color == 1:
00289         msg += color_obj.purple(note)
00290     else:
00291         msg += note
00292         
00293     msg += "-c or --config\t\t\t-> defines config file, if no config file given, default values are used\n"\
00294         "-h or --help\t\t\t-> print this help\n"\
00295         "--nocolor\t\t\t-> no colored console output\n"
00296     if color == 1:
00297         msg += color_obj.green("\n-----  server commands  -----\n\n")
00298     else:
00299         msg += "\n-----  server commands  -----\n\n"
00300     msg += "--rpc_status\t\t\t-> show actual setting of rpc (disabled/enabled) (on server side)\n"\
00301         "--disable_rpc\t\t\t-> disable rpc calls (on server side)\n"\
00302         "--enable_rpc\t\t\t-> enable rpc calls (on server side)\n"\
00303         "--shutdown\t\t\t-> shutdown server\n"\
00304         "--change_interval <int>\t\t-> change parsing interval of server\n"\
00305         "--keyword_status\t\t-> show actual setting of \"keywords\" (on server side)\n"\
00306         "--add_keyword <string>\t\t-> add keyword to keyword list (on server side)\n"\
00307         "--delete_keyword <string>\t-> delete keyword to keyword list (on server side)\n"\
00308         "--ignore_error_status\t\t-> show actual setting of \"ignoer_error\" (on server side)\n"\
00309         "--add_ignore_error <int>\t-> add error, which the parser should ignore (on server side)\n"\
00310         "--delete_ignore_error <int>\t-> delete error, which the parser is ignoring (on server side)\n"
00311     if color == 1:
00312         msg += color_obj.green("\n-----  additional parameters  -----\n")
00313     else:
00314         msg += "\n-----  additional parameters  -----\n"
00315     msg += "\n--ip <ip>\t\t\t-> host IP\n"\
00316         "--port <int>\t\t\t-> port, where the server is listening\n"
00317     if color == 1:
00318         msg += color_obj.green("\n-----  examples  -----\n\n")
00319         msg += color_obj.blue("python gui.py -c config_gui.ini --disable_rpc --ip 127.0.0.1 --port 6000\n")
00320         msg += color_obj.yellow("\t-> disable rpc calls on localhost\n\n")
00321         msg += color_obj.blue("python gui.py -c config_gui.ini --ip 127.0.0.1 --port 6000 --add_keyword status:\!error\n")
00322         msg += color_obj.yellow("\t-> add new keyword set \"status AND NOT error\" into keyword file on localhost\n\n")
00323     else:
00324         msg += "\n-----  examples  -----\n\n"\
00325                 "python gui.py -c config_gui.ini --disable_rpc --ip 127.0.0.1 --port 6000\n\t-> disable rpc calls on localhost\n\n"\
00326                 "python gui.py -c config_gui.ini --ip 127.0.0.1 --port 6000 --add_keyword status:\!error\n\t-> add new keyword set \"status AND NOT error\" into keyword file on localhost\n\n"
00327     msg += "\n"
00328     
00329     return msg
00330 
00331     
00332     
00333 #############################################################    
00334     
00335 def start():
00336     
00337     '''
00338     The functions starts the application.
00339     '''
00340     col = 1
00341     rpc_status = None
00342     disable_rpc = None
00343     enable_rpc = None
00344     shutdown = None
00345     change_interval = None
00346     interval_status = None
00347     keyword_status = None
00348     add_keyword = None
00349     delete_keyword = None
00350     add_error = None
00351     delete_error = None
00352     error_status = None
00353     ip = None
00354     port = None
00355     
00356     # parameter evaluation
00357     try:
00358         opts, args = getopt.getopt(sys.argv[1:], 'c:hg', ['config=', 'nocolor', 'help', 'rpc_status', 'disable_rpc', 'enable_rpc', 'shutdown', 'interval_status', 'change_interval=', 'keyword_status', 'add_keyword=', 'delete_keyword=', 'ignore_error_status', 'add_ignore_error=', 'delete_ignore_error=', 'ip=', 'port='])
00359         for opt, value in opts:
00360             if opt in ('', '--nocolor'):
00361                 col = 0
00362             if opt in ('-h','--help'):
00363                 msg = help_context(col)
00364                 usage_exit(sys.argv[0], msg, col)
00365             if opt in ('-c', '--config'):
00366                 value = value.replace("=", "")
00367                 configfile = os.getcwd()+"/"+value
00368                 
00369         for opt, value in opts:
00370             if opt in ('', '--rpc_status'):
00371                 rpc_status = 1
00372             if opt in ('', '--disable_rpc'):
00373                 disable_rpc = 1
00374             if opt in ('', '--enable_rpc'):
00375                 enable_rpc = 1
00376             if opt in ('', '--shutdown'):
00377                 shutdown = 1
00378             if opt in ('', '--interval_status'):
00379                 interval_status = 1
00380             if opt in ('', '--change_interval'):
00381                 change_interval = int(value)
00382             if opt in ('', '--keyword_status'):
00383                 keyword_status = 1
00384             if opt in ('', '--add_keyword'):
00385                 add_keyword = value
00386             if opt in ('', '--delete_keyword'):
00387                 delete_keyword = value
00388             if opt in ('', '--add_ignore_error'):
00389                 add_error = int(value)
00390             if opt in ('', '--delete_ignore_error'):
00391                 delete_error = int(value)
00392             if opt in ('', '--ignore_error_status'):
00393                 error_status = 1
00394             if opt in ('','--ip'):
00395                 ip = value
00396                 status = re.search('^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}', ip)
00397                 if (None == status):
00398                     usage_exit(sys.argv[0], 'given IP is not valid', col)
00399                 else:
00400                     ip = status.string[status.start():status.end()]                   
00401                     if (0 != check_ip(ip)):
00402                         usage_exit(sys.argv[0], 'given IP is not valid', col)
00403             if opt in ('', '--port'):
00404                 port = int(value)
00405                 if (port < 1024 or port > 50001):
00406                     usage_exit(sys.argv[0], "Server port is out of range! \nMake sure the server port lies between 1025 (inclusive) and 50000 (inclusive)!\n\n", col)
00407     except getopt.error, e:
00408         e = "%s" % e
00409         usage_exit(sys.argv[0], e, col)
00410     except ValueError, e:
00411         e = "%s" % e
00412         usage_exit(sys.argv[0], e, col)
00413            
00414     # load config file or default values
00415     if (configfile != ""):
00416         # check if file exists
00417         if(1 == os.path.exists(configfile)):
00418             config = LoadConfig(configfile)
00419         else:
00420             # if file NOT exists terminate program
00421             print "\n\nSorry, a given config file does NOT exist !\nPlease try again!\n\n"
00422             os._exit(-1)
00423     else:
00424         msg = "\nNo config file spezified !\n"
00425         usage_exit(sys.argv[0], msg, col)
00426         
00427         
00428     gui = Admin(config)    
00429         
00430     if col == 1:
00431         col_obj = Colour()
00432         
00433     #------------------- SERVER COMMANDS -------------------#
00434     
00435     if (1 == rpc_status):
00436         # get rpc status on server side
00437         if (None != ip and None != port):
00438             text = "Check RPC status on server \"%s:%d\"." % (ip, port)
00439             if col == 1:
00440                 text = col_obj.yellow(text)
00441             print
00442             print text
00443             serv_object = gui.connect_to_server(ip, port)
00444             try:
00445                 answer = serv_object.rpc_status()
00446                 if col == 1:
00447                     answer = col_obj.green(answer)                   
00448                 print "\nserver -> %s" % answer
00449             except AssertionError:
00450                 text = "Server is down !"
00451                 if col == 1:
00452                     print col_obj.red(text)
00453                 else:
00454                     print text
00455             except:
00456                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00457                 if col == 1:
00458                     print col_obj.red(text)
00459                 else:
00460                     print text
00461         else:
00462             text = "\nNo IP or port given !\n"
00463             if col == 1:
00464                 print col_obj.red(text)
00465             else:
00466                 print text
00467     
00468     elif (1 == disable_rpc):
00469         # disable_rpc on server side
00470         if (None != ip and None != port):
00471             text = "Disable RPC on server \"%s:%d\"." % (ip, port)
00472             if col == 1:
00473                 text = col_obj.yellow(text)
00474             print
00475             print text
00476             serv_object = gui.connect_to_server(ip, port)
00477             try:
00478                 answer = serv_object.disable_rpc_calls()
00479                 if col == 1:
00480                     answer = col_obj.green(answer)                   
00481                 print "\nserver -> %s" % answer
00482             except AssertionError:
00483                 text = "Server is down !"
00484                 if col == 1:
00485                     print col_obj.red(text)
00486                 else:
00487                     print text
00488             except:
00489                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00490                 if col == 1:
00491                     print col_obj.red(text)
00492                 else:
00493                     print text
00494         else:
00495             text = "\nNo IP or port given !\n"
00496             if col == 1:
00497                 print col_obj.red(text)
00498             else:
00499                 print text
00500     
00501     elif (1 == enable_rpc):
00502         # enable_rpc on server side
00503         if (None != ip and None != port):
00504             text = "Enable RPC on server \"%s:%d\"." % (ip, port)
00505             if col == 1:
00506                 text = col_obj.yellow(text)
00507             print
00508             print text
00509             serv_object = gui.connect_to_server(ip, port)
00510             try:
00511                 answer = serv_object.enable_rpc_calls()
00512                 if col == 1:
00513                     answer = col_obj.green(answer)                   
00514                 print "\nserver -> %s" % answer
00515             except AssertionError:
00516                 text = "Server is down !"
00517                 if col == 1:
00518                     print col_obj.red(text)
00519                 else:
00520                     print text
00521             except:
00522                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00523                 if col == 1:
00524                     print col_obj.red(text)
00525                 else:
00526                     print text
00527         else:
00528             text = "\nNo IP or port given !\n"
00529             if col == 1:
00530                 print col_obj.red(text)
00531             else:
00532                 print text
00533             
00534     elif (1 == shutdown):
00535         # shutdown the server
00536         if (None != ip and None != port):
00537             text = "Shutdown server \"%s:%d\"." % (ip, port)
00538             if col == 1:
00539                 text = col_obj.yellow(text)
00540             print
00541             print text
00542             serv_object = gui.connect_to_server(ip, port)
00543             try:
00544                 answer = serv_object.stop_server()
00545                 if col == 1:
00546                     answer = col_obj.green(answer)                   
00547                 print "\nserver -> %s" % answer
00548             except AssertionError:
00549                 text = "Server is down !"
00550                 if col == 1:
00551                     print col_obj.red(text)
00552                 else:
00553                     print text
00554             except:
00555                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00556                 if col == 1:
00557                     print col_obj.red(text)
00558                 else:
00559                     print text
00560         else:
00561             text = "\nNo IP or port given !\n"
00562             if col == 1:
00563                 print col_obj.red(text)
00564             else:
00565                 print text
00566             
00567     elif (None !=  change_interval):
00568         # change parsing interval time
00569         if (None != ip and None != port):
00570             text = "Change parsing interval on server \"%s:%d\" to %d minutes." % (ip, port, change_interval)
00571             if col == 1:
00572                 text = col_obj.yellow(text)
00573             print
00574             print text
00575             serv_object = gui.connect_to_server(ip, port)
00576             try:
00577                 answer = serv_object.rpc_update_configuration("misc", "minute", change_interval, 2)
00578                 if answer == 0:
00579                     answer = "interval successfully to %d minutes changed" % change_interval
00580                 else:
00581                     answer = "could not change interval \n-> \"%s\"" % answer
00582                 if col == 1:
00583                     answer = col_obj.green(answer)                   
00584                 print "\nserver -> %s" % answer
00585             except AssertionError:
00586                 text = "Server is down !"
00587                 if col == 1:
00588                     print col_obj.red(text)
00589                 else:
00590                     print text
00591             except:
00592                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00593                 if col == 1:
00594                     print col_obj.red(text)
00595                 else:
00596                     print text
00597         else:
00598             text = "\nNo IP or port given !\n"
00599             if col == 1:
00600                 print col_obj.red(text)
00601             else:
00602                 print text     
00603 
00604     elif (1 ==  error_status):
00605         # get ignore error status from server
00606         if (None != ip and None != port):
00607             text = "Get status for \"ignore_error\" from server \"%s:%d\"." % (ip, port)
00608             if col == 1:
00609                 text = col_obj.yellow(text)
00610             print
00611             print text
00612             serv_object = gui.connect_to_server(ip, port)
00613             try:
00614                 answer = serv_object.rpc_update_configuration("misc", "ignore_error", 0, 4)
00615                 if col == 1:
00616                     answer = col_obj.green(answer)                   
00617                 print "\nserver -> %s" % answer
00618             except AssertionError:
00619                 text = "Server is down !"
00620                 if col == 1:
00621                     print col_obj.red(text)
00622                 else:
00623                     print text
00624             except:
00625                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00626                 if col == 1:
00627                     print col_obj.red(text)
00628                 else:
00629                     print text
00630         else:
00631             text = "\nNo IP or port given !\n"
00632             if col == 1:
00633                 print col_obj.red(text)
00634             else:
00635                 print text 
00636 
00637     elif (None !=  add_error):
00638         # add ignore error 
00639         if (None != ip and None != port):
00640             text = "Add \"ignore_error\" %s on server \"%s:%d\"." % ( add_error, ip, port)
00641             if col == 1:
00642                 text = col_obj.yellow(text)
00643             print
00644             print text
00645             serv_object = gui.connect_to_server(ip, port)
00646             try:
00647                 answer = serv_object.rpc_update_configuration("misc", "ignore_error", add_error, 1)
00648                 if col == 1:
00649                     answer = col_obj.green(answer)                   
00650                 print "\nserver -> %s" % answer
00651             except AssertionError:
00652                 text = "Server is down !"
00653                 if col == 1:
00654                     print col_obj.red(text)
00655                 else:
00656                     print text
00657             except:
00658                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00659                 if col == 1:
00660                     print col_obj.red(text)
00661                 else:
00662                     print text
00663         else:
00664             text = "\nNo IP or port given !\n"
00665             if col == 1:
00666                 print col_obj.red(text)
00667             else:
00668                 print text 
00669 
00670     elif (None !=  delete_error):
00671         # delete ignore error
00672         if (None != ip and None != port):
00673             text = "Delete \"ignore_error\" %s on server \"%s:%d\"." % ( delete_error, ip, port)
00674             if col == 1:
00675                 text = col_obj.yellow(text)
00676             print
00677             print text
00678             serv_object = gui.connect_to_server(ip, port)
00679             try:
00680                 answer = serv_object.rpc_update_configuration("misc", "ignore_error", delete_error, 0)
00681                 if col == 1:
00682                     answer = col_obj.green(answer)                 
00683                 print "\nserver -> %s" % answer
00684             except AssertionError:
00685                 text = "Server is down !"
00686                 if col == 1:
00687                     print col_obj.red(text)
00688                 else:
00689                     print text
00690             except:
00691                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00692                 if col == 1:
00693                     print col_obj.red(text)
00694                 else:
00695                     print text
00696         else:
00697             text = "\nNo IP or port given !\n"
00698             if col == 1:
00699                 print col_obj.red(text)
00700             else:
00701                 print text
00702             
00703             
00704     elif (1 ==  keyword_status):
00705         # get keywords which are used currently
00706         if (None != ip and None != port):
00707             text = "Get keywords from server \"%s:%s\"." % (  ip, port)
00708             if col == 1:
00709                 text = col_obj.yellow(text)
00710             print
00711             print text
00712             serv_object = gui.connect_to_server(ip, port)
00713             try:
00714                 answer = serv_object.rpc_update_keyword_file("status", 2)
00715                 if col == 1:
00716                     answer = col_obj.green(answer)                
00717                 print "\nserver -> %s" % answer
00718             except AssertionError:
00719                 text = "Server is down !"
00720                 if col == 1:
00721                     print col_obj.red(text)
00722                 else:
00723                     print text
00724             except:
00725                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00726                 if col == 1:
00727                     print col_obj.red(text)
00728                 else:
00729                     print text
00730         else:
00731             text = "\nNo IP or port given !\n"
00732             if col == 1:
00733                 print col_obj.red(text)
00734             else:
00735                 print text
00736             
00737     elif (None !=  add_keyword):
00738         # add new keyword
00739         if (None != ip and None != port):
00740             text = "Add keyword \"%s\" on server \"%s:%s\"." % (add_keyword, ip, port)
00741             if col == 1:
00742                 text = col_obj.yellow(text)
00743             print
00744             print text
00745             serv_object = gui.connect_to_server(ip, port)
00746             try:
00747                 answer = serv_object.rpc_update_keyword_file(add_keyword, 1)
00748                 if col == 1:
00749                     answer = col_obj.green(answer)
00750                 print "\nserver -> %s" % answer
00751             except AssertionError:
00752                 text = "Server is down !"
00753                 if col == 1:
00754                     print col_obj.red(text)
00755                 else:
00756                     print text
00757             except:
00758                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00759                 if col == 1:
00760                     print col_obj.red(text)
00761                 else:
00762                     print text
00763         else:
00764             text = "\nNo IP or port given !\n"
00765             if col == 1:
00766                 print col_obj.red(text)
00767             else:
00768                 print text
00769                 
00770     elif (None !=  delete_keyword):
00771         # delete keyword
00772         if (None != ip and None != port):
00773             text = "Delete keyword \"%s\" in keyword list on server \"%s:%s\"." % (delete_keyword, ip, port)
00774             if col == 1:
00775                 text = col_obj.yellow(text)
00776             print
00777             print text
00778             serv_object = gui.connect_to_server(ip, port)
00779             try:
00780                 answer = serv_object.rpc_update_keyword_file(delete_keyword, 0)
00781                 if col == 1:
00782                     answer = col_obj.green(answer)
00783                 print "\nserver -> %s" % answer
00784             except AssertionError:
00785                 text = "Server is down !"
00786                 if col == 1:
00787                     print col_obj.red(text)
00788                 else:
00789                     print text
00790             except:
00791                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00792                 if col == 1:
00793                     print col_obj.red(text)
00794                 else:
00795                     print text
00796         else:
00797             text = "\nNo IP or port given !\n"
00798             if col == 1:
00799                 print col_obj.red(text)
00800             else:
00801                 print text
00802                 
00803     elif (1 ==  interval_status):
00804         # get current parsing interval time
00805         if (None != ip and None != port):
00806             text = "Get parsing interval time (in minutes) from server \"%s:%s\"." % (ip, port)
00807             if col == 1:
00808                 text = col_obj.yellow(text)
00809             print
00810             print text
00811             serv_object = gui.connect_to_server(ip, port)
00812             try:
00813                 answer = serv_object.rpc_interval_status()
00814                 if answer != -2:
00815                     answer = "every %d minutes" % answer
00816                 else:
00817                     answer = "RPC disabled"
00818                 if col == 1:
00819                     answer = col_obj.green(answer)
00820 
00821                 print "\nserver -> %s" % answer
00822             except AssertionError:
00823                 text = "Server is down !"
00824                 if col == 1:
00825                     print col_obj.red(text)
00826                 else:
00827                     print text
00828             except:
00829                 text = "Could not connect to server \"%s:%d\"." % (ip, port)
00830                 if col == 1:
00831                     print col_obj.red(text)
00832                 else:
00833                     print text
00834         else:
00835             text = "\nNo IP or port given !\n"
00836             if col == 1:
00837                 print col_obj.red(text)
00838             else:
00839                 print text                
00840     else:
00841         text = "No command given !\nUse option -h or --help to display the help."
00842         usage_exit(sys.argv[0], text, col)
00843         
00844 
00845 if __name__ == '__main__':
00846         
00847     start()
00848     
00849     
00850     
00851     
00852     
00853     
00854     
00855     
00856     

Generated on Sun Mar 5 18:09:13 2006 for Remote Controller by  doxygen 1.4.6-NO