From 6efbe394d2905b1e33847f7fb3d162efc579400f Mon Sep 17 00:00:00 2001 From: qkqpttgf <45693631+qkqpttgf@users.noreply.github.com> Date: Thu, 16 Jan 2020 21:09:26 +0800 Subject: [PATCH] Delete functions.php1 --- functions.php1 | 581 ------------------------------------------------- 1 file changed, 581 deletions(-) delete mode 100644 functions.php1 diff --git a/functions.php1 b/functions.php1 deleted file mode 100644 index 287bd1d..0000000 --- a/functions.php1 +++ /dev/null @@ -1,581 +0,0 @@ -0) $path = substr($_SERVER['REQUEST_URI'], 0, $p); - else $path = $_SERVER['REQUEST_URI']; - $path = path_format( substr($path, strlen($_SERVER['base_path'])) ); - return $path; - //return spurlencode($path, '/'); -} - -function getGET() -{ - $getstr = urldecode(substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'],'?'))); - while (substr($getstr, 0, 1) == '/' || substr($getstr, 0, 1) == '?') $getstr = substr($getstr, 1); - $getstrarr = explode("&",$getstr); - foreach ($getstrarr as $getvalues) { - if ($getvalues != '') { - $pos = strpos($getvalues, "="); - //echo $pos; - if ($pos > 0) { - $getarry[urldecode(substr($getvalues, 0, $pos))] = urldecode(substr($getvalues, $pos + 1)); - } else { - $getarry[urldecode($getvalues)] = true; - } - } - } - if (isset($getarry)) { - return $getarry; - } else { - return []; - } -} - -function getcache($str) -{ - $cache = null; - $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), '.Onedrive'); - return $cache->fetch($str); -} - -function savecache($key, $value, $exp = 3300) -{ - $cache = null; - $cache = new \Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir(), '.Onedrive'); - $cache->save($key, $value, $exp); -} - -function config_oauth() -{ - global $constStr; - $constStr['language'] = $_COOKIE['language']; - if ($constStr['language']=='') $constStr['language'] = getConfig('language'); - if ($constStr['language']=='') $constStr['language'] = 'en-us'; - $_SERVER['sitename'] = getConfig('sitename'); - if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = $constStr['defaultSitename'][$constStr['language']]; - $_SERVER['redirect_uri'] = 'https://scfonedrive.github.io'; - - if (getConfig('Onedrive_ver')=='MS') { - // MS - // https://portal.azure.com - $_SERVER['client_id'] = '4da3e7f2-bf6d-467c-aaf0-578078f0bf7c'; - $_SERVER['client_secret'] = '7/+ykq2xkfx:.DWjacuIRojIaaWL0QI6'; - $_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('Onedrive_ver')=='CN') { - // CN - // https://portal.azure.cn - $_SERVER['client_id'] = '04c3ca0b-8d07-4773-85ad-98b037d25631'; - $_SERVER['client_secret'] = 'h8@B7kFVOmj0+8HKBWeNTgl@pU/z4yLB'; - $_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'; - } - - $_SERVER['client_secret'] = urlencode($_SERVER['client_secret']); - $_SERVER['scope'] = urlencode($_SERVER['scope']); -} - -function getListpath($domain) -{ - $domain_path = getConfig('domain_path'); - /*$tmp_path=''; - if ($domain_path!='') { - $tmp = explode("|",$domain_path); - foreach ($tmp as $multidomain_paths){ - $pos = strpos($multidomain_paths,":"); - $tmp_path = path_format(substr($multidomain_paths,$pos+1)); - if (substr($multidomain_paths,0,$pos)==$host_name) $private_path=$tmp_path; - } - }*/ - if (isset($domain_path[$domain])) return spurlencode($domain_path[$domain],'/'); - return spurlencode(getConfig('public_path'),'/'); -} - -function path_format($path) -{ - $path = '/' . $path; - while (strpos($path, '//') !== FALSE) { - $path = str_replace('//', '/', $path); - } - return $path; -} - -function spurlencode($str,$splite='') -{ - $str = str_replace(' ', '%20',$str); - $tmp=''; - if ($splite!='') { - $tmparr=explode($splite,$str); - for($x=0;$x $headerVal) { - $sendHeaders[] = $headerName . ': ' . $headerVal; - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - if ($data !== false) { - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); - } - curl_setopt($ch, CURLOPT_TIMEOUT, 5); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders); - $response['body'] = curl_exec($ch); - $response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE); - curl_close($ch); - return $response; -} - -function clearbehindvalue($path,$page1,$maxpage,$pageinfocache) -{ - for ($page=$page1+1;$page<$maxpage;$page++) { - $pageinfocache['nextlink_' . $path . '_page_' . $page] = ''; - } - return $pageinfocache; -} - -function comppass($pass) -{ - if ($_POST['password1'] !== '') if (md5($_POST['password1']) === $pass ) { - date_default_timezone_set('UTC'); - $_SERVER['Set-Cookie'] = 'password='.$pass.'; expires='.date(DATE_COOKIE,strtotime('+1hour')); - date_default_timezone_set(get_timezone($_COOKIE['timezone'])); - return 2; - } - if ($_COOKIE['password'] !== '') if ($_COOKIE['password'] === $pass ) return 3; - return 4; -} - -function encode_str_replace($str) -{ - $str = str_replace('&','&',$str); - $str = str_replace('+','%2B',$str); - $str = str_replace('#','%23',$str); - return $str; -} - -function gethiddenpass($path,$passfile) -{ - $ispassfile = fetch_files(spurlencode(path_format($path . '/' . $passfile),'/')); - //echo $path . '
' . json_encode($ispassfile, JSON_PRETTY_PRINT) . '
'; - if (isset($ispassfile['file'])) { - $arr = curl_request($ispassfile['@microsoft.graph.downloadUrl']); - if ($arr['stat']==200) { - $passwordf=explode("\n",$arr['body']); - $password=$passwordf[0]; - $password=md5($password); - return $password; - } else { - //return md5('DefaultP@sswordWhenNetworkError'); - return md5( md5(time()).rand(1000,9999) ); - } - } else { - if ($path !== '' ) { - $path = substr($path,0,strrpos($path,'/')); - return gethiddenpass($path,$passfile); - } else { - return ''; - } - } - return ''; -} - -function get_refresh_token() -{ - global $constStr; - $url = path_format($_SERVER['PHP_SELF'] . '/'); - if ($_GET['authorization_code'] && isset($_GET['code'])) { - $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']; - $str = ' - refresh_token :
'; - /*for ($i=1;strlen($tmptoken)>0;$i++) { - $t['t' . $i] = substr($tmptoken,0,128); - $str .= ' - t' . $i . ':

