def record_stop(self, event):
			uuid = event.getHeader("unique-id")
			session_id = event.getHeader("variable_session_id")	

			if uuid != self.__A.get('uuid', None) and uuid != self.__B.get('uuid', None):
				return

			if not options.record:
				print("ERR : this case is not need record")
				print((1))
				return "end"

			# 检查是否有生成录音文件
			record_file_path = os.path.join('/'.join(event.getHeader("Record-File-Path").split('/')[:-1]), \
				"%s_%s_%s_%s_%s_CALLIN.wav" % (options.appid, options.sipp_num, options.callee_num, self.__A['sip_call_id'][:32], self.__B['call_time']))
			try:
				from neko import Ssh
				ssh = Ssh(options.host)
				stdin, stdout, stderr = ssh.exec_command('ls -l ' + record_file_path)
				if not stdout.readlines():
					print(("ERR :check record file not exists. %s" % (record_file_path)))
					print((1))
					return "end"
				else:
					print(("INFO:check record file exists. %s" % (record_file_path)))
			except Exception as err:
				print(("ERR :" + str(err)))
				print((1))
				return "end"
Exemplo n.º 2
0
    def login(self, host='', port=22, user='******', password=''):
        self.__host = host
        self.__user = user
        self.__password = password

        try:
            p = ProcBar().start("logining server %s@%s:%d ..." %
                                (user, host, port))
            self.__ssh = Ssh(host, port, username=user, password=password)
            p.stop(color_str("OK", "green"))
        except Exception as err:
            if 'p' in list(locals().keys()):
                p and p.stop(color_str(str(err), "red"))
            raise Exception(str(err))
            return False

        return True
Exemplo n.º 3
0
class FCmd:
    def __init__(self, debug=False):
        self.__ssh = None
        self.__debug = debug
        self.__out = None

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, exc_tb):
        if exc_tb:
            return False
        else:
            self.__del__()

    def __del__(self):
        self.__ssh = None

    def login(self, host='', port=22, user='******', password=''):
        self.__host = host
        self.__user = user
        self.__password = password

        try:
            p = ProcBar().start("logining server %s@%s:%d ..." %
                                (user, host, port))
            self.__ssh = Ssh(host, port, username=user, password=password)
            p.stop(color_str("OK", "green"))
        except Exception as err:
            if 'p' in list(locals().keys()):
                p and p.stop(color_str(str(err), "red"))
            raise Exception(str(err))
            return False

        return True

    def run(self, exe='/usr/local/freeswitch/bin/fs_cli -x', cmd=''):
        stdin, self.__out, stderr = self.__ssh.exec_command('%s "%s"' %
                                                            (exe, cmd))

    def show(self):
        if self.__out:
            for l in self.__out.readlines():
                sys.stdout.write(l)
Exemplo n.º 4
0
    parser.add_option('-u',
                      '--user',
                      dest='user',
                      default='root',
                      help='ssh user')
    parser.add_option('-a',
                      '--password',
                      dest='password',
                      default='root',
                      help='ssh password')

    parser.add_option('-l',
                      '--lib',
                      dest='lib',
                      metavar="lib file directory",
                      default='../lib',
                      help='lib directory [default: %default]')

    (options, args) = parser.parse_args()

    run_path = os.path.split(os.path.realpath(sys.argv[0]))[0]
    sys.path.append(os.path.join(run_path, options.lib))
    from neko import Ssh

    try:
        ssh = Ssh(options.host, options.port, options.user, options.password)
        print((0))
    except Exception as err:
        print(err)
        print((1))