当前位置:网站首页>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/
边栏推荐
- [getting started with MySQL] fourth, explore operators in MySQL with Kiko
- Flink parsing (III): memory management
- OpenCV中如何使用滚动条动态调整参数
- Compile and build, from the bottom to the top
- JMeter interface test response data garbled
- The solution that flutterweb browser cannot be rolled back after refreshing
- 2022年大厂Android面试题汇总(二)(含答案)
- 分布式(一致性协议)之领导人选举( DotNext.Net.Cluster 实现Raft 选举 )
- PySpark算子处理空间数据全解析(4): 先说说空间运算
- The NTFS format converter (convert.exe) is missing from the current system
猜你喜欢

一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升

Yarn: unable to load file d:\programfiles\nodejs\yarn PS1, because running scripts is prohibited on this system

Alibaba brand data bank: introduction to the most complete data bank

Unity tips - draw aiming Center

JMeter interface test response data garbled

Basic configuration and use of spark
![[rapid environment construction] openharmony 10 minute tutorial (cub pie)](/img/b5/feb9c56a65c3b07403710e23078a6f.jpg)
[rapid environment construction] openharmony 10 minute tutorial (cub pie)

The problem of "syntax error" when uipath executes insert statement is solved
![[introduction to MySQL] the first sentence · first time in the](/img/1e/2401d821b1008922bc5f8a15de31f9.png)
[introduction to MySQL] the first sentence · first time in the "database" Mainland

基于STM32+华为云IOT设计的智能路灯
随机推荐
Unity粒子特效系列-闪星星的宝箱
06 products and promotion developed by individuals - code statistical tools
[introduction to MySQL] the first sentence · first time in the "database" Mainland
The shell generates JSON arrays and inserts them into the database
mysql高級(索引,視圖,存儲過程,函數,修改密碼)
Kernel link script parsing
Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
node の SQLite
远程代码执行渗透测试——B模块测试
Unity tips - draw aiming Center
03 products and promotion developed by individuals - plan service configurator v3.0
sql语句优化,order by desc速度优化
【MySQL入门】第三话 · MySQL中常见的数据类型
Xin'an Second Edition: Chapter 24 industrial control safety demand analysis and safety protection engineering learning notes
The art of Engineering (1): try to package things that do not need to be exposed
TCP连接不止用TCP协议沟通
The problem of "syntax error" when uipath executes insert statement is solved
MySQL 8 sub database and table backup database shell script
Automatic operation and maintenance sharp weapon ansible Playbook
Sqoop I have everything you want