'; - $tmptoken=substr($tmptoken,128); - } - $str .= ' - Add t1-t'.--$i.' to environments.*/ - $str .= ' -

- Adding refresh_token to Config. - '; - setConfig([ 'refresh_token' => $tmptoken ]); - savecache('access_token', $ret['access_token'], $ret['expires_in'] - 60); - $str .= ' - '; - return message($str, $constStr['WaitJumpIndex'][$constStr['language']]); - } - return message('
' . $tmp['body'] . '
', $tmp['stat']); - //return message('
' . json_encode($ret, JSON_PRETTY_PRINT) . '
', 500); - } - if ($_GET['install3']) { - if (getConfig('Onedrive_ver')=='MS' || getConfig('Onedrive_ver')=='CN' || getConfig('Onedrive_ver')=='MSC') { - return message(' - '.$constStr['JumptoOffice'][$constStr['language']].' - - ', $constStr['Wait'][$constStr['language']].' 1s', 201); - } - } - if ($_GET['install2']) { - // echo $_POST['Onedrive_ver']; - if ($_POST['Onedrive_ver']=='MS' || $_POST['Onedrive_ver']=='CN' || $_POST['Onedrive_ver']=='MSC') { - $tmp['Onedrive_ver'] = $_POST['Onedrive_ver']; - if ($_POST['Onedrive_ver']=='MSC') { - $tmp['client_id'] = $_POST['client_id']; - $tmp['client_secret'] = $_POST['client_secret']; - } - $response = setConfig($tmp); - $title = $constStr['MayinEnv'][$constStr['language']]; - $html = $constStr['Wait'][$constStr['language']] . ' 3s'; - if (!$response) { - $html = $response . '
-Can not write config to file.
-'; - $title = 'Error'; - } - return message($html, $title, 201); - } - } - if ($_GET['install1']) { - if ($_POST['admin']!='') { - $tmp['admin'] = $_POST['admin']; - $tmp['language'] = $_POST['language']; - $response = setConfig($tmp); - if ($response) { - if ($constStr['language']!='zh-cn') { - $linklang='en-us'; - } else $linklang='zh-cn'; - $ru = "https://developer.microsoft.com/".$linklang."/graph/quick-start?appID=_appId_&appName=_appName_&redirectUrl=".$_SERVER['redirect_uri']."&platform=option-php"; - $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 = ' -
- Onedrive_Ver:
-
-
-
- -
'; - $title = 'Install'; - } else { - $html = $response . '
-Can not write config to file.
-'; - $title = 'Error'; - } - return message($html, $title, 201); - } - } - if ($_GET['install0']) { - if (!ConfigWriteable()) { - $html .= 'Plase make sure the config.php is writeable. -run Writeable.sh.'; - $title = 'Error'; - return message($html, $title, 201); - } - if (!RewriteEngineOn()) { - $html .= 'Plase make sure the RewriteEngine is On.'; - $title = 'Error'; - return message($html, $title, 201); - } - $html .= ' -
-
-language:
'; - foreach ($constStr['languages'] as $key1 => $value1) { - $html .= ' -
'; - } - $html .= '
- -
- '; - $title = $constStr['SelectLanguage'][$constStr['language']]; - return message($html, $title, 201); - } - $html .= 'refresh_token not exist, click to install.'; - $title = 'Error'; - return message($html, $title, 201); -} - -function ConfigWriteable() -{ - $t = md5( md5(time()).rand(1000,9999) ); - setConfig([ 'tmp' => $t ]); - $tmp = getConfig('tmp'); - setConfig([ 'tmp' => '' ]); - if ($tmp == $t) return true; - return false; -} - -function RewriteEngineOn() -{ - $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; - $tmpurl=$http_type . $_SERVER['SERVER_NAME'] . path_format($_SERVER['base_path'] . '/config.php'); - $tmp = curl_request($tmpurl); - if ($tmp['stat']==201) return true; //when install return 201, after installed return 404 or 200; - return false; -} - -function get_timezone($timezone = '8') -{ - $timezones = array( - '-12'=>'Pacific/Kwajalein', - '-11'=>'Pacific/Samoa', - '-10'=>'Pacific/Honolulu', - '-9'=>'America/Anchorage', - '-8'=>'America/Los_Angeles', - '-7'=>'America/Denver', - '-6'=>'America/Mexico_City', - '-5'=>'America/New_York', - '-4'=>'America/Caracas', - '-3.5'=>'America/St_Johns', - '-3'=>'America/Argentina/Buenos_Aires', - '-2'=>'America/Noronha', - '-1'=>'Atlantic/Azores', - '0'=>'UTC', - '1'=>'Europe/Paris', - '2'=>'Europe/Helsinki', - '3'=>'Europe/Moscow', - '3.5'=>'Asia/Tehran', - '4'=>'Asia/Baku', - '4.5'=>'Asia/Kabul', - '5'=>'Asia/Karachi', - '5.5'=>'Asia/Calcutta', //Asia/Colombo - '6'=>'Asia/Dhaka', - '6.5'=>'Asia/Rangoon', - '7'=>'Asia/Bangkok', - '8'=>'Asia/Shanghai', - '9'=>'Asia/Tokyo', - '9.5'=>'Australia/Darwin', - '10'=>'Pacific/Guam', - '11'=>'Asia/Magadan', - '12'=>'Asia/Kamchatka' - ); - if ($timezone=='') $timezone = '8'; - return $timezones[$timezone]; -} - -function message($message, $title = 'Message', $statusCode = 200) -{ - return output('

