Example #1
0
 def ldif(self, code):
     obj_ldif = cfg.Configuration()
     file_path = obj_ldif.path + "/modify.ldif"
     file = open(file_path, 'w')
     data = str(code)
     file.write(data + "\n")
     file.close()
Example #2
0
 def loglogged(self, code):
     obj_log = cfg.Configuration()
     file_path = obj_log.path + "/log.log"
     file = open(file_path, 'a')
     data = self.date + " " + str(code)
     file.write(data + "\n")
     file.close()
Example #3
0
 def view_quota(self, action, filesystem, user):
     obj_log = logger.Logger()
     obj_log.loglogged(action, filesystem, user, "show_quota")
     obj_param = cfg.Configuration()
     soft = hard = cat = sed = grep = edquota = getent = cut = run_sudo = sudo = "0"
     if self.run_sudo == "True":
         data, command = self.show_str, self.sudo + ' ' + self.edquota + ' ' + self.user
     else:
         data, command = self.show_str, self.edquota + ' ' + self.user
     obj_view = Quota(filesystem, user, soft, hard, cat, sed, grep, edquota,
                      getent, cut, run_sudo, sudo)
     obj_view.file_create(self.term, data)
     success, output = obj_view.command_execude(command)
     if success:
         head = output[0] + ' ' + output[1] + ' ' + output[2] + ' ' + output[
             3] + ' ' + output[4] + ' ' + output[5] + ' ' + output[6]
         filesystem, user, use, soft, hard = output[14], output[4], output[
             15], output[16], output[17]
         code = [success, head, filesystem, user, use, soft, hard]
         return success, code
     else:
         success, code = 'False', output[1] + ' ' + output[
             2] + ' ' + output[3] + ' ' + output[4] + ' ' + output[5]
         code = [success, code]
         return success, code
Example #4
0
 def report_quota(self, action, cat, edquota, path):
     obj_log = logger.Logger()
     obj_log.loglogged(action, 'report_quota', 'not_user', "report_quota")
     obj_param = cfg.Configuration()
     filesystem = user = soft = hard = sed = grep = getent = cut = "0"
     run_sudo, sudo = self.run_sudo, self.sudo
     command = self.report
     obj_report = Quota(filesystem, user, soft, hard, cat, sed, grep,
                        edquota, getent, cut, run_sudo, sudo)
     success, output = obj_report.command_execude(command)
     if success:
         index, file_path = 0, path + "/report"
         command = "/usr/bin/rm -f " + file_path
         obj_report.command_execude(command)
         while index < len(output):
             obj_report.user = output[index]
             success, code = obj_report.view_quota(action, filesystem,
                                                   output[index])
             file = open(file_path, 'a')
             file.write(str(code) + "\n")
             file.close()
             print code
             index += 1
         code = [success, '[]']
         return success, code
     else:
         success, code = 'False', 'Error ' + action + ' command', output
         code = [success, code]
         return success, code
Example #5
0
	def loglogged(self,action,filesystem,user,code):
		obj_log = cfg.Configuration()
		file_path = obj_log.path+"/log.log"
		file = open(file_path, 'a')
		data = self.date+" "+user+" "+action+" "+filesystem+" "+str(code)
		file.write(data +"\n")
		file.close()
Example #6
0
 def report(self, code):
     obj_rep = cfg.Configuration()
     file_path = obj_rep.path + "/report"
     file = open(file_path, 'a')
     data = str(code)
     file.write(data + "\n")
     file.close()
Example #7
0
 def tmp_file(self, stage, data):
     obj_log = cfg.Configuration()
     if stage == "SIP": name_tmp = obj_log.stageSip
     if stage == "RTP": name_tmp = obj_log.stageRtp
     file_path = obj_log.path + '/tmp/' + name_tmp + '.tmp'
     file = open(file_path, 'w')
     file.write(data + "\n")
     file.close()
Example #8
0
 def dial_cause(self, cause):
     obj_hangup = cfg.Configuration()
     obj_hangup = autodial.Autodial(
         obj_hangup.caller_name, obj_hangup.caller_from_uri,
         obj_hangup.caller_contact_user, obj_hangup.auth_username,
         obj_hangup.auth_password, obj_hangup.module, obj_hangup.location,
         obj_hangup.called_number, obj_hangup.gw, obj_hangup.exten,
         obj_hangup.path)
     status = obj_hangup.cause(cause)
     return status
