From aa15da3ffbcc925c7db21d66c783a555d6f5de61 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Wed, 25 Mar 2020 23:57:18 +0800
Subject: [PATCH 1/4] add sharepoint site
---
conststr.php | 51 ++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/conststr.php b/conststr.php
index 8d1b596..c6d265a 100644
--- a/conststr.php
+++ b/conststr.php
@@ -572,10 +572,6 @@ $constStr = [
],
'defaultSitename' => [
'en-us' => 'OneManager',
- 'zh-cn' => 'OneManager',
- 'ja' => 'OneManager',
- 'ko-kr' => 'OneManager',
- 'fa' => 'OneManager',
],
'SavingToken' => [
'en-us' => 'Saving refresh_token!',
@@ -626,62 +622,71 @@ $constStr = [
'ko-kr' => 'Onedrive 표시 이름',
'fa' => 'نام نشان داده شده Onedrive',
],
- 'OndriveVerMS' => [
- 'en-us' => 'default(Onedrive, Onedrive for business)',
- 'zh-cn' => '默认(支持商业版与个人版)',
- 'ja' => 'デフォルト(商用版および個人版をサポート)',
- 'ko-kr' => '기본 (상업용 및 개인용 버전 지원)',
- 'fa' => 'پیش فرض(Onedrive, Onedrive for business)',
+ 'DriveVerMS' => [
+ 'en-us' => 'Onedrive, Onedrive for business',
+ 'zh-cn' => '国际版(商业版与个人版)',
],
- 'OndriveVerCN' => [
+ 'DriveVerCN' => [
'en-us' => 'Onedrive in China',
'zh-cn' => '世纪互联版',
'ja' => '中国のOnedrive',
'ko-kr' => '중국 Onedrive',
'fa' => 'Onedrive در چین',
],
- 'OndriveVerMSC' =>[
- 'en-us' => 'default but use customer app id & secret',
- 'zh-cn' => '国际版,自己申请应用ID与机密',
- 'ja' => '国際版、アプリケーションIDとシークレットを自分で申請する',
- 'ko-kr' => '국제 버전, 응용 프로그램 ID 및 비밀 신청',
+ 'CustomIdSecret' => [
+ 'en-us' => 'Use custom client id & secret',
+ 'zh-cn' => '自己申请应用ID与机密',
+ 'ja' => 'アプリケーションIDとシークレットを自分で申請する',
+ 'ko-kr' => '응용 프로그램 ID 및 비밀 신청',
'fa' => 'به طور پیش فرض اما از شناسه برنامه و سکرت استفاده کنید',
],
- 'GetSecretIDandKEY' =>[
- 'en-us' => 'Get customer app id & secret',
+ 'GetSecretIDandKEY' => [
+ 'en-us' => 'Get custom client id & secret',
'zh-cn' => '申请应用ID与机密',
'ja' => 'アプリケーションIDとシークレット',
'fa' => 'دریافت شناسه برنامه و سکرت',
],
- 'TagFormatAlert' =>[
+ 'UseSharepointInstead' => [
+ 'en-us' => 'Use space in Sharepoint website instead of Onedrive',
+ 'zh-cn' => '使用Sharepoint网站的空间,不使用Onedrive',
+ ],
+ 'GetSharepointName' => [
+ 'en-us' => 'Login office.com and click the SharePoint, create a website or find an exist website, input the name below',
+ 'zh-cn' => '登录office.com,点击Sharepoint,创建一个网站或使用原有网站,然后将它的名字填在下方',
+ ],
+ 'InputSharepointName' => [
+ 'en-us' => 'Input the name of Sharepoint website',
+ 'zh-cn' => '输入Sharepoint网站的名称',
+ ],
+ 'TagFormatAlert' => [
'en-us' => 'Tag must start with a letter, end with a letter or digit and can only contain lowercase letters, digits, and dashes, at least 2 letters!',
'zh-cn' => '标签只能以字母开头,以字母或数字结尾,至少2位',
'ja' => 'タグは、文字で始まり、文字または数字で終わる必要があります。少なくとも2つ',
'ko-kr' => '태그는 문자로 시작하고 문자 또는 숫자로 끝나야합니다 (2 이상).',
'fa' => 'برچسب باید با یک حرف شروع شود، با یک حرف یا رقم پایان یابد و تنها میتواند حاوی حروف کوچک، ارقام و خط فاصله، حداقل ۲ حرف باشد!',
],
- 'ClickInstall' =>[
+ 'ClickInstall' => [
'en-us' => 'Click to install the project',
'zh-cn' => '点击开始安装程序',
'ja' => 'クリックしてインストールプロセスを開始します',
'ko-kr' => '설치 과정을 시작하려면 클릭',
'fa' => 'برای نصب پروژه کلیک کنید',
],
- 'LogintoBind' =>[
+ 'LogintoBind' => [
'en-us' => 'then login and bind your onedrive in setup',
'zh-cn' => '然后登录后在设置中绑定你的onedrive。',
'ja' => '次に、ログインして、設定でonedriveをバインドします。',
'ko-kr' => '그런 다음 로그인하여 onedrive를 설정에 바인딩하십시오.',
'fa' => 'پس از آن وارد سیستم شوید و تنظیمات خود را در onedrive متصل کنید',
],
- 'MakesuerWriteable' =>[
+ 'MakesuerWriteable' => [
'en-us' => 'Plase make sure the config.php is writeable. run writeable.sh.',
'zh-cn' => '确认config.php可写。',
'ja' => 'config.phpが書き込み可能であることを確認してください。',
'ko-kr' => 'config.php가 쓰기 가능한지 확인하십시오.',
'fa' => 'اطمینان حاصل کنید که config.php قابل نوشتن است. writeable.sh را اجرا کنید.',
],
- 'MakesuerRewriteOn' =>[
+ 'MakesuerRewriteOn' => [
'en-us' => 'Plase make sure the RewriteEngine is On.',
'zh-cn' => '确认重写(伪静态)功能启用。',
'ja' => '書き換え(擬似静的)機能が有効になっていることを確認します。',
From 93839784990fa3a1a0f189936918c3e629e2cb63 Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Wed, 25 Mar 2020 23:58:13 +0800
Subject: [PATCH 2/4] Update classic.php
---
theme/classic.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/theme/classic.php b/theme/classic.php
index 770574a..b6aee69 100644
--- a/theme/classic.php
+++ b/theme/classic.php
@@ -2,7 +2,7 @@
- -
+ -
From 0452f7f278d01fc586a6fdeeee89f9567b710d6c Mon Sep 17 00:00:00 2001
From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com>
Date: Thu, 26 Mar 2020 00:03:35 +0800
Subject: [PATCH 3/4] add sharepoint site disk
---
function/common.php | 125 +++++++++++++++++++++++++++++++++-----------
1 file changed, 94 insertions(+), 31 deletions(-)
diff --git a/function/common.php b/function/common.php
index bdac631..7bba7e7 100644
--- a/function/common.php
+++ b/function/common.php
@@ -17,11 +17,15 @@ $Base64Env = [
//'passfile',
'sitename',
//'theme',
- //'Onedrive_ver',
+ //'Drive_ver',
+ //'Drive_custom',
//'client_id',
'client_secret',
'domain_path',
'guestup_path',
+ //'usesharepoint',
+ 'sharepointname',
+ //'siteid',
'public_path',
//'refresh_token',
//'token_expires',
@@ -62,26 +66,34 @@ $ShowedCommonEnv = [
];
$InnerEnv = [
- 'Onedrive_ver',
+ 'Drive_ver',
+ 'Drive_custom',
'client_id',
'client_secret',
'diskname',
'domain_path',
'downloadencrypt',
'guestup_path',
+ 'usesharepoint',
+ 'sharepointname',
+ 'siteid',
'public_path',
'refresh_token',
'token_expires',
];
$ShowedInnerEnv = [
- //'Onedrive_ver',
+ //'Drive_ver',
+ //'Drive_custom',
//'client_id',
//'client_secret',
'diskname',
'domain_path',
'downloadencrypt',
'guestup_path',
+ //'usesharepoint',
+ //'sharepointname',
+ //'siteid',
'public_path',
//'refresh_token',
//'token_expires',
@@ -127,17 +139,19 @@ function config_oauth()
$_SERVER['sitename'] = getConfig('sitename');
if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
$_SERVER['redirect_uri'] = 'https://scfonedrive.github.io';
-
- if (getConfig('Onedrive_ver')=='MS') {
+ if (getConfig('Drive_ver')=='MS') {
// MS
// https://portal.azure.com
- $_SERVER['client_id'] = '4da3e7f2-bf6d-467c-aaf0-578078f0bf7c';
- $_SERVER['client_secret'] = '7/+ykq2xkfx:.DWjacuIRojIaaWL0QI6';
+ //$_SERVER['client_id'] = '4da3e7f2-bf6d-467c-aaf0-578078f0bf7c';
+ //$_SERVER['client_secret'] = '7/+ykq2xkfx:.DWjacuIRojIaaWL0QI6';
+ $_SERVER['client_id'] = '734ef928-d74c-4555-8d1b-d942fa0a1a41';
+ $_SERVER['client_secret'] = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW';
$_SERVER['oauth_url'] = 'https://login.microsoftonline.com/common/oauth2/v2.0/';
$_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/me/drive/root';
$_SERVER['scope'] = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access';
+ if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/sites/' . getConfig('siteid') . '/drive/root';
}
- if (getConfig('Onedrive_ver')=='CN') {
+ if (getConfig('Drive_ver')=='CN') {
// CN
// https://portal.azure.cn
$_SERVER['client_id'] = '04c3ca0b-8d07-4773-85ad-98b037d25631';
@@ -145,21 +159,36 @@ function config_oauth()
$_SERVER['oauth_url'] = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/';
$_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/me/drive/root';
$_SERVER['scope'] = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access';
- }
- if (getConfig('Onedrive_ver')=='MSC') {
- // MS Customer
- // https://portal.azure.com
- $_SERVER['client_id'] = getConfig('client_id');
- $_SERVER['client_secret'] = getConfig('client_secret');
- $_SERVER['oauth_url'] = 'https://login.microsoftonline.com/common/oauth2/v2.0/';
- $_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/me/drive/root';
- $_SERVER['scope'] = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access';
+ if (getConfig('usesharepoint')=='on') $_SERVER['api_url'] = 'https://microsoftgraph.chinacloudapi.cn/v1.0/sites/' . getConfig('siteid') . '/drive/root';
}
+ if (getConfig('Drive_custom')=='on') {
+ // Customer
+ $_SERVER['client_id'] = getConfig('client_id');
+ $_SERVER['client_secret'] = getConfig('client_secret');
+ }
$_SERVER['client_secret'] = urlencode($_SERVER['client_secret']);
$_SERVER['scope'] = urlencode($_SERVER['scope']);
}
+function get_siteid($access_token)
+{
+ $i=0;
+ $response = [];
+ while ($response['stat']!=200&&$i<4) {
+ $response = curl_request('https://graph.microsoft.com/v1.0/sites/root:/sites/'.getConfig('sharepointname'), false, ['Authorization' => 'Bearer ' . $access_token]);
+ $i++;
+ echo 'https://graph.microsoft.com/v1.0/sites/root:/sites/'.getConfig('sharepointname').$response['stat'].$response['body'].'
+ ';
+ }
+ return json_decode($response['body'],true)['id'];
+ //$_SERVER['api_url'] = 'https://graph.microsoft.com/v1.0/sites/' . $tmp['siteid'] . '/drive/root';
+ //setConfig($tmp);
+
+ //error_log('failed to get siteid. response' . json_encode($response));
+ //throw new Exception($response['stat'].', failed to get siteid.'.$response['body']);
+}
+
function getListpath($domain)
{
$domain_path1 = getConfig('domain_path');
@@ -1189,11 +1218,11 @@ function get_refresh_token()
$tmp = curl_request($_SERVER['oauth_url'] . 'token', 'client_id=' . $_SERVER['client_id'] .'&client_secret=' . $_SERVER['client_secret'] . '&grant_type=authorization_code&requested_token_use=on_behalf_of&redirect_uri=' . $_SERVER['redirect_uri'] .'&code=' . $_GET['code']);
if ($tmp['stat']==200) $ret = json_decode($tmp['body'], true);
if (isset($ret['refresh_token'])) {
- $tmptoken = $ret['refresh_token'];
+ $refresh_token = $ret['refresh_token'];
$str = '
refresh_token :
';
$str .= '
-
+
'.getconstStr('SavingToken').'
';
- setConfig([ 'refresh_token' => $tmptoken, 'token_expires' => time()+30*24*60*60 ], $_COOKIE['disktag']);
+ $tmptoken['refresh_token'] = $refresh_token;
+ $tmptoken['token_expires'] = time()+7*24*60*60;
+ if (getConfig('usesharepoint')=='on') $tmptoken['siteid'] = get_siteid($ret['access_token']);
+ setConfig($tmptoken, $_COOKIE['disktag']);
savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60);
//WaitSCFStat();
$str .= '
@@ -1216,7 +1248,7 @@ function get_refresh_token()
if (isset($_GET['install1'])) {
$_SERVER['disktag'] = $_COOKIE['disktag'];
config_oauth();
- if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') {
+ if (getConfig('Drive_ver')=='MS' || getConfig('Drive_ver')=='CN') {
return message('
'.getconstStr('JumptoOffice').'
', 'Error', 201);
}
$_SERVER['disktag'] = $_COOKIE['disktag'];
$tmp['disktag_add'] = $_POST['disktag_add'];
$tmp['diskname'] = $_POST['diskname'];
- $tmp['Onedrive_ver'] = $_POST['Onedrive_ver'];
- if ($_POST['Onedrive_ver']=='MSC') {
+ $tmp['Drive_ver'] = $_POST['Drive_ver'];
+ if ($_POST['Drive_custom']=='on') {
+ $tmp['Drive_custom'] = $_POST['Drive_custom'];
$tmp['client_id'] = $_POST['client_id'];
$tmp['client_secret'] = $_POST['client_secret'];
}
+ if ($_POST['usesharepoint']=='on') {
+ $tmp['usesharepoint'] = $_POST['usesharepoint'];
+ $tmp['sharepointname'] = $_POST['sharepointname'];
+ }
$response = setConfigResponse( setConfig($tmp, $_COOKIE['disktag']) );
if (api_error($response)) {
$html = api_error_msg($response);
@@ -1263,26 +1300,40 @@ function get_refresh_token()
$deepLink = "/quickstart/graphIO?publicClientSupport=false&appName=OneManager&redirectUrl=".$_SERVER['redirect_uri']."&allowImplicitFlow=false&ru=".urlencode($ru);
$app_url = "https://apps.dev.microsoft.com/?deepLink=".urlencode($deepLink);
$html = '
+