' . $title . '

' . $message . '

', $statusCode); -} - -function needUpdate() -{ - if ($_SERVER['admin']) { - $current_ver = file_get_contents(__DIR__ . '/version'); - $current_ver = substr($current_ver, strpos($current_ver, '.')+1); - $current_ver = explode(urldecode('%0A'),$current_ver)[0]; - $current_ver = explode(urldecode('%0D'),$current_ver)[0]; - $github_version = file_get_contents('https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version'); - $github_ver = substr($github_version, strpos($github_version, '.')+1); - $github_ver = explode(urldecode('%0A'),$github_ver)[0]; - $github_ver = explode(urldecode('%0D'),$github_ver)[0]; - if ($current_ver != $github_ver) { - $_SERVER['github_version'] = $github_version; - return 1; - } - } - return 0; -} - -function output($body, $statusCode = 200, $headers = ['Content-Type' => 'text/html'], $isBase64Encoded = false) -{ - return [ - 'isBase64Encoded' => $isBase64Encoded, - 'statusCode' => $statusCode, - 'headers' => $headers, - 'body' => $body - ]; -} - -function passhidden($path) -{ - $path = str_replace('+','%2B',$path); - $path = str_replace('&','&', path_format(urldecode($path))); - if (getConfig('passfile') != '') { - if (substr($path,-1)=='/') $path=substr($path,0,-1); - $hiddenpass=gethiddenpass($path,getConfig('passfile')); - if ($hiddenpass != '') { - return comppass($hiddenpass); - } else { - return 1; - } - } else { - return 0; - } - return 4; -} - -function size_format($byte) -{ - $i = 0; - while (abs($byte) >= 1024) { - $byte = $byte / 1024; - $i++; - if ($i == 3) break; - } - $units = array('B', 'KB', 'MB', 'GB', 'TB'); - $ret = round($byte, 2); - return ($ret . ' ' . $units[$i]); -} - -function time_format($ISO) -{ - $ISO = str_replace('T', ' ', $ISO); - $ISO = str_replace('Z', ' ', $ISO); - //return $ISO; - return date('Y-m-d H:i:s',strtotime($ISO . " UTC")); -} - -function getConfig($str) -{ - include 'config.php'; - //$s = file_get_contents('config.json'); - if ($configs!='') { - $envs = json_decode($configs, true); - if (isset($envs[$str])) return $envs[$str]; - } - return ''; - /* - if (!class_exists('mydbreader')) { - class mydbreader extends SQLite3 - { - function __construct() - { - $this->open( __DIR__ .'/.ht.db'); - } - } - } - $db = new mydbreader(); - if(!$db){ - echo $db->lastErrorMsg(); - } else { - //echo "Opened database successfully
\n"; - $id=rand(1,309); - $sql="select * from config where id=".$str.";"; - $ret = $db->query($sql); - if(!$ret){ - echo $db->lastErrorMsg(); - } else { - $row = $ret->fetchArray(SQLITE3_ASSOC); - $value1 = $row['value']; - } - $db->close(); - } - return $value1; - */ -} - -function array_value_isnot_null($arr) -{ - return $arr!==''; -} - -function setConfig($arr) -{ - include 'config.php'; - if ($configs!='') $envs = json_decode($configs, true); - foreach ($arr as $k1 => $v1) { - $envs[$k1] = $v1; - } - $envs = array_filter($envs, 'array_value_isnot_null'); - ksort($envs); - //echo '
'. json_encode($envs, JSON_PRETTY_PRINT).'
'; - $prestr = ' 'Bearer ' . $_SERVER['access_token']])['body'], true); - if (isset($files['url'])) return output($files['url']); - return output('', 404); -}