Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
78b55f98
Commit
78b55f98
authored
Oct 12, 2014
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok
parent
fb8b800f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
9 deletions
+84
-9
jumpserver.py
jumpserver.py
+4
-3
views.py
webroot/AutoSa/AutoSa/views.py
+42
-6
downFile.html
webroot/AutoSa/templates/downFile.html
+38
-0
No files found.
jumpserver.py
View file @
78b55f98
...
@@ -164,7 +164,7 @@ def sth_select(username='', ip=''):
...
@@ -164,7 +164,7 @@ def sth_select(username='', ip=''):
"""if username: return password elif ip return port"""
"""if username: return password elif ip return port"""
db
,
cursor
=
connect_db
(
db_user
,
db_password
,
db_db
,
db_host
,
db_port
)
db
,
cursor
=
connect_db
(
db_user
,
db_password
,
db_db
,
db_host
,
db_port
)
if
username
:
if
username
:
cursor
.
execute
(
'select password from
%
s where username="
%
s"'
%
(
user_table
,
username
))
cursor
.
execute
(
'select
ldap_
password from
%
s where username="
%
s"'
%
(
user_table
,
username
))
try
:
try
:
password
=
cursor
.
fetchone
()[
0
]
password
=
cursor
.
fetchone
()[
0
]
except
IndexError
:
except
IndexError
:
...
@@ -292,7 +292,7 @@ if __name__ == '__main__':
...
@@ -292,7 +292,7 @@ if __name__ == '__main__':
sys
.
exit
()
sys
.
exit
()
else
:
else
:
connect_one
(
username
,
option
)
connect_one
(
username
,
option
)
except
(
BaseException
,
Exception
):
#
except (BaseException, Exception):
#
except IndexError:
except
IndexError
:
print
"Exit."
print
"Exit."
sys
.
exit
()
sys
.
exit
()
\ No newline at end of file
webroot/AutoSa/AutoSa/views.py
View file @
78b55f98
...
@@ -901,20 +901,55 @@ def upFile(request):
...
@@ -901,20 +901,55 @@ def upFile(request):
for
chunk
in
upload_file
.
chunks
():
for
chunk
in
upload_file
.
chunks
():
f
.
write
(
chunk
)
f
.
write
(
chunk
)
f
.
close
()
f
.
close
()
asset
=
Assets
.
objects
.
get
(
ip
=
host
,
None
)
asset
=
Assets
.
objects
.
get
(
ip
=
host
)
if
asset
:
if
asset
:
port
=
asset
.
port
port
=
asset
.
port
jm
=
PyCrypt
(
key
)
jm
=
PyCrypt
(
key
)
user
=
User
.
objects
.
get
(
username
)
user
=
User
.
objects
.
get
(
username
=
username
)
t
=
paramiko
.
Transport
(
host
,
port
)
t
=
paramiko
.
Transport
(
(
host
,
port
)
)
t
.
connect
(
username
=
username
,
password
=
jm
.
decrypt
(
user
.
password
))
t
.
connect
(
username
=
username
,
password
=
jm
.
decrypt
(
user
.
ldap_
password
))
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
.
put
(
filename
,
path
)
sftp
.
put
(
filename
,
'
%
s/
%
s'
%
(
path
,
upload_file
.
name
))
msg
=
u'上传成功,位于
%
s主机,位置
%
s.'
%
(
host
,
path
)
return
HttpResponse
(
'save
%
s Ok, size
%
s'
%
(
upload_file
.
name
,
upload_file
.
size
)
)
return
render_to_response
(
'info.html'
,
{
'msg'
:
msg
}
)
else
:
else
:
return
render_to_response
(
'info.html'
,
{
'error'
:
u"上传失败"
})
return
render_to_response
(
'info.html'
,
{
'error'
:
u"上传失败"
})
return
render_to_response
(
'upFile.html'
,
return
render_to_response
(
'upFile.html'
,
{
'username'
:
username
},
context_instance
=
RequestContext
(
request
))
@login_required
def
downFile
(
request
):
username
=
request
.
session
.
get
(
'username'
)
if
request
.
method
==
'POST'
:
host
=
request
.
POST
.
get
(
'host'
)
path
=
request
.
POST
.
get
(
'path'
)
download_dir
=
'/tmp/download/
%
s'
%
username
download_file
=
'
%
s/
%
s'
%
(
download_dir
,
os
.
path
.
basename
(
path
))
if
not
os
.
path
.
exists
(
download_dir
):
os
.
makedirs
(
download_dir
)
asset
=
Assets
.
objects
.
get
(
ip
=
host
)
jm
=
PyCrypt
(
key
)
port
=
asset
.
port
user
=
User
.
objects
.
get
(
username
=
username
)
t
=
paramiko
.
Transport
((
host
,
port
))
t
.
connect
(
username
=
username
,
password
=
jm
.
decrypt
(
user
.
ldap_password
))
sftp
=
paramiko
.
SFTPClient
.
from_transport
(
t
)
sftp
.
get
(
path
,
download_file
)
if
os
.
path
.
isfile
(
download_file
):
f
=
open
(
download_file
)
data
=
f
.
read
()
f
.
close
()
response
=
HttpResponse
(
data
,
mimetype
=
'application/octet-stream'
)
response
[
'Content-Disposition'
]
=
'attachment; filename=
%
s'
%
os
.
path
.
basename
(
path
)
return
response
return
render_to_response
(
'downFile.html'
,
{
'username'
:
username
},
{
'username'
:
username
},
context_instance
=
RequestContext
(
request
))
context_instance
=
RequestContext
(
request
))
\ No newline at end of file
webroot/AutoSa/templates/downFile.html
0 → 100644
View file @
78b55f98
{% extends 'base.html' %}
{% block content %}
<form
class=
"form-horizontal"
enctype=
"multipart/form-data"
role=
"form"
method=
"post"
action=
""
>
<fieldset
>
<legend>
{{ username }} -- 下载文件
</legend>
{% if error %}
<div
class=
"alert alert-danger"
>
{{ error }}
</div>
{% endif %}
{% if msg %}
<div
class=
"alert alert-success"
>
{{ msg }}
</div>
{% endif %}
<input
type=
"text"
name=
"username"
value=
"{{ username }}"
hidden=
"hidden"
>
<div
class=
"form-group"
>
<label
for=
"host"
class=
"col-sm-2 control-label"
>
服务器IP
<span
style=
"color: red"
>
*
</span></label>
<div
class=
"col-sm-4"
>
<input
type=
"text"
class=
"form-control"
id=
"host"
name=
"host"
placeholder=
"IP"
>
</div>
</div>
<div
class=
"form-group"
>
<label
for=
"path"
class=
"col-sm-2 control-label"
>
文件path
<span
style=
"color: red"
>
*
</span></label>
<div
class=
"col-sm-4"
>
<input
type=
"text"
class=
"form-control"
id=
"path"
name=
"path"
placeholder=
"文件绝对位置"
>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-4"
>
<button
class=
"btn btn-primary"
>
下载
</button>
</div>
</div>
</fieldset>
</form>
{% endblock %}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment