# Path: beeswarm/drones/honeypot/helpers/common.py
# def path_to_ls(fn):
#     """ Converts an absolute path to an entry resembling the output of
#         the ls command on most UNIX systems."""
#     st = os.stat(fn)
#     full_mode = 'rwxrwxrwx'
#     mode = ''
#     file_time = ''
#     d = ''
#     for i in range(9):
#         # Incrementally builds up the 9 character string, using characters from the
#         # fullmode (defined above) and mode bits from the stat() system call.
#         mode += ((st.st_mode >> (8 - i)) & 1) and full_mode[i] or '-'
#         d = (os.path.isdir(fn)) and 'd' or '-'
#         file_time = time.strftime(' %b %d %H:%M ', time.gmtime(st.st_mtime))
#     list_format = '{0}{1} 1 ftp ftp {2}\t{3}{4}'.format(d, mode, str(st.st_size), file_time, os.path.basename(fn))
#     return list_format


import argparse
import os
import logging
import sys
import socket
import traceback
import gevent
from datetime import timedelta
from gevent.util import wrap_errors
from fs.errors import ResourceNotFoundError
from fs.path import dirname
from fs.utils import isdir
from telnetsrv.green import TelnetHandler
from telnetsrv.telnetsrvlib import TelnetHandlerBase
from telnetsrv.telnetsrvlib import command
from beeswarm.drones.honeypot.helpers.common import path_to_ls
        'https_proxy': 'http://10.1.0.23/',
        'ftp_proxy': 'http://10.1.0.23/',
        'BROWSER': 'firefox',
        'EDITOR': 'gedit',
        'SHELL': '/bin/bash',
        'PAGER': 'less'
    }

    authNeedUser = True
    authNeedPass = True

    def __init__(self, request, client_address, server, vfs, session):
        self.vfs = vfs
        self.session = session
        with self.vfs.open('/etc/motd') as motd:
            Commands.WELCOME = motd.read()
        self.working_dir = '/'

        self.total_file_size = 0
        self.update_total_file_size(self.working_dir)

        TelnetHandler.__init__(self, request, client_address, server)

    @command('ls')
    def command_ls(self, params):
        if '-l' in params:
            self.writeline('total ' + str(self.total_file_size))  # report a fake random file size
            file_names = self.vfs.listdir(self.working_dir)
            for fname in file_names:
                abspath = self.vfs.getsyspath(self.working_dir + '/' + fname)

# Path: beeswarm/drones/honeypot/helpers/common.py
# def path_to_ls(fn):
#     """ Converts an absolute path to an entry resembling the output of
#         the ls command on most UNIX systems."""
#     st = os.stat(fn)
#     full_mode = 'rwxrwxrwx'
#     mode = ''
#     file_time = ''
#     d = ''
#     for i in range(9):
#         # Incrementally builds up the 9 character string, using characters from the
#         # fullmode (defined above) and mode bits from the stat() system call.
#         mode += ((st.st_mode >> (8 - i)) & 1) and full_mode[i] or '-'
#         d = (os.path.isdir(fn)) and 'd' or '-'
#         file_time = time.strftime(' %b %d %H:%M ', time.gmtime(st.st_mtime))
#     list_format = '{0}{1} 1 ftp ftp {2}\t{3}{4}'.format(d, mode, str(st.st_size), file_time, os.path.basename(fn))
#     return list_format


# Path: beeswarm/drones/honeypot/capabilities/shared/shell.py
import argparse
import os
import logging
import sys
import socket
import traceback
import gevent
from datetime import timedelta
from gevent.util import wrap_errors
from fs.errors import ResourceNotFoundError
from fs.path import dirname
from fs.utils import isdir
from telnetsrv.green import TelnetHandler
from telnetsrv.telnetsrvlib import TelnetHandlerBase
from telnetsrv.telnetsrvlib import command
from beeswarm.drones.honeypot.helpers.common import path_to_ls

        'https_proxy': 'http://10.1.0.23/',
        'ftp_proxy': 'http://10.1.0.23/',
        'BROWSER': 'firefox',
        'EDITOR': 'gedit',
        'SHELL': '/bin/bash',
        'PAGER': 'less'
    }

    authNeedUser = True
    authNeedPass = True

    def __init__(self, request, client_address, server, vfs, session):
        self.vfs = vfs
        self.session = session
        with self.vfs.open('/etc/motd') as motd:
            Commands.WELCOME = motd.read()
        self.working_dir = '/'

        self.total_file_size = 0
        self.update_total_file_size(self.working_dir)

        TelnetHandler.__init__(self, request, client_address, server)

    @command('ls')
    def command_ls(self, params):
        if '-l' in params:
            self.writeline('total ' + str(self.total_file_size))  # report a fake random file size
            file_names = self.vfs.listdir(self.working_dir)
            for fname in file_names:
                abspath = self.vfs.getsyspath(self.working_dir + '/' + fname)

                self.writeline(path_to_ls(abspath))