Skip to content

Commit

Permalink
bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
halcyonone committed Mar 14, 2015
1 parent 691271c commit ce6494b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
2 changes: 2 additions & 0 deletions connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def log_record(username, host):
raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir)

log = Log(user=username, host=host, log_path=log_file_path, start_time=datetime.now(), pid=pid)
log_file.write('Starttime is %s\n' % datetime.now())
log.save()
return log_file, log

Expand Down Expand Up @@ -168,6 +169,7 @@ def posix_shell(chan, username, host):
finally:
timestamp_end = time.time()
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)
log_file.write('Endtime is %s' % datetime.now())
log_file.close()
log.is_finished = True
log.log_finished = False
Expand Down
18 changes: 15 additions & 3 deletions jasset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def index(request):
def f_add_host(ip, port, idc, jtype, group, active, comment, username='', password=''):
groups = []
idc = IDC.objects.get(name=idc)
if type == 'M':
if jtype == 'M':
print username, password
a = Asset(ip=ip, port=port,
login_type=jtype, idc=idc,
is_active=int(active),
Expand Down Expand Up @@ -135,7 +136,15 @@ def batch_host_edit(request):
j_active = request.POST.get(j_active).strip()
j_comment = request.POST.get(j_comment).strip()

jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment)
if j_type == 'M':
j_user = "editable[" + str(i) + "][j_user]"
j_password = "editable[" + str(i) + "][j_password]"
j_user = request.POST.get(j_user).strip()
password = request.POST.get(j_password).strip()
j_password = cryptor.encrypt(password)
jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment, j_user, j_password)
else:
jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment)

return render_to_response('jasset/host_list.html')

Expand Down Expand Up @@ -199,8 +208,11 @@ def host_edit(request):

a = Asset.objects.get(id=int(offset))
if j_type == 'M':
if post.password == request.POST.get('j_password'):
j_password = post.password
else:
j_password = cryptor.encrypt(request.POST.get('j_password'))
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
a.ip = j_ip
a.port = j_port
a.login_type = j_type
Expand Down
8 changes: 4 additions & 4 deletions jumpserver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ database = jumpserver

[ldap]
ldap_enable = 0
host_url = ldap://127.0.0.1:389
base_dn = dc=jumpserver, dc=org
root_dn = cn=admin,dc=jumpserver,dc=org
root_pw = secret234
host_url = ldap://192.168.8.230:389
base_dn = dc=fengxing, dc=com
root_dn = cn=admin,dc=fengxing,dc=com
root_pw = 123456

[websocket]
web_socket_host = 127.0.0.1:3000
Expand Down
2 changes: 1 addition & 1 deletion jumpserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def page_list_return(total, current=1):
return range(min_page, max_page+1)


def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment):
def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment, j_user='', j_password=''):
groups = []
is_active = {u'是': '1', u'否': '2'}
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
Expand Down
18 changes: 13 additions & 5 deletions log_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#coding: utf-8

import os
import re
import time
import psutil
from datetime import datetime
Expand All @@ -15,14 +16,21 @@

def log_hanler(id):
log = Log.objects.get(id=id)
pattern = re.compile(r'\[.*@.*\][\$#].*')
if log:
filename = log.log_path
if os.path.isfile(filename):
ret1 = os.system('cat %s | grep "DateTime" > %s.his' % (filename, filename))
ret2 = os.system('cat %s | grep "\[.*@.*\][\$\#]" >> %s.his' % (filename, filename))
ret3 = os.system('cat %s | grep "EndTime" >> %s.his' % (filename, filename))
if (ret1 + ret2 + ret3) == 0:
print 'Handler %s ok.' % filename
f_his = filename + '.his'
f1 = open(filename)
f2 = open(f_his, 'a')
lines = f1.readlines()
for line in lines[7:]:
match = pattern.match(line)
if match:
newline = re.sub('\[[A-Z]', '', line)
f2.write(newline)
f1.close()
f2.close()
log.log_finished = True
log.save()

Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/group_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h5> 主机组<span class="text-info">{{ group_name }}</span>详细信息列表
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
Expand Down
32 changes: 15 additions & 17 deletions templates/jasset/host_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,25 @@ <h5> 填写主机基本信息 </h5>
{% endfor %}
</div>

<div name="a1" id=a1 style="display:none;">
{% ifequal post.login_type M %}
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户名 </label>
<div class="col-sm-6"><input type="text" name="j_user" placeholder="lilei" class="form-control"></div>
<div class="col-sm-6"><input type="text" name="j_user" value="{{ post.username }}" class="form-control"></div>
</div>

<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户密码 </label>
<div class="col-sm-6"><input type="password" name="j_password" placeholder="Password" class="form-control"></div>
<div class="col-sm-6"><input type="password" name="j_password" value="{{ post.password }}" class="form-control"></div>
</div>
</div>
{% else %}
<div name="a1" id=a1 style="display:none;">
<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户名 </label>
<div class="col-sm-6"><input type="text" name="j_user" placeholder="lilei" class="form-control"></div>
</div>

<div class="form-group"><label class="col-sm-2 col-sm-offset-1 control-label"> 普通用户密码 </label>
<div class="col-sm-6"><input type="password" name="j_password" placeholder="Password" class="form-control"></div>
</div>
</div>
{% endifequal %}
</div>

<div class="hr-line-dashed"></div>
Expand Down Expand Up @@ -177,19 +187,7 @@ <h5> 填写主机基本信息 </h5>
msg: {required: "请填写用户名"}
},
"j_password": {
rule: "required(type_m);length[6~16]",
tip: "密码6-16位",
ok: "",
msg: {required: "6-16位"}
},
"j_root": {
rule: "required(type_m)",
tip: "超管用户名",
ok: "",
msg: {required: "请填写用户名"}
},
"j_passwd": {
rule: "required(type_m);length[6~16]",
rule: "required(type_m);length[6~100]",
tip: "密码6-16位",
ok: "",
msg: {required: "6-16位"}
Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/host_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h5> 主机详细信息列表</h5>
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/host_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
Expand Down
2 changes: 1 addition & 1 deletion templates/jasset/idc_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h5> IDC<span class="text-info"> {{ idc_name }} </span>详细信息列表 </h5>
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
Expand Down

0 comments on commit ce6494b

Please sign in to comment.