Example #9
0
 def file_create(self, head, data):
     obj_log = logger.Logger()
     obj_log.loglogged('file_create', 'file_create', 'not_user',
                       'apply_file')
     obj_file = cfg.Configuration()
     file_path = obj_file.path_sh + "/edquota.sh"
     file = open(file_path, 'w')
     file.write(head + "\n")
     file.write(data + "\n")
     file.close()
Example #10
0
 def log_logged(self, level, data):
     obj_log = cfg.Configuration()
     if level == 'info':
         file_path = obj_log.path + '/log/log_info.log'
     if level == 'debug':
         file_path = obj_log.path + '/log/log_debug.log'
     file = open(file_path, 'a')
     data = self.date + ' ' + data
     file.write(data + "\n")
     file.close()
Example #11
0
 def autodial(self, connect):
     obj_autodial = cfg.Configuration()
     obj_autodial = autodial.Autodial(
         obj_autodial.caller_name, obj_autodial.caller_from_uri,
         obj_autodial.caller_contact_user, obj_autodial.auth_username,
         obj_autodial.auth_password, obj_autodial.module,
         obj_autodial.location, obj_autodial.called_number, obj_autodial.gw,
         obj_autodial.exten, obj_autodial.path)
     status, channel_state = obj_autodial.dial(connect)
     hangup_cause, dtmf_digest = obj_autodial.dial_status(
         connect, status, channel_state)
     return hangup_cause, dtmf_digest
Example #12
0
 def validate_param_filesystem(self, param_filesystem):
     obj_validate, obj_log = cfg.Configuration(), logger.Logger()
     valid, index, index_max = False, 0, len(obj_validate.filesystem)
     while index < index_max:
         if param_filesystem != obj_validate.filesystem[index]:
             obj_log.loglogged(
                 'run', validate_param_filesystem, 'not',
                 "Not find set quota file system in settings")
             print "Not find set quota file system in settings"
             return valid
         index += 1
     valid = True
     return valid
Example #13
0
 def no_dial(self, connect, dial, dtmf, timeuot):
     try_call = cfg.Configuration()
     call_try = Core()
     call = 0
     while call != int(try_call.error_try_sip):
         code = call_try.dial_cause(dial) + ' - ' + 'No Answer!'
         call_try.write_log(connect, code)
         sleep(timeuot)
         dial, dtmf = call_try.autodial(connect)
         if dial == "['NORMAL_CLEARING']":
             return dial, dtmf
         call = call + 1
         if call == 5:
             call_try.write_tmp(call_try.sip_flag_bad,
                                call_try.rtp_flag_bad)
     if call == int(try_call.error_try_sip):
         return dial, dtmf
Example #14
0
 def no_dtmf(self, connect, dial, dtmf, timeuot):
     try_call = cfg.Configuration()
     call_try = Core()
     call = 0
     while call != int(try_call.error_try_dtmf):
         code = 'Answer - ' + 'No DTMF!'
         call_try.write_log(connect, code)
         sleep(timeuot)
         dial, dtmf = call_try.autodial(connect)
         if dial == "['NORMAL_CLEARING']":
             if dtmf == "['0']":
                 return dial, dtmf
             if call == 2:
                 call_try.write_tmp(call_try.sip_flag_good,
                                    call_try.rtp_flag_bad)
         call = call + 1
     if call == int(try_call.error_try_dtmf):
         return dial, dtmf
Example #15
0
 def initialization_param(self,num_param,action,key_key,user_number_file):
  obj_initialization,obj_log = cfg.Configuration(),logger.Logger()
  if num_param == self.help_param and action == "-h":
  #help() method
   obj_initialization = help.Help(action)
   obj_initialization.view_help()
  elif num_param == self.work_param:
  #show(), edit(), all() method
  if action == "--show" or action == "--edit" or action == "--all":
   if key_key == "-u" or key_key == "-n":
    return action,key_key,user_number_file,self.stop
   else:
    self.stop=True
    obj_log.loglogged("Not parameter in "+action+
     " run with the -h key for help")
    print "Not parameter in",action," run with the -h key for help"
    return action,key_key,user_number_file,self.stop
  else:
   self.stop=True
   obj_log.loglogged("Not find action "+action+
    " run with the -h key for help")
   print "Not find action",action," run with the -h key for help"
   return action,key_key,user_number_file,self.stop
Example #16
0
 def get_connect_variable(self):
     obj_variable = cfg.Configuration()
     return obj_variable.host, obj_variable.port, obj_variable.password
