From 1a8f08a07d8b74bfde0fa94ad863f74118b7be35 Mon Sep 17 00:00:00 2001
From: zanbin168 <zanbin168@qq.com>
Date: 星期三, 17 五月 2023 10:02:45 +0800
Subject: [PATCH] update
---
_example/latest/README.md | 466 ++++++++++++++++++++++++++++++++++++++++++++++
.vscode/launch.json | 15 +
_example/latest/latest.go | 15
_example/latest/afrog.exe.old | 0
_example/latest/LICENSE | 21 ++
update.go | 66 +++++-
_example/latest/reports/0517-094242.html | 0
7 files changed, 559 insertions(+), 24 deletions(-)
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..61b381c
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,15 @@
+{
+ // 使用 IntelliSense 了解相关属性。
+ // 悬停以查看现有属性的描述。
+ // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Launch Package",
+ "type": "go",
+ "request": "launch",
+ "mode": "auto",
+ "program": "${fileDirname}"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/_example/latest/LICENSE b/_example/latest/LICENSE
new file mode 100644
index 0000000..c8f34c9
--- /dev/null
+++ b/_example/latest/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2022 zan8in
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/_example/latest/README.md b/_example/latest/README.md
new file mode 100644
index 0000000..e943524
--- /dev/null
+++ b/_example/latest/README.md
@@ -0,0 +1,466 @@
+<p align="center">
+ <a href="http://afrog.net"><img src="images/afrog-logo.svg" width="60px" alt="afrog"></a>
+</p>
+<!-- </a> <h1 align="center">afrog</h1> -->
+
+<h4 align="center">A Security Tool for Bug Bounty, Pentest and Red Teaming</h4>
+
+<p align="center">
+<img src="https://img.shields.io/github/go-mod/go-version/zan8in/afrog?filename=go.mod">
+<a href="https://github.com/zan8in/afrog/releases"><img src="https://img.shields.io/github/downloads/zan8in/afrog/total">
+<a href="https://github.com/zan8in/afrog/graphs/contributors"><img src="https://img.shields.io/github/contributors-anon/zan8in/afrog">
+<a href="https://github.com/zan8in/afrog/releases/"><img src="https://img.shields.io/github/release/zan8in/afrog">
+<a href="https://github.com/zan8in/afrog/issues"><img src="https://img.shields.io/github/issues-raw/zan8in/afrog">
+<a href="https://github.com/zan8in/afrog/discussions"><img src="https://img.shields.io/github/discussions/zan8in/afrog">
+</p>
+
+<p align="center" dir="auto">
+ <a href="https://github.com/zan8in/afrog/releases">Download</a> •
+ <!-- <a href="https://github.com/zan8in/afrog/blob/main/docs/GUIDE.md">指南</a> • -->
+ <a href="https://github.com/zan8in/afrog/blob/main/docs/CONTRIBUTION.md">Contributors</a> •
+ <a href="https://github.com/zan8in/afrog/tree/main/pocs/afrog-pocs">PoC</a>
+ <!-- <a href="https://github.com/zan8in/afrog/blob/main/docs/POCLIST.md">列表</a> • -->
+ <!-- <a href="https://github.com/zan8in/afrog/blob/main/docs/README_en.md">English Doc</a> -->
+</p>
+
+## PoC Contributors
+
+<div><table frame=void>
+ <tr>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/1.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://blog.csdn.net/U_U520"><sub>不动明王</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/2.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://www.linuxlz.com/"><sub>雪山</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/3.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/White-hua"><sub>White-hua</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/5.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0)"><sub>123456</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/6.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/ifofor"><sub>ifofor</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/7.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/SkinAir"><sub>Air</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/8.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/zhizhuoshuma"><sub>执着</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/4.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/purple-WL"><sub>purple-WL</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/9.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>throat</sub></a>
+ </td>
+ </tr>
+ <tr>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/10.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="http://secx.store:4000/archives/"><sub>Secx</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/11.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/yueyu0740"><sub>冰河</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/12.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>Sheen</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/13.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>a16</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/14.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>A1</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/15.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/rainbow2972"><sub>rainbow2972</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/16.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/wuha0926"><sub>wuha0926</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/17.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>茄子</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/18.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>lei_sec</sub></a>
+ </td>
+ </tr>
+ <tr>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/19.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/G-H-Z"><sub>G-H-Z</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/20.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/LDDP"><sub>wh1te</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/21.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>清月</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/22.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>york</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/23.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>7eleven.eth</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/24.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/Double-q1015"><sub>Double...</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/25.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/iceyjchen"><sub>ICEY_</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/26.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/Ablackcatlazy"><sub>lazy</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/27.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/Lay0us1"><sub>Lay0us</sub></a>
+ </td>
+ </tr>
+ <tr>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/28.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>m4sk</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/29.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://www.yuque.com/chenmoshuren/qyxg2k"><sub>沉默树人</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/30.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>陈麻子</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/31.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/leonardo-o1"><sub>leonardo-o1</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/32.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>江湖人称魏...</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/33.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>若兮风</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/34.png&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>-sudo</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/35.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/Cuerz"><sub>Cuerz</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/36.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="javascript:void(0);"><sub>laohuan12138</sub></a>
+ </td>
+ </tr>
+ <tr>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/37.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/exp0l0zzz"><sub>exp0l0zzz</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/38.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/1derian"><sub>1derian</sub></a>
+ </td>
+ <td align="center">
+ <img src="https://images.weserv.nl/?url=raw.githubusercontent.com/zan8in/afrog/main/images/contributors/39.jpg&mask=circle&w=60&h=60"
+ alt="Typora-Logo"
+ />
+ <br>
+ <a href="https://github.com/CMDB-M"><sub>CMDB-M</sub></a>
+ </td>
+ </tr>
+</table></div>
+
+
+
+## What is afrog
+
+afrog is a high-performance vulnerability scanner that is fast and stable. It supports user-defined PoC and comes with several built-in types, such as CVE, CNVD, default passwords, information disclosure, fingerprint identification, unauthorized access, arbitrary file reading, and command execution. With afrog, network security professionals can quickly validate and remediate vulnerabilities, which helps to enhance their security defense capabilities.
+
+## Features
+
+* [x] Open source
+* [x] Fast, stable, with low false positives
+* [x] Detailed HTML vulnerability reports
+* [x] Customizable and stably updatable PoCs
+* [x] Active community exchange group
+
+## Installation
+
+### Prerequisites
+
+- [Go](https://go.dev/) version 1.19 or higher.
+
+you can install it with:
+
+**Binary**
+```sh
+$ https://github.com/zan8in/afrog/releases
+```
+
+**Github**
+```sh
+$ git clone https://github.com/zan8in/afrog.git
+$ cd afrog
+$ go build cmd/afrog/main.go
+$ ./afrog -h
+```
+
+**Go**
+```sh
+$ go install -v https://github.com/zan8in/afrog/cmd/afrog@latest
+```
+
+## Running afrog
+
+By default, afrog scans all built-in PoCs, and if it finds any vulnerabilities, it automatically creates an HTML report with the date of the scan as the filename.
+
+```sh
+afrog -t https://example.com
+```
+
+**Warning occurs when running afrog**
+
+If you see an error message saying:
+```
+[ERR] ceye reverse service not set: /home/afrog/.config/afrog/afrog-config.yaml
+```
+it means you need to modify the [configuration file](#configuration-file).
+
+To execute a custom PoC directory, you can use the following command:
+
+```sh
+afrog -t https://example.com -P mypocs/
+```
+
+Use the command `-s keyword` to perform a fuzzy search on all PoCs and scan the search results. Multiple keywords can be used, separated by commas. For example: `-s weblogic,jboss`.
+
+```sh
+afrog -t https://example.com -s weblogic,jboss
+```
+
+Use the command `-S keyword` to scan vulnerabilities based on their severity level. Severity levels include: `info`, `low`, `medium`, `high`, and `critical`. For example, to only scan high and critical vulnerabilities, use the command `-S high,critical`.
+
+```sh
+afrog -t https://example.com -S high,critical
+```
+
+You can scan multiple URLs at the same time as well.
+
+```sh
+afrog -T urls.txt
+```
+
+## Configuration file
+
+The first time you start afrog, it will automatically create a configuration file called `afrog-config.yaml`, which will be saved in the current user directory under `$HOME/.config/afrog/afrog-config.yaml`.
+
+Here is an example config file:
+
+```yaml
+reverse:
+ ceye:
+ api-key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
+ domain: "xxxxxx.ceye.io"
+```
+
+`reverse` is a reverse connection platform used to verify command execution vulnerabilities that cannot be echoed back. Currently, only ceye can be used for verification. To obtain ceye, follow these steps:
+
+- Go to the [ceye.io](http://ceye.io/) website and register an account.
+- Log in and go to the personal settings page.
+- Copy the `domain` and `api-key` and correctly configure them in the `afrog-config.yaml` file.
+
+
+## Json Output (For developers)
+
+### Json
+Optional command: `-json` `-j`, Save the scan results to a JSON file. The JSON file includes the following contents by default: `target`, `fulltarget`, `id`, and `info`. The info field includes the following sub-fields: `name`, `author`, `severity`, `description`, and `reference`. If you want to save both `request` and `response` contents, please use the [-json-all](#jsonall) command parameter.
+
+```sh
+afrog -t https://example.com -json result.json
+afrog -t https://example.com -j result.json
+```
+
+::: warning
+The content of the JSON file is updated in real time. However, there is an important note to keep in mind: before the scan is completed, if developers want to parse the file content, they need to add a '`]`' symbol to the end of the file by themselves, otherwise it will cause parsing errors. Of course, if you wait for the scan to complete before parsing the file, this issue will not occur.
+:::
+
+
+### JsonAll
+
+Optional command: `-json-all` `-ja`, The only difference between the `-json-all` and `-json` commands is that `-json-all` writes all vulnerability results, including `request` and `response`, to a JSON file.
+
+```sh
+afrog -t https://example.com -json-all result.json
+afrog -t https://example.com -ja result.json
+```
+
+
+## Screenshot
+
+
+
+<!--  -->
+
+## Discussion group
+
+To join the afrog communication group on WeChat, please first add the afrog personal account and mark it as **afrog**. Then, you will be added to the group by the administrator.
+
+<img src="https://github.com/zan8in/afrog/blob/main/images/discussion.jpg" width="33%" />
+
+## 404Starlink
+<img src="https://github.com/knownsec/404StarLink-Project/raw/master/logo.png" width="30%">
+
+afrog has joined [404Starlink](https://github.com/knownsec/404StarLink)
+
+## Disclaimer
+
+This tool is intended only for **legally authorized** enterprise security construction purposes. If you want to test the functionality of this tool, you should build a target environment by yourself.
+
+To prevent malicious use, all PoCs included in this project are theoretical assessments of vulnerabilities. The tool does not exploit vulnerabilities, launch real attacks or exploits on targets.
+
+When using this tool for vulnerability scanning, it is important to ensure that your behavior complies with local laws and regulations, and that you have obtained sufficient authorization. **Do not scan unauthorized targets**.
+
+If you engage in any illegal behavior while using this tool, you will be solely responsible for any corresponding consequences, and we will not bear any legal or joint responsibility.
+
+Before installing and using this tool, please **read each clause carefully and thoroughly**. Restrictions, disclaimers, or other clauses that may significantly affect your rights and interests may be highlighted in bold or underlined to draw your attention. Unless you have fully read, fully understood, and agreed to all the terms of this agreement, do not install or use this tool. Your use of the tool or your acceptance of this agreement in any other express or implied manner will be deemed as your acknowledgment and agreement to be bound by this agreement.
\ No newline at end of file
diff --git a/_example/latest/afrog.exe.old b/_example/latest/afrog.exe.old
new file mode 100644
index 0000000..1144d02
--- /dev/null
+++ b/_example/latest/afrog.exe.old
Binary files differ
diff --git a/_example/latest/latest.go b/_example/latest/latest.go
index 84c80f3..6b27584 100644
--- a/_example/latest/latest.go
+++ b/_example/latest/latest.go
@@ -5,7 +5,6 @@
"runtime"
"github.com/apex/log"
- "github.com/kierdavis/ansi"
update "github.com/zan8in/goupdate"
"github.com/zan8in/goupdate/progress"
@@ -17,16 +16,16 @@
}
func main() {
- ansi.HideCursor()
- defer ansi.ShowCursor()
+ // ansi.HideCursor()
+ // defer ansi.ShowCursor()
// update polls(1) from tj/gh-polls on github
m := &update.Manager{
- Command: "polls",
+ Command: "afrog.exe",
Store: &github.Store{
- Owner: "tj",
- Repo: "gh-polls",
- Version: "0.0.3",
+ Owner: "zan8in",
+ Repo: "afrog",
+ Version: "2.3.1",
},
}
@@ -46,7 +45,7 @@
latest := releases[0]
// find the tarball for this system
- a := latest.FindTarball(runtime.GOOS, runtime.GOARCH)
+ a := latest.FindZip(runtime.GOOS, runtime.GOARCH)
if a == nil {
log.Info("no binary for your system")
return
diff --git a/_example/latest/reports/0517-094242.html b/_example/latest/reports/0517-094242.html
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/_example/latest/reports/0517-094242.html
diff --git a/update.go b/update.go
index a765f13..13e3ceb 100644
--- a/update.go
+++ b/update.go
@@ -8,7 +8,6 @@
"io/ioutil"
"net/http"
"os"
- "os/exec"
"path/filepath"
"runtime"
"strconv"
@@ -62,40 +61,42 @@
return errors.Wrap(err, "opening tarball")
}
- err = unpackit.Unpack(f, dir)
+ tempdir := filepath.Join(dir, "tmp")
+ err = unpackit.Unpack(f, tempdir)
if err != nil {
f.Close()
return errors.Wrap(err, "unpacking tarball")
}
+ defer os.RemoveAll(tempdir)
if err := f.Close(); err != nil {
return errors.Wrap(err, "closing tarball")
}
- bin := filepath.Join(path, m.Command)
+ latestBinary := filepath.Join(tempdir, m.Command)
- if err := os.Chmod(bin, 0755); err != nil {
+ if err := os.Chmod(latestBinary, 0755); err != nil {
return errors.Wrap(err, "chmod")
}
- dst := filepath.Join(dir, m.Command)
- tmp := dst + ".tmp"
+ currentBinary := filepath.Join(dir, m.Command)
+ latestBinaryTmp := currentBinary + ".tmp"
- log.Debugf("copy %q to %q", bin, tmp)
- if err := copyFile(tmp, bin); err != nil {
+ log.Debugf("copy %q to %q", latestBinary, latestBinaryTmp)
+ if err := copyFile(latestBinaryTmp, latestBinary); err != nil {
return errors.Wrap(err, "copying")
}
if runtime.GOOS == "windows" {
- old := dst + ".old"
- log.Debugf("windows workaround renaming %q to %q", dst, old)
- if err := os.Rename(dst, old); err != nil {
+ old := currentBinary + ".old"
+ log.Debugf("windows workaround renaming %q to %q", currentBinary, old)
+ if err := os.Rename(currentBinary, old); err != nil {
return errors.Wrap(err, "windows renaming")
}
}
- log.Debugf("renaming %q to %q", tmp, dst)
- if err := os.Rename(tmp, dst); err != nil {
+ log.Debugf("renaming %q to %q", latestBinaryTmp, currentBinary)
+ if err := os.Rename(latestBinaryTmp, currentBinary); err != nil {
return errors.Wrap(err, "renaming")
}
@@ -104,12 +105,16 @@
// Install binary to replace the current version.
func (m *Manager) Install(path string) error {
- bin, err := exec.LookPath("./" + m.Command)
+ // bin, err := exec.LookPath(m.Command) // 获取当前程序的绝对路径
+ // if err != nil {
+ // return errors.Wrapf(err, "looking up path of %q", m.Command)
+ // }
+
+ // dir := filepath.Dir(bin)
+ dir, err := getExecutablePath()
if err != nil {
return errors.Wrapf(err, "looking up path of %q", m.Command)
}
-
- dir := filepath.Dir(bin)
return m.InstallTo(path, dir)
}
@@ -231,3 +236,32 @@
return
}
+
+func getExecutablePath() (string, error) {
+ exePath, err := os.Executable()
+ if err != nil {
+ return exePath, err
+ }
+
+ // 检查可执行文件是否存在
+ _, err = os.Stat(exePath)
+ if os.IsNotExist(err) {
+ // 可执行文件不存在,采取适当的处理措施
+ // 例如记录错误信息或提供备用路径
+ return exePath, err
+ }
+
+ // 处理相对路径
+ if !filepath.IsAbs(exePath) {
+ exePath, err = filepath.Abs(exePath)
+ if err != nil {
+ // 处理转换为绝对路径时的错误
+ return exePath, err
+ }
+ }
+
+ // 获取可执行文件所在目录的绝对路径
+ exeDir := filepath.Dir(exePath)
+
+ return exeDir, err
+}
--
Gitblit v1.8.0