├── README.md └── index.js /README.md: -------------------------------------------------------------------------------- 1 | # OneManager-cfworkerskv 2 | 1, 进KV,添加命名空间,名字随便英文 3 | 2, 进workers,新建,粘贴代码,保存 4 | 3,在workers设置中,KV 命名空间绑定,变量名称填入OMKV,右边下拉选择。 5 | 4,访问开始安装。 6 | 7 | 熟悉的操作过程,做配置不用动代码,一路点点点。 8 | 9 | 只是主要功能可用,可以添加盘,可以刷新缓存。 10 | 不可用:加密目录、管理操作、上传。 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | var THEME = 'https://github.com/qkqpttgf/OneManager-php/raw/master/theme/classic.html'; 3 | var OMKV; 4 | var disk = new Object(); 5 | var GET; 6 | var POST; 7 | var COOKIE = new Object(); 8 | var SERVER = new Object(); 9 | var ConfigEnvs = { 10 | 'admin' : 0b000, 11 | //'adminloginpage' : 0b010, 12 | 'autoJumpFirstDisk' : 0b010, 13 | 'background' : 0b011, 14 | 'backgroundm' : 0b011, 15 | 'disableShowThumb' : 0b010, 16 | //'disableChangeTheme': 0b010, 17 | 'disktag' : 0b000, 18 | 'hideFunctionalityFile': 0b010, 19 | //'timezone' : 0b010, 20 | 'passfile' : 0b011, 21 | 'sitename' : 0b011, 22 | 'customScript' : 0b011, 23 | 'customCss' : 0b011, 24 | //'customTheme' : 0b011, 25 | //'theme' : 0b010, 26 | 'dontBasicAuth' : 0b010, 27 | 28 | 'Driver' : 0b100, 29 | 'client_id' : 0b100, 30 | 'client_secret' : 0b101, 31 | 'sharepointSite' : 0b101, 32 | 'shareurl' : 0b101, 33 | //'sharecookie' : 0b101, 34 | 'shareapiurl' : 0b101, 35 | 'siteid' : 0b100, 36 | 'refresh_token' : 0b100, 37 | 'token_expires' : 0b100, 38 | 'default_drive_id' : 0b100, 39 | 'default_sbox_drive_id': 0b100, 40 | 41 | 'diskname' : 0b111, 42 | //'domain_path' : 0b111, 43 | 'downloadencrypt' : 0b110, 44 | 'guestup_path' : 0b111, 45 | 'domainforproxy' : 0b111, 46 | 'public_path' : 0b111, 47 | }; 48 | var exts = new Object(); 49 | exts['img'] = new Array('ico', 'bmp', 'gif', 'jpg', 'jpeg', 'jpe', 'jfif', 'tif', 'tiff', 'png', 'heic', 'webp'); 50 | exts['music'] = new Array('mp3', 'wma', 'flac', 'ape', 'wav', 'ogg', 'm4a'); 51 | exts['office'] = new Array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx'); 52 | exts['txt'] = new Array('txt', 'bat', 'sh', 'php', 'asp', 'js', 'css', 'json', 'html', 'c', 'cpp', 'md', 'py', 'omf'); 53 | exts['video'] = new Array('mp4', 'webm', 'mkv', 'mov', 'flv', 'blv', 'avi', 'wmv', 'm3u8', 'rm', 'rmvb'); 54 | exts['zip'] = new Array('zip', 'rar', '7z', 'gz', 'tar'); 55 | 56 | addEventListener('fetch', event => { 57 | let url=new URL(event.request.url); 58 | if (url.protocol == 'http:') { 59 | url.protocol = 'https:' 60 | event.respondWith( Response.redirect(url.href) ) 61 | } else { 62 | let response = main(event.request); 63 | event.respondWith( response ); 64 | } 65 | }) 66 | // await NAMESPACE.put(key, value) 67 | // NAMESPACE.get(key) 68 | // NAMESPACE.put(key, value, {expiration: secondsSinceEpoch}) 69 | // NAMESPACE.put(key, value, {expirationTtl: secondsFromNow}) 70 | // await NAMESPACE.delete(key) 71 | async function main(req) { 72 | if (OMKV==null) { 73 | return message('请在Workers的设置中将 变量名称 OMKV 绑到目标KV命名空间。', 'Error', 500); 74 | } 75 | let url=new URL(req.url); 76 | let path = url.pathname; 77 | let body = await req.text(); 78 | POST = parseBody(body, '&'); 79 | let query = url.search; 80 | if (query.substr(0,1)=='?') query = query.substr(1,query.length); 81 | GET = parseBody(query, '&'); 82 | let co = req.headers.get("cookie"); 83 | COOKIE = parseBody(co, '; '); 84 | SERVER['PHP_SELF'] = path; 85 | 86 | let admin = await getConfig('admin'); 87 | if (admin==null||admin=='') return install(); 88 | 89 | SERVER['admin'] = false; 90 | if (COOKIE['admin']==await md5(admin)) { 91 | SERVER['admin'] = true; 92 | } else if (GET['admin']==true) { 93 | if (POST['password1']==admin) { 94 | SERVER['admin'] = true; 95 | return adminlogin('admin', await md5(POST['password1']), path); 96 | } else { 97 | return adminlogin(); 98 | } 99 | } 100 | 101 | if (GET['setup']==true) { 102 | if (SERVER['admin']==true) return setup(); 103 | else { 104 | let Location = req.url; 105 | Location = Location.replace('?setup&', '?'); 106 | Location = Location.replace('&setup', ''); 107 | Location = Location.replace('?setup', ''); 108 | return Response.redirect(Location); 109 | } 110 | } 111 | 112 | if (('AddDisk' in GET) && SERVER['admin']==true) { 113 | disk = await diskObject(GET['AddDisk'], GET['disktag']); 114 | return disk.AddDisk(); 115 | } 116 | 117 | SERVER['base_path'] = '/'; 118 | SERVER['base_disk_path'] = SERVER['base_path']; 119 | let files = new Object(); 120 | let disktags = (await getConfig('disktag')).split('|'); 121 | if (disktags.length>1) { 122 | if (path=='/'||path=='') { 123 | files['type'] = 'folder'; 124 | files['childcount'] = disktags.length; 125 | files['showname'] = 'root'; 126 | let list = new Object(); 127 | for (let num in disktags) { 128 | let disktag = disktags[num]; 129 | let child_tmp = new Object(); 130 | child_tmp['type'] = 'folder'; 131 | child_tmp['name'] = disktag; 132 | child_tmp['showname'] = await getConfig('diskname', disktag); 133 | list[disktag] = child_tmp; 134 | } 135 | files['list'] = list; 136 | if ('json' in GET) { 137 | // return a json 138 | return output(JSON.stringify(files), 200, {'Content-Type' : 'application/json'}); 139 | } 140 | if (await getConfig('autoJumpFirstDisk')) return output('', 302, { 'Location' : path_format(SERVER['base_path'] + '/' + disktags[0] + '/') }); 141 | } else { 142 | SERVER['disktag'] = splitfirst( path_format(path).substr(1), '/' )[0]; 143 | if (!(disktags.indexOf(SERVER['disktag'])>-1)) { 144 | let tmp = path_format(SERVER['base_path'] + '/' + disktags[0] + '/' + path); 145 | if (GET.length>0) { 146 | tmp += '?'; 147 | for (k in GET) { 148 | let v = GET[k]; 149 | if (v === true) tmp += k + '&'; 150 | else tmp += k + '=' + v + '&'; 151 | } 152 | tmp = tmp.substr(0, tmp.length-1); 153 | } 154 | return output('Please visit ' + tmp + '.', 302, { 'Location' : tmp }); 155 | //return message('Please visit from Home Page.', 'Error', 404); 156 | } 157 | path = path.substr(('/' + SERVER['disktag']).length); 158 | if (SERVER['disktag']!='') SERVER['base_disk_path'] = path_format(SERVER['base_disk_path'] + '/' + SERVER['disktag'] + '/'); 159 | } 160 | } else SERVER['disktag'] = disktags[0]; 161 | 162 | if (files['showname'] == 'root'|| SERVER['disktag']=='') return render(path, files); 163 | 164 | SERVER['list_path'] = await getListpath(SERVER['disktag']); 165 | if (SERVER['list_path']=='') SERVER['list_path'] = '/'; 166 | let path1 = path_format(SERVER['list_path'] + path_format(path)); 167 | if (path1!='/'&&path1.substr(-1)=='/') path1 = path1.substr(0, path1.length-1); 168 | //SERVER['is_guestup_path'] = await is_guestup_path(path); 169 | SERVER['ajax']=0; 170 | if ('HTTP_X_REQUESTED_WITH' in SERVER) if (SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') SERVER['ajax']=1; 171 | 172 | /*if (SERVER['ajax']) { 173 | if ($_GET['action']=='del_upload_cache') { 174 | // del '.tmp' without login. 无需登录即可删除.tmp后缀文件 175 | return $drive->del_upload_cache(path); 176 | } 177 | if ($_GET['action']=='upbigfile') { 178 | if (!SERVER['admin']) { 179 | if (!SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400); 180 | if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400); 181 | } 182 | path1 = path_format(SERVER['list_path'] . path_format(path)); 183 | if (substr(path1, -1)=='/') path1=substr(path1, 0, -1); 184 | return $drive->bigfileupload(path1); 185 | } 186 | }*/ 187 | if (SERVER['admin']) { 188 | let tmp = await adminoperate(path); 189 | if (tmp['status'] > 0) { 190 | await savecache('path_' + path1, JSON.parse('{}'), SERVER['disktag'], 0); 191 | return tmp; 192 | } 193 | } else { 194 | if (SERVER['ajax']) return output('管理操作前先登录',401); 195 | } 196 | SERVER['ishidden'] = 0; 197 | /*SERVER['ishidden'] = passhidden($path); 198 | if (isset($_GET['thumbnails'])) { 199 | if (SERVER['ishidden']<4) { 200 | if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) { 201 | $path1 = path_format(SERVER['list_path'] . path_format($path)); 202 | if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1); 203 | $thumb_url = $drive->get_thumbnails_url($path1); 204 | if ($thumb_url!='') { 205 | if ($_GET['location']) { 206 | $url = $thumb_url; 207 | $domainforproxy = ''; 208 | $domainforproxy = getConfig('domainforproxy', SERVER['disktag']); 209 | if ($domainforproxy!='') { 210 | $url = proxy_replace_domain($url, $domainforproxy); 211 | } 212 | return output('', 302, [ 'Location' => $url ]); 213 | } else return output($thumb_url); 214 | } 215 | return output('', 404); 216 | } else return output(json_encode($exts['img']), 400); 217 | } else return output('', 401); 218 | }*/ 219 | 220 | disk = await diskObject((await getConfig('Driver', SERVER['disktag'])), SERVER['disktag']); 221 | if (await disk.isfine()) files = await disk.list_files(path1); 222 | 223 | if (JSON.stringify(files)=='{}') return render(path, files); 224 | if (('type' in files) && (files['type']=='file') && !('preview' in GET)) { 225 | //return Response.redirect(files['url']); 226 | return output('', 302, { 'Location' : files['url'] }); 227 | } 228 | if ('type' in files) return render(path, files); 229 | else return message(JSON.stringify(files), 'Error', 404); 230 | } 231 | 232 | async function diskObject(type, tag) { 233 | if (type==null||type=='') return null; 234 | let disk = new Object(); 235 | if (type=='Onedrive') { 236 | disk = new Onedrive(tag); 237 | await disk.init(tag); 238 | } 239 | if (type=='OnedriveCN') { 240 | disk = new OnedriveCN(tag); 241 | await disk.init(tag); 242 | } 243 | if (type=='Sharepoint') { 244 | disk = new Sharepoint(tag); 245 | await disk.init(tag); 246 | } 247 | if (type=='SharepointCN') { 248 | disk = new SharepointCN(tag); 249 | await disk.init(tag); 250 | } 251 | if (type=='Sharelink') { 252 | disk = new Sharelink(tag); 253 | await disk.init(tag); 254 | } 255 | return disk; 256 | } 257 | 258 | function isCommonEnv(key) { 259 | if (key in ConfigEnvs) return ConfigEnvs[key]&0b100?false:true; 260 | return null; 261 | } 262 | 263 | function isDiskEnv(key) { 264 | if (key in ConfigEnvs) return ConfigEnvs[key]&0b100?true:false; 265 | return null; 266 | } 267 | 268 | function isShowedEnv(key) { 269 | if (key in ConfigEnvs) return ConfigEnvs[key]&0b010?true:false; 270 | return null; 271 | } 272 | 273 | function isBase64Env(key) { 274 | if (key in ConfigEnvs) return ConfigEnvs[key]&0b001?true:false; 275 | return null; 276 | } 277 | 278 | async function md5(str) { 279 | let msgUint8 = new TextEncoder().encode(str) // encode as (utf-8) Uint8Array 280 | let hashBuffer = await crypto.subtle.digest('MD5', msgUint8) // hash the message 281 | let hashArray = Array.from(new Uint8Array(hashBuffer)) // convert buffer to byte array 282 | let hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('') 283 | return hashHex; 284 | } 285 | 286 | function adminlogin(name, pass, path) { 287 | if (name!='' && name!=null && pass!='' && pass!=null) { 288 | if (path==null||path=='') path = '/'; 289 | return output('\n\ 290 | \n\ 291 | \n\ 292 | 登录成功', 200, {'Set-Cookie': name + '=' + pass + ';path=' + path + ';', 'Content-Type': 'text/html'}); 293 | } else { 294 | html = '\n\ 295 |
\n\ 296 |

输入密码

