diff --git a/connect.py b/connect.py index 531c608a9..603f57f60 100755 --- a/connect.py +++ b/connect.py @@ -523,7 +523,13 @@ class Nav(object): if gid_pattern.match(str_r): gid = int(str_r.lstrip('g')) # 获取资产组包含的资产 - user_asset_search = get_object(AssetGroup, id=gid).asset_set.all() + asset_group = get_object(AssetGroup, id=gid) + if asset_group: + user_asset_search = asset_group.asset_set.all() + else: + color_print('没有该资产组或没有权限') + return + else: # 匹配 ip, hostname, 备注 for asset in user_asset_all: @@ -609,6 +615,9 @@ class Nav(object): command = raw_input("\033[1;32mCmds>:\033[0m ").strip() if command == 'q': break + elif not command: + color_print('命令不能为空...') + continue runner.run('shell', command, pattern=pattern) ExecLog(host=asset_name_str, user=self.user.username, cmd=command, remote_ip=remote_ip, result=runner.results).save() @@ -661,7 +670,7 @@ class Nav(object): runner = MyRunner(res) runner.run('copy', module_args='src=%s dest=%s directory_mode' - % (tmp_dir, tmp_dir), pattern=pattern) + % (tmp_dir, '/tmp'), pattern=pattern) ret = runner.results FileLog(user=self.user.name, host=asset_name_str, filename=filename_str, remote_ip=remote_ip, type='upload', result=ret).save() @@ -815,7 +824,6 @@ def main(): except IndexError, e: color_print(e) time.sleep(5) - pass if __name__ == '__main__': main() diff --git a/functions b/install/functions similarity index 100% rename from functions rename to install/functions diff --git a/install/install.py b/install/install.py index 007c10503..d7c25660a 100755 --- a/install/install.py +++ b/install/install.py @@ -97,13 +97,13 @@ class PreSetup(object): conf = ConfigParser.ConfigParser() conf.read(conf_file) conf.set('base', 'url', 'http://%s' % self.ip) + conf.set('base', 'websocket_url', 'ws://%s' % self.ip) conf.set('base', 'key', self.key) conf.set('db', 'host', self.db_host) conf.set('db', 'port', self.db_port) conf.set('db', 'user', self.db_user) conf.set('db', 'password', self.db_pass) conf.set('db', 'database', self.db) - conf.set('websocket', 'web_socket_host', '%s:3000' % self.ip) conf.set('mail', 'email_host', self.mail_host) conf.set('mail', 'email_port', self.mail_port) conf.set('mail', 'email_host_user', self.mail_addr) @@ -237,7 +237,7 @@ class PreSetup(object): print def start(self): - color_print('请务必先查看wiki https://github.com/ibuler/jumpserver/wiki/Quickinstall') + color_print('请务必先查看wiki https://github.com/jumpserver/jumpserver/wiki') time.sleep(3) self._rpm_repo() self._depend_rpm() diff --git a/install/next.py b/install/next.py index 49d62db25..e11d4151b 100755 --- a/install/next.py +++ b/install/next.py @@ -86,7 +86,7 @@ class Setup(object): os.chmod('init.sh', 0755) os.chmod('connect.py', 0755) os.chmod('manage.py', 0755) - os.chmod('run_websocket.py', 0755) + os.chmod('run_server.py', 0755) os.chmod('service.sh', 0755) os.chmod('logs', 0777) os.chmod('keys', 0777) @@ -95,7 +95,7 @@ class Setup(object): def _run_service(): os.system('sh %s start' % os.path.join(jms_dir, 'service.sh')) print - color_print('安装成功,请访问web, 祝你使用愉快。\n请访问 https://github.com/jumpserver/jumpserver 查看文档', 'green') + color_print('安装成功,请访问web, 祝你使用愉快。\n请访问 https://github.com/jumpserver/jumpserver/wiki 查看文档', 'green') def start(self): print "开始安装Jumpserver, 要求环境为 CentOS 6.5 x86_64" diff --git a/jlog/views.py b/jlog/views.py index 61ab19ddc..0d49269b6 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -9,7 +9,7 @@ from django.http import HttpResponseNotFound from jlog.log_api import renderTemplate from jlog.models import Log, ExecLog, FileLog -from jumpserver.settings import WEB_SOCKET_HOST +from jumpserver.settings import WEB_SOCKET_URL @require_role('admin') @@ -66,8 +66,8 @@ def log_list(request, offset): contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) - web_monitor_uri = '%s/monitor' % WEB_SOCKET_HOST - web_kill_uri = '/kill' + web_monitor_url = '%s/monitor' % WEB_SOCKET_URL + web_kill_url = '/kill' session_id = request.session.session_key return render_to_response('jlog/log_%s.html' % offset, locals(), context_instance=RequestContext(request)) diff --git a/jumpserver.conf b/jumpserver.conf index 5db9cdd9d..a24203220 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -1,9 +1,10 @@ [base] url = http://192.168.244.129 -key = 88aaaf7ffe3c6c04 +websocket_url = ws://192.168.244.129 +key = i6k2zeu8x6mncl76 +ip = 0.0.0.0 +port = 80 log = debug -ip = 127.0.0.1 -port = 8080 [db] host = 127.0.0.1 @@ -12,14 +13,11 @@ user = jumpserver password = mysql234 database = jumpserver -[websocket] -web_socket_host = 192.168.244.129:3000 - [mail] mail_enable = 1 -email_host = smtp.qq.com +email_host = smtp.exmail.qq.com email_port = 25 -email_host_user = xxxxxxxx@qq.com -email_host_password = xxxxxx -email_use_tls = False +email_host_user = noreply@jumpserver.org +email_host_password = xxxxxxxxxx +email_use_tls = True diff --git a/jumpserver/api.py b/jumpserver/api.py index 691aafb11..a4840f206 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -484,7 +484,8 @@ def my_render(template, data, request): def get_tmp_dir(): - dir_name = os.path.join('/tmp', uuid.uuid4().hex) + seed = uuid.uuid4().hex[:4] + dir_name = os.path.join('/tmp', '%s-%s' % (datetime.datetime.now().strftime('%Y%m%d-%H%M%S'), seed)) mkdir(dir_name, mode=0777) return dir_name diff --git a/jumpserver/settings.py b/jumpserver/settings.py index eb418ad8e..24c0ea27a 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -41,7 +41,7 @@ SSH_KEY_DIR = os.path.join(BASE_DIR, 'keys/role_keys') KEY = config.get('base', 'key') URL = config.get('base', 'url') LOG_LEVEL = config.get('base', 'log') -WEB_SOCKET_HOST = config.get('websocket', 'web_socket_host') +WEB_SOCKET_URL = config.get('base', 'websocket_url') IP = config.get('base', 'ip') PORT = config.get('base', 'port') diff --git a/jumpserver/views.py b/jumpserver/views.py index 7aa51dcac..ab97a66e8 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -286,7 +286,7 @@ def upload(request): res = gen_resource({'user': user, 'asset': asset_select}) runner = MyRunner(res) runner.run('copy', module_args='src=%s dest=%s directory_mode' - % (upload_dir, upload_dir), pattern='*') + % (upload_dir, '/tmp'), pattern='*') ret = runner.results logger.debug(ret) FileLog(user=request.user.username, host=' '.join([asset.hostname for asset in asset_select]), @@ -356,8 +356,7 @@ def web_terminal(request): if asset: print asset hostname = asset.hostname - # web_terminal_uri = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_HOST, asset_id, role_name) - web_terminal_uri = '/ws/terminal?id=%s&role=%s' % (asset_id, role_name) + web_terminal_url = '%s/ws/terminal?id=%s&role=%s' % (WEB_SOCKET_URL, asset_id, role_name) return render_to_response('jlog/web_terminal.html', locals()) diff --git a/run_websocket.py b/run_server.py similarity index 99% rename from run_websocket.py rename to run_server.py index 34263f18b..c8240ea9f 100755 --- a/run_websocket.py +++ b/run_server.py @@ -464,6 +464,6 @@ if __name__ == '__main__': # server.bind(options.port, options.host) # #server.listen(options.port) # server.start(num_processes=5) - # print "Run server on %s:%s" % (options.host, options.port) # tornado.ioloop.IOLoop.instance().start() + print "Run server on %s:%s" % (options.host, options.port) main() diff --git a/service.sh b/service.sh index 202096642..f338938ee 100755 --- a/service.sh +++ b/service.sh @@ -4,85 +4,84 @@ # chkconfig: - 85 12 # description: Open source detecting system # processname: jumpserver -# Date: 2015-04-12 -# Version: 2.0.0 +# Date: 2016-02-27 +# Version: 3.0.1 # Site: http://www.jumpserver.org # Author: Jumpserver Team +jumpserver_dir= + base_dir=$(dirname $0) +jumpserver_dir=${jumpserver_dir:-$base_dir} +export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -. ${base_dir}/functions -export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin +if [ -f ${jumpserver_dir}/install/functions ];then + . ${jumpserver_dir}/install/functions +elif [ -f /etc/init.d/functions ];then + . /etc/init.d/functions +else + echo "No functions script found in [./functions, ./install/functions, /etc/init.d/functions]" + exit 1 +fi - - - - - -PROC_NAME="jumpsever" +PROC_NAME="jumpserver" lockfile=/var/lock/subsys/${PROC_NAME} - start() { jump_start=$"Starting ${PROC_NAME} service:" - if [ -f $lockfile ];then - echo "jumpserver is running..." - success "$jump_start" + echo -n "jumpserver is running..." + success "$jump_start" + echo else -# daemon python $base_dir/manage.py runserver 0.0.0.0:80 &>> /tmp/jumpserver.log 2>&1 & - daemon python $base_dir/manage.py crontab add &>> /tmp/jumpserver.log 2>&1 - daemon python $base_dir/run_websocket.py &> /dev/null 2>&1 & - sleep 4 - - echo -n "$jump_start" - nums=0 - for i in manage.py run_websocket.py;do - if ps aux | grep "$i" | grep -v 'grep' &> /dev/null; then - nums=$[nums+1] - else - echo "$i not running" - fi - done - - if [ "x$nums" == "x2" ];then - success "$jump_start" - if [ ! -e $lockfile ]; then - lockfile_dir=`dirname $lockfile` - mkdir -pv $lockfile_dir + daemon python $jumpserver_dir/manage.py crontab add &>> /var/log/jumpserver.log 2>&1 + daemon python $jumpserver_dir/run_server.py &> /dev/null 2>&1 & + sleep 1 + echo -n "$jump_start" + ps axu | grep 'run_server' | grep -v 'grep' &> /dev/null + if [ $? == '0' ];then + success "$jump_start" + touch "$lockfile" + echo + else + failure "$jump_start" + echo fi - touch "$lockfile" - echo - else - failure "$jump_start" - echo - fi - fi - - + fi } stop() { - - echo -n $"Stopping ${PROC_NAME} service:" - - daemon python $base_dir/manage.py crontab remove &>> /tmp/jumpserver.log 2>&1 - ps aux | grep -E 'manage.py|run_websocket.py' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null - ret=$? - - if [ $ret -eq 0 ]; then - echo_success - echo + echo -n $"Stopping ${PROC_NAME} service:" + daemon python $jumpserver_dir/manage.py crontab remove &>> /var/log/jumpserver.log 2>&1 + ps aux | grep -E 'run_server.py' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null + ret=$? + if [ $ret -eq 0 ]; then + echo_success + echo rm -f "$lockfile" - else - echo_failure - echo + else + echo_failure + echo rm -f "$lockfile" - fi + fi } +status(){ + ps axu | grep 'run_server' | grep -v 'grep' &> /dev/null + if [ $? == '0' ];then + echo -n "jumpserver is running..." + success + touch "$lockfile" + echo + else + echo -n "jumpserver is not running." + failure + echo + fi +} + restart(){ @@ -103,7 +102,10 @@ case "$1" in restart ;; + status) + status + ;; *) - echo $"Usage: $0 {start|stop|restart}" + echo $"Usage: $0 {start|stop|restart|status}" exit 2 esac diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 9d52ecfe8..c17c92129 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -136,13 +136,8 @@ {# })#} {# });#} function init(obj){ - var protocol = "ws://"; - if (window.location.protocol == 'https:') { - protocol = 'wss://'; - } - var file_path = obj.attr('file_path'); - var wsUri = protocol + '{{ web_monitor_uri }}'; + var wsUri = '{{ web_monitor_url }}'; var socket = new WebSocket(wsUri + '?file_path=' + file_path); var term = new Terminal({ @@ -211,7 +206,7 @@ function cut(num, login_type){ console.log(login_type); if (login_type=='web'){ - var g_url = '{{ web_kill_uri }}' + '?id=' + num; + var g_url = '{{ web_kill_url }}' + '?id=' + num; } else { var g_url = "{% url 'log_kill' %}?id=" + num; } diff --git a/templates/jlog/web_terminal.html b/templates/jlog/web_terminal.html index 547002f19..3f4683399 100644 --- a/templates/jlog/web_terminal.html +++ b/templates/jlog/web_terminal.html @@ -43,12 +43,7 @@ } WSSHClient.prototype.connect = function(options) { - var protocol = "ws://"; - if (window.location.protocol == 'https:') { - protocol = 'wss://'; - } - - var endpoint = protocol + document.URL.match(RegExp('//(.*?)/'))[1] + '{{ web_terminal_uri }}'; + var endpoint = '{{ web_terminal_url }}'; if (window.WebSocket) { this._connection = new WebSocket(endpoint);