Example #17
0
                                                    help_show.action, key_f,
                                                    filesystem, key_u, user,
                                                    key_s, soft, key_h, hard)

    elif (obj_scripts.num_param == obj_scripts.report_param):
        report_show = Core()
        report_show.action = str(sys.argv[1])
        report_show.key_f = str(sys.argv[2])
        filesystem = key_u = user = key_s = soft = key_h = hard = None
        action = report_show.initialization_param(obj_scripts.num_param,
                                                  report_show.action,
                                                  report_show.key_f,
                                                  filesystem, key_u, user,
                                                  key_s, soft, key_h, hard)
        if action == "--all":
            obj_param, filesystem, user, soft, hard = cfg.Configuration(
            ), 'All', 'All', '0', '0'
            obj_report = quota.Quota(filesystem, user, soft, hard,
                                     obj_param.cat, obj_param.sed,
                                     obj_param.grep, obj_param.edquota,
                                     obj_param.getent, obj_param.cut,
                                     obj_param.run_sudo, obj_param.sudo)
            success, code = obj_report.report_quota(action, obj_param.cat,
                                                    obj_param.edquota,
                                                    obj_param.path)
            if success: print code
            else: print code

    elif (obj_scripts.num_param == obj_scripts.show_remove_param):
        quota_show_rm = Core()
        quota_show_rm.action = str(sys.argv[1])
        quota_show_rm.key_f = str(sys.argv[2])
Example #18
0
class Core(object):
 def __init__(self):
  self.name = "Core"
  self.num_param = len(sys.argv)
  self.action = ""
  self.key_u = "-u"
  self.user = ""
  self.key_n = "-n"
  self.number = ""
  self.file = "-f"
  self.help_param = 2
  self.work_param = 4
  self.stop = False

 def initialization_param(self,num_param,action,key_key,user_number_file):
  obj_initialization,obj_log = cfg.Configuration(),logger.Logger()
  if num_param == self.help_param and action == "-h":
  #help() method
   obj_initialization = help.Help(action)
   obj_initialization.view_help()
  elif num_param == self.work_param:
  #show(), edit(), all() method
  if action == "--show" or action == "--edit" or action == "--all":
   if key_key == "-u" or key_key == "-n":
    return action,key_key,user_number_file,self.stop
   else:
    self.stop=True
    obj_log.loglogged("Not parameter in "+action+
     " run with the -h key for help")
    print "Not parameter in",action," run with the -h key for help"
    return action,key_key,user_number_file,self.stop
  else:
   self.stop=True
   obj_log.loglogged("Not find action "+action+
    " run with the -h key for help")
   print "Not find action",action," run with the -h key for help"
   return action,key_key,user_number_file,self.stop

if __name__ == "__main__":
 obj_scripts,obj_conf,obj_log = Core(),cfg.Configuration(),logger.Logger()
 if (obj_scripts.num_param == obj_scripts.help_param):
  help_show = Core()
  help_show.action=str(sys.argv[1])
  key_key=user_number_file=None
  load_param = help_show.initialization_param(obj_scripts.num_param,
   help_show.action,key_key,user_number_file)
 elif (obj_scripts.num_param == obj_scripts.work_param):
  work_show_set = Core()
  work_show_set.action=str(sys.argv[1])
  work_show_set.key_key=str(sys.argv[2])
  work_show_set.user_number_file=str(sys.argv[3])
  action,key,user_number_file,stop = work_show_set.initialization_param(
   obj_scripts.num_param,work_show_set.action,
   work_show_set.key_key,work_show_set.user_number_file)
 if stop: exit()
  obj_ldap = ldap.Ldap(
  obj_conf.ldap_host,
  obj_conf.ldap_port,
  obj_conf.ldap_user,
  obj_conf.ldap_password,
  obj_conf.ldap_dc,
  obj_conf.ldap_ou,
  obj_conf.filter_number,
  obj_conf.filter_name,
  obj_conf.ldapsearch,
  obj_conf.ldapmodify,
  obj_conf.grep,
  obj_conf.ldap_set)
 if action == "--show":
  search = obj_ldap.search(key,user_number_file)
 if action == "--edit":
  modify = obj_ldap.modify(key,user_number_file)
 if action == "--all":
  modify = obj_ldap.modify_cicle(key,user_number_file)
 else:
  obj_log.loglogged('Not parameter, run with the -h key for help')
  print 'Not parameter, run with the -h key for help'
