Browse Source

dbfile依赖环境变量JUMPDB

master
牛批的一批 5 years ago
parent
commit
4df50638a8
  1. 36
      README.md
  2. 14
      client/jumpcli.py
  3. 12
      server/jumpserver.py

36
README.md

@ -5,14 +5,40 @@
```shell ```shell
├── README.md ├── README.md
├── client ├── client
│ ├── README.md
│ ├── go.mod
│ ├── go.sum
│ ├── jumpcli.go
│ └── jumpcli.svg
│   ├── README.md
│   ├── go.mod
│   ├── go.sum
│   ├── jumpcli.go
│   ├── jumpcli.py
│   ├── jumpcli.svg
│   └── requirements.txt
└── server └── server
├── jumpserver.py ├── jumpserver.py
├── manager_user.sh ├── manager_user.sh
├── proto.md ├── proto.md
└── requirements.txt └── requirements.txt
``` ```
### 设置环境变量
'JUMPDB'是sqlite3本地数据库文件路径,这个环境变量是jumpserver和jumpcli必要的一个参数
```shell script
export JUMPDB=/usr/local/jumpserver/jumpserver.db # 设置sqlite3 db文件路径
chmod 755 $JUMPDB # 设置权限755
```
### JumpServer启动
```shell script
./jumpserver.py -host 192.168.1.44 -port 8080
```
### JumpCli命令
把jumpcli拷贝到PATH路径下
```shell script
cp jumpcli.py /usr/bin/jumpcli # 拷贝到path路径
jumpcli # 执行
```

14
client/jumpcli.py

@ -18,7 +18,7 @@ KEYS_UP = (curses.KEY_UP, ord('k'))
KEYS_DOWN = (curses.KEY_DOWN, ord('j')) KEYS_DOWN = (curses.KEY_DOWN, ord('j'))
KEYS_SELECT = (curses.KEY_RIGHT, ord(' ')) KEYS_SELECT = (curses.KEY_RIGHT, ord(' '))
# 数据库文件
# 数据库文件 default
gSqlite3File = "/usr/local/jumpserver/jumpserver.db" gSqlite3File = "/usr/local/jumpserver/jumpserver.db"
# ssh_private_path ssh私钥路径 # ssh_private_path ssh私钥路径
@ -28,8 +28,17 @@ if system_type == "Darwin":
elif system_type == "Linux": elif system_type == "Linux":
ssh_private_path = "/home/%s/.ssh/id_rsa" ssh_private_path = "/home/%s/.ssh/id_rsa"
else: else:
print("Don't support your system(%s)" % system_type)
exit(1) exit(1)
def init():
global gSqlite3File
jumpDb = os.environ.get("JUMPDB")
if jumpDb is not None:
gSqlite3File = jumpDb
else:
print("ERROR: Hadn't set environ var 'JUMPDB' for jump database! mod 755")
exit(1)
class Picker(object): class Picker(object):
def __init__(self, options, title=None, indicator='*', default_index=0, multiselect=False, multi_select=False, def __init__(self, options, title=None, indicator='*', default_index=0, multiselect=False, multi_select=False,
@ -278,6 +287,9 @@ def get_hosts(user):
return resp return resp
def main(): def main():
# 初始化检测
init()
user = getpass.getuser() user = getpass.getuser()
print("current user: " + user) print("current user: " + user)

12
server/jumpserver.py

@ -1,3 +1,4 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
import argparse import argparse
@ -59,6 +60,14 @@ SSO_TIMER_PERIOD = 5 * 60
# sso过期时间 # sso过期时间
SSO_EXPIRE_TIMEOUT = 24 * 60 * 60 SSO_EXPIRE_TIMEOUT = 24 * 60 * 60
def init():
global gSqlite3File
jumpDb = os.environ.get("JUMPDB")
if jumpDb is not None:
gSqlite3File = jumpDb
else:
print("ERROR: Hadn't set environ var 'JUMPDB' for jump database! mod 755")
exit(1)
# 解析命令行 # 解析命令行
def parse_cmd(): def parse_cmd():
@ -776,6 +785,9 @@ def init_log():
def main(): def main():
# 初始化检测
init()
# 初始化日志 # 初始化日志
init_log() init_log()

Loading…
Cancel
Save