modify service.sh bug

pull/6/head
ibuler 2015-04-24 18:19:43 +08:00
parent 0beb683c40
commit c01a489dce
3 changed files with 34 additions and 20 deletions

View File

@ -8,7 +8,6 @@ sys.setdefaultencoding('utf8')
import socket import socket
import os import os
import re import re
import ast
import select import select
import time import time
import paramiko import paramiko
@ -16,25 +15,24 @@ import struct
import fcntl import fcntl
import signal import signal
import textwrap import textwrap
import django
import getpass import getpass
import fnmatch import fnmatch
import readline import readline
import datetime
from multiprocessing import Pool from multiprocessing import Pool
os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
#django.setup()
from juser.models import User from juser.models import User
from jlog.models import Log from jlog.models import Log
from jumpserver.api import * from jumpserver.api import CONF, BASE_DIR, ServerError, user_perm_group_api, user_perm_group_hosts_api, get_user_host
from jumpserver.api import AssetAlias, get_connect_item
try: try:
import termios import termios
import tty import tty
except ImportError: except ImportError:
print '\033[1;31mOnly postfix supported.\033[0m' print '\033[1;31mOnly UnixLike supported.\033[0m'
time.sleep(3) time.sleep(3)
sys.exit() sys.exit()
@ -194,13 +192,16 @@ def verify_connect(username, part_ip):
except ServerError, e: except ServerError, e:
color_print(e, 'red') color_print(e, 'red')
return False return False
for ip_info in hosts: for ip_info in hosts:
for info in ip_info[1:]: for info in ip_info[1:]:
if part_ip in info: if part_ip in info:
ip_matched.append(ip_info[1]) ip_matched.append(ip_info[1])
ip_matched = list(set(ip_matched))
if len(ip_matched) > 1: if len(ip_matched) > 1:
for ip in ip_matched: for ip in ip_matched:
print '%s -- %s' % (ip, hosts_attr[ip][2]) print '%-15s -- %s' % (ip, hosts_attr[ip][2])
elif len(ip_matched) < 1: elif len(ip_matched) < 1:
color_print('No Permission or No host.', 'red') color_print('No Permission or No host.', 'red')
else: else:
@ -210,7 +211,7 @@ def verify_connect(username, part_ip):
def print_prompt(): def print_prompt():
msg = """\033[1;32m### Welcome Use JumpServer To Login. ### \033[0m msg = """\033[1;32m### Welcome Use JumpServer To Login. ### \033[0m
1) Type \033[32mIP ADDRESS\033[0m To Login. 1) Type \033[32mIP or Part IP, Host Alias or Comments \033[0m To Login.
2) Type \033[32mP/p\033[0m To Print The Servers You Available. 2) Type \033[32mP/p\033[0m To Print The Servers You Available.
3) Type \033[32mG/g\033[0m To Print The Server Groups You Available. 3) Type \033[32mG/g\033[0m To Print The Server Groups You Available.
4) Type \033[32mG/g(1-N)\033[0m To Print The Server Group Hosts You Available. 4) Type \033[32mG/g(1-N)\033[0m To Print The Server Group Hosts You Available.
@ -322,18 +323,25 @@ def multi_remote_exec_cmd(hosts, username, cmd):
def exec_cmd_servers(username): def exec_cmd_servers(username):
hosts = [] color_print("You can choose in the following IP(s), Use glob or ips split by comma. q/Q to PreLayer.", 'green')
color_print("Input the Host IP(s),Separated by Commas, q/Q to Quit.\n \
You can choose in the following IP(s), Use Linux / Unix glob.", 'green')
print_user_host(LOGIN_NAME) print_user_host(LOGIN_NAME)
while True: while True:
hosts = []
inputs = raw_input('\033[1;32mip(s)>: \033[0m') inputs = raw_input('\033[1;32mip(s)>: \033[0m')
if inputs in ['q', 'Q']: if inputs in ['q', 'Q']:
break break
get_hosts = get_user_host(username).keys() get_hosts = get_user_host(username).keys()
for host in get_hosts:
if fnmatch.fnmatch(host, inputs): if ',' in inputs:
hosts.append(host.strip()) ips_input = inputs.split(',')
for host in ips_input:
if host in get_hosts:
hosts.append(host)
else:
for host in get_hosts:
if fnmatch.fnmatch(host, inputs):
hosts.append(host.strip())
if len(hosts) == 0: if len(hosts) == 0:
color_print("Check again, Not matched any ip!", 'red') color_print("Check again, Not matched any ip!", 'red')
continue continue

View File

@ -14,4 +14,10 @@ class Log(models.Model):
end_time = models.DateTimeField(null=True) end_time = models.DateTimeField(null=True)
def __unicode__(self): def __unicode__(self):
return self.log_path return self.log_path
class Alert(models.Model):
msg = models.CharField(max_length=20)
time = models.DateTimeField(null=True)
is_finished = models.BigIntegerField(default=False)

View File

@ -28,15 +28,15 @@ start() {
daemon python $base_dir/manage.py runserver 0.0.0.0:80 &>> /tmp/jumpserver.log 2>&1 & daemon python $base_dir/manage.py runserver 0.0.0.0:80 &>> /tmp/jumpserver.log 2>&1 &
daemon python $base_dir/log_handler.py &> /dev/null 2>&1 & daemon python $base_dir/log_handler.py &> /dev/null 2>&1 &
cd $base_dir/websocket/;daemon node index.js &> /dev/null 2>&1 & cd $base_dir/websocket/;daemon node index.js &> /dev/null 2>&1 &
sleep 1 sleep 2
echo "$jump_start" echo -n "$jump_start"
nums=0 nums=0
for i in manage.py log_handler.py index.js;do for i in manage.py log_handler.py index.js;do
ps aux | grep "$i" | grep -v 'grep' && let nums+=1 &> /dev/null ps aux | grep "$i" | grep -v 'grep' &> /dev/null && let nums+=1
done done
if [ "x$nums" = "x4" ];then if [ "x$nums" == "x3" ];then
success "$jump_start" success "$jump_start"
touch "$lockfile" touch "$lockfile"
echo echo