Gabriel há 6 anos atrás
commit
9e1def82f5

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+**/*.log

+ 2 - 0
.ssh/config

@@ -0,0 +1,2 @@
+Host *
+    StrictHostKeyChecking no

+ 43 - 0
Dockerfile

@@ -0,0 +1,43 @@
+FROM docker.infra.flowdat.com/fd3/sf-php:latest
+
+EXPOSE 80/tcp 22
+
+ENV DEBIAN_FRONTEND noninteractive
+ENV NOTVISIBLE "in users profile"
+
+COPY . /etc/supervisord
+COPY var/ /var/log/supervisor/
+COPY sshd_config /etc/ssh/sshd_config
+COPY .ssh/config /root/.ssh/config
+COPY cron.d/fd3_stats /etc/cron.d/fd3_stats
+COPY script.sh /opt/script.sh
+ADD bin/* /usr/bin/
+
+WORKDIR /opt
+
+RUN echo Acquire::http::Proxy "http://aptcache.infra.flowdat.com/"; > /etc/apt/apt.conf.d/00aptproxy; \
+    apt-get update; \
+    apt-get install -yq parallel lockfile-progs expect telnet sudo cron patch \
+                        openssh-server gdal-bin; \
+    pip install supervisor paramiko argparse; \
+    mkdir -p /var/log/supervisor/; \
+    mkdir /var/run/sshd; \
+    sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd; \
+    echo "export VISIBLE=now" >> /etc/profile; \
+    mkdir /etc/ssh/keys/; \
+    chmod 400 /root/.ssh/config; \
+    cp keys/bitbucket.id_rsa.pub /etc/ssh/keys/authorized_keys; \
+    cp keys/bitbucket.id_rsa /etc/ssh/keys/bitbucket.id_rsa; \
+    chmod 0600 /etc/ssh/keys; \
+    chmod 0600 /etc/ssh/keys/authorized_keys; \
+    chown root:root -R /etc/ssh/keys; \
+    chmod 0644 /etc/cron.d/fd3_stats; \
+    /usr/bin/crontab /etc/cron.d/fd3_stats; \
+    touch /var/log/cron.log; \
+    touch /var/log/cron.err.log; \
+    touch /var/log/cron.out.log; \
+    chmod +x /opt/script.sh; \
+    rm /etc/apt/apt.conf.d/00aptproxy; \
+    rm -rf /var/lib/apt/lists/*
+
+CMD /opt/script.sh

+ 21 - 0
bin/connect/FiberHome.py

@@ -0,0 +1,21 @@
+from OLTBase import OLTBase
+
+
+class FiberHome(OLTBase):
+    def __init__(self, model, ssh):
+        OLTBase.__init__(self, model, ssh)
+
+    def get_expected_name(self):
+        return "Login:"
+
+    def get_expected_password(self):
+        return "Password:"
+
+    def get_write_exit(self):
+        return "quit"
+
+    def run_enable(self):
+        return True
+
+    def get_character_error(self):
+        return "%"

BIN
bin/connect/FiberHome.pyc


+ 18 - 0
bin/connect/Furukawa.py

@@ -0,0 +1,18 @@
+from OLTBase import OLTBase
+
+
+class Furukawa(OLTBase):
+    def __init__(self, model, ssh):
+        OLTBase.__init__(self, model, ssh)
+
+    def get_expected_name(self):
+        return "Login:"
+
+    def get_expected_password(self):
+        return "Password:"
+
+    def get_write_exit(self):
+        return "quit"
+
+    def run_enable(self):
+        return True

BIN
bin/connect/Furukawa.pyc


+ 21 - 0
bin/connect/Huawei.py

@@ -0,0 +1,21 @@
+from OLTBase import OLTBase
+
+
+class Huawei(OLTBase):
+    def __init__(self, model, ssh):
+        OLTBase.__init__(self, model, ssh)
+
+    def run_enable(self):
+        return True
+
+    def get_write_exit(self):
+        return "quit"
+
+    def get_expected_exit(self):
+        return "[n]:"
+
+    def get_write_exit_confirmation(self):
+        return "y"
+
+    def run_enable_password(self):
+        return False

BIN
bin/connect/Huawei.pyc


+ 43 - 0
bin/connect/OLTBase.py

@@ -0,0 +1,43 @@
+class OLTBase:
+    model = None
+    ssh = None
+
+    def __init__(self, model, ssh):
+        self.model = model
+        self.ssh = ssh
+
+    def get_expected_name(self):
+        return "name:"
+
+    def get_expected_password(self):
+        return "password:"
+
+    def get_expected_cardinal(self):
+        return "#"
+
+    def get_expected_initial(self):
+        return ">"
+
+    def run_enable(self):
+        return False
+
+    def run_enable_password(self):
+        return True
+
+    def get_write_enable(self):
+        return "enable"
+
+    def get_expected_enable_password(self):
+        return "Password:"
+
+    def get_write_exit(self):
+        return "exit"
+
+    def get_expected_exit(self):
+        return None
+
+    def get_write_exit_confirmation(self):
+        return None
+
+    def get_character_error(self):
+        return "^"

BIN
bin/connect/OLTBase.pyc


+ 78 - 0
bin/connect/ObjectConnection.py

@@ -0,0 +1,78 @@
+class ObjectConnection:
+    def __init__(self):
+        self.RUN_OK = 0
+        self.QUIT = True
+        self.olt = None
+        self.brand = None
+        self.model = None
+        self.hostname = None
+        self.user = None
+        self.password = None
+        self.password_enable = None
+        self.port = None
+        self.file_name = None
+        self.file_name_log = None
+        self.file_name_exec = None
+        self.data = None
+        self.all_data = ""
+        self.NEW_LINE_UNIX = '\n'
+        self.NEW_LINE_WINDOWS = '\r\n'
+
+    def initialize(self, brand, model, hostname, user, password, password_enable, port, file_name, data):
+        """
+        Initialize all properties
+        :param brand:
+        :param model:
+        :param hostname:
+        :param user:
+        :param password:
+        :param password_enable:
+        :param port:
+        :param file_name:
+        :param data:
+        :return:
+        """
+        self.brand = brand
+        self.model = model
+        self.hostname = hostname
+        self.user = user
+        self.password = password
+        self.password_enable = password_enable
+        self.port = port
+        self.file_name = file_name
+        self.data = data
+        if file_name is not None:
+            fl = file_name.split(".")
+            fl.pop()
+            self.file_name_log = ".".join(fl) + ".log"
+        if file_name is not None:
+            fl = file_name.split(".")
+            fl.pop()
+            self.file_name_exec = ".".join(fl) + ".exec"
+
+    def save_log(self):
+        """
+        Save all data in log
+        """
+        if self.file_name_log:
+            f = open(self.file_name_log, "w+")
+            f.write(self.all_data)
+            f.close()
+        self.check_error_log()
+
+    def check_error_log(self):
+        """
+        Check if scripts produce error
+        """
+        if self.olt.get_character_error() in self.all_data:
+            self.RUN_OK = 1
+        f = open(self.file_name_exec, "w+")
+        f.write(str(self.RUN_OK))
+        f.close()
+
+    def command_print(self, command):
+        """
+        Print command
+        :param command:
+        """
+        print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" + command)

BIN
bin/connect/ObjectConnection.pyc


+ 166 - 0
bin/connect/ObjectSsh.py

@@ -0,0 +1,166 @@
+import types
+
+import paramiko
+import sys
+import time
+from FiberHome import FiberHome
+from Furukawa import Furukawa
+from Huawei import Huawei
+from ZTE import ZTE
+from OLTBase import OLTBase
+from ObjectConnection import ObjectConnection
+
+
+class ObjectSsh(ObjectConnection):
+
+    def __init__(self):
+        ObjectConnection.__init__(self)
+        self.stdin = None
+        self.stdout = None
+
+    def connect(self):
+        """
+        Connect by ssh to olt
+        """
+        if self.brand.upper() == ZTE.__name__.upper():
+            self.olt = ZTE(self.model, False)
+        elif self.brand.upper() == FiberHome.__name__.upper():
+            self.olt = FiberHome(self.model, False)
+        elif self.brand.upper() == Furukawa.__name__.upper():
+            self.olt = Furukawa(self.model, False)
+        elif self.brand.upper() == Huawei.__name__.upper():
+            self.olt = Huawei(self.model, False)
+        else:
+            self.olt = OLTBase(None, False)
+        ssh = paramiko.SSHClient()
+        ssh.load_system_host_keys()
+        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+        ssh.connect(hostname=self.hostname, port=self.port, username=self.user, password=self.password,
+                    allow_agent=False, look_for_keys=False)
+        chan = ssh.invoke_shell()
+        self.stdin = chan.makefile('wb')
+        self.stdout = chan.makefile('r')
+        # wait to olt to initialice terminal
+        self.read_data(self.olt.get_expected_initial())
+        if self.file_name is not None:
+            self.connection_file()
+        elif self.data is not None:
+            self.connection_data()
+        else:
+            self.connection_old()
+        while self.QUIT:
+            # send quit to terminal until exit confirmation
+            self.command_quit(self.olt.get_write_exit())
+        self.stdin.close()
+        self.stdout.close()
+        ssh.close()
+        self.save_log()
+        exit(self.RUN_OK)
+
+    def command_enable(self, command):
+        """
+        Check's if the command is enable and execute then
+        :param command:
+        :return: Return True if enable otherwise False
+        """
+        if command.lower() == self.olt.get_write_enable().lower():
+            if self.olt.run_enable():
+                self.stdin.write(self.olt.get_write_enable() + self.NEW_LINE_UNIX)
+                if self.olt.run_enable_password():
+                    self.read_data(self.olt.get_expected_enable_password())
+                    self.stdin.write(self.password_enable + self.NEW_LINE_UNIX)
+                self.read_data(self.olt.get_expected_cardinal())
+            return True
+        return False
+
+    def command_quit(self, command):
+        """
+        Check's if the command is quit and execute then
+        :param command:
+        :return: Return True if enable otherwise False
+        """
+        if command.lower() == self.olt.get_write_exit().lower():
+            self.stdin.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
+            position = self.read_data([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()])
+            if position == 2:
+                # quit terminal
+                self.stdin.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
+                self.stdin.flush()
+                self.QUIT = False
+            return True
+        return False
+
+    def command_execute(self, command, expected):
+        """
+        Check's the command
+        :param command:
+        :param expected: Expected string to stop listening
+        """
+        self.command_print(command)
+        if not self.command_enable(command) and not self.command_quit(command):
+            command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
+            if command.__len__() > 0:
+                self.stdin.write(command + self.NEW_LINE_UNIX)
+                self.stdin.flush()
+                self.read_data(expected)
+
+    def read_data(self, character):
+        """
+        Read channel waiting parameter character
+        :param character: The character
+        """
+        buffer_size = 1024
+        all_data = ""
+        stop = False
+        position = 1
+        if isinstance(character, types.StringType):
+            character = [character]
+        while not self.stdout.channel.exit_status_ready() and not stop:
+            all_data += self.stdout.channel.recv(buffer_size)
+            while self.stdout.channel.recv_ready():
+                all_data += self.stdout.channel.recv(buffer_size)
+            nc = 1
+            for ch in character:
+                if ch in all_data:
+                    stop = True
+                    position = nc
+                    break
+                nc += 1
+        print(str(all_data))
+        self.all_data = self.all_data + str(all_data)
+        return position
+
+    def connection_old(self):
+        """
+        Old method
+        """
+        while 1:
+            line = sys.stdin.readline()
+            if not line:
+                break
+            self.command_execute(line, self.olt.get_expected_cardinal())
+            time.sleep(1)
+            if not self.QUIT:
+                return
+
+    def connection_data(self):
+        """
+        Recive data separeted by ;
+        """
+        # $(sed ':a;N;$!ba;s/\n/;/g' file)
+        content = self.data.split(";")
+        for line in content:
+            self.command_execute(line, self.olt.get_expected_cardinal())
+            if not self.QUIT:
+                return
+
+    def connection_file(self):
+        """
+        Execute command from file
+        """
+        with open(self.file_name) as f:
+            content = f.readlines()
+            for line in content:
+                self.command_execute(line, self.olt.get_expected_cardinal())
+                if not self.QUIT:
+                    return

BIN
bin/connect/ObjectSsh.pyc


+ 160 - 0
bin/connect/ObjectTelnet.py

@@ -0,0 +1,160 @@
+import sys
+import telnetlib
+import time
+import fcntl
+from FiberHome import FiberHome
+from Furukawa import Furukawa
+from Huawei import Huawei
+from ZTE import ZTE
+from OLTBase import OLTBase
+from ObjectConnection import ObjectConnection
+
+
+class ObjectTelnet(ObjectConnection):
+
+    def __init__(self):
+        ObjectConnection.__init__(self)
+        self.tn = None
+
+    def connect(self):
+        """
+        Connect by ssh to olt
+        """
+        if self.brand.upper() == ZTE.__name__.upper():
+            self.olt = ZTE(self.model, False)
+        elif self.brand.upper() == FiberHome.__name__.upper():
+            self.olt = FiberHome(self.model, False)
+        elif self.brand.upper() == Furukawa.__name__.upper():
+            self.olt = Furukawa(self.model, False)
+        elif self.brand.upper() == Huawei.__name__.upper():
+            self.olt = Huawei(self.model, False)
+        else:
+            self.olt = OLTBase(None, False)
+        print("Telnet client ...\n")
+        f = open("/var/lock/" + self.hostname, "w")
+        print("Open lock file\n")
+        fcntl.flock(f, fcntl.LOCK_EX)
+        print("Lock Acquire\n")
+        print("Login in...\n")
+        self.tn = telnetlib.Telnet(self.hostname, self.port)
+        # self.tn.set_debuglevel(1)
+        self.read_data([self.olt.get_expected_name()])
+        self.tn.write(self.user + self.NEW_LINE_UNIX)
+        self.read_data([self.olt.get_expected_password()])
+        self.tn.write(self.password + self.NEW_LINE_UNIX)
+        print("Loged in...\n")
+        print self.tn.read_very_lazy()
+        self.read_data([self.olt.get_expected_initial()])
+        if self.file_name is not None:
+            self.connection_file()
+        elif self.data is not None:
+            self.connection_data()
+        else:
+            self.connection_old()
+        print("fin-----")
+        while self.QUIT:
+            # send quit to terminal until exit confirmation
+            self.command_quit(self.olt.get_write_exit())
+        self.tn.close()
+        self.save_log()
+        exit(self.RUN_OK)
+
+    def connection_old(self):
+        """
+        Old method
+        """
+        while 1:
+            line = sys.stdin.readline()
+            if not line:
+                break
+            print(self.tn.read_until(self.olt.get_expected_cardinal()))
+            time.sleep(1)
+
+    def connection_data(self):
+        """
+        Recive data separeted by ;
+        """
+        # $(sed ':a;N;$!ba;s/\n/;/g' file)
+        content = self.data.split(";")
+        for line in content:
+            self.command_execute(line, self.olt.get_expected_cardinal())
+
+    def connection_file(self):
+        """
+        Execute command from file
+        """
+        with open(self.file_name) as f:
+            content = f.readlines()
+            for line in content:
+                self.command_execute(line, self.olt.get_expected_cardinal())
+
+    def command_enable(self, command):
+        """
+        Check's if the command is enable and execute then
+        :param command:
+        :return: Return True if enable otherwise False
+        """
+        if command.lower() == self.olt.get_write_enable().lower():
+            if self.olt.run_enable():
+                self.tn.write(self.olt.get_write_enable() + self.NEW_LINE_UNIX)
+                if self.olt.run_enable_password():
+                    self.read_data([self.olt.get_expected_enable_password()])
+                    self.tn.write(self.password_enable + self.NEW_LINE_UNIX)
+                self.read_data([self.olt.get_expected_cardinal()])
+            return True
+        return False
+
+    def command_quit(self, command):
+        """
+        Check's if the command is quit and execute then
+        :param command:
+        :return: Return True if enable otherwise False
+        """
+        if command.lower() == self.olt.get_write_exit().lower():
+            self.tn.write(self.olt.get_write_exit() + self.NEW_LINE_UNIX)
+            if self.olt.get_expected_exit() is not None:
+                # data = self.tn.read_all()
+                position = self.read_data([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()])
+                if position == 2:
+                    # quit terminal
+                    self.tn.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
+                    self.QUIT = False
+                # (i, obj, data) = self.tn.expect([self.olt.get_expected_cardinal(), self.olt.get_expected_exit()], 10)
+                # if self.olt.get_expected_exit() in data:
+                    # # quit terminal
+                    # self.tn.write(self.olt.get_write_exit_confirmation() + self.NEW_LINE_UNIX)
+                    # self.QUIT = False
+            return True
+        return False
+
+    def command_execute(self, command, expected):
+        """
+        Check's the command
+        :param command:
+        :param expected: Expected string to stop listening
+        """
+        command = command.strip()
+        if not (command[:-1] == self.NEW_LINE_UNIX or command[:-2] == self.NEW_LINE_WINDOWS):
+            self.command_print(command)
+            if not self.command_enable(command) and not self.command_quit(command):
+                command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
+                if command.__len__() > 0:
+                    self.tn.write(command + self.NEW_LINE_UNIX)
+                    self.read_data([expected])
+
+    def read_data(self, expected):
+        """
+        Read channel waiting parameter character
+        :param expected: List of expected string
+        """
+        position = 1
+        (i, obj, all_data) = self.tn.expect(expected, 10)
+        nc = 1
+        for ch in expected:
+            if ch in all_data:
+                position = nc
+                break
+            nc += 1
+        print(str(all_data))
+        self.all_data = self.all_data + str(all_data)
+        return position

BIN
bin/connect/ObjectTelnet.pyc


+ 21 - 0
bin/connect/ZTE.py

@@ -0,0 +1,21 @@
+from OLTBase import OLTBase
+
+
+class ZTE(OLTBase):
+    def __init__(self, model, ssh):
+        OLTBase.__init__(self, model, ssh)
+
+    def get_expected_password(self):
+        return "assword:"
+
+    def run_enable_password(self):
+        return False
+
+    def get_expected_initial(self):
+        return "#"
+
+    def get_write_exit_confirmation(self):
+        return "y"
+
+    def get_expected_exit(self):
+        return "[yes/no]:"

BIN
bin/connect/ZTE.pyc


+ 0 - 0
bin/connect/__init__.py


+ 61 - 0
bin/connect/connect.py

@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import argparse
+import os.path
+import time
+from ObjectTelnet import ObjectTelnet
+from ObjectSsh import ObjectSsh
+
+parser = argparse.ArgumentParser(description='Arguments')
+
+parser.add_argument('-tc', '--type_connection', type=str, help='SSH or TELNET', required=True)
+parser.add_argument('-b', '--brand', type=str, help='Brand', required=True)
+parser.add_argument('-m', '--model', type=str, help='Modle Olt', required=False, default=None)
+parser.add_argument('-hn', '--host_name', type=str, help='Host name', required=True)
+parser.add_argument('-u', '--user_name', type=str, help='User name', required=True)
+parser.add_argument('-p', '--password', type=str, help='Password', required=True)
+parser.add_argument('-pe', '--password_enable', type=str, help='Password enable', required=False, default="")
+parser.add_argument('-pt', '--port', type=str, help='Port', required=False, default=None)
+parser.add_argument('-f', '--file', type=str, help='File name', required=False, default=None)
+parser.add_argument('-d', '--data', type=str, help='Data to execute', required=False, default=None)
+
+args = parser.parse_args()
+
+if __name__ == "__main__":
+
+    if args.password_enable is None or args.password_enable is "":
+        password_enable = args.password
+    else:
+        password_enable = args.password_enable
+
+    if args.file is not None:
+        # wait 60 seconds to file exists
+        nc = 0
+        while not os.path.exists(args.file):
+            time.sleep(1)
+            nc += 1
+            print(nc)
+            if nc == 60:
+                break
+        if not os.path.isfile(args.file):
+            raise ValueError("%s isn't a file!" % args.file)
+        print("FILE EXISTS: " + args.file)
+    if args.type_connection == 'ssh':
+        try:
+            val = int(args.port)
+            port = args.port
+        except ValueError:
+            port = 22
+        obj = ObjectSsh()
+    else:
+        try:
+            val = int(args.port)
+            port = args.port
+        except ValueError:
+            port = 23
+        obj = ObjectTelnet()
+    obj.initialize(brand=args.brand, model=args.model, hostname=args.host_name, user=args.user_name,
+                   password=args.password, password_enable=password_enable, port=port,
+                   file_name=args.file, data=args.data)
+    obj.connect()
+    exit(1)

+ 60 - 0
bin/fiberhome/telnet

@@ -0,0 +1,60 @@
+#!/usr/bin/expect -d
+#As first thing we check to have 5 arguments:
+if {[llength $argv] != 3} {
+ 
+# We give a message so the user know our syntax:
+puts "usage: ssh.exp username password server port program"
+ 
+#We exit with return code = 1
+exit 1
+}
+ 
+# Now we set variables in expect, note:  [lrange $argv 0 0 =$1 the first parameter, and so on.
+ 
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set server [lrange $argv 2 2]
+
+set timeout 30
+
+spawn telnet $server 
+
+### Login:
+expect {
+    "Login:"    { send -- "$username\r" }
+    timeout        { exit 1 }
+}
+
+### Password:
+expect {
+    "Password:"    { send -- "$password\r" }
+    timeout        { exit 1 }
+}
+
+### User>
+expect {
+    "User>"    { send -- "enable\r" }
+    timeout        { exit 1 }
+}
+
+expect {
+    "Password:"    { send -- "$password\r" }
+    timeout        { exit 1 }
+}
+
+expect {
+    -re ".*#"    {
+	send_user "Login Success\n"
+	foreach line [split [gets stdin ] "\n"] {
+		# do s
+		send_user "....$line\n"
+	}
+    }
+    timeout        { exit 1 }
+}
+
+
+#send "quit\n"
+
+#exit 0
+#interact

+ 56 - 0
bin/fiberhome/telnet.py

@@ -0,0 +1,56 @@
+import getpass
+import sys
+import telnetlib
+import time
+
+###############################################################################
+
+user = sys.argv[1]
+password = sys.argv[2]
+HOST = sys.argv[3]
+
+###############################################################################
+import struct, fcntl, os
+
+print("Telnet client ...\n")
+f = open("/var/lock/" + HOST, "w")
+print("Open lock file\n")
+fcntl.flock(f, fcntl.LOCK_EX)
+print("Lock Acquire\n")
+
+###############################################################################
+print("Login in...\n")
+
+tn = telnetlib.Telnet(HOST)
+tn.set_debuglevel(1)
+tn.expect(["Login:"],10)
+tn.write(user + "\n")
+tn.expect(["Password:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+tn.write("enable\n");
+tn.expect(["Password:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+#tn.expect(["Password:"],10)
+#tn.write(password + "\n")
+
+print("Loged in...\n")
+print tn.read_very_lazy()
+
+tn.expect(["#"],10)
+
+#tn.interact()
+time.sleep(1)
+while 1:
+   line = sys.stdin.readline()
+   if not line:
+       break
+   print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+   print(line)
+   tn.write(line + "\n")
+   time.sleep(1)
+   print(tn.read_until("#"))
+
+tn.write("\nquit\n")
+

+ 0 - 0
bin/fiberlink/.gitkeep


+ 60 - 0
bin/furukawa/telnet

@@ -0,0 +1,60 @@
+#!/usr/bin/expect -d
+#As first thing we check to have 5 arguments:
+if {[llength $argv] != 3} {
+ 
+# We give a message so the user know our syntax:
+puts "usage: ssh.exp username password server port program"
+ 
+#We exit with return code = 1
+exit 1
+}
+ 
+# Now we set variables in expect, note:  [lrange $argv 0 0 =$1 the first parameter, and so on.
+ 
+set username [lrange $argv 0 0]
+set password [lrange $argv 1 1]
+set server [lrange $argv 2 2]
+
+set timeout 30
+
+spawn telnet $server 
+
+### Login:
+expect {
+    "Login:"    { send -- "$username\r" }
+    timeout        { exit 1 }
+}
+
+### Password:
+expect {
+    "Password:"    { send -- "$password\r" }
+    timeout        { exit 1 }
+}
+
+### User>
+expect {
+    "User>"    { send -- "enable\r" }
+    timeout        { exit 1 }
+}
+
+expect {
+    "Password:"    { send -- "$password\r" }
+    timeout        { exit 1 }
+}
+
+expect {
+    -re ".*#"    {
+	send_user "Login Success\n"
+	foreach line [split [gets stdin ] "\n"] {
+		# do s
+		send_user "....$line\n"
+	}
+    }
+    timeout        { exit 1 }
+}
+
+
+#send "quit\n"
+
+#exit 0
+#interact

+ 56 - 0
bin/furukawa/telnet.py

@@ -0,0 +1,56 @@
+import getpass
+import sys
+import telnetlib
+import time
+
+###############################################################################
+
+user = sys.argv[1]
+password = sys.argv[2]
+HOST = sys.argv[3]
+
+###############################################################################
+import struct, fcntl, os
+
+print("Telnet client ...\n")
+f = open("/var/lock/" + HOST, "w")
+print("Open lock file\n")
+fcntl.flock(f, fcntl.LOCK_EX)
+print("Lock Acquire\n")
+
+###############################################################################
+print("Login in...\n")
+
+tn = telnetlib.Telnet(HOST)
+tn.set_debuglevel(1)
+tn.expect(["Login:"],10)
+tn.write(user + "\n")
+tn.expect(["Password:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+tn.write("enable\n");
+tn.expect(["Password:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+#tn.expect(["Password:"],10)
+#tn.write(password + "\n")
+
+print("Loged in...\n")
+print tn.read_very_lazy()
+
+tn.expect(["#"],10)
+
+#tn.interact()
+time.sleep(1)
+while 1:
+   line = sys.stdin.readline()
+   if not line:
+       break
+   print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+   print(line)
+   tn.write(line + "\n")
+   time.sleep(1)
+   print(tn.read_until("#"))
+
+tn.write("\nquit\n")
+

+ 56 - 0
bin/huawei/telnet.py

@@ -0,0 +1,56 @@
+import getpass
+import sys
+import telnetlib
+import time
+
+###############################################################################
+
+user = sys.argv[1]
+password = sys.argv[2]
+HOST = sys.argv[3]
+
+###############################################################################
+import struct, fcntl, os
+
+print("Telnet client ...\n")
+f = open("/var/lock/" + HOST, "w")
+print("Open lock file\n")
+fcntl.flock(f, fcntl.LOCK_EX)
+print("Lock Acquire\n")
+
+###############################################################################
+print("Login in...\n")
+
+tn = telnetlib.Telnet(HOST)
+tn.set_debuglevel(1)
+tn.expect(["name:"],10)
+tn.write(user + "\n")
+tn.expect(["password:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+tn.write("enable\n");
+time.sleep(1);
+#tn.expect(["Password:"],10)
+#tn.write(password + "\n")
+
+print("Loged in...\n")
+print tn.read_very_lazy()
+
+tn.expect(["#"],10)
+#tn.write("display board 0/1\n");
+#tn.interact()
+time.sleep(1)
+while 1:
+   line = sys.stdin.readline()
+   if not line:
+       break
+   print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+   print(line)
+   tn.write(line + "\n")
+   time.sleep(1)
+   print(tn.read_until("#"))
+
+tn.write("\nquit\n")
+tn.expect(["[n]::"],10)
+tn.write("y\n");
+

+ 0 - 0
bin/server1


+ 7 - 0
bin/tmux-send.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+lockfile-create $1
+while IFS='$\n' read -r line; do
+    # do whatever with line
+    tmux send-keys -t $1 "$line" "C-m"
+done
+lockfile-remove $1

+ 55 - 0
bin/zte/telnet.py

@@ -0,0 +1,55 @@
+import getpass
+import sys
+import telnetlib
+import time
+
+###############################################################################
+
+user = sys.argv[1]
+password = sys.argv[2]
+HOST = sys.argv[3]
+
+###############################################################################
+import struct, fcntl, os
+
+print("Telnet client ...\n")
+f = open("/var/lock/" + HOST, "w")
+print("Open lock file\n")
+fcntl.flock(f, fcntl.LOCK_EX)
+print("Lock Acquire\n")
+
+###############################################################################
+print("Login in...\n")
+
+tn = telnetlib.Telnet(HOST)
+tn.set_debuglevel(1)
+tn.expect(["name:"],10)
+tn.write(user + "\n")
+tn.expect(["assword:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+#tn.write("enable\n");
+#time.sleep(1);
+#tn.expect(["assword:"],10)
+#tn.write(enable + "\n")
+
+print("Loged in...\n")
+print tn.read_very_lazy()
+
+tn.expect(["#"],10)
+#tn.write("show gpon onu state\n");
+#tn.interact()
+time.sleep(1)
+while 1:
+   line = sys.stdin.readline()
+   if not line:
+       break
+   print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+   print(line)
+   tn.write(line + "\n")
+   time.sleep(1)
+   print(tn.read_until("#"))
+
+tn.write("\nexit\n")
+#tn.expect(["[n]::"],10)
+#tn.write("y\n");

+ 0 - 0
conf.d/.gitkeep


+ 6 - 0
conf.d/cron.conf

@@ -0,0 +1,6 @@
+[program:cron]
+command=/usr/sbin/cron -l -f -L 15
+redirect_stderr=true
+stdout_logfile=/dev/stdout
+stdout_logfile_maxbytes=0
+autorestart=true

+ 3 - 0
cron.d/fd3_ftth

@@ -0,0 +1,3 @@
+0 22 * * * /opt/ftth/bin/console ik:config:olt  >> /var/log/cron.log 2>&1
+
+#

+ 6 - 0
cron.d/fd3_stats

@@ -0,0 +1,6 @@
+SHELL=/bin/bash
+BASH_ENV=/container.env
+
+* * * * * /opt/stats/bin/console stats:crontab:remote >> /var/log/cron.log 2>&1
+
+#

+ 3 - 0
cron.d/statsd_commands

@@ -0,0 +1,3 @@
+*/20 * * * * root /opt/extra/statsd/command/mongodelete.js >> /var/log/cron.log
+*/20 * * * * root /opt/extra/statsd/command/mysqldelete.js >> /var/log/cron.log
+

