OneManager是一个php制作的,可以网页挂载微软Onedrive的工具。

当然还有其它版本的程序,go语言的、linux直接运行的,以及其它程序,比如alist或者panindex之类的工具的,效果都一样。

这里用的是下面github上的版本的~

建站后大概是这样:https://cloud.chatcyf.com/

php的源码:https://github.com/qkqpttgf/OneManager-php

 

安装很简单,直接打包下载,放到能运行php的目录就行了,当初的虚拟主机都可以,所以就不做多解释了。

然后就是网址访问,并且登录微软账号,这里就直接用这个程序申请权限就行,很简单。

 

nginx的伪静态

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

 

然后普通的使用挺简单的,下面主要放几个反代理的代码

我这里主要宝塔面板演示

本地反代理,大概是用你的vps先去下载微软的文件,再把这个文件发送给下载这个文件的人

比如你的网盘域名是  pan.test.com   然后你打算用 bendi.test.com 做反代理来做演示。

 

首先,你需要知道你的微软盘的完整网址,大概是这样  https://youid-my.sharepoint.com

youid那里大概是你的微软用户名,你可以下载一个你的网盘文件看下载链接就知道了

 

接下来要做的是,使用 bendi.test.com 这个网址,来代替 youid-my.sharepoint.com

宝塔面板创建 bendi.test.com,先把https证书搞上,然后点击添加反代理,大概这样写就行

上面的是你的微软网盘网址,下面会自动填写

关闭缓存

然后点击反代理的设置,改成这样

添加三行

proxy_buffering off;
proxy_cache off;
proxy_set_header X-Forwarded-Proto $scheme;

 

好了,大概就这些,然后去 OneManager 后台,找到 domainforproxy

填写你的网址就行了,就是上面提到的 https://bendi.test.com

 

接下来是使用cloudflare的反代理方法,首先,得需要有个在cloudflare停放的域名,比如打算使用 cf.test.com

首先创建一个 Worker

然后用下面的代码

// 替换成你OneDrive的网址
const upstream = 'youid-my.sharepoint.com'
const upstream_mobile = 'youid-my.sharepoint.com'
 
// 下面的配置都不用动
const upstream_path = '/'
 
const blocked_region = ['KP', 'SY', 'PK', 'CU']
 
const blocked_ip_address = ['0.0.0.0', '127.0.0.1']
 
const https = true
 
const disable_cache = false
 
const replace_dict = {
    '$upstream': '$custom_domain',
    '//sunpma.com': ''
}
 
addEventListener('fetch', event => {
    event.respondWith(fetchAndApply(event.request));
})
 
async function fetchAndApply(request) {
    const region = request.headers.get('cf-ipcountry').toUpperCase();
    const ip_address = request.headers.get('cf-connecting-ip');
    const user_agent = request.headers.get('user-agent');
 
    let response = null;
    let url = new URL(request.url);
    let url_hostname = url.hostname;
 
    if (https == true) {
        url.protocol = 'https:';
    } else {
        url.protocol = 'http:';
    }
 
    if (await device_status(user_agent)) {
        var upstream_domain = upstream;
    } else {
        var upstream_domain = upstream_mobile;
    }
 
    url.host = upstream_domain;
    if (url.pathname == '/') {
        url.pathname = upstream_path;
    } else {
        url.pathname = upstream_path + url.pathname;
    }
 
    if (blocked_region.includes(region)) {
        response = new Response('Access denied: WorkersProxy is not available in your region yet.', {
            status: 403
        });
    } else if (blocked_ip_address.includes(ip_address)) {
        response = new Response('Access denied: Your IP address is blocked by WorkersProxy.', {
            status: 403
        });
    } else {
        let method = request.method;
        let request_headers = request.headers;
        let new_request_headers = new Headers(request_headers);
 
        new_request_headers.set('Host', upstream_domain);
        new_request_headers.set('Referer', url.protocol + '//' + url_hostname);
 
        let original_response = await fetch(url.href, {
            method: method,
            headers: new_request_headers
        })
 
        connection_upgrade = new_request_headers.get("Upgrade");
        if (connection_upgrade && connection_upgrade.toLowerCase() == "websocket") {
            return original_response;
        }
 
        let original_response_clone = original_response.clone();
        let original_text = null;
        let response_headers = original_response.headers;
        let new_response_headers = new Headers(response_headers);
        let status = original_response.status;
  
        if (disable_cache) {
            new_response_headers.set('Cache-Control', 'no-store');
        }
 
        new_response_headers.set('access-control-allow-origin', '*');
        new_response_headers.set('access-control-allow-credentials', true);
        new_response_headers.delete('content-security-policy');
        new_response_headers.delete('content-security-policy-report-only');
        new_response_headers.delete('clear-site-data');
  
        if (new_response_headers.get("x-pjax-url")) {
            new_response_headers.set("x-pjax-url", response_headers.get("x-pjax-url").replace("//" + upstream_domain, "//" + url_hostname));
        }
  
        const content_type = new_response_headers.get('content-type');
        if (content_type != null && content_type.includes('text/html') && content_type.includes('UTF-8')) {
            original_text = await replace_response_text(original_response_clone, upstream_domain, url_hostname);
        } else {
            original_text = original_response_clone.body
        }
  
        response = new Response(original_text, {
            status,
            headers: new_response_headers
        })
    }
    return response;
}
 
async function replace_response_text(response, upstream_domain, host_name) {
    let text = await response.text()
 
    var i, j;
    for (i in replace_dict) {
        j = replace_dict[i]
        if (i == '$upstream') {
            i = upstream_domain
        } else if (i == '$custom_domain') {
            i = host_name
        }
 
        if (j == '$upstream') {
            j = upstream_domain
        } else if (j == '$custom_domain') {
            j = host_name
        }
 
        let re = new RegExp(i, 'g')
        text = text.replace(re, j);
    }
    return text;
}
 
 
async function device_status(user_agent_info) {
    var agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
    var flag = true;
    for (var v = 0; v < agents.length; v++) {
        if (user_agent_info.indexOf(agents[v]) > 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

 

主意把上面提到的网址,替换成你的

然后提交保存,再去触发器 里面,给这个worker绑定个自定义域名,就是刚才提到的 cf.test.com

完成了,接下来也是去 OneManager 后台,添加反代理就行了,网址写 https://cf.test.com