\n\ 297 |
\n\ 298 |
\n\ 299 | \n\ 300 | \n\ 301 | \n\ 302 |
\n\ 303 |
\n\ 304 |
\n\ 305 |
\n\ 306 | \n\ 307 | '; 314 | return message(html, '管理登录', 401); 315 | } 316 | } 317 | 318 | async function adminoperate(path) 319 | { 320 | let path1 = path_format(SERVER['list_path'] + path_format(path)); 321 | if (path1.substr(-1)=='/') path1 = path1.substr(0, path1.length-1); 322 | tmpget = GET; 323 | tmppost = POST; 324 | let tmparr = new Object(); 325 | tmparr['statusCode'] = 0; 326 | if ( (('rename_newname' in tmpget)&&tmpget['rename_newname']!=tmpget['rename_oldname'] && tmpget['rename_newname']!='') || (('rename_newname' in tmppost)&&tmppost['rename_newname']!=tmppost['rename_oldname'] && tmppost['rename_newname']!='') ) { 327 | return output('无管理操作', 423); 328 | /*if (isset(tmppost['rename_newname'])) $VAR = 'tmppost'; 329 | else $VAR = 'tmpget'; 330 | // rename 重命名 331 | $file['path'] = path1; 332 | $file['name'] = ${$VAR}['rename_oldname']; 333 | $file['id'] = ${$VAR}['rename_fileid']; 334 | return $drive->Rename($file, ${$VAR}['rename_newname']);*/ 335 | } 336 | if (('delete_name' in tmpget) || ('delete_name' in tmppost)) { 337 | return output('无管理操作', 423); 338 | /*if (isset(tmppost['delete_name'])) $VAR = 'tmppost'; 339 | else $VAR = 'tmpget'; 340 | // delete 删除 341 | $file['path'] = path1; 342 | $file['name'] = ${$VAR}['delete_name']; 343 | $file['id'] = ${$VAR}['delete_fileid']; 344 | return $drive->Delete($file);*/ 345 | } 346 | if ( (('encrypt_newpass' in tmpget)&&tmpget['encrypt_newpass']!='') || (('encrypt_newpass' in tmppost)&&tmppost['encrypt_newpass']!='') ) { 347 | return output('无管理操作', 423); 348 | /*if (isset(tmppost['operate_action'])) $VAR = 'tmppost'; 349 | else $VAR = 'tmpget'; 350 | // encrypt 加密 351 | if (getConfig('passfile')=='') return message(getconstStr('SetpassfileBfEncrypt'),'',403); 352 | if (${$VAR}['encrypt_folder']=='/') ${$VAR}['encrypt_folder']==''; 353 | $folder['path'] = path_format(path1 . '/' . spurlencode(${$VAR}['encrypt_folder'], '/')); 354 | $folder['name'] = ${$VAR}['encrypt_folder']; 355 | $folder['id'] = ${$VAR}['id']; 356 | return $drive->Encrypt($folder, getConfig('passfile'), ${$VAR}['encrypt_newpass']);*/ 357 | } 358 | if (('move_folder' in tmpget) || ('move_folder' in tmppost)) { 359 | return output('无管理操作', 423); 360 | /*if (isset(tmppost['move_folder'])) $VAR = 'tmppost'; 361 | else $VAR = 'tmpget'; 362 | // move 移动 363 | $moveable = 1; 364 | if (path == '/' && ${$VAR}['move_folder'] == '/../') $moveable=0; 365 | if (${$VAR}['move_folder'] == ${$VAR}['move_name']) $moveable=0; 366 | if ($moveable) { 367 | $file['path'] = path1; 368 | $file['name'] = ${$VAR}['move_name']; 369 | $file['id'] = ${$VAR}['move_fileid']; 370 | if (${$VAR}['move_folder'] == '/../') { 371 | $foldername = path_format('/' . urldecode(path1 . '/')); 372 | $foldername = substr($foldername, 0, -1); 373 | $foldername = splitlast($foldername, '/')[0]; 374 | } else $foldername = path_format('/' . urldecode(path1) . '/' . ${$VAR}['move_folder']); 375 | $folder['path'] = $foldername; 376 | $folder['name'] = ${$VAR}['move_folder']; 377 | $folder['id'] = ''; 378 | return $drive->Move($file, $folder); 379 | } else { 380 | return output('{"error":"' . getconstStr('CannotMove') . '"}', 403); 381 | }*/ 382 | } 383 | if (('copy_name' in tmpget) || ('copy_name' in tmppost)) { 384 | return output('无管理操作', 423); 385 | /*if (isset(tmppost['copy_name'])) $VAR = 'tmppost'; 386 | else $VAR = 'tmpget'; 387 | // copy 复制 388 | $file['path'] = path1; 389 | $file['name'] = ${$VAR}['copy_name']; 390 | $file['id'] = ${$VAR}['copy_fileid']; 391 | return $drive->Copy($file);*/ 392 | } 393 | if ('editfile' in tmppost) { 394 | return output('无管理操作', 423); 395 | /*// edit 编辑 396 | $file['path'] = path1; 397 | $file['name'] = ''; 398 | $file['id'] = ''; 399 | return $drive->Edit($file, tmppost['editfile']);*/ 400 | } 401 | if (('create_name' in tmpget) || ('create_name' in tmppost)) { 402 | return output('无管理操作', 423); 403 | /*if (isset(tmppost['create_name'])) $VAR = 'tmppost'; 404 | else $VAR = 'tmpget'; 405 | // create 新建 406 | $parent['path'] = path1; 407 | $parent['name'] = ''; 408 | $parent['id'] = ${$VAR}['create_fileid']; 409 | return $drive->Create($parent, ${$VAR}['create_type'], ${$VAR}['create_name'], ${$VAR}['create_text']);*/ 410 | } 411 | if ('RefreshCache' in GET) { 412 | await savecache('path_' + path1 + '/?password', '', SERVER['disktag'], 0); 413 | await savecache('customTheme', '', '', 0); 414 | return message('\n\ 415 | ', '刷新缓存', 202); 416 | } 417 | return tmparr; 418 | } 419 | 420 | function isHideFile(str) { 421 | return false; 422 | } 423 | 424 | async function get_content(path) 425 | { 426 | let path1 = path_format(SERVER['list_path'] + path_format(path)); 427 | if (path1!='/'&&path1.substr(-1)=='/') path1 = path1.substr(0, path1.length-1); 428 | let file = await disk.list_files(path1); 429 | //console.log(file); 430 | return file; 431 | } 432 | 433 | function parseBody(str, sp) { 434 | let tmp = new Object(); 435 | if (str===null) return tmp; 436 | let arr = str.split(sp); 437 | for(j = 0, len = arr.length; j < len; j++) { 438 | if (arr[j]=='') { 439 | let a = 1; 440 | } else if (arr[j].indexOf('=')<1) { 441 | tmp[arr[j]] = true; 442 | } else { 443 | let tmp1 = arr[j].split('='); 444 | if (tmp1[1]==null||tmp1[1]=='') tmp[tmp1[0]] = ''; 445 | else tmp[decodeURIComponent(tmp1[0])] = decodeURIComponent(tmp1[1].replace(/\+/g, '%20')); 446 | //else tmp[tmp1[0]] = tmp1[1]; 447 | } 448 | } 449 | return tmp; 450 | } 451 | 452 | function splitfirst(str, sp) { 453 | let tmp = new Array(); 454 | let pos = str.indexOf(sp); 455 | if (pos===-1) { 456 | tmp[0] = str; 457 | tmp[1] = ''; 458 | } else if (pos>0) { 459 | tmp[0] = str.substr(0, pos); 460 | tmp[1] = str.substr(pos+sp.length); 461 | } else { 462 | tmp[0] = ''; 463 | tmp[1] = str.substr(sp.length); 464 | } 465 | return tmp; 466 | } 467 | 468 | function splitlast(str, sp) { 469 | let tmp = new Array(); 470 | let pos = str.lastIndexOf(sp); 471 | if (pos===-1) { 472 | tmp[0] = str; 473 | tmp[1] = ''; 474 | } else if (pos>0) { 475 | tmp[0] = str.substr(0, pos); 476 | tmp[1] = str.substr(pos+sp.length); 477 | } else { 478 | tmp[0] = ''; 479 | tmp[1] = str.substr(sp.length); 480 | } 481 | return tmp; 482 | } 483 | 484 | function path_format(path) { 485 | path = '/' + path; 486 | while (path.indexOf('//')>-1) path = path.replace(/\/\//g, '/'); 487 | return path; 488 | } 489 | 490 | function spurlencode(str, sp) { 491 | str = str.replace(/ /g, '%20'); 492 | let tmp=''; 493 | if (sp!=null) { 494 | let tmparr = str.split(sp); 495 | for (let num in tmparr) { 496 | let str1 = tmparr[num]; 497 | tmp += encodeURIComponent(str1) + sp; 498 | } 499 | tmp = tmp.substr(0, tmp.length-sp.length); 500 | } else { 501 | tmp = encodeURIComponent(str); 502 | } 503 | tmp = tmp.replace(/\%2520/g, '%20'); 504 | tmp = tmp.replace(/\%26amp\%3B/g, '&'); 505 | return tmp; 506 | } 507 | 508 | async function getListpath(disktag) { 509 | let public_path = await getConfig('public_path', disktag); 510 | return spurlencode(public_path, '/'); 511 | } 512 | 513 | function message(body, title, status) { 514 | html = '' + title + '\n\ 515 | \n\ 516 | \n\ 517 | \n\ 518 |

' + title + '

