go将青龙面板里面的脚本文件都下载到本地

纯粹练手用的,大家轻喷
青龙面板的脚本文件可以下载到本地,这样的话自己可以研究一下对应的脚本文件,能学到更多的知识,原理其实很简单,F12一下就知道了,青龙面板使用Request Headers里面放入Authorization,那么Token我们已经拿到了,然后获取到所有文件的名称,分级目录,太过于简单,直接上代码了

go将青龙面板里面的脚本文件都下载到本地
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "io/ioutil"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

func main() {

    recordbody := getData("http://yourIp:5600/api/scripts/files?t=")

    var conf recordConfig
    err := json.Unmarshal(recordbody, &conf)
    if err != nil {
        fmt.Println("error:", err)
    }

    fmt.Printf("\r\n获取到的body code:%s \n", strconv.Itoa(conf.Code))
    for _, val := range conf.Data {
        if val.Children != nil {
            for _, childval := range val.Children {
                childbody := getData(fmt.Sprintf("http://yourIp:5600/api/scripts/%s?path=%s&t=", childval.Value, childval.Parent))
                var jsconf jsConfig
                err := json.Unmarshal(childbody, &jsconf)
                if err != nil {
                    fmt.Println("error:", err)
                }

                downloadFile(strings.NewReader(string(jsconf.Data)), childval.Parent, childval.Value)
            }
        } else {
            childbody := getData(fmt.Sprintf("http://yourIp:5600/api/scripts/%s?t=", val.Value))
            var jsconf jsConfig
            err := json.Unmarshal(childbody, &jsconf)
            if err != nil {
                fmt.Println("error:", err)
            }

            downloadFile(strings.NewReader(string(jsconf.Data)), "", val.Value)
        }
    }
    fmt.Println("执行完毕")
}
func getData(urlstr string) []byte {
    times := strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
    var bt bytes.Buffer
    bt.WriteString(urlstr)
    bt.WriteString(times)
    fmt.Printf(bt.String())
    fmt.Printf("\n")
    client := &http.Client{}
    req, _ := http.NewRequest("GET", bt.String(), nil)
    req.Header.Add("Authorization", "Bearer yourToken")
    resp, _ := client.Do(req)
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    return body
}
func downloadFile(body io.Reader, path string, name string) {
    filepath := fmt.Sprintf("./%s", name)
    // Create output file
    if path != "" {
        if _, err := os.Stat(path); os.IsNotExist(err) {
            // 必须分成两步:先创建文件夹、再修改权限
            os.Mkdir(path, 0777) //0777也可以os.ModePerm
            os.Chmod(path, 0777)
        }
        filepath = fmt.Sprintf("./%s/%s", path, name)
    }
    out, err := os.Create(filepath)
    if err != nil {
        panic(err)
    }
    defer out.Close()
    // copy stream
    _, err = io.Copy(out, body)
    if err != nil {
        panic(err)
    }
}

type jsConfig struct {
    Code int json:"code"

    Data string json:"data"
}

type recordConfig struct {
    Code int json:"code"

    Data []bodymsg json:"data"
}
type bodymsg struct {
    Disabled bool json:"disabled"

    Key string json:"key"

    Mtime float32 json:"mtime"

    Title string json:"title"

    Value string json:"value"

    Children []bodymsgchildren json:"children"
}

type bodymsgchildren struct {
    Key string json:"key"

    Mtime float32 json:"mtime"

    Title  string json:"title"
    Value  string json:"value"
    Parent string json:"parent"
}

Original: https://www.cnblogs.com/spatxos/p/15614177.html
Author: spatxos
Title: go将青龙面板里面的脚本文件都下载到本地

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/582916/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • shell实现group by聚合操作统计

    在sql中,我们可以方便的使用group by及相应的聚合函数如sum avg count来实现分组统计需求,那当我们面对一个文本,在shell中也可以实现相应的功能吗? 在she…

    Linux 2023年5月28日
    0128
  • ELF文件的笔记

    ELF 说明 ELF文件的英文全称是 The Executable and Link Format, 最初是由UNIX系统实验室开发、发布的ABI(Application Bina…

    Linux 2023年6月7日
    0121
  • 苹果手机使用altstore免越狱安装第三方应用

    转自52pojie 开发人员Riley Testut推&#x5…

    Linux 2023年6月7日
    0271
  • MySQL注入流程

    确认注入点 信息收集 数据获取 提权 写个MySQL注入流程的大纲,类似一份全局地图,能指导下一步工作。MySQL注入流程分为四步: 确认注入点 信息收集 数据获取 提权 确认注入…

    Linux 2023年6月6日
    0122
  • Ansible简介

    Ansible 是一种常用的自动运维化工具,基于 python 开发,分布式,无需客户端,轻量级,配置语言采用 YAML。 模块化:调用特定的模块,完成特殊的任务。 2.Param…

    Linux 2023年6月6日
    094
  • Linux中安装JDK详细步骤

    一、下载Linux版本的JDK 进入官网下载对应的JDK,下载之前需要先登录 官网地址 -> https://www.oracle.com/ 登录成功后,找到对应的下载位置 …

    Linux 2023年6月7日
    0108
  • LINUX系统虚拟机环境的安装

    安装VM和Centos Step 1 去BIOS里修改设置开启虚拟化设备支持 设置BIOS: 1.开机按F2 、F12 、DEL 、ESC 等进入BIOS ,一般来说可以看屏幕的左…

    Linux 2023年6月7日
    084
  • 【原创】Linux PCI驱动框架分析(一)

    背景 Read the fucking source code! –By 鲁迅 A picture is worth a thousand words. –…

    Linux 2023年6月8日
    0121
  • Linux查看服务器内存、磁盘、cpu、网络占用、端口占用情况

    1、查看物理CPU个数:cat cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l2、…

    Linux 2023年6月13日
    0133
  • MybatisPlus拓展——实现多数据源操作

    多数据源 适用:一般工作时候会有多个数据库,每个库对应不同的业务数据。程序如果每次数据都访问同一个数据库,该数据库压力很大访问会很慢。 1、导入依赖 com.baomidou dy…

    Linux 2023年6月7日
    080
  • jmeter学习记录–04–Beanshell

    一、什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法;BeanShell是一种松散类型的脚本语言(这点和JS类…

    Linux 2023年5月28日
    0116
  • macbook air 2019 安装win10单系统

    目前不考虑写的太详细了,如果有同学遇到问题了我再完善,主要是把遇到的坑讲下第一步,准备2个U盘(如果不嫌麻烦一个也可以)1.用大白菜或者老毛桃将其中一个做成启动盘2.在window…

    Linux 2023年6月14日
    0127
  • CentOS shell中的变量

    shell中的变量 变量的介绍 变量即变化的量,核心是”变”与”量”二字,变即变化,量即衡量状态。 量:是记录现实世界当中的某种状态…

    Linux 2023年6月7日
    095
  • IOC容器模拟实现

    运用反射机制和自定义注解模拟实现IOC容器,使其具有自动加载、自动装配和根据全限定类名获取Bean的功能。 1-1 IOC容器的本质 IOC容器可理解为是一个map,其中的一个en…

    Linux 2023年6月8日
    095
  • 【已解决】Windows环境下启动redis服务失败

    在redis安装目录下打开cmd窗口: 依次输入: redis-cli.exe shutdown exit redis-server.exe redis.windows.conf …

    Linux 2023年6月14日
    068
  • Nginx进阶篇—web模块及proxy代理

    server { #在server{下面输入 sub_filter n…

    Linux 2023年6月6日
    081
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球