当前位置:网站首页>OliveTin能在网页上安全运行shell命令(上)
OliveTin能在网页上安全运行shell命令(上)
2022-07-06 09:41:00 【杨浦老苏】
昨天下午突然接到居委会的通知,晚上 7 点全员筛查。看意思这两天应该还会再有一次
网友
figo
问:有没有什么软件或者docker能够一键关机和一键重启Linux主机?而不用打开命令行去执行命令。
,老苏第一时间就想起了在计划列表中躺了很久的OliveTin
,之所以迟迟不动是因为没想好用来做什么。等真正开始折腾的时候才发现,OliveTin
比想象中遇到的问题多,居然跑官方的示例都能遇到坑,可能是因为采用了docker
方式在群晖
上运行的缘故,这反而激发了老苏的兴趣。
什么是 OliveTin ?
OliveTin
可让您从Web
界面安全且简单地访问预定义的shell
命令。
准备
首先要准备 config.yaml
文件,最简单的当然是复制官方的示例文档,可以复制粘贴,也可以另存为。https://raw.githubusercontent.com/OliveTin/OliveTin/main/config.yaml
Action
一个标准的 action
(我们可以理解为按钮)包含几个部分:
title
:标题,这是必填的,用来标识action
;shell
:脚本,也是必填的,用来执行具体的任务;icon
:图标,这个是非必须的,但是有的话看起来会比较舒服,除了图片外,还支持 https://unicode-table.com/en/emoji/ 的emoji
;arguments
:参数,这个是非必须的,可以用来实现一些变量,让shell
具有一定的灵活性;timeout
:超时,这个也是非必须的;
所以综合来看,一个按钮只要 title
和 shell
就可以了,举个最简单的完整的 config.yaml
例子
# 侦听端口
listenAddressSingleHTTPFrontend: 0.0.0.0:1337
# 日志级别:INFO (default), WARN 和 DEBUG
logLevel: "INFO"
# 显示新版本
showNewVersions: true
# Actions (buttons) to show up on the WebUI:
actions:
# 从最简单的开始
- title: 运行echo
icon: "📝"
shell: echo "我是老苏."
你也可以用这个作为 config.yaml
,让容器先运行起来再来修改、完善和丰富功能。
安装
在群晖上以 Docker 方式安装。
在注册表中搜索 olivetin
,选择第一个 jamesread/olivetin
,版本选择 latest
。
容器名称
因为后面还要通过命令行进入容器,建议将容器名称改为 olivetin
,当然这不是必须的,你也可以直接改命令行里的容器名称
卷
在 docker
文件夹中,创建一个新文件夹 olivetin
文件夹 | 装载路径 | 说明 |
---|---|---|
docker/olivetin | /config | 存放设置 |
建议勾选
只读
端口
本地端口不冲突就行,不确定的话可以用命令查一下
# 查看端口占用
netstat -tunlp | grep 端口号
本地端口 | 容器端口 |
---|---|
1337 | 1337 |
命令行安装
如果你熟悉命令行,可能用 docker cli
更快捷
# 新建文件夹 kavita 和 子目录
mkdir -p /volume2/docker/olivetin
# 进入 kavita 目录
cd /volume2/docker/olivetin
# 上传 config.yaml 文件到当前目录下
# 运行容器
docker run -d \
--restart unless-stopped \
--name olivetin \
-p 1337:1337 \
-v $(pwd):/config:ro \
jamesread/olivetin
也可以用 docker-compose
安装,下面是官方提供的 docker-compose.yml
,注意修改路径
version: "3.8"
services:
olivetin:
container_name: olivetin
image: jamesread/olivetin
volumes:
- ./:/config # replace host path or volume as needed
ports:
- "1337:1337"
restart: unless-stopped
networks:
web:
section:
external: true
然后执行下面的命令,因为采用了相对路径,在 portainer
中执行也是可以的
# 新建文件夹 kavita 和 子目录
mkdir -p /volume2/docker/olivetin
# 进入 kavita 目录
cd /volume2/docker/olivetin
# 将 docker-compose.yml 和 config.yaml 放入当前目录
# 一键启动
docker-compose up -d
运行
在浏览器中输入 http://群晖IP:1337
就能看到主界面
这是官方
config.yaml
的界面
如果你用了老苏的最小化示例,则只有一个按钮,我们点击 运行echo
按钮
会显示 [Success]
详细的信息可以在右上角的 Logs
中查看
遗留问题
问题1:权限
官方有个 ping
的示例,考虑到国内不能访问 google
,所以老苏把目标地址改为了 baidu
actions:
# This sends 1 ping to baidu.com.
- title: ping baidu.com
shell: ping baidu.com -c 4
icon: ping
timeout: 3
默认情况下,你会遇到 ping: usage error: Destination address required
而如果你将 shell
改为 sudo ping baidu.com -c 1
时,会需要你输入 password for olivetin
,所以唯一的办法是 docker cli
下执行容器增加 --user=root
或者 --privileged
# 用 root 运行容器
docker run -d \
--restart unless-stopped \
--name olivetin \
--user=root \
-p 1337:1337 \
-v $(pwd):/config:ro \
jamesread/olivetin
问题2:ssh密码
官方也提供了 ssh
的示例,老苏做了调整
ssh
登录主机的身份可以是用root
或者其他任何有权限的账号,这里只是为了演示,一般不建议直接用root
actions:
- title: 登录到 ds3617xs ping 百度
shell: ssh [email protected] 'ping baidu.com -c 4'
icon: "📌"
timeout: 50
执行 ssh
并不需要 root
权限, 但因为不能在命令行直接输入密码,所以会导致超时
或者 Exit code 255
官方提供的思路是用 SSH
密钥设置无密码登录,但老苏觉得这种方式不够灵活。
老苏想到了一种又比较灵活,但是又相对安全的解决办法,敬请期待~
周五,不见不散!
参考文档
OliveTin/OliveTin: OliveTin gives safe and simple access to predefined shell commands from a web interface.
地址:https://github.com/OliveTin/OliveTin
OliveTin - give safe and simple access to predefined shell commands from a web interface
地址:https://www.olivetin.app/
OliveTin documentation
地址:https://docs.olivetin.app/
List of common exit codes for GNU/Linux
地址:https://slg.ddnss.de/list-of-common-exit-codes-for-gnu-linux/
边栏推荐
- Summary of Android interview questions of Dachang in 2022 (II) (including answers)
- The art of Engineering (3): do not rely on each other between functions of code robustness
- Run xv6 system
- Sqoop I have everything you want
- Xin'an Second Edition: Chapter 25 mobile application security requirements analysis and security protection engineering learning notes
- Flink parsing (III): memory management
- Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
- Xin'an Second Edition: Chapter 26 big data security demand analysis and security protection engineering learning notes
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- 2022年大厂Android面试题汇总(一)(含答案)
猜你喜欢
BearPi-HM_ Nano development environment
sql语句优化,order by desc速度优化
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
[ASM] introduction and use of bytecode operation classwriter class
【ASM】字节码操作 ClassWriter 类介绍与使用
04 products and promotion developed by individuals - data push tool
06 products and promotion developed by individuals - code statistical tools
RepPoints:可形变卷积的进阶
基于STM32+华为云IOT设计的智能路灯
[introduction to MySQL] the first sentence · first time in the "database" Mainland
随机推荐
Sqoop I have everything you want
Compile and build, from the bottom to the top
Concept and basic knowledge of network layering
RepPoints:可形变卷积的进阶
Flink parsing (III): memory management
Remote code execution penetration test - B module test
Precipitated database operation class - version C (SQL Server)
C WinForm series button easy to use
Run xv6 system
04 products and promotion developed by individuals - data push tool
FlutterWeb浏览器刷新后无法回退的解决方案
EasyCVR授权到期页面无法登录,该如何解决?
OpenCV中如何使用滚动条动态调整参数
Alibaba brand data bank: introduction to the most complete data bank
How to use scroll bars to dynamically adjust parameters in opencv
MySQL error reporting solution
Flink parsing (IV): recovery mechanism
sql语句优化,order by desc速度优化
PySpark算子处理空间数据全解析(5): 如何在PySpark里面使用空间运算接口
MySQL stored procedure