\n\ 519 | 返回首页
\n\ 520 |
' + body + '
'; 521 | return output(html, status, {'Content-Type':'text/html'}); 522 | } 523 | 524 | function output(body, status, headers) { 525 | //if (headers!=null) 526 | headers = new Headers(headers); 527 | if (headers!=null) { 528 | let Location = headers.get('Location'); 529 | if (Location!=null) { 530 | if (Location.substr(0,7)=='http://'||Location.substr(0,8)=='https://') return Response.redirect(Location); 531 | //if (headers!=null && headers.get('Content-Type')==null) headers.set('Content-Type', ''); 532 | } 533 | } 534 | //headers.set('content-type', 'text/html'); 535 | return new Response(body, { 536 | status: status, 537 | headers: headers 538 | }); 539 | } 540 | 541 | async function install() { 542 | if (('install0' in GET) && POST['admin']!='') { 543 | let tmp = new Object(); 544 | tmp['admin'] = POST['admin']; 545 | await setConfig(tmp); 546 | return message('', '成功', 200); 547 | } 548 | html = '\n\ 549 |
\n\ 550 | 设置admin密码\n\ 551 |
\n\ 552 | \n\ 553 |
'; 554 | return message(html, '安装', 201); 555 | } 556 | 557 | function base64y_encode(str) 558 | { 559 | if (str===null) return ""; 560 | str = btoa(str); 561 | while (str.substr(-1)=='=') str=str.substr(0,str.length-1); 562 | str = str.replace(/\+/g, '-'); 563 | str = str.replace(/\//g, '_'); 564 | return str; 565 | } 566 | 567 | function base64y_decode(str) 568 | { 569 | if (str===null) return ""; 570 | str = str.replace(/\-/g, '+'); 571 | str = str.replace(/_/g, '/'); 572 | while (str.length%4>0) str += '='; 573 | str = atob(str); 574 | //if (strpos(str, '%')!==false) str = urldecode(str); 575 | return str; 576 | } 577 | 578 | async function getcache(key, disktag) { 579 | if (disktag==null) disktag = ''; 580 | let tmp = await OMKV.get('OneManagerCache/' + disktag + '/' + key); 581 | if (tmp===null) return ''; 582 | else { 583 | if (tmp.substr(0,14)=='KVObjectCache.') { 584 | tmp = tmp.substr(14); 585 | return JSON.parse(tmp); 586 | } else return tmp; 587 | } 588 | } 589 | 590 | async function savecache(key, value, disktag, ttl) { 591 | if (disktag==null) disktag = ''; 592 | if (ttl==null) ttl = 3000; 593 | if (typeof value == 'object') { 594 | let tmp = JSON.stringify(value); 595 | value = null; 596 | value = 'KVObjectCache.' + tmp; 597 | } 598 | if (ttl===0||ttl===1) await OMKV.delete('OneManagerCache/' + disktag + '/' + key); 599 | else await OMKV.put('OneManagerCache/' + disktag + '/' + key, value, {expirationTtl: ttl}); 600 | } 601 | 602 | async function getConfig(key, disktag) { 603 | if (key==null||key=='') return ''; 604 | if (isDiskEnv(key)) { 605 | if (disktag==null||disktag=='') disktag = SERVER['disktag']; 606 | if (disktag==null||disktag=='') return ''; 607 | let diskstr = await OMKV.get(disktag); 608 | let disk = JSON.parse(diskstr); 609 | //if (isBase64Env(key)) return base64y_decode(disk[key]); 610 | //else 611 | if (disk!=null && (key in disk)) return disk[key]; 612 | } else { 613 | let value = await OMKV.get(key); 614 | //if (isBase64Env(key)) return base64y_decode(value); 615 | //else 616 | if (value!=null) return value; 617 | } 618 | return ''; 619 | } 620 | 621 | async function setConfig(arr, disktag) { 622 | if (disktag==null||disktag=='') disktag = SERVER['disktag']; 623 | let disktags = (await getConfig('disktag')).split('|'); 624 | let a = await getConfig(disktag); 625 | let diskconfig = new Array(); 626 | if (a!='') diskconfig = JSON.parse(a); 627 | let tmp = new Object(); 628 | let indisk = 0; 629 | let operatedisk = 0; 630 | for (let key in arr) { 631 | if (isDiskEnv(key)) { 632 | //if (isBase64Env(key)) diskconfig[key] = base64y_encode(arr[key]); 633 | //else 634 | diskconfig[key] = arr[key]; 635 | indisk = 1; 636 | } else if (key=='disktag_add') { 637 | disktags.push(arr[key]); 638 | operatedisk = 1; 639 | } else if (key=='disktag_del') { 640 | let pos = disktags.indexOf(arr[key]); 641 | if (pos>-1) { 642 | disktags.splice(pos, 1); 643 | tmp[arr[key]] = ''; 644 | operatedisk = 1; 645 | } 646 | } else if (key=='disktag_copy') { 647 | newtag = arr[key] + '_' + new Date().getTime(); 648 | tmp[newtag] = await getConfig(arr[key]); 649 | disktags.push(newtag); 650 | operatedisk = 1; 651 | } else if (key=='disktag_rename' || key=='disktag_newname') { 652 | if (arr['disktag_rename']!=arr['disktag_newname']) operatedisk = 1; 653 | } else { 654 | //if (isBase64Env(key)) tmp[key] = base64y_encode(arr[key]); 655 | //else 656 | tmp[key] = arr[key]; 657 | } 658 | } 659 | 660 | if (indisk == 1) { 661 | let diskconfig_tmp = new Object(); 662 | Object.keys(diskconfig).sort().forEach(function(key) { 663 | if (diskconfig[key]!=null&&diskconfig[key]!=undefined&&diskconfig[key]!='') diskconfig_tmp[key] = diskconfig[key]; 664 | }); 665 | tmp[disktag] = JSON.stringify(diskconfig_tmp); 666 | } 667 | if (operatedisk==1) { 668 | if (('disktag_newname' in arr) && arr['disktag_newname']!='') { 669 | tags = new Array(); 670 | for (let num in disktags) { 671 | let tag = disktags[num]; 672 | if (tag==arr['disktag_rename']) tags.push(arr['disktag_newname']); 673 | else tags.push(tag); 674 | } 675 | tmp['disktag'] = tags.join('|'); 676 | tmp[arr['disktag_newname']] = await getConfig(arr['disktag_rename']); 677 | tmp[arr['disktag_rename']] = ''; 678 | } else { 679 | let x = new Set(disktags); 680 | let x1 = [...x].join('|'); 681 | while (x1.substr(0,1)=='|') x1 = x1.substr(1); 682 | while (x1.substr(-1)=='|') x1 = x1.substr(0, x1.length-1); 683 | tmp['disktag'] = x1; 684 | } 685 | } 686 | //console.log(tmp); 687 | for (let key in tmp) { 688 | if (tmp[key]=='') { 689 | await OMKV.delete(key); 690 | } else { 691 | await OMKV.put(key, tmp[key]); 692 | } 693 | } 694 | return tmp; 695 | } 696 | function htmlSpecialChars(str) 697 | { 698 | if (str===null) return ""; 699 | let s = ""; 700 | if (str.length == 0) return ""; 701 | for (let i=0; i": s += ">"; break; 705 | case "&": s += "&"; break; 706 | case " ": 707 | if(str.substr(i + 1, 1) == " ") { 708 | s += "  "; 709 | i++; 710 | } else s += " "; 711 | break; 712 | case "\"": s += """; break; 713 | //case "\n": s += "
"; break; 714 | default: s += str.substr(i,1); break; 715 | } 716 | } 717 | return s; 718 | } 719 | function time_format(str) 720 | { 721 | if (str==null||str=='') return ''; 722 | return str.replace('T', ' '); 723 | let t = new Date(str); 724 | // 725 | /*if (str.indexOf('T')>0) { 726 | str = str.replace('T', ' '); 727 | str = str.replace('Z', ' '); 728 | str += ' UTC'; 729 | }*/ 730 | //return date('Y-m-d H:i:s',strtotime($ISO . " UTC")); 731 | let tmp = t.getFullYear() + '-' + (t.getMonth()+1) + '-' + t.getDate(); 732 | tmp += ' ' + t.getHours() + ':' + t.getMinutes() + ':' + t.getSeconds(); 733 | return tmp; 734 | } 735 | function size_format(byte) 736 | { 737 | if (byte==null) return '' 738 | let i = 0; 739 | while (byte >= 1024) { 740 | byte = byte / 1024; 741 | i++; 742 | if (i == 3) break; 743 | } 744 | let units = new Array('B', 'KB', 'MB', 'GB', 'TB'); 745 | let r; 746 | if (i==0) r = byte; 747 | else r = byte.toFixed(2); 748 | return (r + ' ' + units[i]); 749 | } 750 | async function curl(method, url, data, headers, returnhead) { 751 | let head = new Headers(); 752 | head.set('content-type', 'application/x-www-form-urlencoded;charset=utf-8;'); 753 | for (let key in headers) { 754 | head.set(key, headers[key]); 755 | } 756 | let res = new Object(); 757 | let tmp; 758 | if (method=='GET') { 759 | tmp = await fetch(url,{ 760 | method: method, 761 |   //mode: 'cors',跨域请求 762 |   headers: head 763 |  }); 764 | } else { 765 | tmp = await fetch(url,{ 766 | method: method, 767 |   //mode: 'cors',跨域请求 768 |   headers: head, 769 |   body: data 770 |  }) 771 | } 772 | res['stat'] = tmp.status; 773 | res['body'] = await tmp.text(); 774 | if (returnhead!=null) { 775 | let r_head = new Headers(tmp.headers); 776 | let h = new Object(); 777 | let c = r_head.get('Set-Cookie'); 778 | if (c!=null) h['Set-Cookie'] = c; 779 | let Location = r_head.get('Location'); 780 | if (Location!=null) h['Location'] = Location; 781 | res['returnhead'] = h; 782 | } 783 | return res; 784 | } 785 | 786 | async function setup() { 787 | let title = 'OneManager 设置'; 788 | let html = ''; 789 | if ('submit1' in POST) { 790 | SERVER['disk_oprating'] = ''; 791 | let tmp = new Object(); 792 | for (let k in POST) { 793 | if (isShowedEnv(k) || k=='disktag_del' || k=='disktag_add' || k=='disktag_rename' || k=='disktag_copy') { 794 | tmp[k] = POST[k]; 795 | } 796 | if (k=='disktag_newname') { 797 | let tmptag = await getConfig(POST[k]); 798 | //v = preg_replace('/[^0-9a-zA-Z|_]/i', '', v); 799 | //f = substr(v, 0, 1); 800 | //if (strlen(v)==1) v .= '_'; 801 | if (isCommonEnv(POST[k])) { 802 | return message('不要输入固有变量
返回', 'Error', 201); 803 | } else /*if (!(('a'<=f && f<='z') || ('A'<=f && f<='Z'))) { 804 | return message('' . getconstStr('Back') . '', 'Please start with letters', 201); 805 | } else */ 806 | if (tmptag!='') { 807 | return message('返回', '已有此标签', 201); 808 | } else { 809 | tmp[k] = POST[k]; 810 | } 811 | } 812 | if (k=='disktag_sort') { 813 | let td = JSON.parse(POST[k]).join('|'); 814 | let dt = await getConfig('disktag'); 815 | if (td.length===dt.length) tmp['disktag'] = td; 816 | else return message('Something wrong.', 'Error', 500); 817 | } 818 | if (k == 'disk') SERVER['disk_oprating'] = POST[k]; 819 | } 820 | let res = await setConfig(tmp, SERVER['disk_oprating']); 821 | //html += JSON.stringify(POST); 822 | //html += JSON.stringify(tmp); 823 | html += '成功!
返回'; 824 | //html += JSON.stringify(res); 825 | title = '设置'; 826 | return message(html, title); 827 | } 828 | let env_tmp = new Array(); 829 | Object.keys(ConfigEnvs).sort().forEach(function(key) { 830 | env_tmp[key] = ConfigEnvs[key]; 831 | }); 832 | ConfigEnvs = env_tmp; 833 | let preurl = ''; 834 | if ('preview' in GET) { 835 | preurl = path_format(SERVER['PHP_SELF'] + '?preview'); 836 | } else { 837 | preurl = path_format(SERVER['PHP_SELF'] + '/'); 838 | } 839 | html += '\n\ 840 | 返回
\n\ 841 | Github
'; 842 | 843 | html += '\n\ 844 | \n\ 845 | \n\ 846 | \n\ 847 | \n\ 848 | '; 849 | for (let key in ConfigEnvs) if (isCommonEnv(key) && isShowedEnv(key)) { 850 | html += '\n\ 851 | \n\ 852 | \n\ 853 | \n\ 854 | '; 855 | } 856 | html += '\n\ 857 | \n\ 858 | \n\ 859 |
平台变量

'; 860 | let disktags = (await getConfig('disktag')).split('|'); 861 | if (disktags.length>1) { 862 | html += '\n\ 863 | \n\ 864 | \n\ 873 | \n\ 874 | \n\ 875 | \n\ 876 | '; 877 | let num = 0; 878 | for (let key in disktags) { 879 | let disktag = disktags[key]; 880 | if (disktag!='') { 881 | num++; 882 | html += '\n\ 883 | '; 884 | } 885 | } 886 | html += '\n\ 887 | \n\ 888 | \n\ 889 | \n\ 890 |
' + disktag + '
拖动以交换位置
\n\ 891 |
'; 930 | } 931 | for (let key in disktags) { 932 | let disktag = disktags[key]; 933 | if (disktag!='') { 934 | let disk_tmp = await diskObject(await getConfig('Driver', disktag), disktag); 935 | //console.log(disk_tmp); 936 | let diskok; 937 | if (disk_tmp!=null) diskok = await disk_tmp.isfine(); 938 | else diskok = false; 939 | html += '\n\ 940 | \n\ 941 | \n\ 942 | \n\ 948 | \n\ 958 | \n\ 959 | \n\ 960 | \n\ 961 | \n\ 964 | \n\ 965 | '; 966 | if (diskok) { 967 | html += '\n\ 968 | \n\ 969 | '; 970 | for (let key in ConfigEnvs) if (isDiskEnv(key) && isShowedEnv(key)) { 971 | html += '\n\ 972 | \n\ 973 | \n\ 974 | \n\ 975 | '; 976 | } 977 | html += '\n\ 978 | \n\ 979 | '; 980 | } else { 981 | html += '\n\ 982 | \n\ 983 | \n\ 984 | '; 985 | } 986 | html += '\n\ 987 |
\n\ 943 |
\n\ 944 | \n\ 945 | \n\ 946 |
\n\ 947 |
\n\ 949 |
\n\ 950 | \n\ 951 | \n\ 952 | \n\ 953 |
\n\ 954 |
\n\ 955 | \n\ 956 | \n\ 957 |
Driver' + await getConfig('Driver', disktag); 962 | if (diskok && disk_tmp.baseclassname=='MS365') html += ' 切换Onedrive与Sharepoint'; 963 | html += '
此盘无法正常工作,重新尝试添加

'; 988 | } 989 | } 990 | let envs = JSON.stringify(Object.keys(ConfigEnvs)); 991 | html += '\n\ 992 | 添加盘\n\ 993 | \n\ 1023 |