Example #19
0
				obj_log.loglogged('Return data '+data)
                		return data
			except (paramiko.AuthenticationException,
					paramiko.ssh_exception.NoValidConnectionsError) as e:
					obj_log.loglogged('Timeout connect host '+host[index])
			except paramiko.SSHException as e:
					obj_log.loglogged('Logical error ssh connect host '+host[index])
			except (paramiko.ssh_exception.BadHostKeyException,
					paramiko.ssh_exception.BadAuthenticationType) as e:
					obj_log.loglogged('Bad key error ssh connect host '+host[index])
			finally:
            			client.close()
			index+=1

if __name__ == "__main__":
	obj_scripts,obj_conf,obj_log = Core(),cfg.Configuration(),logger.Logger()
	if len(sys.argv) >= 2:
		#Show help
		if sys.argv[1] == "-h":
			print obj_scripts.help
			exit()
		#Email alert
		if sys.argv[1] == "--all":
			str_param = obj_scripts.packing_parameters(sys.argv)
                	command_out = obj_scripts.ssh_connect_command(obj_conf.ssh_host,obj_conf.ssh_port,obj_conf.ssh_user,
                        	obj_conf.command_worker,str_param)
                	if command_out:
				obj_log.loglogged('Receive quota usage report')
				obj_log.loglogged(command_out)
				quota_arr = command_out.split('\n')
				index,index_max,sys_user=0,len(quota_arr),int(obj_conf.sys_user)
Example #20
0
    def initialization_param(self, num_param, action, key_f, filesystem, key_u,
                             user, key_s, soft, key_h, hard):
        obj_initialization, obj_log = cfg.Configuration(), logger.Logger()
        if num_param == self.help_param and action == "-h":
            #If number param == help_param => help() method
            obj_initialization = help.Help(action)
            obj_initialization.view_help()
        elif num_param == self.report_param and action == "--all":
            #If number param == report_param => report() method
            if key_f != "-r":
                obj_log.loglogged(
                    'run', 'initialization_param', 'not', 'Not parameter in ' +
                    action + ' run with the -h key for help')
                print 'Not parameter in', action, 'run with the -h key for help'
            else:
                return action
        elif num_param == self.show_remove_param:
            #If number param == show_remove_param => remove() or show() method
            if action == "--remove" or action == "--show":
                if key_f != "-f" or\
                 not filesystem or\
                 key_u != "-u" or\
                 not user:
                    obj_log.loglogged(
                        'run', 'initialization_param', 'not',
                        'Not parameter in ' + action +
                        ' run with the -h key for help')
                    print 'Not parameter in', action, 'run with the -h key for help'
                    self.stop = True
                    return action, key_f, filesystem, key_u, user, self.stop
                else:
                    return action, key_f, filesystem, key_u, user, self.stop
            else:
                obj_log.loglogged(
                    'run', 'initialization_param', 'not', 'Not find action ' +
                    action + ' run with the -h key for help')
                print 'Not find action', action, 'run with the -h key for help'
                return action, key_f, filesystem, key_u, user, self.stop
        elif num_param == self.add_edit_param:
            #If number param == add_edit_param => add() or edit() method
            if action == "--add" or action == "--edit" or "--change":
                if key_f != "-f" or\
                        not filesystem or\
                        key_u != "-u" or\
                        not user or\
key_s != "-s" or\
not soft or\
not hard or\
key_h != "-h" or\
(soft.isdigit() == False) or\
(hard.isdigit() == False):
                    obj_log.loglogged(
                        'run', 'initialization_param', 'not',
                        'Not parameter in ' + action +
                        ' run with the -h key for help')
                    print 'Not parameter in', action, 'run with the -h key for help'
                    self.stop = True
                    return action, key_f, filesystem, key_u, user, key_s, soft, key_h, hard, self.stop
                else:
                    return action, key_f, filesystem, key_u, user, key_s, soft, key_h, hard, self.stop
            else:
                obj_log.loglogged(
                    'run', 'initialization_param', 'not', 'Not find action ' +
                    action + ' run with the -h key for help')
                print 'Not find action', action, 'run with the -h key for help'
                return action, key_f, filesystem, key_u, user, key_s, soft, key_h, hard, self.stop
        else:
            obj_log.loglogged(
                'run', 'initialization_param', 'not',
                'Not action ' + action + ' run with the -h key for help')
            print 'Not action', action, 'run with the -h key for help'