+ 27 - 0
keys/bitbucket.id_rsa

@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEAsCo4Xa/fLaryiZt6igRK1IPNJsKeDLWBN6CWrv3TQ2iMcwE1
+zhTTX115N+KngVN8p1v5VrSMHKpvyXQDZPG/FJnWm5ry75qSYTmEtY8nfRsGAbwT
+i4swY+4jqrH1RRjbuVMsXPGjFX34SZTTJEl8ouVAFy/7HR+ODUe2+enWVnaouhVs
+Xj+bW2u7/dV1kZctFa5g5iV3hqGH32dBME5ztg4Fh7fAxkRTiJl+NBI7/LIdv9dl
+qmtDAdNdRqaI1dBpy8sHyZhRfjPeVbhdKsjE5IBhDLlYzyxK5FC41us08VCdq+M1
+1qVzIVM61PBosW5NfwlrRgLDPEXkazUdhJO6YwIDAQABAoIBAFEf4D0klH4PTwmX
+k+Ki/2LGH19OGEJ6Azt+tGV5diSArMz5LbHtXTl5bi0SL1ka/TiE3lnTYwKAamI3
+DqkZuojeHzohLOayI96qAjcp6WFvZGDAH7APNQWP0NT2hqB/RhAeATv7+sIW9JPN
++T2oqcDKGa2T5uwOb/glolmMGaxOzNfAFAgnD7p7cnR0yijW5t3bc4q0sOFu/H3N
+jYsAqvMu6Nkpt9hjlu42x5Muwj9YeKwpZoE1sno62JeQFZo7nO7DrOrE7DOENoWV
+PMDxs8Hz0SRQlZcJn2I/W9wX8A8gCAWGhbAtUGQkS8gCaMp0dOcxoV3EttriQgtU
+X1oUwIECgYEA2Vge4E8E53BzLGTk8sozn1qteYn3cLGgJgC78MEzZN/G57DxVbC9
+ntlSlYaYLlaPlSlNzZyG0s3UhpPY7YgP9srpohfPyXvb0ycfsGYMOcRNjVwdi2ap
+dPiG+p9vLSG3raNoeTxDEtjFZz1EM1rQECx2N40JwIuzeM2g+kE0JjMCgYEAz38r
+NTs1wASG7Bc7geIDxb34PWM8Nnw/DN57ceJP+Miwq/hYAJg6eK57ar9n44Y3xf7a
+mHkkgBU1vzuIyYfC5jVut6XkbialLsJUHfCNi3fPDBR7sEy6soiN34GoGp2vnCVD
+pDf2aCSMeFGfgwe4imFHbqE0R87cnet+q+CjCxECgYA8EbfO5OgFEzYxwdzpIWtt
+EoG5gqEpu134wuEupCcRLSvrIyNAPK3btlK10tJClFfwsM65EhbNMmgXncspsx4+
+Zkx2KUCbfij+TeTbOwkL+i448ImV2pThKEMeB2yRu6zpR617PGWJUvIUG4G689Fn
+dvJhXhCg77t1mtdv8w93swKBgQCIxor0y9LigBlwBuBy/Uj/T/oSfRdz0vK8yOsW
+ZtfQZnoO4eUgfzgL1PgFpaYVlKOvIA938mLdCx4isFu6fIM8vHv/EptBALhh2jcY
+hTjIdnFExTvDOtDWXq0mZ5En+kmH5Ahyd3E1tOHjbep3tN8wWG99vUV5ECLc9h7J
+rYnMAQKBgQDQ/JiBT7ygfzAblxPnq5Dnr52C3CFTE57GNA8FIEx+On6FdtVDRM0g
+cNjoc2e+2MfbaJXFAuMvXDvzb2qxrHgf2TosxeuPTg79iYOfWMU8G62i/v0wPr1M
+0Cj2hszJg4H0dMQPS0kDmO6mZmt6FB4E2gItmeBlTGfMwdJpaQC4rw==
+-----END RSA PRIVATE KEY-----