'; 1024 | return message(html, title); 1025 | } 1026 | 1027 | class MS365 { 1028 | constructor(tag) { 1029 | this.baseclassname = 'MS365'; 1030 | this.disktag = tag; 1031 | this.redirect_uri = 'https://scfonedrive.github.io'; 1032 | return this; 1033 | return (async () => { 1034 | 1035 | this.classname = 'Onedrive'; 1036 | 1037 | 1038 | let client_id = await getConfig('client_id', tag); 1039 | let client_secret = await getConfig('client_secret', tag); 1040 | if (client_id!='' && client_secret!='') { 1041 | this.client_id = client_id; 1042 | this.client_secret = client_secret; 1043 | } else { 1044 | this.client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; 1045 | this.client_secret = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; 1046 | } 1047 | this.oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; 1048 | this.api_url = 'https://graph.microsoft.com/v1.0'; 1049 | this.scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; 1050 | this.client_secret = encodeURIComponent(this.client_secret); 1051 | this.scope = encodeURIComponent(this.scope); 1052 | this.DownurlStrName = '@microsoft.graph.downloadUrl'; 1053 | this.ext_api_url = '/me/drive/root'; 1054 | this.access_token = ''; 1055 | let res = await this.get_access_token(await getConfig('refresh_token', tag)); 1056 | 1057 | })(); 1058 | } 1059 | 1060 | async isfine() { 1061 | if (this.access_token!='') return true; 1062 | return false; 1063 | } 1064 | 1065 | async list_files(path) 1066 | { 1067 | if (path=='') path = '/'; 1068 | let files = await getcache('path_' + path, this.disktag); 1069 | if (files == '') { 1070 | //console.log(path + '无缓存'); 1071 | let pos = splitlast(path, '/'); 1072 | let parentpath = pos[0]; 1073 | if (parentpath=='') parentpath = '/'; 1074 | let filename = pos[1]; 1075 | let parentfiles = await getcache('path_' + parentpath, this.disktag); 1076 | if (parentfiles!='') { 1077 | if (('children' in parentfiles) && (filename in parentfiles['children']) && (this.DownurlStrName in parentfiles['children'][filename])) { 1078 | if (exts['txt'].indexOf(splitlast(filename,'.')[1])>-1) { 1079 | let file = parentfiles['children'][filename]; 1080 | if (!(('content' in file)&&file['content']['stat']==200)) { 1081 | let content1 = await curl('GET', file[this.DownurlStrName]); 1082 | //console.log(content1); 1083 | parentfiles['children'][filename]['content'] = content1; 1084 | await savecache('path_' + parentpath, parentfiles, this.disktag); 1085 | } 1086 | } 1087 | return this.files_format(parentfiles['children'][filename]); 1088 | } 1089 | } 1090 | 1091 | let url = this.api_url + this.ext_api_url; 1092 | //console.log(url); 1093 | if (path !== '/') { 1094 | url += ':' + path; 1095 | if (url.substr(-1)=='/') url=url.substr(0, url.length-1); 1096 | } 1097 | url += '?expand=children(select=id,name,size,file,folder,parentReference,lastModifiedDateTime,' + this.DownurlStrName + ')'; 1098 | let retry = 0; 1099 | let arr = new Object(); 1100 | while (JSON.stringify(arr)=='{}'||(retry<3&&arr.status==0)) { 1101 | arr = await curl('GET', url, '', {'Authorization' : 'Bearer ' + this.access_token}, 1); 1102 | retry++; 1103 | } 1104 | //console.log(arr); 1105 | //echo url . '
' . json_encode($arr, JSON_PRETTY_PRINT) . '
'; 1106 | if (arr['stat']<500) { 1107 | files = JSON.parse(arr['body']); 1108 | //echo '
' . json_encode(files, JSON_PRETTY_PRINT) . '
'; 1109 | if ('folder' in files) { 1110 | /*if (files['folder']['childCount']>200) { 1111 | // files num > 200 , then get nextlink 1112 | let page = ('pagenum' in POST)?POST['pagenum']:1; 1113 | if (page>1) 1114 | //if (!(files = getcache('path_1' . path . '_' . $page, this.disktag))) 1115 | { 1116 | let children = this.fetch_files_children(path, page); 1117 | //echo '
' . json_encode($children, JSON_PRETTY_PRINT) . '
'; 1118 | files['children'] = $children['value']; 1119 | //files['children'] = children_name(files['children']); 1120 | files['folder']['page'] = $page; 1121 | //savecache('path_' + path . '_' . $page, files, this.disktag); 1122 | } 1123 | } else {*/ 1124 | // files num < 200 , then cache 1125 | //if (isset(files['children'])) { 1126 | //files['children'] = children_name(files['children']); 1127 | //} 1128 | await savecache('path_' + path, files, this.disktag); 1129 | /*}*/ 1130 | } 1131 | if ('file' in files) { 1132 | //console.log(path + '是file'); 1133 | if (exts['txt'].indexOf(splitlast(files['name'],'.')[1])>-1) { 1134 | if (!(('content' in files)&&files['content']['stat']==200)) { 1135 | let content1 = await curl('GET', files[this.DownurlStrName]); 1136 | files['content'] = content1; 1137 | await savecache('path_' + path, files, this.disktag); 1138 | } 1139 | } 1140 | } 1141 | if ('error' in files) { 1142 | files['error']['stat'] = arr.status; 1143 | } 1144 | } else { 1145 | //error_log1(await arr.text()); 1146 | files = JSON.parse(await arr.text()); 1147 | if ('error' in files) { 1148 | files['error']['stat'] = arr.status; 1149 | } else { 1150 | files['error'] = new Object(); 1151 | files['error']['stat'] = 503; 1152 | files['error']['code'] = 'unknownError'; 1153 | files['error']['message'] = 'unknownError'; 1154 | } 1155 | //files = json_decode( '{"unknownError":{ "stat":'.arr.status.',"message":"'.await arr.text().'"}}', true); 1156 | //error_log1(json_encode(files, JSON_PRETTY_PRINT)); 1157 | } 1158 | } 1159 | //echo '
' . json_encode(files, JSON_PRETTY_PRINT) . '
'; 1160 | //console.log(path); 1161 | //console.log(files); 1162 | return this.files_format(files); 1163 | } 1164 | 1165 | files_format(files) 1166 | { 1167 | //return files; 1168 | let tmp = new Object(); 1169 | if ('file' in files) { 1170 | tmp['type'] = 'file'; 1171 | tmp['id'] = files['id']; 1172 | tmp['name'] = files['name']; 1173 | tmp['time'] = files['lastModifiedDateTime']; 1174 | tmp['size'] = files['size']; 1175 | tmp['mime'] = files['file']['mimeType']; 1176 | tmp['url'] = files[this.DownurlStrName]; 1177 | tmp['content'] = files['content']; 1178 | } else if ('folder' in files) { 1179 | tmp['type'] = 'folder'; 1180 | tmp['id'] = files['id']; 1181 | tmp['name'] = files['name']; 1182 | tmp['time'] = files['lastModifiedDateTime']; 1183 | tmp['size'] = files['size']; 1184 | tmp['childcount'] = files['folder']['childCount']; 1185 | tmp['page'] = files['folder']['page']; 1186 | tmp['list'] = new Object(); 1187 | for (let num in files['children']) { 1188 | let file = files['children'][num]; 1189 | let filename = file['name'].toLowerCase(); 1190 | let file_tmp = new Object(); 1191 | if ('file' in file) { 1192 | file_tmp['type'] = 'file'; 1193 | file_tmp['url'] = file[this.DownurlStrName]; 1194 | file_tmp['mime'] = file['file']['mimeType']; 1195 | } else if ('folder' in files) { 1196 | file_tmp['type'] = 'folder'; 1197 | } 1198 | file_tmp['id'] = file['id']; 1199 | file_tmp['name'] = file['name']; 1200 | file_tmp['time'] = file['lastModifiedDateTime']; 1201 | file_tmp['size'] = file['size']; 1202 | tmp['list'][filename] = file_tmp; 1203 | } 1204 | } else if ('error' in files) { 1205 | return files; 1206 | } 1207 | //console.log(tmp); 1208 | return tmp; 1209 | } 1210 | 1211 | async AddDisk() { 1212 | let url = path_format(SERVER['PHP_SELF'] + '/'); 1213 | if ('Finish' in GET) { 1214 | if (this.access_token == '') { 1215 | let refresh_token = await getConfig('refresh_token', this.disktag); 1216 | if (refresh_token=='') { 1217 | let html = 'No refresh_token config, please AddDisk again or wait minutes.
' + this.disktag; 1218 | let title = 'Error'; 1219 | return message(html, title, 201); 1220 | } 1221 | let response = await this.get_access_token(refresh_token); 1222 | if (!response) return message('获取A_T失败', 'Error', 500); 1223 | } 1224 | 1225 | let tmp = new Object(); 1226 | if (POST['DriveType']=='Onedrive') { 1227 | if (this.classname=='Sharepoint') tmp['Driver'] = 'Onedrive'; 1228 | else if (this.classname=='SharepointCN') tmp['Driver'] = 'OnedriveCN'; 1229 | tmp['sharepointSite'] = ''; 1230 | tmp['siteid'] = ''; 1231 | } else if (POST['DriveType']=='Custom') { 1232 | // sitename计算siteid 1233 | let tmp1 = await this.get_siteid(POST['sharepointSite']); 1234 | if (typeof tmp1 == 'object') return message(tmp1['stat'] + tmp1['body'], 'Get Sharepoint Site ID ' + POST['sharepointSite'], tmp1['stat']); 1235 | let siteid = tmp1; 1236 | //api = this.api_url . '/sites/' . siteid . '/drive/'; 1237 | //arr = curl('GET', api, '', [ 'Authorization' => 'Bearer ' . this.access_token ], 1); 1238 | //if (arr['stat']!=200) return message(arr['stat'] . arr['body'], 'Get Sharepoint Drive ID ' . _POST['DriveType'], arr['stat']); 1239 | tmp['siteid'] = siteid; 1240 | tmp['sharepointSite'] = POST['sharepointSite']; 1241 | if (this.classname=='Onedrive') tmp['Driver'] = 'Sharepoint'; 1242 | else if (this.classname=='OnedriveCN') tmp['Driver'] = 'SharepointCN'; 1243 | } else { 1244 | // 直接是siteid 1245 | tmp['siteid'] = POST['DriveType']; 1246 | tmp['sharepointSite'] = POST['sharepointSiteUrl']; 1247 | if (this.classname=='Onedrive') tmp['Driver'] = 'Sharepoint'; 1248 | else if (this.classname=='OnedriveCN') tmp['Driver'] = 'SharepointCN'; 1249 | } 1250 | 1251 | let response = await setConfig(tmp, this.disktag); 1252 | 1253 | let str = '\n\ 1254 | '; 1260 | return message(str, '跳转到首页', 201); 1261 | 1262 | } 1263 | 1264 | if ('SelectDrive' in GET) { 1265 | if (this.classname=='Sharelink') return message('Can not change to other.', 'Back', 201); 1266 | if (this.access_token == '') { 1267 | let refresh_token = await getConfig('refresh_token', this.disktag); 1268 | if (refresh_token=='') { 1269 | let html = 'No refresh_token config, please AddDisk again or wait minutes.
' + this.disktag; 1270 | let title = 'Error'; 1271 | return message(html, title, 201); 1272 | } 1273 | let response = await this.get_access_token(refresh_token); 1274 | if (!response) return message('获取A_T失败', 'Error', 500); 1275 | } 1276 | 1277 | let api = this.api_url + '/sites/root'; 1278 | let arr = await curl('GET', api, '', { 'Authorization' : 'Bearer ' + this.access_token }); 1279 | let Tenant = (JSON.parse(arr['body']))['webUrl']; 1280 | 1281 | api = this.api_url + '/me/followedSites'; 1282 | arr = await curl('GET', api, '', { 'Authorization' : 'Bearer ' + this.access_token }); 1283 | if (!(arr['stat']==200||arr['stat']==403||arr['stat']==400)) return message(arr['stat'] + arr['body'], 'Get followedSites', arr['stat']); 1284 | let sites = JSON.parse(arr['body'])['value']; 1285 | 1286 | let title = 'Select Driver'; 1287 | let html = '\n\ 1288 |
\n\ 1289 |
\n\ 1290 |
'; 1291 | if (sites!=null) for (let k in sites) { 1292 | let v = sites[k]; 1293 | html += '\n\ 1294 | '; 1297 | } 1298 | html += '\n\ 1299 | \n\ 1300 |
\n\ 1306 | '; 1307 | html += '\n\ 1308 | \n\ 1309 |
\n\ 1310 |
\n\ 1311 | \n\ 1327 | '; 1328 | return message(html, title, 201); 1329 | } 1330 | 1331 | if (('install2' in GET) && ('code' in GET)) { 1332 | let tmp = await curl('POST', this.oauth_url + 'token', 'client_id=' + this.client_id + '&client_secret=' + this.client_secret + '&grant_type=authorization_code&requested_token_use=on_behalf_of&redirect_uri=' + this.redirect_uri + '&code=' + GET['code']); 1333 | let res = new Object(); 1334 | if (tmp['stat']==200) res = JSON.parse(tmp['body']); 1335 | if ('refresh_token' in res) { 1336 | let refresh_token = res['refresh_token']; 1337 | let str = '\n\ 1338 | refresh_token :
'; 1339 | str += '\n\ 1340 |

