利用Onedrive搭建下载站【宝塔方式】

·
日常 function headers response url cloudflare 服务器 宝塔 安装 代理 文件 站点 密码 目录 worker 卡 host const workers 代码 地址 let out_body January 23, 2021

需要的东西:

一个教育邮箱或E5账号
一台VPS
一个域名

配置环境

安装宝塔
https://4url.pw/Qpde

安装完成后登录,选择lnmp
注意PHP版本选择7.2

安装Onemanager

点击站点,添加站点

add a webside

添加完成后,进入网站路径,点击远程下载
下载这个压缩包

https://github.com/qkqpttgf/OneManager-php/archive/master.zip

解压,将文件夹中的内容剪切到网站根目录

回到网站设置,点击伪静态,填入如下内容

rewrite ^/(?!.well-known)(.*)$ /index.php?/$1 last;

保存

打开网页,应该就可以看见
install

全程下一步(注意设置密码)

before see this

左上角登录

选择ShareLink并点击添加盘

add drive

不出意外可以看见这个

might see this

前两项随便填,Sharelink需要到你自己的OD生成一个
填写完成后,你应该就可以看见文件夹了

finish half

使用cloudflare workers反向代理SharePoint

注意,这样做有极大可能性导致你的cloudflare账户黑号,届时将只能传输纯HTML文件

设置中的反向代理流量是走你自己的服务器的,但是效果并不理想,还耗流量
因此使用Cloudflare Workers进行反向代理

打开cloudflare,创建一个worker
贴入如下内容

// odd, 单日
const SingleDay = '你的域名(带https://)'
// even, 双日
const DoubleDay = '你的域名(带https://)'

//const SingleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'
//const DoubleDay = 'https://153xxxxx0.cn-hongkong.fc.aliyuncs.com/2016-08-15/proxy/onedrive/xxx/'

// CF proxy all, 一切给CF代理,true/false
const CFproxy = true

// Used in cloudflare workers, odd or even days point to 2 heroku account.

// 由于heroku不绑卡不能自定义域名,就算绑卡后https也不方便
// 另外免费套餐每月550小时,有些人不够用
// 于是在CF Workers使用此代码,分单双日拉取不同heroku帐号下的相同网页
// 只改上面,下面不用动

addEventListener('fetch', event => {
    let url=new URL(event.request.url);
    if (url.protocol == 'http:') {
        url.protocol = 'https:'
        event.respondWith( Response.redirect(url.href) )
    } else {
        let response = null;
        let nd = new Date();
        if (nd.getDate()%2) {
            host = SingleDay
        } else {
            host = DoubleDay
        }
        if (host.substr(0, 7)!='http://'&&host.substr(0, 8)!='https://') host = 'http://' + host;

        response = fetchAndApply(host, event.request);

        event.respondWith( response );
    }
})

async function fetchAndApply(host, request) {
    let f_url = new URL(request.url);
    let a_url = new URL(host);
    let replace_path = a_url.pathname;
    if (replace_path.substr(replace_path.length-1)!='/') replace_path += '/';
    let replaced_path = '/';
    let query = f_url.search;
    let path = f_url.pathname;
    if (host.substr(host.length-1)=='/') path = path.substr(1);
    f_url.href = host + path + query;

    let response = null;
    if (!CFproxy) {
        response = await fetch(f_url, request);
    } else {
        let method = request.method;
        let body = request.body;
        let request_headers = request.headers;
        let new_request_headers = new Headers(request_headers);
        new_request_headers.set('Host', f_url.host);
        new_request_headers.set('Referer', request.url);

        response = await fetch(f_url.href, {
            method: method,
            body: body,
            headers: new_request_headers
        });
    }

    let out_headers = new Headers(response.headers);
    if (out_headers.get('Content-Disposition')=='attachment') out_headers.delete('Content-Disposition');
    let out_body = null;
    let contentType = out_headers.get('Content-Type');
    if (contentType.includes("application/text")) {
        out_body = await response.text();
        while (out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
    } else if (contentType.includes("text/html")) {
        out_body = await response.text();
        while (replace_path!='/'&&out_body.includes(replace_path)) out_body = out_body.replace(replace_path, replaced_path);
    } else {
        out_body = await response.body;
    }

    let out_response = new Response(out_body, {
        status: response.status,
        headers: out_headers
    })

    return out_response;
}

保存后添加一条无效解析(要与源服务器的域名不同),如解析到1.1.1.1

bad dns

点击添加路由,添加一条地址

plash speed!

打开这个路由,应该就可以看见你的onemanager了

-END

  • 利用Onedrive搭建下载站【手动方式】
  • Nano文本编辑器的使用方法

已有 2 条评论
  1. 一条咸鱼与狗

    谢谢大佬的教程,下载站已经搭好了 qwq

    一条咸鱼与狗 March 4th, 2021 at 09:27 pm回复
  2. admin

    不要把这玩意用到生产环境,否则cloudflare直接给你制裁

    admin January 30th, 2021 at 10:47 am回复
取消回复

说点什么?
Title
需要的东西:
-END

© 2022 Type boom
友链&RSS