+ 1 - 0
keys/bitbucket.id_rsa.pub

@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwKjhdr98tqvKJm3qKBErUg80mwp4MtYE3oJau/dNDaIxzATXOFNNfXXk34qeBU3ynW/lWtIwcqm/JdANk8b8UmdabmvLvmpJhOYS1jyd9GwYBvBOLizBj7iOqsfVFGNu5Uyxc8aMVffhJlNMkSXyi5UAXL/sdH44NR7b56dZWdqi6FWxeP5tba7v91XWRly0VrmDmJXeGoYffZ0EwTnO2DgWHt8DGRFOImX40Ejv8sh2/12Wqa0MB011GpojV0GnLywfJmFF+M95VuF0qyMTkgGEMuVjPLErkULjW6zTxUJ2r4zXWpXMhUzrU8Gixbk1/CWtGAsM8ReRrNR2Ek7pj flowdat@bitbucket

+ 2 - 0
script.sh

@@ -0,0 +1,2 @@
+bash -c  "declare -p > /container.env"
+bash -c "/usr/sbin/sshd ; while true; do supervisord --configuration /etc/supervisord/supervisor.conf  --nodaemon ; sleep 5 ; done"

+ 35 - 0
sshd_config

@@ -0,0 +1,35 @@
+Port 22
+Protocol 2
+HostKey /etc/ssh/ssh_host_rsa_key
+HostKey /etc/ssh/ssh_host_dsa_key
+HostKey /etc/ssh/ssh_host_ecdsa_key
+HostKey /etc/ssh/ssh_host_ed25519_key
+UsePrivilegeSeparation yes
+
+#KeyRegenerationInterval 3600
+#ServerKeyBits 1024
+
+SyslogFacility AUTH
+LogLevel INFO
+
+LoginGraceTime 120
+PermitRootLogin without-password
+StrictModes yes
+
+#RSAAuthentication yes
+PubkeyAuthentication yes
+AuthorizedKeysFile	/etc/ssh/keys/authorized_keys
+
+IgnoreRhosts yes
+#RhostsRSAAuthentication no
+HostbasedAuthentication no
+PermitEmptyPasswords no
+ChallengeResponseAuthentication no
+
+PrintMotd no
+PrintLastLog yes
+TCPKeepAlive yes
+
+Subsystem sftp /usr/lib/openssh/sftp-server
+
+UsePAM yes