\n\ 1341 | 正在保存 refresh_token\n\ 1342 | '; 1348 | this.access_token = res['access_token']; 1349 | let tmptoken = new Object(); 1350 | tmptoken['refresh_token'] = refresh_token; 1351 | tmptoken['token_expires'] = new Date().getTime()+7*24*60*60*1000; 1352 | let response = await setConfig(tmptoken, this.disktag); 1353 | 1354 | await savecache('access_token', res['access_token'], this.disktag, res['expires_in'] - 60); 1355 | str += '\n\ 1356 | '; 1357 | return message(str, '等待 3s', 201); 1358 | } 1359 | return message(tmp['body'], tmp['stat'], tmp['stat']); 1360 | } 1361 | 1362 | if ('install1' in GET) { 1363 | let disktag = await getConfig('Driver', GET['disktag']); 1364 | if (disktag=='Onedrive' || disktag=='OnedriveCN') { 1365 | return message('\n\ 1366 | 跳转到office\n\ 1367 | \n\ 1374 | ', '等待 1s', 201); 1375 | } else { 1376 | return message('Something error, retry after a few seconds.', 'Retry', 201); 1377 | } 1378 | } 1379 | 1380 | if ('install0' in GET) { 1381 | if (POST['disktag_add']!=null&&POST['disktag_add']!='') { 1382 | /*POST['disktag_add'] = preg_replace('/[^0-9a-zA-Z|_]/i', '', _POST['disktag_add']); 1383 | f = substr(_POST['disktag_add'], 0, 1); 1384 | if (strlen(_POST['disktag_add'])==1) _POST['disktag_add'] .= '_'; 1385 | if (isCommonEnv(_POST['disktag_add'])) { 1386 | return message('Do not input ' . envs . '
', 'Error', 201); 1387 | } elseif (!(('a'<=f && f<='z') || ('A'<=f && f<='Z'))) { 1388 | return message('Please start with letters
1389 | ', 'Error', 201); 1395 | }*/ 1396 | 1397 | let tmp = new Object(); 1398 | // clear envs 1399 | for (let env in ConfigEnvs) if (isDiskEnv(env)) tmp[env] = ''; 1400 | 1401 | SERVER['disktag'] = POST['disktag_add']; 1402 | tmp['disktag_add'] = POST['disktag_add']; 1403 | tmp['diskname'] = POST['diskname']; 1404 | tmp['Driver'] = POST['Drive_ver']; 1405 | if (POST['Drive_ver']=='Sharelink') { 1406 | tmp['shareurl'] = POST['shareurl']; 1407 | } else { 1408 | if (POST['Drive_ver']=='Onedrive' && POST['NT_Drive_custom']=='on') { 1409 | tmp['client_id'] = POST['NT_client_id']; 1410 | tmp['client_secret'] = POST['NT_client_secret']; 1411 | } else if (POST['Drive_ver']=='OnedriveCN' && POST['CN_Drive_custom']=='on') { 1412 | tmp['client_id'] = POST['CN_client_id']; 1413 | tmp['client_secret'] = POST['CN_client_secret']; 1414 | } 1415 | } 1416 | //console.log(tmp); 1417 | let response = await setConfig(tmp, SERVER['disktag']); 1418 | 1419 | let title = '应该已经写入'; 1420 | let html = '等待 3s'; 1421 | if (POST['Drive_ver']=='Sharelink') html = '等待 3s'; 1422 | return message(html, title, 201); 1423 | } 1424 | } 1425 | 1426 | let html = '\n\ 1427 |
\n\ 1428 |
\n\ 1429 | 标签: ('; 1430 | let disktags = await getConfig('disktag'); 1431 | html += disktags + ')\n\ 1432 |
\n\ 1433 | 盘名:\n\ 1434 |
\n\ 1435 |
\n\ 1436 |
\n\ 1437 |
\n\ 1438 |
\n\ 1447 |
\n\ 1448 |
\n\ 1457 |
\n\ 1458 | \n\ 1462 |
\n\ 1463 |
'; 1464 | html += '你要明白 scfonedrive.github.io 是github上的静态网站,
除非github真的挂掉了,
不然,稍后你如果连不上,请检查你的运营商或其它“你懂的”问题!
'; 1465 | let envs = JSON.stringify(Object.keys(ConfigEnvs)); 1466 | html +='\n\ 1467 | \n\ 1468 |
\n\ 1469 |
\n\ 1470 | '; 1514 | return message(html, '选择帐号版本', 201); 1515 | } 1516 | async get_access_token(refresh_token) { 1517 | this.access_token = await getcache('access_token', this.disktag); 1518 | if (this.access_token == '') { 1519 | let p = 0; 1520 | let response = null; 1521 | let res = null; 1522 | while (response==null||(response.status==0&&p<3)) { 1523 | response = await curl('POST', this.oauth_url + 'token', 'client_id=' + this.client_id + '&client_secret=' + this.client_secret + '&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' + refresh_token ); 1524 | p++; 1525 | } 1526 | //console.log(response); 1527 | if (response['stat']==200) { 1528 | res = JSON.parse(response['body']); 1529 | } 1530 | if (res==null||!('access_token' in res)) { 1531 | //error_log1(this.oauth_url . 'token' . '?client_id=' . this.client_id . '&client_secret=' . this.client_secret . '&grant_type=refresh_token&requested_token_use=on_behalf_of&refresh_token=' . substr(refresh_token, 0, 20) . '******' . substr(refresh_token, -20)); 1532 | //error_log1('failed to get [' . this.disktag . '] access_token. response' . json_encode(res)); 1533 | //response['body'] = json_encode(json_decode(response['body']), JSON_PRETTY_PRINT); 1534 | //response['body'] .= '\nfailed to get [' . this.disktag . '] access_token.'; 1535 | //return response; 1536 | return false; 1537 | } 1538 | //tmp = res; 1539 | //tmp['access_token'] = '******'; 1540 | //tmp['refresh_token'] = '******'; 1541 | //error_log1('[' . this.disktag . '] Get access token:' . json_encode(tmp, JSON_PRETTY_PRINT)); 1542 | this.access_token = res['access_token']; 1543 | await savecache('access_token', this.access_token, this.disktag, res['expires_in'] - 300); 1544 | let nt = new Date().getTime(); 1545 | let exp = await getConfig('token_expires', this.disktag); 1546 | if (nt>exp) await setConfig({ 'refresh_token' : res['refresh_token'], 'token_expires' : nt+7*24*60*60 }, this.disktag); 1547 | return true; 1548 | } 1549 | return true; 1550 | } 1551 | async get_siteid(sharepointSite) 1552 | { 1553 | while (sharepointSite.substr(-1)=='/') sharepointSite = sharepointSite.substr(0, sharepointSite.length-1); 1554 | let tmp = splitlast(sharepointSite, '/'); 1555 | let sharepointname = ''; 1556 | if (tmp[1]==decodeURIComponent(tmp[1])) { 1557 | sharepointname = encodeURIComponent(tmp[1]); 1558 | } else { 1559 | sharepointname = tmp[1]; 1560 | } 1561 | tmp = splitlast(tmp[0], '/'); 1562 | let url = ''; 1563 | if (this.classname=='Onedrive') url = 'https://graph.microsoft.com/v1.0/sites/root:/' + tmp[1] + '/' + sharepointname; 1564 | if (this.classname=='OnedriveCN') url = 'https://microsoftgraph.chinacloudapi.cn/v1.0/sites/root:/' + tmp[1] + '/' + sharepointname; 1565 | 1566 | let i=0; 1567 | let response = null; 1568 | while (response==null || response['stat']!=200&&i<3) { 1569 | response = await curl('GET', url, false, {'Authorization' : 'Bearer ' + this.access_token}); 1570 | i++; 1571 | } 1572 | if (response['stat']!=200) { 1573 | //error_log1('failed to get siteid. response' . json_encode($response)); 1574 | response['body'] += '\nfailed to get siteid.'; 1575 | return response; 1576 | } 1577 | return JSON.parse(response['body'])['id']; 1578 | } 1579 | } 1580 | 1581 | class Onedrive extends MS365 { 1582 | constructor(tag) { 1583 | super(tag); 1584 | return this; 1585 | } 1586 | async init(tag) { 1587 | //this.baseclassname = 'MS365'; 1588 | this.classname = 'Onedrive'; 1589 | //this.disktag = tag; 1590 | //this.redirect_uri = 'https://scfonedrive.github.io'; 1591 | let client_id = await getConfig('client_id', tag); 1592 | let client_secret = await getConfig('client_secret', tag); 1593 | if (client_id!='' && client_secret!='') { 1594 | this.client_id = client_id; 1595 | this.client_secret = client_secret; 1596 | } else { 1597 | this.client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; 1598 | this.client_secret = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; 1599 | } 1600 | this.oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; 1601 | this.api_url = 'https://graph.microsoft.com/v1.0'; 1602 | this.scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; 1603 | this.client_secret = encodeURIComponent(this.client_secret); 1604 | this.scope = encodeURIComponent(this.scope); 1605 | this.DownurlStrName = '@microsoft.graph.downloadUrl'; 1606 | this.ext_api_url = '/me/drive/root'; 1607 | this.access_token = ''; 1608 | let res = await this.get_access_token(await getConfig('refresh_token', tag)); 1609 | } 1610 | } 1611 | 1612 | class OnedriveCN extends MS365 { 1613 | constructor(tag) { 1614 | super(tag); 1615 | return this; 1616 | } 1617 | async init(tag) { 1618 | //this.baseclassname = 'MS365'; 1619 | this.classname = 'OnedriveCN'; 1620 | //this.disktag = tag; 1621 | //this.redirect_uri = 'https://scfonedrive.github.io'; 1622 | let client_id = await getConfig('client_id', tag); 1623 | let client_secret = await getConfig('client_secret', tag); 1624 | if (client_id!='' && client_secret!='') { 1625 | this.client_id = client_id; 1626 | this.client_secret = client_secret; 1627 | } else { 1628 | this.client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617'; 1629 | this.client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y'; 1630 | } 1631 | this.oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/'; 1632 | this.api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0'; 1633 | this.scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access'; 1634 | this.client_secret = encodeURIComponent(this.client_secret); 1635 | this.scope = encodeURIComponent(this.scope); 1636 | this.DownurlStrName = '@microsoft.graph.downloadUrl'; 1637 | this.ext_api_url = '/me/drive/root'; 1638 | this.access_token = ''; 1639 | let res = await this.get_access_token(await getConfig('refresh_token', tag)); 1640 | return this; 1641 | } 1642 | } 1643 | 1644 | class Sharepoint extends MS365 { 1645 | constructor(tag) { 1646 | super(tag); 1647 | return this; 1648 | } 1649 | async init(tag) { 1650 | //this.baseclassname = 'MS365'; 1651 | this.classname = 'Sharepoint'; 1652 | //this.disktag = tag; 1653 | //this.redirect_uri = 'https://scfonedrive.github.io'; 1654 | let client_id = await getConfig('client_id', tag); 1655 | let client_secret = await getConfig('client_secret', tag); 1656 | if (client_id!='' && client_secret!='') { 1657 | this.client_id = client_id; 1658 | this.client_secret = client_secret; 1659 | } else { 1660 | this.client_id = '734ef928-d74c-4555-8d1b-d942fa0a1a41'; 1661 | this.client_secret = ':EK[e0/4vQ@mQgma8LmnWb6j4_C1CSIW'; 1662 | } 1663 | this.oauth_url = 'https://login.microsoftonline.com/common/oauth2/v2.0/'; 1664 | this.api_url = 'https://graph.microsoft.com/v1.0'; 1665 | this.scope = 'https://graph.microsoft.com/Files.ReadWrite.All offline_access'; 1666 | this.client_secret = encodeURIComponent(this.client_secret); 1667 | this.scope = encodeURIComponent(this.scope); 1668 | this.DownurlStrName = '@microsoft.graph.downloadUrl'; 1669 | let siteid = await getConfig('siteid', tag); 1670 | this.ext_api_url = '/sites/' + siteid + '/drive/root'; 1671 | this.access_token = ''; 1672 | let res = await this.get_access_token(await getConfig('refresh_token', tag)); 1673 | } 1674 | } 1675 | 1676 | class SharepointCN extends MS365 { 1677 | constructor(tag) { 1678 | super(tag); 1679 | return this; 1680 | } 1681 | async init(tag) { 1682 | //this.baseclassname = 'MS365'; 1683 | this.classname = 'SharepointCN'; 1684 | //this.disktag = tag; 1685 | //this.redirect_uri = 'https://scfonedrive.github.io'; 1686 | let client_id = await getConfig('client_id', tag); 1687 | let client_secret = await getConfig('client_secret', tag); 1688 | if (client_id!='' && client_secret!='') { 1689 | this.client_id = client_id; 1690 | this.client_secret = client_secret; 1691 | } else { 1692 | this.client_id = '31f3bed5-b9d9-4173-86a4-72c73d278617'; 1693 | this.client_secret = 'P5-ZNtFK-tT90J.We_-DcsuB8uV7AfjL8Y'; 1694 | } 1695 | this.oauth_url = 'https://login.partner.microsoftonline.cn/common/oauth2/v2.0/'; 1696 | this.api_url = 'https://microsoftgraph.chinacloudapi.cn/v1.0'; 1697 | this.scope = 'https://microsoftgraph.chinacloudapi.cn/Files.ReadWrite.All offline_access'; 1698 | this.client_secret = encodeURIComponent(this.client_secret); 1699 | this.scope = encodeURIComponent(this.scope); 1700 | this.DownurlStrName = '@microsoft.graph.downloadUrl'; 1701 | let siteid = await getConfig('siteid', tag); 1702 | this.ext_api_url = '/sites/' + siteid + '/drive/root'; 1703 | this.access_token = ''; 1704 | let res = await this.get_access_token(await getConfig('refresh_token', tag)); 1705 | } 1706 | } 1707 | 1708 | class Sharelink extends MS365 { 1709 | constructor(tag) { 1710 | super(tag); 1711 | return this; 1712 | } 1713 | async init(tag) { 1714 | //this.baseclassname = 'MS365'; 1715 | this.classname = 'SharepointCN'; 1716 | //this.disktag = tag; 1717 | //this.redirect_uri = 'https://scfonedrive.github.io'; 1718 | this.api_url = await getConfig('shareapiurl', tag); 1719 | this.ext_api_url = ''; 1720 | this.DownurlStrName = '@content.downloadUrl'; 1721 | this.access_token = ''; 1722 | let res = await this.get_access_token(1); 1723 | } 1724 | async get_access_token(refresh_token) { 1725 | this.access_token = await getcache('access_token', this.disktag); 1726 | if (this.access_token == '') { 1727 | let shareurl = await getConfig('shareurl', this.disktag); 1728 | this.sharecookie = await getcache('sharecookie', this.disktag); 1729 | if (this.sharecookie == '') { 1730 | this.sharecookie = await curl('GET', shareurl, false, [], 1)['returnhead']['Set-Cookie']; 1731 | //tmp = curl_request(shareurl, false, [], 1); 1732 | //tmp['body'] .= json_encode(tmp['returnhead'],JSON_PRETTY_PRINT); 1733 | //return tmp; 1734 | //SERVER['sharecookie'] = tmp['returnhead']['Set-Cookie']; 1735 | //if (tmp['stat']==302) $url = tmp['returnhead']['Location']; 1736 | //return curl('GET', $url, [ 'Accept' => 'application/json;odata=verbose', 'Content-Type' => 'application/json;odata=verbose', 'Cookie' => SERVER['sharecookie'] ]); 1737 | await savecache('sharecookie', this.sharecookie, this.disktag); 1738 | } 1739 | let tmp1 = splitlast(shareurl, '/')[0]; 1740 | let account = splitlast(tmp1, '/')[1]; 1741 | let domain = splitlast(shareurl, '/:')[0]; 1742 | let response = await curl('POST', 1743 | domain + "/personal/" + account + "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" + encodeURIComponent("/personal/" + account + "/Documents") + "'&RootFolder=" + encodeURIComponent("/personal/" + account + "/Documents/") + "&TryNewExperienceSingle=TRUE", 1744 | '{"parameters":{"__metadata":{"type":"SP.RenderListDataParameters"},"RenderOptions":136967,"AllowMultipleValueFilterForTaxonomyFields":true,"AddRequiredFields":true}}', 1745 | { 'Accept' : 'application/json;odata=verbose', 'Content-Type' : 'application/json;odata=verbose', 'origin' : domain, 'Cookie' : this.sharecookie } 1746 | ); 1747 | let res = new Object(); 1748 | if (response['stat']==200) res = JSON.parse(response['body']); 1749 | this.access_token = splitlast(res['ListSchema']['.driveAccessToken'],'=')[1]; 1750 | this.api_url = res['ListSchema']['.driveUrl'] + '/root'; 1751 | if (this.access_token == '') { 1752 | //error_log1($domain . "/personal/" . $account . "/_api/web/GetListUsingPath(DecodedUrl=@a1)/RenderListDataAsStream?@a1='" . urlencode("/personal/" . $account . "/Documents") . "'&RootFolder=" . urlencode("/personal/" . $account . "/Documents/") . "&TryNewExperienceSingle=TRUE"); 1753 | //error_log1('failed to get share access_token. response' . json_encode($ret)); 1754 | //response['body'] = json_encode(json_decode($response['body']), JSON_PRETTY_PRINT); 1755 | response['body'] += '\nfailed to get shareurl access_token.'; 1756 | return response; 1757 | //throw new Exception($response['stat'].', failed to get share access_token.'.$response['body']); 1758 | } 1759 | //tmp = $ret; 1760 | //tmp['access_token'] = '******'; 1761 | //error_log1('['.this.disktag.'] Get access token:'.json_encode(tmp, JSON_PRETTY_PRINT)); 1762 | await savecache('access_token', this.access_token, this.disktag); 1763 | tmp1 = null; 1764 | if (await getConfig('shareapiurl', this.disktag)!=this.api_url) tmp1['shareapiurl'] = this.api_url; 1765 | //if (getConfig('sharecookie', this.disktag)!=this.sharecookie) tmp1['sharecookie'] = this.sharecookie; 1766 | if (tmp1!=null) await setConfig(tmp1); 1767 | return true; 1768 | } 1769 | return true; 1770 | } 1771 | } 1772 | 1773 | async function render(path, files) { 1774 | let sitename = await getConfig('sitename'); 1775 | if (sitename==='') sitename = 'OneManager'; 1776 | 1777 | if (('list' in files) && ('index.html' in files['list']) && !SERVER['admin']) { 1778 | //$htmlcontent = fetch_files(spurlencode(path_format(urldecode(path) . '/index.html'), '/'))['content']; 1779 | let htmlcontent = (await get_content(spurlencode(path_format(decodeURIComponent(path) + '/index.html'), '/')))['content']; 1780 | return output(htmlcontent['body'], htmlcontent['stat']); 1781 | } 1782 | path = path.replace('%20','%2520'); 1783 | path = path.replace('+','%2B'); 1784 | path = path_format(decodeURIComponent(path)).replace('&','&',); 1785 | path = path.replace('%20',' '); 1786 | path = path.replace('#','%23'); 1787 | let p_path=''; 1788 | let pretitle = ''; 1789 | if (path !== '/') { 1790 | if (('type' in files) && files['type']=='file') { 1791 | pretitle = files['name'].replace('&','&'); 1792 | /*n_path = pretitle; 1793 | tmp = splitlast(splitlast(path,'/')[0],'/'); 1794 | if (tmp[1]=='') { 1795 | $p_path = tmp[0]; 1796 | } else { 1797 | $p_path = tmp[1]; 1798 | }*/ 1799 | } else { 1800 | if (path.substr(0, 1)=='/') pretitle = path.substr(1); 1801 | if (pretitle.substr(-1)=='/') pretitle = pretitle.substr(0, pretitle.length-1); 1802 | /*tmp=splitlast($pretitle,'/'); 1803 | if (tmp[1]=='') { 1804 | $n_path = tmp[0]; 1805 | } else { 1806 | $n_path = tmp[1]; 1807 | tmp = splitlast(tmp[0],'/'); 1808 | if (tmp[1]=='') { 1809 | $p_path = tmp[0]; 1810 | } else { 1811 | $p_path = tmp[1]; 1812 | } 1813 | }*/ 1814 | } 1815 | } else { 1816 | pretitle = '首页'; 1817 | n_path = pretitle; 1818 | } 1819 | 1820 | let authinfo =` 1821 | `; 1825 | 1826 | let theme1 = await fetch(THEME); 1827 | let html = await theme1.text(); 1828 | 1829 | let tmp = html.split(''); 1830 | html = tmp[0]; 1831 | tmp = tmp[1].split(''); 1832 | let IconValues = JSON.parse(tmp[0]); 1833 | html += tmp[1]; 1834 | 1835 | html = html.replace(//g, 'zh-CN'); 1836 | html = html.replace(//g, SERVER['base_path']); 1837 | tmp = splitfirst(html, ''); 1838 | html = tmp[0]; 1839 | tmp = splitfirst(tmp[1], ''); 1840 | html += tmp[1]; 1841 | 1842 | if (files==null||JSON.stringify(files)=='{}'||files=='') { 1843 | while (html.indexOf('')!==-1) { 1844 | tmp = splitfirst(html, ''); 1845 | html = tmp[0]; 1846 | tmp = splitfirst(tmp[1], ''); 1847 | html += tmp[1]; 1848 | } 1849 | while (html.indexOf('')!==-1) { 1850 | tmp = splitfirst(html, ''); 1851 | html = tmp[0]; 1852 | tmp = splitfirst(tmp[1], ''); 1853 | html += tmp[1]; 1854 | } 1855 | while (html.indexOf('')!==-1) { 1856 | tmp = splitfirst(html, ''); 1857 | html = tmp[0]; 1858 | tmp = splitfirst(tmp[1], ''); 1859 | html += tmp[1]; 1860 | } 1861 | while (html.indexOf('')!==-1) { 1862 | tmp = splitfirst(html, ''); 1863 | html = tmp[0]; 1864 | tmp = splitfirst(tmp[1], ''); 1865 | html += tmp[1]; 1866 | } 1867 | while (html.indexOf('')!==-1) { 1868 | tmp = splitfirst(html, ''); 1869 | html = tmp[0]; 1870 | tmp = splitfirst(tmp[1], ''); 1871 | html += tmp[1]; 1872 | } 1873 | while (html.indexOf('')!==-1) { 1874 | tmp = splitfirst(html, ''); 1875 | html = tmp[0]; 1876 | tmp = splitfirst(tmp[1], ''); 1877 | html += tmp[1]; 1878 | } 1879 | while (html.indexOf('')!==-1) { 1880 | tmp = splitfirst(html, ''); 1881 | html = tmp[0]; 1882 | tmp = splitfirst(tmp[1], ''); 1883 | html += tmp[1]; 1884 | } 1885 | while (html.indexOf('')!==-1) { 1886 | tmp = splitfirst(html, ''); 1887 | html = tmp[0]; 1888 | tmp = splitfirst(tmp[1], ''); 1889 | html += tmp[1]; 1890 | } 1891 | while (html.indexOf('')!==-1) { 1892 | tmp = splitfirst(html, ''); 1893 | html = tmp[0]; 1894 | tmp = splitfirst(tmp[1], ''); 1895 | html += tmp[1]; 1896 | } 1897 | } 1898 | if (SERVER['admin']===true) { 1899 | while (html.indexOf('')!==-1) { 1900 | tmp = splitfirst(html, ''); 1901 | html = tmp[0]; 1902 | tmp = splitfirst(tmp[1], ''); 1903 | html += tmp[1]; 1904 | } 1905 | while (html.indexOf('')!==-1) { 1906 | tmp = splitfirst(html, ''); 1907 | html = tmp[0]; 1908 | tmp = splitfirst(tmp[1], ''); 1909 | html += tmp[1]; 1910 | } 1911 | while (html.indexOf('')!==-1) { 1912 | html = html.replace(//g, ''); 1913 | html = html.replace(//g, ''); 1914 | } 1915 | html = html.replace(//g, '管理'); 1916 | html = html.replace(//g, '创建'); 1917 | html = html.replace(//g, '加密'); 1918 | html = html.replace(//g, '刷新缓存'); 1919 | html = html.replace(//g, '设置'); 1920 | html = html.replace(//g, '登出'); 1921 | html = html.replace(//g, '重命名'); 1922 | html = html.replace(//g, '提交'); 1923 | html = html.replace(//g, '删除'); 1924 | html = html.replace(//g, '复制'); 1925 | html = html.replace(//g, '移动'); 1926 | html = html.replace(//g, '目录'); 1927 | html = html.replace(//g, '文件'); 1928 | html = html.replace(//g, '名'); 1929 | html = html.replace(//g, '内容'); 1930 | } else { 1931 | while (html.indexOf('')!==-1) { 1932 | tmp = splitfirst(html, ''); 1933 | html = tmp[0]; 1934 | tmp = splitfirst(tmp[1], ''); 1935 | html += tmp[1]; 1936 | } 1937 | let adminloginpage = await getConfig('adminloginpage'); 1938 | if (adminloginpage==null||adminloginpage=='') { 1939 | //while (html.indexOf('')!==-1) { 1940 | html = html.replace(//g, ''); 1941 | html = html.replace(//g, ''); 1942 | //} 1943 | html = html.replace(//g, '登录'); 1944 | } else { 1945 | while (html.indexOf('')!==-1) { 1946 | tmp = splitfirst(html, ''); 1947 | html = tmp[0]; 1948 | tmp = splitfirst(tmp[1], ''); 1949 | html += tmp[1]; 1950 | } 1951 | } 1952 | html = html.replace(//g, ''); 1953 | html = html.replace(//g, ''); 1954 | } 1955 | if (SERVER['ishidden']==4) { 1956 | // 加密状态 1957 | if (await getConfig('dontBasicAuth')=='') { 1958 | // use Basic Auth 1959 | return output('Need password.', 401, {'WWW-Authenticate':'Basic realm="Secure Area"'}); 1960 | } 1961 | while (html.indexOf('')!==-1) { 1962 | tmp = splitfirst(html, ''); 1963 | html = tmp[0]; 1964 | tmp = splitfirst(tmp[1], ''); 1965 | html += tmp[1]; 1966 | } 1967 | while (html.indexOf('')!==-1) { 1968 | tmp = splitfirst(html, ''); 1969 | html = tmp[0]; 1970 | tmp = splitfirst(tmp[1], ''); 1971 | html += tmp[1]; 1972 | } 1973 | while (html.indexOf('')!==-1) { 1974 | tmp = splitfirst(html, ''); 1975 | html = tmp[0]; 1976 | tmp = splitfirst(tmp[1], ''); 1977 | html += tmp[1]; 1978 | } 1979 | html = html.replace(//g, ''); 1980 | html = html.replace(//g, ''); 1981 | while (html.indexOf('')!==-1) { 1982 | tmp = splitfirst(html, ''); 1983 | html = tmp[0]; 1984 | tmp = splitfirst(tmp[1], ''); 1985 | html += tmp[1]; 1986 | } 1987 | while (html.indexOf('')!==-1) { 1988 | tmp = splitfirst(html, ''); 1989 | html = tmp[0]; 1990 | tmp = splitfirst(tmp[1], ''); 1991 | html += tmp[1]; 1992 | } 1993 | while (html.indexOf('')!==-1) { 1994 | tmp = splitfirst(html, ''); 1995 | html = tmp[0]; 1996 | tmp = splitfirst(tmp[1], ''); 1997 | html += tmp[1]; 1998 | } 1999 | while (html.indexOf('')!==-1) { 2000 | tmp = splitfirst(html, ''); 2001 | html = tmp[0]; 2002 | tmp = splitfirst(tmp[1], ''); 2003 | html += tmp[1]; 2004 | } 2005 | while (html.indexOf('')!==-1) { 2006 | tmp = splitfirst(html, ''); 2007 | html = tmp[0]; 2008 | tmp = splitfirst(tmp[1], ''); 2009 | html += tmp[1]; 2010 | } 2011 | } else { 2012 | while (html.indexOf('')!==-1) { 2013 | tmp = splitfirst(html, ''); 2014 | html = tmp[0]; 2015 | tmp = splitfirst(tmp[1], ''); 2016 | html += tmp[1]; 2017 | } 2018 | html = html.replace(//g, ''); 2019 | html = html.replace(//g, ''); 2020 | } 2021 | html = html.replace(//g, '下载'); 2022 | if (SERVER['is_guestup_path']===true&&SERVER['admin']!==true) { 2023 | while (html.indexOf('')!==-1) { 2024 | tmp = splitfirst(html, ''); 2025 | html = tmp[0]; 2026 | tmp = splitfirst(tmp[1], ''); 2027 | html += tmp[1]; 2028 | } 2029 | while (html.indexOf('')!==-1) { 2030 | tmp = splitfirst(html, ''); 2031 | html = tmp[0]; 2032 | tmp = splitfirst(tmp[1], ''); 2033 | html += tmp[1]; 2034 | } 2035 | while (html.indexOf('')!==-1) { 2036 | tmp = splitfirst(html, ''); 2037 | html = tmp[0]; 2038 | tmp = splitfirst(tmp[1], ''); 2039 | html += tmp[1]; 2040 | } 2041 | html = html.replace(//g, ''); 2042 | html = html.replace(//g, ''); 2043 | } else { 2044 | while (html.indexOf('')!==-1) { 2045 | tmp = splitfirst(html, ''); 2046 | html = tmp[0]; 2047 | tmp = splitfirst(tmp[1], ''); 2048 | html += tmp[1]; 2049 | } 2050 | html = html.replace(//g, ''); 2051 | html = html.replace(//g, ''); 2052 | } 2053 | if (SERVER['is_guestup_path']==true||( SERVER['admin']==true&&files['type']=='folder' )) { 2054 | html = html.replace(//g, ''); 2055 | html = html.replace(//g, ''); 2056 | 2057 | html = html.replace(//g, ''); 2058 | html = html.replace(//g, ''); 2059 | while (html.indexOf('')!==-1) { 2060 | tmp = splitfirst(html, ''); 2061 | html = tmp[0]; 2062 | tmp = splitfirst(tmp[1], ''); 2063 | html += tmp[1]; 2064 | } 2065 | 2066 | html = html.replace(//g, '计算'); 2067 | } else { 2068 | while (html.indexOf('')!==-1) { 2069 | tmp = splitfirst(html, ''); 2070 | html = tmp[0]; 2071 | tmp = splitfirst(tmp[1], ''); 2072 | html += tmp[1]; 2073 | } 2074 | while (html.indexOf('')!==-1) { 2075 | tmp = splitfirst(html, ''); 2076 | html = tmp[0]; 2077 | tmp = splitfirst(tmp[1], ''); 2078 | html += tmp[1]; 2079 | } 2080 | while (html.indexOf('')!==-1) { 2081 | tmp = splitfirst(html, ''); 2082 | html = tmp[0]; 2083 | tmp = splitfirst(tmp[1], ''); 2084 | html += tmp[1]; 2085 | } 2086 | } 2087 | if (files!=null&&files['type']=='file') { 2088 | while (html.indexOf('')!==-1) { 2089 | tmp = splitfirst(html, ''); 2090 | html = tmp[0]; 2091 | tmp = splitfirst(tmp[1], ''); 2092 | html += tmp[1]; 2093 | } 2094 | while (html.indexOf('')!==-1) { 2095 | tmp = splitfirst(html, ''); 2096 | html = tmp[0]; 2097 | tmp = splitfirst(tmp[1], ''); 2098 | html += tmp[1]; 2099 | } 2100 | while (html.indexOf('')!==-1) { 2101 | tmp = splitfirst(html, ''); 2102 | html = tmp[0]; 2103 | tmp = splitfirst(tmp[1], ''); 2104 | html += tmp[1]; 2105 | } 2106 | html = html.replace(//g, ''); 2107 | html = html.replace(//g, ''); 2108 | html = html.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path)); 2109 | //html = str_replace('', str_replace('%2523', '%23', str_replace('%26amp%3B','&',spurlencode(path_format(_SERVER['base_disk_path'] . '/' . path), '/'))), html); 2110 | html = html.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path)); 2111 | 2112 | let ext = (splitlast(path, '.')[1]).toLowerCase(); 2113 | if (exts['img'].indexOf(ext)>-1) ext = 'img'; 2114 | else if (exts['video'].indexOf(ext)>-1) ext = 'video'; 2115 | else if (exts['music'].indexOf(ext)>-1) ext = 'music'; 2116 | //elseif (in_array(ext, exts['pdf'])) ext = 'pdf'; 2117 | else if (ext=='pdf') ext = 'pdf'; 2118 | else if (exts['office'].indexOf(ext)>-1) ext = 'office'; 2119 | else if (exts['txt'].indexOf(ext)>-1) ext = 'txt'; 2120 | else ext = 'Other'; 2121 | let previewext = ['img', 'video', 'music', 'pdf', 'office', 'txt', 'Other']; 2122 | //previewext = array_diff(previewext, [ ext ]); 2123 | for (let num in previewext) { 2124 | let ext1 = previewext[num]; 2125 | if (ext!=ext1) { 2126 | while (html.indexOf('')!==-1) { 2127 | tmp = splitfirst(html, ''); 2128 | html = tmp[0]; 2129 | tmp = splitfirst(tmp[1], ''); 2130 | html += tmp[1]; 2131 | } 2132 | } else { 2133 | let startreg = new RegExp('//g') 2134 | html = html.replace(startreg, ''); 2135 | let endreg = new RegExp('//g') 2136 | html = html.replace(endreg, ''); 2137 | } 2138 | } 2139 | //while (strpos(html, '')) html = str_replace('', files[_SERVER['DownurlStrName']], html); 2140 | html = html.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path)); 2141 | html = html.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path)); 2142 | html = html.replace(//g, files['name']); 2143 | html = html.replace(//g, encodeURIComponent(files['url'])); 2144 | html = html.replace(//g, '点击后编辑'); 2145 | html = html.replace(//g, '取消编辑'); 2146 | html = html.replace(//g, '保存'); 2147 | if (html.indexOf('')>-1) html = html.replace(//g, htmlSpecialChars( (await curl('GET', files['url']))['body'] ) ); 2148 | html = html.replace(//g, '文件不支持'); 2149 | 2150 | } else if (files!=null&&files['type']=='folder') { 2151 | while (html.indexOf('')!==-1) { 2152 | tmp = splitfirst(html, ''); 2153 | html = tmp[0]; 2154 | tmp = splitfirst(tmp[1], ''); 2155 | html += tmp[1]; 2156 | } 2157 | while (html.indexOf('')!==-1) { 2158 | tmp = splitfirst(html, ''); 2159 | html = tmp[0]; 2160 | tmp = splitfirst(tmp[1], ''); 2161 | html += tmp[1]; 2162 | } 2163 | while (html.indexOf('')!==-1) { 2164 | tmp = splitfirst(html, ''); 2165 | html = tmp[0]; 2166 | tmp = splitfirst(tmp[1], ''); 2167 | html += tmp[1]; 2168 | } 2169 | html = html.replace(//g, ''); 2170 | html = html.replace(//g, ''); 2171 | html = html.replace(//g, '文件'); 2172 | html = html.replace(//g, '缩略图'); 2173 | html = html.replace(//g, '复制下载链接'); 2174 | html = html.replace(//g, '修改时间'); 2175 | html = html.replace(//g, '大小'); 2176 | 2177 | let filenum = 0; 2178 | tmp = splitfirst(html, ''); 2179 | html = tmp[0]; 2180 | tmp = splitfirst(tmp[1], ''); 2181 | let FolderList = tmp[0]; 2182 | for (let name in files['list']) { 2183 | let file = files['list'][name]; 2184 | if (file['type']=='folder') { 2185 | if (SERVER['admin'] || !isHideFile(file['name'])) { 2186 | filenum++; 2187 | let FolderListStr = FolderList.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path + '/' + file['name'])); 2188 | FolderListStr = FolderListStr.replace(//g, file['id']); 2189 | FolderListStr = FolderListStr.replace(//g, (('showname' in file)&&file['showname']!='')?file['showname']:file['name']); 2190 | FolderListStr = FolderListStr.replace(//g, time_format(file['time'])); 2191 | FolderListStr = FolderListStr.replace(//g, size_format(file['size'])); 2192 | FolderListStr = FolderListStr.replace(//g, filenum); 2193 | html += FolderListStr; 2194 | } 2195 | } 2196 | } 2197 | html += tmp[1]; 2198 | 2199 | tmp = splitfirst(html, ''); 2200 | html = tmp[0]; 2201 | tmp = splitfirst(tmp[1], ''); 2202 | let FileList = tmp[0]; 2203 | for (let name in files['list']) { 2204 | //console.log(FileList); 2205 | let file = files['list'][name]; 2206 | if (file['type']=='file') { 2207 | if (SERVER['admin'] || !isHideFile(file['name'])) { 2208 | let ext = (splitlast(file['name'], '.')[1]).toLowerCase(); 2209 | filenum++; 2210 | let FileListStr = FileList.replace(//g, path_format(SERVER['base_disk_path'] + '/' + path + '/' + file['name'])); 2211 | FileListStr = FileListStr.replace(//g, file['id']); 2212 | FileListStr = FileListStr.replace(//g, file['name'].replace('&','&')); 2213 | FileListStr = FileListStr.replace(//g, time_format(file['time'])); 2214 | FileListStr = FileListStr.replace(//g, size_format(file['size'])); 2215 | FileListStr = FileListStr.replace(//g, filenum); 2216 | 2217 | //FileListStr = str_replace('', path_format(_SERVER['base_disk_path'] . '/' . path . '/' . encode_str_replace(file['name'])), FolderList); 2218 | FileListStr = FileListStr.replace(//g, ext); 2219 | if (exts['music'].indexOf(ext)>-1) FileListStr = FileListStr.replace(//g, 'audio'); 2220 | else if (exts['video'].indexOf(ext)>-1) FileListStr = FileListStr.replace(//g, 'iframe'); 2221 | else FileListStr = FileListStr.replace(//g, ''); 2222 | //FileListStr = str_replace('', path_format(_SERVER['base_disk_path'] . '/' . path . '/' . str_replace('&','&', file['name'])), FileListStr); 2223 | if (IconValues!=null&&JSON.stringify(IconValues)!='{}') { 2224 | for (let key1 in IconValues) if (FileListStr.indexOf('')>-1) { 2225 | let value1 = IconValues[key1]; 2226 | if ((key1 in exts)&&(exts[key1].indexOf(ext)>-1)) { 2227 | FileListStr = FileListStr.replace('', value1); 2228 | } 2229 | if (ext==key1) { 2230 | FileListStr = FileListStr.replace('', value1); 2231 | } 2232 | //error_log1('file:'.file['name'].':'.key1); 2233 | } 2234 | if (FileListStr.indexOf('')>-1) FileListStr = FileListStr.replace('', IconValues['default']); 2235 | } 2236 | 2237 | html += FileListStr; 2238 | } 2239 | } 2240 | } 2241 | html += tmp[1]; 2242 | 2243 | while (html.indexOf('')>-1) html = html.replace('', filenum); 2244 | 2245 | if (files['childcount']>200) { 2246 | while (html.indexOf('')>-1) html = html.replace('', ''); 2247 | while (html.indexOf('')>-1) html = html.replace('', ''); 2248 | 2249 | let pagenum = files['page']; 2250 | if (pagenum=='') pagenum = 1; 2251 | let maxpage = Math.ceil(files['childcount']/200); 2252 | 2253 | if (pagenum!=1) { 2254 | html = html.replace('', ''); 2255 | html = html.replace('', ''); 2256 | html = html.replace('', '上一页'); 2257 | html = html.replace('', pagenum-1); 2258 | } else { 2259 | tmp = splitfirst(html, ''); 2260 | html = tmp[0]; 2261 | tmp = splitfirst(tmp[1], ''); 2262 | html += tmp[1]; 2263 | } 2264 | //html .= json_encode(files['folder']); 2265 | if (pagenum!=maxpage) { 2266 | html = html.replace('', ''); 2267 | html = html.replace('', ''); 2268 | html = html.replace('', '下一页'); 2269 | html = html.replace('', pagenum+1); 2270 | } else { 2271 | tmp = splitfirst(html, ''); 2272 | html = tmp[0]; 2273 | tmp = splitfirst(tmp[1], ''); 2274 | html += tmp[1]; 2275 | } 2276 | tmp = splitfirst(html, ''); 2277 | html = tmp[0]; 2278 | tmp = splitfirst(tmp[1], ''); 2279 | let MorePageListNow = tmp[0].replace('', pagenum); 2280 | html += tmp[1]; 2281 | 2282 | tmp = splitfirst(html, ''); 2283 | html = tmp[0]; 2284 | tmp = splitfirst(tmp[1], ''); 2285 | let MorePageList = tmp[0]; 2286 | for (page=1;page<=maxpage;page++) { 2287 | let MorePageListStr = ''; 2288 | if (page == pagenum) { 2289 | MorePageListStr = MorePageListNow; 2290 | } else { 2291 | MorePageListStr = MorePageList.replace('', page); 2292 | MorePageListStr = MorePageListStr.replace('', page); 2293 | } 2294 | html += MorePageListStr; 2295 | } 2296 | html += tmp[1]; 2297 | 2298 | while (html.indexOf('')>-1) html = html.replace('', maxpage); 2299 | 2300 | } else { 2301 | while (html.indexOf('')>-1) { 2302 | tmp = splitfirst(html, ''); 2303 | html = tmp[0]; 2304 | tmp = splitfirst(tmp[1], ''); 2305 | html += tmp[1]; 2306 | } 2307 | } 2308 | } 2309 | let title = pretitle; 2310 | if (SERVER['base_disk_path']!=SERVER['base_path']) { 2311 | let diskname = await getConfig('diskname', SERVER['disktag']); 2312 | if (diskname=='') diskname = SERVER['disktag']; 2313 | title += ' - ' + diskname; 2314 | } 2315 | title += ' - ' + sitename; 2316 | html = html.replace('', title); 2317 | 2318 | /*keywords = n_path; 2319 | if (p_path!='') keywords .= ', ' . p_path; 2320 | if (_SERVER['sitename']!='OneManager') keywords .= ', ' . _SERVER['sitename'] . ', OneManager'; 2321 | else keywords .= ', OneManager'; 2322 | html = str_replace('', keywords, html); 2323 | 2324 | if (_GET['preview']) { 2325 | description = n_path.', '.getconstStr('Preview');//'Preview of '. 2326 | } elseif (files['type']=='folder') { 2327 | description = n_path.', '.getconstStr('List');//'List of '.n_path.'. '; 2328 | } 2329 | //description .= 'In '._SERVER['sitename']; 2330 | html = str_replace('', description, html);*/ 2331 | 2332 | html = html.replace(//g, sitename); 2333 | html = html.replace(//g, SERVER['base_disk_path']); 2334 | html = html.replace(//g, path); 2335 | customCss = await getConfig('customCss'); 2336 | html = html.replace(//g, customCss!=null?customCss:''); 2337 | customScript = await getConfig('customScript'); 2338 | html = html.replace(//g, customScript!=null?customScript:''); 2339 | html = html.replace(//g, '首页'); 2340 | html = html.replace(//g, '关闭'); 2341 | html = html.replace(//g, '输入密码'); 2342 | html = html.replace(//g, '输入你想要的密码'); 2343 | html = html.replace(//g, '提交'); 2344 | html = html.replace(//g, '成功'); 2345 | html = html.replace(//g, '获取上传链接'); 2346 | html = html.replace(//g, '文件过大'); 2347 | html = html.replace(//g, '上传开始'); 2348 | html = html.replace(//g, '上传开始于'); 2349 | html = html.replace(//g, '最终上传'); 2350 | html = html.replace(//g, '本次'); 2351 | html = html.replace(//g, '上传'); 2352 | html = html.replace(//g, '平均速度'); 2353 | html = html.replace(//g, '当前速度'); 2354 | html = html.replace(//g, '期望'); 2355 | html = html.replace(//g, '上传出错,重新上传'); 2356 | html = html.replace(//g, '结束于'); 2357 | html = html.replace(//g, '上传结束'); 2358 | html = html.replace(//g, '复制链接'); 2359 | html = html.replace(//g, '上传失败,文件名可能有#'); 2360 | html = html.replace(//g, '获取文件名失败'); 2361 | html = html.replace(//g, '上传文件'); 2362 | html = html.replace(//g, '上传目录'); 2363 | html = html.replace(//g, '选择文件'); 2364 | html = html.replace(//g, GET['preview']==true?'?preview&':'?'); 2365 | 2366 | if (html.indexOf('')!==-1) { 2367 | tmp = splitfirst(html, ''); 2368 | html = tmp[0]; 2369 | tmp = splitfirst(tmp[1], ''); 2370 | let background = await getConfig('background'); 2371 | if (background!='') html += tmp[0].replace('', background); 2372 | html += tmp[1]; 2373 | } 2374 | if (html.indexOf('')!==-1) { 2375 | tmp = splitfirst(html, ''); 2376 | html = tmp[0]; 2377 | tmp = splitfirst(tmp[1], ''); 2378 | let backgroundm = await getConfig('backgroundm'); 2379 | if (backgroundm!='null') html += tmp[0].replace('', backgroundm); 2380 | html += tmp[1]; 2381 | } 2382 | //console.log(SERVER['disktag']); 2383 | let disknamenow = ''; 2384 | tmp = splitfirst(html, ''); 2385 | html = tmp[0]; 2386 | tmp = splitfirst(tmp[1], ''); 2387 | let disktags = (await getConfig('disktag')).split('|'); 2388 | let MultiDiskArea = ''; 2389 | let diskname = ''; 2390 | if (disktags.length>1) { 2391 | let tmp1 = tmp[1]; 2392 | tmp = splitfirst(tmp[0], ''); 2393 | MultiDiskArea = tmp[0]; 2394 | tmp = splitfirst(tmp[1], ''); 2395 | let MultiDisks = tmp[0]; 2396 | for (let key in disktags) { 2397 | let disk = disktags[key]; 2398 | if (disk!='') { 2399 | diskname = await getConfig('diskname', disk); 2400 | if (diskname=='') diskname = disk; 2401 | if (SERVER['disktag']==disk) disknamenow = diskname; 2402 | let MultiDisksStr = MultiDisks.replace(//g, path_format(SERVER['base_path'] + '/' + disk + '/')); 2403 | MultiDisksStr = MultiDisksStr.replace(//g, (SERVER['disktag']==disk?' now':'')); 2404 | MultiDisksStr = MultiDisksStr.replace(//g, diskname); 2405 | MultiDiskArea += MultiDisksStr; 2406 | } 2407 | } 2408 | MultiDiskArea += tmp[1]; 2409 | tmp[1] = tmp1; 2410 | } 2411 | html += MultiDiskArea + tmp[1]; 2412 | //if (strlen(diskname)>15) diskname = substr(diskname, 0, 12).'...'; 2413 | html = html.replace(//g, disknamenow); 2414 | 2415 | 2416 | tmp = splitfirst(html, ''); 2417 | html = tmp[0]; 2418 | if (tmp[1]!='') { 2419 | tmp = splitfirst(tmp[1], ''); 2420 | let PathArrayStr = tmp[0]; 2421 | let tmp_url = SERVER['base_disk_path']; 2422 | let tmp_path = (decodeURIComponent(SERVER['PHP_SELF'])).substr(tmp_url.length).replace(/\&/g, '&'); 2423 | while (tmp_path!='') { 2424 | let tmp1 = splitfirst(tmp_path, '/'); 2425 | let folder1 = tmp1[0]; 2426 | if (folder1!='') { 2427 | tmp_url += folder1 + '/'; 2428 | let PathArrayStr1 = PathArrayStr.replace('', (folder1==files['name']?'':tmp_url)); 2429 | PathArrayStr1 = PathArrayStr1.replace('', folder1); 2430 | html += PathArrayStr1; 2431 | } 2432 | tmp_path = tmp1[1]; 2433 | } 2434 | html += tmp[1]; 2435 | } 2436 | tmp = splitfirst(html, ''); 2437 | html = tmp[0]; 2438 | if (tmp[1]!='') { 2439 | tmp = splitfirst(tmp[1], ''); 2440 | let PathArrayStr = tmp[0]; 2441 | let tmp_url = SERVER['base_path']; 2442 | let tmp_path = (decodeURIComponent(SERVER['PHP_SELF'])).substr(tmp_url.length).replace(/\&/g, '&'); 2443 | while (tmp_path!='') { 2444 | let tmp1 = splitfirst(tmp_path, '/'); 2445 | let folder1 = tmp1[0]; 2446 | if (folder1!='') { 2447 | tmp_url += folder1 + '/'; 2448 | PathArrayStr1 = PathArrayStr.replace('', (folder1==files['name']?'':tmp_url)); 2449 | PathArrayStr1 = PathArrayStr1.replace('', (folder1==SERVER['disktag']?(disknamenow==''?SERVER['disktag']:disknamenow):folder1)); 2450 | html += PathArrayStr1; 2451 | } 2452 | tmp_path = tmp1[1]; 2453 | } 2454 | html += tmp[1]; 2455 | } 2456 | if (html.indexOf('')!==-1) { 2457 | tmp = splitfirst(html, ''); 2458 | html = tmp[0]; 2459 | tmp = splitfirst(tmp[1], ''); 2460 | html += tmp[1]; 2461 | } 2462 | tmp = splitfirst(html, ''); 2463 | html = tmp[0]; 2464 | tmp = splitfirst(tmp[1], ''); 2465 | let current_url = path_format(SERVER['PHP_SELF'] + '/'); 2466 | let parent_url = ''; 2467 | let BackArrow = ''; 2468 | if (current_url !== SERVER['base_path']) { 2469 | while (current_url.substr(-1) === '/') { 2470 | current_url = current_url.substr(0, current_url.length-1); 2471 | } 2472 | if (current_url.indexOf('/')>-1) { 2473 | parent_url = current_url.substr(0, current_url.lastIndexOf('/')); 2474 | } else { 2475 | parent_url = current_url; 2476 | } 2477 | BackArrow = tmp[0].replace('', parent_url + '/'); 2478 | } 2479 | html += BackArrow + tmp[1]; 2480 | 2481 | while (html.indexOf('')!==-1) { 2482 | tmp = splitfirst(html, ''); 2483 | html = tmp[0]; 2484 | tmp = splitfirst(tmp[1], ''); 2485 | let disableShowThumb = await getConfig('disableShowThumb'); 2486 | if (disableShowThumb=='') { 2487 | html += tmp[0].replace('', '原图'); 2488 | } 2489 | html += tmp[1]; 2490 | } 2491 | 2492 | let imgextstr = JSON.stringify(exts['img']); 2493 | imgextstr = imgextstr.substr(1, imgextstr.length-2); 2494 | html = html.replace('', imgextstr); 2495 | 2496 | html = html.replace(//g, sitename); 2497 | 2498 | tmp = splitfirst(html, ''); 2499 | html = tmp[0]; 2500 | tmp = splitfirst(tmp[1], ''); 2501 | if (('list' in files) && ('head.omf' in files['list'])) { 2502 | //let headomfcontent = files['list']['head.omf']; 2503 | let headomfcontent = await get_content(spurlencode(path_format(path + '/head.omf'), '/')); 2504 | //console.log(headomfcontent); 2505 | let headomfbody = headomfcontent['content']['body']; 2506 | let headomf = tmp[0].replace('', headomfbody); 2507 | html += headomf; 2508 | } 2509 | html += tmp[1]; 2510 | 2511 | tmp = splitfirst(html, ''); 2512 | html = tmp[0]; 2513 | tmp = splitfirst(tmp[1], ''); 2514 | if (('list' in files) && ('head.md' in files['list'])) { 2515 | let headmdcontent = await get_content(spurlencode(path_format(path + '/head.md'), '/')); 2516 | //console.log(headmdcontent); 2517 | let headmdbody = headmdcontent['content']['body']; 2518 | let headmd = tmp[0].replace('', headmdbody); 2519 | //let headmd = tmp[0].replace('', await get_content(spurlencode(path_format(path + '/head.md'), '/'))['content']['body']); 2520 | html += headmd + tmp[1]; 2521 | html = html.replace(//g, ''); 2522 | html = html.replace(//g, ''); 2523 | } else { 2524 | html += tmp[1]; 2525 | while (html.indexOf('')!==-1) { 2526 | tmp = splitfirst(html, ''); 2527 | html = tmp[0]; 2528 | tmp = splitfirst(tmp[1], ''); 2529 | html += tmp[1]; 2530 | } 2531 | } 2532 | 2533 | while (html.indexOf('')!==-1) { 2534 | tmp = splitfirst(html, ''); 2535 | html = tmp[0]; 2536 | tmp = splitfirst(tmp[1], ''); 2537 | if (JSON.stringify(files)!='{}') html += tmp[0]; 2538 | html += tmp[1]; 2539 | } 2540 | tmp = splitfirst(html, ''); 2541 | html = tmp[0]; 2542 | tmp = splitfirst(tmp[1], ''); 2543 | if (('list' in files) && ('readme.md' in files['list'])) { 2544 | let readmemdcontent = await get_content(spurlencode(path_format(path + '/readme.md'), '/')); 2545 | //console.log(headomfcontent); 2546 | let readmebody = readmemdcontent['content']['body']; 2547 | let Readmemd = tmp[0].replace('', readmebody); 2548 | //let Readmemd = tmp[0].replace('', await get_content(spurlencode(path_format(path + '/head.md'), '/'))['content']['body']); 2549 | html += Readmemd + tmp[1]; 2550 | html = html.replace(//g, ''); 2551 | html = html.replace(//g, ''); 2552 | } else { 2553 | html += tmp[1]; 2554 | while (html.indexOf('')!==-1) { 2555 | tmp = splitfirst(html, ''); 2556 | html = tmp[0]; 2557 | tmp = splitfirst(tmp[1], ''); 2558 | html += tmp[1]; 2559 | } 2560 | } 2561 | tmp = splitfirst(html, ''); 2562 | html = tmp[0]; 2563 | tmp = splitfirst(tmp[1], ''); 2564 | if (('list' in files) && ('foot.omf' in files['list'])) { 2565 | let footomfcontent = await get_content(spurlencode(path_format(path + '/foot.omf'), '/')); 2566 | //console.log(headomfcontent); 2567 | let footomfbody = footomfcontent['content']['body']; 2568 | let Footomf = tmp[0].replace('', footomfbody); 2569 | //let Footomf = tmp[0].replace('', await get_content(spurlencode(path_format(path + '/head.omf'), '/'))['content']['body']); 2570 | html += Footomf; 2571 | } 2572 | html += tmp[1]; 2573 | 2574 | tmp = splitfirst(html, ''); 2575 | html = tmp[0]; 2576 | tmp = splitfirst(tmp[1], ''); 2577 | if ((('list' in files) && ('head.md' in files['list']))||(('list' in files) && ('readme.md' in files['list']))) { 2578 | html += tmp[0]; 2579 | } 2580 | html += tmp[1]; 2581 | 2582 | if (await getConfig('passfile')!='') { 2583 | tmp = splitfirst(html, ''); 2584 | html = tmp[0]; 2585 | tmp = splitfirst(tmp[1], ''); 2586 | html += tmp[0].replace('', '加油') + tmp[1]; 2587 | tmp = splitfirst(html, ''); 2588 | html = tmp[0]; 2589 | tmp = splitfirst(tmp[1], ''); 2590 | html += tmp[1]; 2591 | } else { 2592 | tmp = splitfirst(html, ''); 2593 | html = tmp[0]; 2594 | tmp = splitfirst(tmp[1], ''); 2595 | html += tmp[0].replace('', '先设置passfile才能加密') + tmp[1]; 2596 | tmp = splitfirst(html, ''); 2597 | html = tmp[0]; 2598 | tmp = splitfirst(tmp[1], ''); 2599 | html += tmp[1]; 2600 | } 2601 | 2602 | tmp = splitfirst(html, ''); 2603 | html = tmp[0]; 2604 | tmp = splitfirst(tmp[1], ''); 2605 | if (path != '/') { 2606 | html += tmp[0].replace('', '上级目录'); 2607 | } 2608 | html += tmp[1]; 2609 | 2610 | tmp = splitfirst(html, ''); 2611 | html = tmp[0]; 2612 | tmp = splitfirst(tmp[1], ''); 2613 | let MoveDirs = tmp[0]; 2614 | if (('type' in files) && files['type']=='folder') { 2615 | for (let key in files['list']) { 2616 | let file = files['list'][key]; 2617 | 2618 | if (('type' in file) && file['type']=='folder') { 2619 | //str_replace('&','&', $file['name']) 2620 | let MoveDirsStr = MoveDirs.replace(//g, file['name']); 2621 | html += MoveDirsStr; 2622 | } 2623 | } 2624 | } 2625 | html += tmp[1]; 2626 | 2627 | tmp = splitfirst(html, ''); 2628 | html = tmp[0]; 2629 | tmp = splitfirst(tmp[1], ''); 2630 | //if (!('timezone' in COOKIE)) html += tmp[0].replace('', SERVER['timezone']); 2631 | html += tmp[1]; 2632 | html = html.replace(//g, SERVER['timezone']); 2633 | 2634 | 2635 | if (html.indexOf('{{.RawData}}')!==-1) { 2636 | let str = '['; 2637 | let i = 0; 2638 | for (let key in files['list']) { 2639 | let file = files['list'][key]; 2640 | if (SERVER['admin'] || !isHideFile(file['name'])) { 2641 | let file_tmp = new Object(); 2642 | file_tmp['name'] = file['name']; 2643 | file_tmp['size'] = size_format(file['size']); 2644 | file_tmp['date'] = time_format(file['lastModifiedDateTime']); 2645 | file_tmp['@time'] = file['date']; 2646 | file_tmp['@type'] = (file['type']=='folder')?'folder':'file'; 2647 | str += JSON.stringify(file_tmp) + ','; 2648 | } 2649 | } 2650 | if (str == '[') { 2651 | str = ''; 2652 | } else str = str.substr(0, str.length-1) + ']'; 2653 | html = html.replace('{{.RawData}}', btoa(str)); 2654 | } 2655 | 2656 | //清除换行 2657 | while (html.indexOf('\n\n')!==-1) html = html.replace(/\n\n/g, '\n'); 2658 | 2659 | tmp = splitfirst(html, ''); 2660 | html = tmp[0] + '' + authinfo + tmp[1]; 2661 | 2662 | //html += JSON.stringify(files, null, 2); 2663 | 2664 | let out_body = html; 2665 | let out_stat = 200; 2666 | let out_headers = new Headers(); 2667 | if ('Set-Cookie' in SERVER) out_headers.set('Set-Cookie', SERVER['Set-Cookie']); 2668 | out_headers.set('Content-Type', 'text/html'); 2669 | return output(out_body, out_stat, out_headers); 2670 | } 2671 | --------------------------------------------------------------------------------