+ 37 - 0
supervisor.conf

@@ -0,0 +1,37 @@
+; supervisor config file
+
+[unix_http_server]
+file=/var/run/supervisor.sock   ; (the path to the socket file)
+chmod=0700                       ; sockef file mode (default 0700)
+username = iksop
+password = queRini6
+
+[supervisord]
+logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
+pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
+childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)
+user=root
+
+[inet_http_server]
+port = 0.0.0.0:9001
+username = iksop
+password = queRini6
+
+; the below section must remain in the config file for RPC
+; (supervisorctl/web interface) to work, additional interfaces may be
+; added by defining them in separate rpcinterface: sections
+[rpcinterface:supervisor]
+supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
+
+[supervisorctl]
+serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
+
+; The [include] section can just contain the "files" setting.  This
+; setting can list multiple files (separated by whitespace or
+; newlines).  It can also contain wildcards.  The filenames are
+; interpreted as relative to this file.  Included files *cannot*
+; include files themselves.
+
+[include]
+files = /etc/supervisord/conf.d/*.conf
+

+ 0 - 0
var/.gitkeep


+ 63 - 0
zte/telnet.py

@@ -0,0 +1,63 @@
+import getpass
+import sys
+import telnetlib
+import time
+
+###############################################################################
+
+user = sys.argv[1]
+password = sys.argv[2]
+HOST = sys.argv[3]
+
+###############################################################################
+
+import struct, fcntl, os
+
+
+print("Telnet client ...\n")
+f = open("/var/lock/" + HOST, "w")
+print("Open lock file\n")
+fcntl.flock(f, fcntl.LOCK_EX)
+print("Lock Acquire\n")
+
+
+
+###############################################################################
+
+print("Login in...\n")
+
+
+tn = telnetlib.Telnet(HOST)
+tn.set_debuglevel(1)
+tn.expect(["name:"],10)
+tn.write(user + "\n")
+tn.expect(["assword:"],10)
+tn.write(password + "\n")
+time.sleep(1);
+#tn.write("enable\n");
+#time.sleep(1);
+#tn.expect(["assword:"],10)
+#tn.write(enable + "\n")
+
+print("Loged in...\n")
+print tn.read_very_lazy()
+
+tn.expect(["#"],10)
+#tn.write("show gpon onu state\n");
+#tn.interact()
+time.sleep(1)
+while 1:
+   line = sys.stdin.readline()
+   if not line:
+       break
+   print("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
+   print(line)
+   tn.write(line + "\n")
+   time.sleep(1)
+   print(tn.read_until("#"))
+
+tn.write("\nexit\n")
+#tn.expect(["[n]::"],10)
+#tn.write("y\n");
+
+