common.php 119.0 KB
Newer Older
Q
qkqpttgf 已提交
1 2
<?php

Q
qkqpttgf 已提交
3
global $timezones;
R
v3  
root 已提交
4 5 6 7 8 9 10 11 12
global $slash;
global $drive;

global $EnvConfigs;
$EnvConfigs = [
    // 1 inner, 0 common
    // 1 showed/enableEdit, 0 hidden/disableEdit
    // 1 base64 to save, 0 not base64
    'APIKey'            => 0b000, // used in heroku.
R
root 已提交
13 14
    'SecretId'          => 0b000, // used in SCF/CFC.
    'SecretKey'         => 0b000, // used in SCF/CFC.
R
v3  
root 已提交
15 16 17 18 19
    'AccessKeyID'       => 0b000, // used in FC.
    'AccessKeySecret'   => 0b000, // used in FC.
    'HW_urn'            => 0b000, // used in FG.
    'HW_key'            => 0b000, // used in FG.
    'HW_secret'         => 0b000, // used in FG.
R
root 已提交
20
    'HerokuappId'       => 0b000, // used in heroku.
R
v3  
root 已提交
21

Q
qkqpttgf 已提交
22
    'admin'             => 0b000,
R
v3  
root 已提交
23 24 25 26 27
    'adminloginpage'    => 0b010,
    'autoJumpFirstDisk' => 0b010,
    'background'        => 0b011,
    'backgroundm'       => 0b011,
    'disableShowThumb'  => 0b010,
28
    //'disableChangeTheme'=> 0b010,
R
v3  
root 已提交
29 30 31 32 33 34 35 36 37
    'disktag'           => 0b000,
    'hideFunctionalityFile'=> 0b010,
    'timezone'          => 0b010,
    'passfile'          => 0b011,
    'sitename'          => 0b011,
    'customScript'      => 0b011,
    'customCss'         => 0b011,
    'customTheme'       => 0b011,
    'theme'             => 0b010,
Q
qkqpttgf 已提交
38
    'dontBasicAuth'     => 0b010,
R
refer  
root 已提交
39
    'referrer'          => 0b011,
R
root 已提交
40
    'forceHttps'        => 0b010,
R
v3  
root 已提交
41 42 43 44 45 46 47 48 49 50 51

    'Driver'            => 0b100,
    'client_id'         => 0b100,
    'client_secret'     => 0b101,
    'sharepointSite'    => 0b101,
    'shareurl'          => 0b101,
    //'sharecookie'       => 0b101,
    'shareapiurl'       => 0b101,
    'siteid'            => 0b100,
    'refresh_token'     => 0b100,
    'token_expires'     => 0b100,
Q
qkqpttgf 已提交
52
    'activeLimit'       => 0b100,
Q
qkqpttgf 已提交
53
    'driveId'           => 0b100,
R
root 已提交
54 55

    'diskname'          => 0b111,
R
root 已提交
56
    'diskDescription'   => 0b111,
R
root 已提交
57 58 59 60 61
    'domain_path'       => 0b111,
    'downloadencrypt'   => 0b110,
    'guestup_path'      => 0b111,
    'domainforproxy'    => 0b111,
    'public_path'       => 0b111,
Q
qkqpttgf 已提交
62 63
];

Q
qkqpttgf 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
$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'
);

R
v3  
root 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
function isCommonEnv($str)
{
    global $EnvConfigs;
    if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? false : true;
    else return null;
}

function isInnerEnv($str)
{
    global $EnvConfigs;
    if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b100 ) ? true : false;
    else return null;
}

function isShowedEnv($str)
{
    global $EnvConfigs;
    if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b010 ) ? true : false;
    else return null;
}

function isBase64Env($str)
{
    global $EnvConfigs;
    if (isset($EnvConfigs[$str])) return ( $EnvConfigs[$str] & 0b001 ) ? true : false;
    else return null;
}

126 127 128 129
function main($path)
{
    global $exts;
    global $constStr;
R
v3  
root 已提交
130 131
    global $slash;
    global $drive;
132

R
v3  
root 已提交
133 134
    $slash = '/';
    if (strpos(__DIR__, ':')) $slash = '\\';
Q
qkqpttgf 已提交
135
    $_SERVER['php_starttime'] = microtime(true);
Q
qkqpttgf 已提交
136
    $path = path_format($path);
R
root 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
    $_SERVER['PHP_SELF'] = path_format($_SERVER['base_path'] . $path);
    if (getConfig('forceHttps')&&$_SERVER['REQUEST_SCHEME']=='http') {
        if ($_GET) {
            $tmp = '';
            foreach ($_GET as $k => $v) {
                if ($v===true) $tmp .= '&' . $k;
                else $tmp .= '&' . $k . '=' . $v;
            }
            $tmp = substr($tmp, 1);
            if ($tmp!='') $param = '?' . $tmp;
        }
        return output('visit via https.', 302, [ 'Location' => 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . $param ]);
    }
Q
qkqpttgf 已提交
150 151 152 153 154 155 156 157 158 159 160
    if (in_array($_SERVER['firstacceptlanguage'], array_keys($constStr['languages']))) {
        $constStr['language'] = $_SERVER['firstacceptlanguage'];
    } else {
        $prelang = splitfirst($_SERVER['firstacceptlanguage'], '-')[0];
        foreach ( array_keys($constStr['languages']) as $lang) {
            if ($prelang == splitfirst($lang, '-')[0]) {
                $constStr['language'] = $lang;
                break;
            }
        }
    }
Q
qkqpttgf 已提交
161
    if (isset($_COOKIE['language'])&&$_COOKIE['language']!='') $constStr['language'] = $_COOKIE['language'];
162 163
    if ($constStr['language']=='') $constStr['language'] = 'en-us';
    $_SERVER['language'] = $constStr['language'];
Q
qkqpttgf 已提交
164 165 166
    $_SERVER['timezone'] = getConfig('timezone');
    if (isset($_COOKIE['timezone'])&&$_COOKIE['timezone']!='') $_SERVER['timezone'] = $_COOKIE['timezone'];
    if ($_SERVER['timezone']=='') $_SERVER['timezone'] = 0;
167 168 169 170 171 172 173 174 175 176 177 178 179

    if (getConfig('admin')=='') return install();
    if (getConfig('adminloginpage')=='') {
        $adminloginpage = 'admin';
    } else {
        $adminloginpage = getConfig('adminloginpage');
    }
    if (isset($_GET[$adminloginpage])) {
        if (isset($_GET['preview'])) {
            $url = $_SERVER['PHP_SELF'] . '?preview';
        } else {
            $url = path_format($_SERVER['PHP_SELF'] . '/');
        }
Q
qkqpttgf 已提交
180 181 182 183 184
        if (isset($_POST['password1'])) {
            $compareresult = compareadminsha1($_POST['password1'], $_POST['timestamp'], getConfig('admin'));
            if ($compareresult=='') {
                return adminform('admin', adminpass2cookie('admin', getConfig('admin')), $url);
            } else return adminform($compareresult);
185
        } else return adminform();
186
    }
Q
qkqpttgf 已提交
187
    if ( isset($_COOKIE['admin'])&&compareadminmd5($_COOKIE['admin'], 'admin', getConfig('admin')) ) {
188 189 190 191 192
        $_SERVER['admin']=1;
        $_SERVER['needUpdate'] = needUpdate();
    } else {
        $_SERVER['admin']=0;
    }
193 194 195 196 197 198 199 200 201
    if (isset($_GET['setup']))
        if ($_SERVER['admin']) {
            // setup Environments. 设置,对环境变量操作
            return EnvOpt($_SERVER['needUpdate']);
        } else {
            $url = path_format($_SERVER['PHP_SELF'] . '/');
            return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]);
        }

Q
qkqpttgf 已提交
202 203
    $_SERVER['sitename'] = getConfig('sitename');
    if (empty($_SERVER['sitename'])) $_SERVER['sitename'] = getconstStr('defaultSitename');
204
    $_SERVER['base_disk_path'] = $_SERVER['base_path'];
205
    $disktags = explode("|", getConfig('disktag'));
206
    //    echo 'count$disk:'.count($disktags);
207
    if (count($disktags)>1) {
Q
qkqpttgf 已提交
208
        if ($path=='/'||$path=='') {
R
v3  
root 已提交
209 210
            $files['type'] = 'folder';
            $files['childcount'] = count($disktags);
211
            $files['showname'] = 'root';
Q
qkqpttgf 已提交
212
            foreach ($disktags as $disktag) {
R
v3  
root 已提交
213 214 215
                $files['list'][$disktag]['type'] = 'folder';
                $files['list'][$disktag]['name'] = $disktag;
                $files['list'][$disktag]['showname'] = getConfig('diskname', $disktag);
Q
qkqpttgf 已提交
216
            }
Q
qkqpttgf 已提交
217 218
            if ($_GET['json']) {
                // return a json
Q
qkqpttgf 已提交
219
                return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
Q
qkqpttgf 已提交
220
            }
Q
qkqpttgf 已提交
221
            if (getConfig('autoJumpFirstDisk')) return output('', 302, [ 'Location' => path_format($_SERVER['base_path'].'/'.$disktags[0].'/') ]);
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
        } else {
            $_SERVER['disktag'] = splitfirst( substr(path_format($path), 1), '/' )[0];
            //$pos = strpos($path, '/');
            //if ($pos>1) $_SERVER['disktag'] = substr($path, 0, $pos);
            if (!in_array($_SERVER['disktag'], $disktags)) {
                $tmp = path_format($_SERVER['base_path'] . '/' . $disktags[0] . '/' . $path);
                if (!!$_GET) {
                    $tmp .= '?';
                    foreach ($_GET as $k => $v) {
                        if ($v === true) $tmp .= $k . '&';
                        else $tmp .= $k . '=' . $v . '&';
                    }
                    $tmp = substr($tmp, 0, -1);
                }
                return output('Please visit <a href="' . $tmp . '">' . $tmp . '</a>.', 302, [ 'Location' => $tmp ]);
                //return message('<meta http-equiv="refresh" content="2;URL='.$_SERVER['base_path'].'">Please visit from <a href="'.$_SERVER['base_path'].'">Home Page</a>.', 'Error', 404);
            }
            $path = substr($path, strlen('/' . $_SERVER['disktag']));
            if ($_SERVER['disktag']!='') $_SERVER['base_disk_path'] = path_format($_SERVER['base_disk_path'] . '/' . $_SERVER['disktag'] . '/');
Q
qkqpttgf 已提交
241
        }
242
    } else $_SERVER['disktag'] = $disktags[0];
243
    //    echo 'main.disktag:'.$_SERVER['disktag'].',path:'.$path.'';
244 245 246 247 248 249
    $_SERVER['list_path'] = getListpath($_SERVER['HTTP_HOST']);
    if ($_SERVER['list_path']=='') $_SERVER['list_path'] = '/';
    $_SERVER['is_guestup_path'] = is_guestup_path($path);
    $_SERVER['ajax']=0;
    if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) if ($_SERVER['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest') $_SERVER['ajax']=1;

R
v3  
root 已提交
250 251 252 253
    // Add disk
    if (isset($_GET['AddDisk'])) {
        if ($_SERVER['admin']) {
            if (!class_exists($_GET['AddDisk'])) require 'disk' . $slash . $_GET['AddDisk'] . '.php';
Q
qkqpttgf 已提交
254
                $drive = new $_GET['AddDisk']($_GET['disktag']);
R
v3  
root 已提交
255 256 257 258 259 260 261 262 263 264 265
                return $drive->AddDisk();
        } else {
            $url = $_SERVER['PHP_SELF'];
            if ($_GET) {
                $tmp = null;
                $tmp = '';
                foreach ($_GET as $k => $v) {
                    if ($k!='setup') {
                        if ($v===true) $tmp .= '&' . $k;
                        else $tmp .= '&' . $k . '=' . $v;
                    }
266
                }
R
v3  
root 已提交
267 268
                $tmp = substr($tmp, 1);
                if ($tmp!='') $url .= '?' . $tmp;
269
            }
R
v3  
root 已提交
270
            return output('<script>alert(\''.getconstStr('SetSecretsFirst').'\');</script>', 302, [ 'Location' => $url ]);
271
        }
R
v3  
root 已提交
272 273
    }

R
refer  
root 已提交
274 275
    if (!isreferhost()) return message('Must visit from designated host', 'NOT_ALLOWED', 403);

R
v3  
root 已提交
276 277 278
    // Show disks in root
    if ($files['showname'] == 'root') return render_list($path, $files);

Q
qkqpttgf 已提交
279
    if (!driveisfine($_SERVER['disktag'], $drive)) return render_list();
R
v3  
root 已提交
280 281 282 283 284

    // Operate
    if ($_SERVER['ajax']) {
        if ($_GET['action']=='del_upload_cache') {
            // del '.tmp' without login. 无需登录即可删除.tmp后缀文件
Q
qkqpttgf 已提交
285
            return $drive->del_upload_cache($path);
286
        }
R
v3  
root 已提交
287 288
        if ($_GET['action']=='upbigfile') {
            if (!$_SERVER['admin']) {
Q
qkqpttgf 已提交
289
                if (!$_SERVER['is_guestup_path']) return output('Not_Guest_Upload_Folder', 400);
R
v3  
root 已提交
290
                if (strpos($_GET['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
Q
qkqpttgf 已提交
291
                if (strpos($_POST['upbigfilename'], '../')!==false) return output('Not_Allow_Cross_Path', 400);
R
v3  
root 已提交
292 293 294 295
            }
            $path1 = path_format($_SERVER['list_path'] . path_format($path));
            if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
            return $drive->bigfileupload($path1);
296
        }
R
v3  
root 已提交
297 298 299 300 301
    }
    if ($_SERVER['admin']) {
        $tmp = adminoperate($path);
        if ($tmp['statusCode'] > 0) {
            $path1 = path_format($_SERVER['list_path'] . path_format($path));
Q
qkqpttgf 已提交
302 303
            if ($path1!='/'&&substr($path1,-1)=='/') $path1 = substr($path1, 0, -1);
            savecache('path_' . $path1, '', $_SERVER['disktag'], 1);
R
v3  
root 已提交
304
            return $tmp;
Q
qkqpttgf 已提交
305
        }
R
v3  
root 已提交
306 307 308 309 310 311 312 313 314 315 316 317 318
    } else {
        if ($_SERVER['ajax']) return output(getconstStr('RefreshtoLogin'),401);
    }
    $_SERVER['ishidden'] = passhidden($path);
    if (isset($_GET['thumbnails'])) {
        if ($_SERVER['ishidden']<4) {
            if (in_array(strtolower(substr($path, strrpos($path, '.') + 1)), $exts['img'])) {
                $path1 = path_format($_SERVER['list_path'] . path_format($path));
                if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
                $thumb_url = $drive->get_thumbnails_url($path1);
                if ($thumb_url!='') {
                    if ($_GET['location']) {
                        $url = $thumb_url;
R
root 已提交
319
                        $header['Location'] = $url;
R
v3  
root 已提交
320 321 322
                        $domainforproxy = '';
                        $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
                        if ($domainforproxy!='') {
R
root 已提交
323
                            $url = proxy_replace_domain($url, $domainforproxy, $header);
R
v3  
root 已提交
324
                        }
R
root 已提交
325
                        return output('', 302, $header);
R
v3  
root 已提交
326
                    } else return output($thumb_url);
327
                }
R
v3  
root 已提交
328 329 330 331 332 333 334 335
                return output('', 404);
            } else return output(json_encode($exts['img']), 400);
        } else return output('', 401);
    }

    // list folder
    if ($_SERVER['is_guestup_path'] && !$_SERVER['admin']) {
        $files = json_decode('{"type":"folder"}', true);
336 337 338 339
    } elseif ($_SERVER['ishidden']==4) {
        if (!getConfig('downloadencrypt', $_SERVER['disktag'])) {
            $files = json_decode('{"type":"folder"}', true);
        } else {
R
v3  
root 已提交
340 341 342
            $path1 = path_format($_SERVER['list_path'] . path_format($path));
            if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
            $files = $drive->list_files($path1);
343
            if ($files['type']=='folder') $files = json_decode('{"type":"folder"}', true);
Q
qkqpttgf 已提交
344
        }
R
v3  
root 已提交
345 346 347 348 349
    } else {
        $path1 = path_format($_SERVER['list_path'] . path_format($path));
        if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
        $files = $drive->list_files($path1);
    }
Q
qkqpttgf 已提交
350 351 352 353 354
    if ($files['type']=='folder' && !$_SERVER['admin']) {
        foreach ($files['list'] as $k => $v) {
            if (isHideFile($k)) unset($files['list'][$k]);
        }
    }
R
v3  
root 已提交
355 356 357

    if ($_GET['json']) {
        // return a json
Q
qkqpttgf 已提交
358
        return output(json_encode($files), 200, ['Content-Type' => 'application/json']);
R
v3  
root 已提交
359 360 361 362 363 364 365 366 367 368 369 370
    }
    // random file
    if (isset($_GET['random'])&&$_GET['random']!=='') {
        if ($_SERVER['ishidden']<4) {
            $tmp = [];
            foreach (array_keys($files['list']) as $filename) {
                if (strtolower(splitlast($filename, '.')[1])==strtolower($_GET['random'])) $tmp[$filename] = $files['list'][$filename]['url'];
            }
            $tmp = array_values($tmp);
            if (count($tmp)>0) {
                $url = $tmp[rand(0, count($tmp)-1)];
                if (isset($_GET['url'])) return output($url, 200);
R
root 已提交
371
                $header['Location'] = $url;
Q
qkqpttgf 已提交
372
                $domainforproxy = '';
R
v3  
root 已提交
373
                $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
Q
qkqpttgf 已提交
374
                if ($domainforproxy!='') {
R
root 已提交
375
                    $url = proxy_replace_domain($url, $domainforproxy, $header);
Q
qkqpttgf 已提交
376
                }
R
root 已提交
377
                return output('', 302, $header);
R
v3  
root 已提交
378 379 380 381 382 383 384 385 386 387 388
            } else return output('No ' . $_GET['random'] . 'file', 404);
        } else return output('Hidden', 401);
    }
    // is file && not preview mode, download file
    if ($files['type']=='file' && !isset($_GET['preview'])) {
        if ( $_SERVER['ishidden']<4 || (!!getConfig('downloadencrypt', $_SERVER['disktag'])&&$files['name']!=getConfig('passfile')) ) {
            $url = $files['url'];
            if ( strtolower(splitlast($files['name'], '.')[1])=='html' ) return output($files['content']['body'], $files['content']['stat']);
            else {
                if ($_SERVER['HTTP_RANGE']!='') $header['Range'] = $_SERVER['HTTP_RANGE'];
                $header['Location'] = $url;
R
root 已提交
389 390 391 392 393
                $domainforproxy = '';
                $domainforproxy = getConfig('domainforproxy', $_SERVER['disktag']);
                if ($domainforproxy!='') {
                    $url = proxy_replace_domain($url, $domainforproxy, $header);
                }
R
v3  
root 已提交
394
                return output('', 302, $header);
395 396 397
            }
        }
    }
R
v3  
root 已提交
398 399 400 401 402 403 404 405 406 407
    // Show folder
    if ( $files['type']=='folder' || $files['type']=='file' ) {
        return render_list($path, $files);
    } else {
        if (!isset($files['error'])) {
            if (is_array($files)) $files['error']['message'] = json_encode($files, JSON_PRETTY_PRINT);
            else $files['error']['message'] = $files;
            $files['error']['code'] = 'unknownError';
            $files['error']['stat'] = 500;
        }
Q
qkqpttgf 已提交
408
        return message('<div style="margin:8px;"><pre>' . $files['error']['message'] . '</pre></div><a href="javascript:history.back(-1)">'.getconstStr('Back').'</a>', $files['error']['code'], $files['error']['stat']);
R
v3  
root 已提交
409 410 411 412 413 414 415 416 417 418 419 420 421
    }
}

function get_content($path)
{
    global $drive;
    $path1 = path_format($_SERVER['list_path'] . path_format($path));
    if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1, 0, -1);
    $file = $drive->list_files($path1);
    //var_dump($file);
    return $file;
}

Q
qkqpttgf 已提交
422
function driveisfine($tag, &$drive = null)
R
v3  
root 已提交
423 424 425 426 427 428 429 430 431 432
{
    global $slash;
    $disktype = getConfig('Driver', $tag);
    if (!$disktype) return false;
    if (!class_exists($disktype)) require 'disk' . $slash . $disktype . '.php';
    $drive = new $disktype($tag);
    if ($drive->isfine()) return true;
    else return false;
}

Q
qkqpttgf 已提交
433
function baseclassofdrive($d = null)
R
v3  
root 已提交
434 435
{
    global $drive;
Q
qkqpttgf 已提交
436 437 438 439 440 441 442 443
    if (!$d) $dr = $drive;
    else $dr = $d;
    if (!$dr) return false;
    return $dr->show_base_class();
}

function extendShow_diskenv($drive)
{
Q
qkqpttgf 已提交
444
    if (!$drive) return [];
Q
qkqpttgf 已提交
445
    return $drive->ext_show_innerenv();
446 447
}

R
refer  
root 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460
function isreferhost() {
    $referer = $_SERVER['referhost'];
    if ($referer=='') return true;
    if ($referer==$_SERVER['HTTP_HOST']) return true;
    $referrer = getConfig('referrer');
    if ($referrer=='') return true;
    $arr = explode('|', $referrer);
    foreach ($arr as $host) {
        if ($host == $referer) return true;
    }
    return false;
}

Q
qkqpttgf 已提交
461
function adminpass2cookie($name, $pass)
Q
qkqpttgf 已提交
462
{
Q
qkqpttgf 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475
    $timestamp = time()+7*24*60*60;
    return md5($name . ':' . md5($pass) . '@' . $timestamp) . "(" . $timestamp . ")";
}
function compareadminmd5($admincookie, $name, $pass)
{
    $c = splitfirst($admincookie, '(');
    $c_md5 = $c[0];
    $c_time = substr($c[1], 0, -1);
    if (!is_numeric($c_time)) return false;
    if (time() > $c_time) return false;
    if (md5($name . ':' . md5($pass) . '@' . $c_time) == $c_md5) return true;
    else return false;
}
R
root 已提交
476

Q
qkqpttgf 已提交
477 478
function compareadminsha1($adminsha1, $timestamp, $pass)
{
Q
qkqpttgf 已提交
479
    if (!is_numeric($timestamp)) return 'Timestamp not Number';
Q
qkqpttgf 已提交
480 481
    if (abs(time()-$timestamp) > 5*60) {
        date_default_timezone_set('UTC');
Q
qkqpttgf 已提交
482
        return 'The timestamp in server is ' . time() . ' (' . date("Y-m-d H:i:s") . ' UTC),<br>and your posted timestamp is ' . $timestamp . ' (' . date("Y-m-d H:i:s", $timestamp) . ' UTC)';
Q
qkqpttgf 已提交
483
    }
Q
qkqpttgf 已提交
484 485
    if ($adminsha1 == sha1($timestamp . $pass)) return '';
    else return 'Error password';
Q
qkqpttgf 已提交
486 487
}

R
root 已提交
488
function proxy_replace_domain($url, $domainforproxy, &$header)
Q
qkqpttgf 已提交
489
{
R
root 已提交
490
    global $drive;
Q
qkqpttgf 已提交
491 492 493 494 495 496 497 498
    $tmp = splitfirst($url, '//');
    $http = $tmp[0];
    $tmp = splitfirst($tmp[1], '/');
    $domain = $tmp[0];
    $uri = $tmp[1];
    if (substr($domainforproxy, 0, 7)=='http://' || substr($domainforproxy, 0, 8)=='https://') $aim = $domainforproxy;
    else $aim = $http . '//' . $domainforproxy;
    if (substr($aim, -1)=='/') $aim = substr($aim, 0, -1);
R
root 已提交
499 500
    //$header['Location'] = $aim . '/' . $uri;
    //return $aim . '/' . $uri;
R
root 已提交
501 502
    if (strpos($url, '?')>0) $sp = '&';
    else $sp = '?';
R
root 已提交
503 504 505
    $aim .= '/' . $uri . $sp . 'Origindomain=' . $domain;
    if ($drive->show_base_class()=='Aliyundrive') $aim .= '&Aliyundrive';
    $header['Location'] = $aim;
R
root 已提交
506
    return $aim . '/' . $uri . $sp . 'Origindomain=' . $domain;
Q
qkqpttgf 已提交
507 508
}

Q
qkqpttgf 已提交
509 510 511 512 513
function isHideFile($name)
{
    $FunctionalityFile = [
        'head.md',
        'readme.md',
Q
qkqpttgf 已提交
514 515
        'head.omf',
        'foot.omf',
Q
qkqpttgf 已提交
516
        'favicon.ico',
R
root 已提交
517
        'robots.txt',
Q
qkqpttgf 已提交
518
        'index.html',
Q
qkqpttgf 已提交
519 520 521 522 523 524 525 526
    ];

    if ($name == getConfig('passfile')) return true;
    if (substr($name,0,1) == '.') return true;
    if (getConfig('hideFunctionalityFile')) if (in_array(strtolower($name), $FunctionalityFile)) return true;
    return false;
}

Q
qkqpttgf 已提交
527
function getcache($str, $disktag = '')
Q
qkqpttgf 已提交
528
{
Q
qkqpttgf 已提交
529
    $cache = filecache($disktag);
Q
qkqpttgf 已提交
530 531 532
    return $cache->fetch($str);
}

Q
qkqpttgf 已提交
533
function savecache($key, $value, $disktag = '', $exp = 1800)
Q
qkqpttgf 已提交
534
{
Q
qkqpttgf 已提交
535
    $cache = filecache($disktag);
Q
qkqpttgf 已提交
536 537 538
    return $cache->save($key, $value, $exp);
}

Q
qkqpttgf 已提交
539
function filecache($disktag)
Q
qkqpttgf 已提交
540 541 542
{
    $dir = sys_get_temp_dir();
    if (!is_writable($dir)) {
543 544 545 546
        $tmp = __DIR__ . '/tmp/';
        if (file_exists($tmp)) {
            if ( is_writable($tmp) ) $dir = $tmp;
        } elseif ( mkdir($tmp) ) $dir = $tmp;
Q
qkqpttgf 已提交
547
    }
Q
qkqpttgf 已提交
548
    $tag = __DIR__ . '/OneManager/' . $disktag;
Q
qkqpttgf 已提交
549
    while (strpos($tag, '/')>-1) $tag = str_replace('/', '_', $tag);
Q
qkqpttgf 已提交
550
    if (strpos($tag, ':')>-1) {
Q
qkqpttgf 已提交
551 552
        $tag = str_replace(':', '_', $tag);
        $tag = str_replace('\\', '_', $tag);
Q
qkqpttgf 已提交
553
    }
554
    // error_log1('DIR:' . $dir . ' TAG: ' . $tag);
Q
qkqpttgf 已提交
555 556
    $cache = new \Doctrine\Common\Cache\FilesystemCache($dir, $tag);
    return $cache;
Q
qkqpttgf 已提交
557 558
}

R
v3  
root 已提交
559
function sortConfig(&$arr)
Q
qkqpttgf 已提交
560
{
R
v3  
root 已提交
561
    ksort($arr);
Q
qkqpttgf 已提交
562

R
v3  
root 已提交
563 564 565 566 567 568 569 570 571 572 573
    $tags = explode('|', $arr['disktag']);
    unset($arr['disktag']);
    if ($tags[0]!='') {
        foreach($tags as $tag) {
            $disks[$tag] = $arr[$tag];
            unset($arr[$tag]);
        }
        $arr['disktag'] = implode('|', $tags);
        foreach($disks as $k => $v) {
            $arr[$k] = $v;
        }
574
    }
R
v3  
root 已提交
575 576

    return $arr;
Q
qkqpttgf 已提交
577 578
}

R
v3  
root 已提交
579
function getconstStr($str)
Q
qkqpttgf 已提交
580
{
R
v3  
root 已提交
581 582 583
    global $constStr;
    if ($constStr[$str][$constStr['language']]!='') return $constStr[$str][$constStr['language']];
    return $constStr[$str]['en-us'];
Q
qkqpttgf 已提交
584 585
}

Q
qkqpttgf 已提交
586 587
function getListpath($domain)
{
R
v3  
root 已提交
588 589
    $domain_path1 = getConfig('domain_path', $_SERVER['disktag']);
    $public_path = getConfig('public_path', $_SERVER['disktag']);
Q
qkqpttgf 已提交
590 591 592
    $tmp_path='';
    if ($domain_path1!='') {
        $tmp = explode("|",$domain_path1);
Q
qkqpttgf 已提交
593 594
        foreach ($tmp as $multidomain_paths){
            $pos = strpos($multidomain_paths,":");
Q
qkqpttgf 已提交
595 596 597 598 599
            if ($pos>0) {
                $domain1 = substr($multidomain_paths,0,$pos);
                $tmp_path = path_format(substr($multidomain_paths,$pos+1));
                $domain_path[$domain1] = $tmp_path;
                if ($public_path=='') $public_path = $tmp_path;
Q
qkqpttgf 已提交
600
            //if (substr($multidomain_paths,0,$pos)==$host_name) $private_path=$tmp_path;
Q
qkqpttgf 已提交
601
            }
Q
qkqpttgf 已提交
602
        }
Q
qkqpttgf 已提交
603
    }
Q
qkqpttgf 已提交
604
    if (isset($domain_path[$domain])) return spurlencode($domain_path[$domain],'/');
R
refer  
root 已提交
605
    return spurlencode($public_path, '/');
Q
qkqpttgf 已提交
606 607 608 609 610 611 612 613 614 615 616
}

function path_format($path)
{
    $path = '/' . $path;
    while (strpos($path, '//') !== FALSE) {
        $path = str_replace('//', '/', $path);
    }
    return $path;
}

617
function spurlencode($str, $split='')
Q
qkqpttgf 已提交
618
{
R
v3  
root 已提交
619
    $str = str_replace(' ', '%20', $str);
Q
qkqpttgf 已提交
620
    $tmp='';
Q
qkqpttgf 已提交
621
    if ($split!='') {
622 623 624
        $tmparr=explode($split, $str);
        foreach ($tmparr as $str1) {
            $tmp .= urlencode($str1) . $split;
Q
qkqpttgf 已提交
625
        }
R
v3  
root 已提交
626
        $tmp = substr($tmp, 0, strlen($tmp)-strlen($split));
Q
qkqpttgf 已提交
627 628 629
    } else {
        $tmp = urlencode($str);
    }
R
v3  
root 已提交
630 631
    $tmp = str_replace('%2520', '%20', $tmp);
    $tmp = str_replace('%26amp%3B', '&', $tmp);
Q
qkqpttgf 已提交
632 633 634
    return $tmp;
}

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
function base64y_encode($str)
{
    $str = base64_encode($str);
    while (substr($str,-1)=='=') $str=substr($str,0,-1);
    while (strpos($str, '+')!==false) $str = str_replace('+', '-', $str);
    while (strpos($str, '/')!==false) $str = str_replace('/', '_', $str);
    return $str;
}

function base64y_decode($str)
{
    while (strpos($str, '_')!==false) $str = str_replace('_', '/', $str);
    while (strpos($str, '-')!==false) $str = str_replace('-', '+', $str);
    while (strlen($str)%4) $str .= '=';
    $str = base64_decode($str);
R
v3  
root 已提交
650
    //if (strpos($str, '%')!==false) $str = urldecode($str);
Q
qkqpttgf 已提交
651 652 653
    return $str;
}

654 655 656 657 658
function error_log1($str)
{
    error_log($str);
}

Q
qkqpttgf 已提交
659 660
function is_guestup_path($path)
{
R
v3  
root 已提交
661 662 663 664 665
    if (getConfig('guestup_path', $_SERVER['disktag'])!='') {
        $a1 = path_format(path_format(urldecode($_SERVER['list_path'].path_format($path))).'/');
        $a2 = path_format(path_format(getConfig('guestup_path', $_SERVER['disktag'])).'/');
        if (strtolower($a1)==strtolower($a2)) return 1;
    }
Q
qkqpttgf 已提交
666 667 668
    return 0;
}

Q
qkqpttgf 已提交
669 670 671 672 673
function array_value_isnot_null($arr)
{
    return $arr!=='';
}

R
root 已提交
674
function curl($method, $url, $data = '', $headers = [], $returnheader = 0, $location = 0)
Q
qkqpttgf 已提交
675 676 677 678
{
    //if (!isset($headers['Accept'])) $headers['Accept'] = '*/*';
    //if (!isset($headers['Referer'])) $headers['Referer'] = $url;
    //if (!isset($headers['Content-Type'])) $headers['Content-Type'] = 'application/x-www-form-urlencoded';
R
root 已提交
679
    if (!isset($headers['Content-Type'])&&!isset($headers['content-type'])) $headers['Content-Type'] = '';
Q
qkqpttgf 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694
    $sendHeaders = array();
    foreach ($headers as $headerName => $headerVal) {
        $sendHeaders[] = $headerName . ': ' . $headerVal;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,$method);
    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, $returnheader);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $sendHeaders);
R
root 已提交
695
    if ($location) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Q
qkqpttgf 已提交
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
    //$response['body'] = curl_exec($ch);
    if ($returnheader) {
        list($returnhead, $response['body']) = explode("\r\n\r\n", curl_exec($ch));
        foreach (explode("\r\n", $returnhead) as $head) {
            $tmp = explode(': ', $head);
            $heads[$tmp[0]] = $tmp[1];
        }
        $response['returnhead'] = $heads;
    } else {
        $response['body'] = curl_exec($ch);
    }
    $response['stat'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $response;
}

Q
qkqpttgf 已提交
712 713 714 715 716
function clearbehindvalue($path,$page1,$maxpage,$pageinfocache)
{
    for ($page=$page1+1;$page<$maxpage;$page++) {
        $pageinfocache['nextlink_' . $path . '_page_' . $page] = '';
    }
Q
qkqpttgf 已提交
717
    $pageinfocache = array_filter($pageinfocache, 'array_value_isnot_null');
Q
qkqpttgf 已提交
718 719 720 721 722 723 724 725
    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'));
Q
qkqpttgf 已提交
726
        date_default_timezone_set(get_timezone($_SERVER['timezone']));
Q
qkqpttgf 已提交
727 728 729
        return 2;
    }
    if ($_COOKIE['password'] !== '') if ($_COOKIE['password'] === $pass ) return 3;
Q
qkqpttgf 已提交
730 731 732 733 734 735 736 737 738
    if (!getConfig('dontBasicAuth')) {
        // use Basic Auth
        //$_SERVER['PHP_AUTH_USER']
        if ($_SERVER['PHP_AUTH_PW'] !== '') if (md5($_SERVER['PHP_AUTH_PW']) === $pass ) {
            date_default_timezone_set('UTC');
            $_SERVER['Set-Cookie'] = 'password='.$pass.'; expires='.date(DATE_COOKIE,strtotime('+1hour'));
            date_default_timezone_set(get_timezone($_SERVER['timezone']));
            return 2;
        }
739
    }
Q
qkqpttgf 已提交
740 741 742 743 744
    return 4;
}

function encode_str_replace($str)
{
Q
qkqpttgf 已提交
745
    $str = str_replace('%','%25',$str);
Q
qkqpttgf 已提交
746
    if (strpos($str, '&amp;')) $str = str_replace('&amp;', '&amp;amp;', $str);
Q
qkqpttgf 已提交
747 748 749 750 751 752 753
    $str = str_replace('+','%2B',$str);
    $str = str_replace('#','%23',$str);
    return $str;
}

function gethiddenpass($path,$passfile)
{
Q
qkqpttgf 已提交
754
    $path1 = path_format($_SERVER['list_path'] . path_format($path));
Q
qkqpttgf 已提交
755
    if ($path1!='/'&&substr($path1,-1)=='/') $path1=substr($path1,0,-1);
Q
qkqpttgf 已提交
756
    $password=getcache('path_' . $path1 . '/?password', $_SERVER['disktag']);
Q
qkqpttgf 已提交
757
    if ($password=='') {
R
v3  
root 已提交
758
        $ispassfile = get_content(path_format($path . '/' . urlencode($passfile)));
Q
qkqpttgf 已提交
759
        //echo $path . '<pre>' . json_encode($ispassfile, JSON_PRETTY_PRINT) . '</pre>';
R
v3  
root 已提交
760 761
        if ($ispassfile['type']=='file') {
            $arr = curl('GET', $ispassfile['url']);
Q
qkqpttgf 已提交
762 763 764
            if ($arr['stat']==200) {
                $passwordf=explode("\n",$arr['body']);
                $password=$passwordf[0];
Q
qkqpttgf 已提交
765 766 767 768 769 770 771
                if ($password==='') {
                    return '';
                } else {
                    $password=md5($password);
                    savecache('path_' . $path1 . '/?password', $password, $_SERVER['disktag']);
                    return $password;
                }
Q
qkqpttgf 已提交
772 773 774 775
            } else {
                //return md5('DefaultP@sswordWhenNetworkError');
                return md5( md5(time()).rand(1000,9999) );
            }
Q
qkqpttgf 已提交
776
        } else {
Q
qkqpttgf 已提交
777
            savecache('path_' . $path1 . '/?password', 'null', $_SERVER['disktag']);
Q
qkqpttgf 已提交
778 779 780 781 782 783
            if ($path !== '' ) {
                $path = substr($path,0,strrpos($path,'/'));
                return gethiddenpass($path,$passfile);
            } else {
                return '';
            }
Q
qkqpttgf 已提交
784
        }
Q
qkqpttgf 已提交
785 786 787 788 789 790 791 792 793
    } elseif ($password==='null') {
        if ($path !== '' ) {
            $path = substr($path,0,strrpos($path,'/'));
            return gethiddenpass($path,$passfile);
        } else {
            return '';
        }
    } else return $password;
    // return md5('DefaultP@sswordWhenNetworkError');
Q
qkqpttgf 已提交
794 795 796 797
}

function get_timezone($timezone = '8')
{
Q
qkqpttgf 已提交
798
    global $timezones;
Q
qkqpttgf 已提交
799 800 801 802 803 804
    if ($timezone=='') $timezone = '8';
    return $timezones[$timezone];
}

function message($message, $title = 'Message', $statusCode = 200)
{
Q
qkqpttgf 已提交
805
    return output('
Q
qkqpttgf 已提交
806
<html lang="' . $_SERVER['language'] . '">
Q
qkqpttgf 已提交
807 808
<html>
    <meta charset=utf-8>
Q
qkqpttgf 已提交
809
    <meta name=viewport content="width=device-width,initial-scale=1">
Q
qkqpttgf 已提交
810 811
    <body>
        <h1>' . $title . '</h1>
R
refer  
root 已提交
812
        <a href="' . $_SERVER['base_path'] . '">' . getconstStr('Back') . getconstStr('Home') . '</a>
Q
qkqpttgf 已提交
813
        <p>
Q
qkqpttgf 已提交
814

Q
qkqpttgf 已提交
815
' . $message . '
Q
qkqpttgf 已提交
816

Q
qkqpttgf 已提交
817 818
        </p>
    </body>
Q
qkqpttgf 已提交
819 820
</html>
', $statusCode);
Q
qkqpttgf 已提交
821 822 823 824
}

function needUpdate()
{
R
v3  
root 已提交
825
    global $slash;
Q
qkqpttgf 已提交
826
    $current_version = file_get_contents(__DIR__ . $slash . 'version');
827
    $current_ver = substr($current_version, strpos($current_version, '.')+1);
Q
qkqpttgf 已提交
828 829
    $current_ver = explode(urldecode('%0A'),$current_ver)[0];
    $current_ver = explode(urldecode('%0D'),$current_ver)[0];
830
    $split = splitfirst($current_version, '.' . $current_ver)[0] . '.' . $current_ver;
R
v3  
root 已提交
831 832 833 834 835 836
    if (!($github_version = getcache('github_version'))) {
        $tmp = curl('GET', 'https://raw.githubusercontent.com/qkqpttgf/OneManager-php/master/version');
        if ($tmp['stat']==0) return 0;
        $github_version = $tmp['body'];
        savecache('github_version', $github_version);
    }
Q
qkqpttgf 已提交
837 838 839 840
    $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) {
841 842 843
        //$_SERVER['github_version'] = $github_version;
        $_SERVER['github_ver_new'] = splitfirst($github_version, $split)[0];
        $_SERVER['github_ver_old'] = splitfirst($github_version, $_SERVER['github_ver_new'])[1];
Q
qkqpttgf 已提交
844
        return 1;
Q
qkqpttgf 已提交
845 846 847 848 849 850
    }
    return 0;
}

function output($body, $statusCode = 200, $headers = ['Content-Type' => 'text/html'], $isBase64Encoded = false)
{
R
refer  
root 已提交
851
    if (isset($_SERVER['Set-Cookie'])) $headers['Set-Cookie'] = $_SERVER['Set-Cookie'];
Q
qkqpttgf 已提交
852
    if (baseclassofdrive()=='Aliyundrive') $headers['Referrer-Policy'] = 'no-referrer';
R
root 已提交
853 854
    //$headers['Referrer-Policy'] = 'same-origin';
    //$headers['X-Frame-Options'] = 'sameorigin';
Q
qkqpttgf 已提交
855 856 857 858 859 860 861 862 863 864
    return [
        'isBase64Encoded' => $isBase64Encoded,
        'statusCode' => $statusCode,
        'headers' => $headers,
        'body' => $body
    ];
}

function passhidden($path)
{
865
    if ($_SERVER['admin']) return 0;
Q
qkqpttgf 已提交
866 867 868
    $path = str_replace('+','%2B',$path);
    $path = str_replace('&amp;','&', path_format(urldecode($path)));
    if (getConfig('passfile') != '') {
Q
qkqpttgf 已提交
869
        $path = spurlencode($path,'/');
Q
qkqpttgf 已提交
870
        if (substr($path,-1)=='/') $path=substr($path,0,-1);
R
v3  
root 已提交
871
        $hiddenpass=gethiddenpass($path, getConfig('passfile'));
Q
qkqpttgf 已提交
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888
        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++;
Q
qkqpttgf 已提交
889
        if ($i == 4) break;
Q
qkqpttgf 已提交
890 891 892 893 894 895 896 897
    }
    $units = array('B', 'KB', 'MB', 'GB', 'TB');
    $ret = round($byte, 2);
    return ($ret . ' ' . $units[$i]);
}

function time_format($ISO)
{
Q
qkqpttgf 已提交
898
    if ($ISO=='') return date('Y-m-d H:i:s');
Q
qkqpttgf 已提交
899 900 901 902 903 904 905
    $ISO = str_replace('T', ' ', $ISO);
    $ISO = str_replace('Z', ' ', $ISO);
    return date('Y-m-d H:i:s',strtotime($ISO . " UTC"));
}

function adminform($name = '', $pass = '', $path = '')
{
Q
qkqpttgf 已提交
906 907
    $html = '<html><head><title>' . getconstStr('AdminLogin') . '</title><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"></head>';
    if ($name=='admin'&&$pass!='') {
R
v3  
root 已提交
908 909
        $html .= '<meta http-equiv="refresh" content="3;URL=' . $path . '">
        <body>' . getconstStr('LoginSuccess') . '</body></html>';
Q
qkqpttgf 已提交
910
        $statusCode = 201;
Q
qkqpttgf 已提交
911
        date_default_timezone_set('UTC');
R
refer  
root 已提交
912 913
        $_SERVER['Set-Cookie'] = $name . '=' . $pass . '; path=/; expires=' . date(DATE_COOKIE, strtotime('+7day'));
        return output($html, $statusCode);
Q
qkqpttgf 已提交
914
    }
Q
qkqpttgf 已提交
915
    $statusCode = 401;
Q
qkqpttgf 已提交
916
    $html .= '
R
v3  
root 已提交
917 918 919
<body>
    <div>
    <center><h4>' . getconstStr('InputPassword') . '</h4>
Q
qkqpttgf 已提交
920
    ' . $name . '
Q
qkqpttgf 已提交
921
    <form action="" method="post" onsubmit="return sha1loginpass(this);">
R
v3  
root 已提交
922
        <div>
Q
qkqpttgf 已提交
923
            <input id="password1" name="password1" type="password"/>
R
v3  
root 已提交
924 925 926 927 928 929 930 931 932
            <input name="timestamp" type="hidden"/>
            <input type="submit" value="' . getconstStr('Login') . '">
        </div>
    </form>
    </center>
    </div>
</body>';
    $html .= '
<script>
Q
qkqpttgf 已提交
933 934 935
    document.getElementById("password1").focus();
    function sha1loginpass(f) {
        if (f.password1.value=="") return false;
Q
qkqpttgf 已提交
936 937 938 939 940 941 942 943 944 945
        try {
            timestamp = new Date().getTime() + "";
            timestamp = timestamp.substr(0, timestamp.length-3);
            f.timestamp.value = timestamp;
            f.password1.value = sha1(timestamp + "" + f.password1.value);
            return true;
        } catch {
            alert("sha1.js not loaded.");
            return false;
        }
R
v3  
root 已提交
946
    }
Q
qkqpttgf 已提交
947 948
</script>
<script src="https://cdn.bootcss.com/js-sha1/0.6.0/sha1.min.js"></script>';
R
v3  
root 已提交
949
    $html .= '</html>';
Q
qkqpttgf 已提交
950
    return output($html, $statusCode);
Q
qkqpttgf 已提交
951 952 953 954
}

function adminoperate($path)
{
R
v3  
root 已提交
955
    global $drive;
Q
qkqpttgf 已提交
956
    $path1 = path_format($_SERVER['list_path'] . path_format($path));
R
v3  
root 已提交
957
    if (substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
R
root 已提交
958 959
    $tmpget = $_GET;
    $tmppost = $_POST;
Q
qkqpttgf 已提交
960
    $tmparr['statusCode'] = 0;
R
root 已提交
961 962 963
    if ( (isset($tmpget['rename_newname'])&&$tmpget['rename_newname']!=$tmpget['rename_oldname'] && $tmpget['rename_newname']!='') || (isset($tmppost['rename_newname'])&&$tmppost['rename_newname']!=$tmppost['rename_oldname'] && $tmppost['rename_newname']!='') ) {
        if (isset($tmppost['rename_newname'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
964
        // rename 重命名
R
v3  
root 已提交
965 966 967 968
        $file['path'] = $path1;
        $file['name'] = ${$VAR}['rename_oldname'];
        $file['id'] = ${$VAR}['rename_fileid'];
        return $drive->Rename($file, ${$VAR}['rename_newname']);
Q
qkqpttgf 已提交
969
    }
R
root 已提交
970 971 972
    if (isset($tmpget['delete_name']) || isset($tmppost['delete_name'])) {
        if (isset($tmppost['delete_name'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
973
        // delete 删除
R
v3  
root 已提交
974 975 976 977
        $file['path'] = $path1;
        $file['name'] = ${$VAR}['delete_name'];
        $file['id'] = ${$VAR}['delete_fileid'];
        return $drive->Delete($file);
Q
qkqpttgf 已提交
978
    }
R
root 已提交
979 980 981
    if ( (isset($tmpget['operate_action'])&&$tmpget['operate_action']==getconstStr('Encrypt')) || (isset($tmppost['operate_action'])&&$tmppost['operate_action']==getconstStr('Encrypt')) ) {
        if (isset($tmppost['operate_action'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
982 983
        // encrypt 加密
        if (getConfig('passfile')=='') return message(getconstStr('SetpassfileBfEncrypt'),'',403);
R
root 已提交
984
        if (${$VAR}['encrypt_folder']=='/') ${$VAR}['encrypt_folder']=='';
R
v3  
root 已提交
985 986 987 988
        $folder['path'] = path_format($path1 . '/' . spurlencode(${$VAR}['encrypt_folder'], '/'));
        $folder['name'] = ${$VAR}['encrypt_folder'];
        $folder['id'] = ${$VAR}['id'];
        return $drive->Encrypt($folder, getConfig('passfile'), ${$VAR}['encrypt_newpass']);
Q
qkqpttgf 已提交
989
    }
R
root 已提交
990 991 992
    if (isset($tmpget['move_folder']) || isset($tmppost['move_folder'])) {
        if (isset($tmppost['move_folder'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
993 994
        // move 移动
        $moveable = 1;
R
root 已提交
995 996
        if ($path == '/' && ${$VAR}['move_folder'] == '/../') $moveable=0;
        if (${$VAR}['move_folder'] == ${$VAR}['move_name']) $moveable=0;
Q
qkqpttgf 已提交
997
        if ($moveable) {
R
v3  
root 已提交
998 999 1000
            $file['path'] = $path1;
            $file['name'] = ${$VAR}['move_name'];
            $file['id'] = ${$VAR}['move_fileid'];
R
root 已提交
1001
            if (${$VAR}['move_folder'] == '/../') {
R
v3  
root 已提交
1002
                $foldername = path_format('/' . urldecode($path1 . '/'));
Q
qkqpttgf 已提交
1003 1004
                $foldername = substr($foldername, 0, -1);
                $foldername = splitlast($foldername, '/')[0];
R
root 已提交
1005
            } else $foldername = path_format('/' . urldecode($path1) . '/' . ${$VAR}['move_folder']);
R
v3  
root 已提交
1006 1007 1008 1009
            $folder['path'] = $foldername;
            $folder['name'] = ${$VAR}['move_folder'];
            $folder['id'] = '';
            return $drive->Move($file, $folder);
Q
qkqpttgf 已提交
1010
        } else {
R
v3  
root 已提交
1011
            return output('{"error":"' . getconstStr('CannotMove') . '"}', 403);
Q
qkqpttgf 已提交
1012 1013
        }
    }
R
root 已提交
1014 1015 1016
    if (isset($tmpget['copy_name']) || isset($tmppost['copy_name'])) {
        if (isset($tmppost['copy_name'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
1017
        // copy 复制
R
v3  
root 已提交
1018 1019 1020 1021
        $file['path'] = $path1;
        $file['name'] = ${$VAR}['copy_name'];
        $file['id'] = ${$VAR}['copy_fileid'];
        return $drive->Copy($file);
Q
qkqpttgf 已提交
1022
    }
R
root 已提交
1023
    if (isset($tmppost['editfile'])) {
Q
qkqpttgf 已提交
1024
        // edit 编辑
R
v3  
root 已提交
1025 1026 1027 1028
        $file['path'] = $path1;
        $file['name'] = '';
        $file['id'] = '';
        return $drive->Edit($file, $tmppost['editfile']);
Q
qkqpttgf 已提交
1029
    }
R
root 已提交
1030 1031 1032
    if (isset($tmpget['create_name']) || isset($tmppost['create_name'])) {
        if (isset($tmppost['create_name'])) $VAR = 'tmppost';
        else $VAR = 'tmpget';
Q
qkqpttgf 已提交
1033
        // create 新建
R
v3  
root 已提交
1034 1035 1036 1037
        $parent['path'] = $path1;
        $parent['name'] = '';
        $parent['id'] = ${$VAR}['create_fileid'];
        return $drive->Create($parent, ${$VAR}['create_type'], ${$VAR}['create_name'], ${$VAR}['create_text']);
Q
qkqpttgf 已提交
1038
    }
R
root 已提交
1039
    if (isset($tmpget['RefreshCache'])) {
R
v3  
root 已提交
1040 1041
        //$path1 = path_format($_SERVER['list_path'] . path_format($path));
        //if ($path1!='/'&&substr($path1, -1)=='/') $path1=substr($path1, 0, -1);
Q
qkqpttgf 已提交
1042 1043
        savecache('path_' . $path1 . '/?password', '', $_SERVER['disktag'], 1);
        savecache('customTheme', '', '', 1);
R
v3  
root 已提交
1044 1045
        return message('<meta http-equiv="refresh" content="2;URL=./">
        <meta name=viewport content="width=device-width,initial-scale=1">', getconstStr('RefreshCache'), 202);
Q
qkqpttgf 已提交
1046 1047 1048 1049
    }
    return $tmparr;
}

Q
qkqpttgf 已提交
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
function splitfirst($str, $split)
{
    $len = strlen($split);
    $pos = strpos($str, $split);
    if ($pos===false) {
        $tmp[0] = $str;
        $tmp[1] = '';
    } elseif ($pos>0) {
        $tmp[0] = substr($str, 0, $pos);
        $tmp[1] = substr($str, $pos+$len);
    } else {
        $tmp[0] = '';
        $tmp[1] = substr($str, $len);
    }
    return $tmp;
}

Q
qkqpttgf 已提交
1067 1068
function splitlast($str, $split)
{
Q
qkqpttgf 已提交
1069
    $len = strlen($split);
Q
qkqpttgf 已提交
1070 1071 1072 1073 1074 1075
    $pos = strrpos($str, $split);
    if ($pos===false) {
        $tmp[0] = $str;
        $tmp[1] = '';
    } elseif ($pos>0) {
        $tmp[0] = substr($str, 0, $pos);
Q
qkqpttgf 已提交
1076
        $tmp[1] = substr($str, $pos+$len);
Q
qkqpttgf 已提交
1077 1078
    } else {
        $tmp[0] = '';
Q
qkqpttgf 已提交
1079
        $tmp[1] = substr($str, $len);
Q
qkqpttgf 已提交
1080 1081 1082 1083
    }
    return $tmp;
}

Q
qkqpttgf 已提交
1084 1085 1086 1087
function children_name($children)
{
    $tmp = [];
    foreach ($children as $file) {
1088
        $tmp[strtolower($file['name'])] = $file;
Q
qkqpttgf 已提交
1089 1090 1091 1092
    }
    return $tmp;
}

Q
qkqpttgf 已提交
1093 1094 1095
function EnvOpt($needUpdate = 0)
{
    global $constStr;
R
v3  
root 已提交
1096
    global $EnvConfigs;
Q
qkqpttgf 已提交
1097
    global $timezones;
R
v3  
root 已提交
1098 1099 1100
    global $slash;
    global $drive;
    ksort($EnvConfigs);
R
root 已提交
1101
    $disktags = explode('|', getConfig('disktag'));
R
root 已提交
1102
    $envs = '';
R
refer  
root 已提交
1103 1104
    //foreach ($EnvConfigs as $env => $v) if (isCommonEnv($env)) $envs .= '\'' . $env . '\', ';
    $envs = substr(json_encode(array_keys ($EnvConfigs)), 1, -1);
R
root 已提交
1105

Q
qkqpttgf 已提交
1106 1107
    $html = '<title>OneManager '.getconstStr('Setup').'</title>';
    if (isset($_POST['updateProgram'])&&$_POST['updateProgram']==getconstStr('updateProgram')) {
Q
qkqpttgf 已提交
1108
        $response = setConfigResponse(OnekeyUpate($_POST['auth'], $_POST['project'], $_POST['branch']));
Q
qkqpttgf 已提交
1109 1110 1111
        if (api_error($response)) {
            $html = api_error_msg($response);
            $title = 'Error';
Q
qkqpttgf 已提交
1112
        } else {
Q
qkqpttgf 已提交
1113
            //WaitSCFStat();
1114
            $html .= getconstStr('UpdateSuccess') . '<br><a href="">' . getconstStr('Back') . '</a>';
Q
qkqpttgf 已提交
1115
            $title = getconstStr('Setup');
Q
qkqpttgf 已提交
1116
        }
Q
qkqpttgf 已提交
1117 1118 1119 1120 1121
        return message($html, $title);
    }
    if (isset($_POST['submit1'])) {
        $_SERVER['disk_oprating'] = '';
        foreach ($_POST as $k => $v) {
R
root 已提交
1122
            if (isShowedEnv($k) || $k=='disktag_del' || $k=='disktag_add' || $k=='disktag_rename' || $k=='disktag_copy') {
Q
qkqpttgf 已提交
1123
                $tmp[$k] = $v;
Q
qkqpttgf 已提交
1124
            }
R
root 已提交
1125 1126 1127 1128
            if ($k=='disktag_newname') {
                $v = preg_replace('/[^0-9a-zA-Z|_]/i', '', $v);
                $f = substr($v, 0, 1);
                if (strlen($v)==1) $v .= '_';
R
v3  
root 已提交
1129
                if (isCommonEnv($v)) {
1130
                    return message('Do not input ' . $envs . '<br><a href="">' . getconstStr('Back') . '</a>', 'Error', 201);
R
root 已提交
1131
                } elseif (!(('a'<=$f && $f<='z') || ('A'<=$f && $f<='Z'))) {
1132
                    return message('<a href="">' . getconstStr('Back') . '</a>', 'Please start with letters', 201);
Q
qkqpttgf 已提交
1133
                } elseif (getConfig($v)) {
1134
                    return message('<a href="">' . getconstStr('Back') . '</a>', 'Same tag', 201);
R
root 已提交
1135 1136 1137 1138 1139 1140 1141 1142 1143
                } else {
                    $tmp[$k] = $v;
                }
            }
            if ($k=='disktag_sort') {
                $td = implode('|', json_decode($v));
                if (strlen($td)==strlen(getConfig('disktag'))) $tmp['disktag'] = $td;
                else return message('Something wrong.');
            }
Q
qkqpttgf 已提交
1144
            if ($k == 'disk') $_SERVER['disk_oprating'] = $v;
Q
qkqpttgf 已提交
1145
        }
Q
qkqpttgf 已提交
1146 1147 1148 1149 1150 1151
        /*if ($tmp['domain_path']!='') {
            $tmp1 = explode("|",$tmp['domain_path']);
            $tmparr = [];
            foreach ($tmp1 as $multidomain_paths){
                $pos = strpos($multidomain_paths,":");
                if ($pos>0) $tmparr[substr($multidomain_paths, 0, $pos)] = path_format(substr($multidomain_paths, $pos+1));
Q
qkqpttgf 已提交
1152
            }
Q
qkqpttgf 已提交
1153 1154 1155 1156
            $tmp['domain_path'] = $tmparr;
        }*/
        $response = setConfigResponse( setConfig($tmp, $_SERVER['disk_oprating']) );
        if (api_error($response)) {
Q
qkqpttgf 已提交
1157 1158 1159
            $html = api_error_msg($response);
            $title = 'Error';
        } else {
Q
qkqpttgf 已提交
1160
            $html .= getconstStr('Success') . '!<br>
1161
            <a href="">' . getconstStr('Back') . '</a>';
Q
qkqpttgf 已提交
1162
            $title = getconstStr('Setup');
Q
qkqpttgf 已提交
1163
        }
Q
qkqpttgf 已提交
1164 1165
        return message($html, $title);
    }
R
root 已提交
1166
    if (isset($_POST['config_b'])) {
Q
qkqpttgf 已提交
1167 1168 1169 1170 1171
        if (!$_POST['pass']) return output("{\"Error\": \"No admin pass\"}", 403);
        if (!is_numeric($_POST['timestamp'])) return output("{\"Error\": \"Error time\"}", 403);
        if (abs(time() - $_POST['timestamp']/1000) > 5*60) return output("{\"Error\": \"Timeout\"}", 403);

        if ($_POST['pass']==sha1(getConfig('admin') . $_POST['timestamp'])) {
R
root 已提交
1172 1173 1174 1175 1176 1177 1178 1179 1180
            if ($_POST['config_b'] == 'export') {
                foreach ($EnvConfigs as $env => $v) {
                    if (isCommonEnv($env)) {
                        $value = getConfig($env);
                        if ($value) $tmp[$env] = $value;
                    }
                }
                foreach ($disktags as $disktag) {
                    $d = getConfig($disktag);
Q
qkqpttgf 已提交
1181
                    if ($d == '') {
R
root 已提交
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
                        $d = '';
                    } elseif (gettype($d)=='array') {
                        $tmp[$disktag] = $d;
                    } else {
                        $tmp[$disktag] = json_decode($d, true);
                    }
                }
                unset($tmp['admin']);
                return output(json_encode($tmp, JSON_PRETTY_PRINT));
            }
            if ($_POST['config_b'] == 'import') {
                if (!$_POST['config_t']) return output("{\"Error\": \"Empty config.\"}", 403);
                $c = '{' . splitfirst($_POST['config_t'], '{')[1];
                $c = splitlast($c, '}')[0] . '}';
                $tmp = json_decode($c, true);
                if (!!!$tmp) return output("{\"Error\": \"Config input error. " . $c . "\"}", 403);
Q
qkqpttgf 已提交
1198
                if (isset($tmp['disktag'])) $tmptag = $tmp['disktag'];
R
root 已提交
1199 1200 1201 1202 1203 1204 1205 1206 1207
                foreach ($EnvConfigs as $env => $v) {
                    if (isCommonEnv($env)) {
                        if (isShowedEnv($env)) {
                            if (getConfig($env)!=''&&!isset($tmp[$env])) $tmp[$env] = '';
                        } else {
                            unset($tmp[$env]);
                        }
                    }
                }
Q
qkqpttgf 已提交
1208 1209
                if ($disktags) foreach ($disktags as $disktag) {
                    if ($disktag!=''&&!isset($tmp[$disktag])) $tmp[$disktag] = '';
R
root 已提交
1210
                }
Q
qkqpttgf 已提交
1211 1212
                if ($tmptag) $tmp['disktag'] = $tmptag;
                $response = setConfigResponse( setConfig($tmp) );
R
root 已提交
1213 1214 1215 1216 1217 1218 1219 1220
                if (api_error($response)) {
                    return output("{\"Error\": \"" . api_error_msg($response) . "\"}", 500);
                } else {
                    return output("{\"Success\": \"Success\"}", 200);
                }
            }
            return output(json_encode($_POST), 500);
        } else {
Q
qkqpttgf 已提交
1221
            return output("{\"Error\": \"Admin pass error\"}", 403);
R
root 已提交
1222 1223
        }
    }
Q
qkqpttgf 已提交
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
    if (isset($_POST['changePass'])) {
        if (!is_numeric($_POST['timestamp'])) return message("Error time<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        if (abs(time() - $_POST['timestamp']/1000) > 5*60) return message("Timeout<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        if ($_POST['newPass1']==''||$_POST['newPass2']=='') return message("Empty new pass<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        if ($_POST['newPass1']!==$_POST['newPass2']) return message("Twice new pass not the same<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        if ($_POST['newPass1']==getConfig('admin')) return message("New pass same to old one<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        if ($_POST['oldPass']==sha1(getConfig('admin') . $_POST['timestamp'])) {
            $tmp['admin'] = $_POST['newPass1'];
            $response = setConfigResponse( setConfig($tmp) );
            if (api_error($response)) {
                return message(api_error_msg($response) . "<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
            } else {
                return message("Success<a href=\"\">" . getconstStr('Back') . "</a>", "Success", 200);
            }
        } else {
            return message("Old pass error<a href=\"\">" . getconstStr('Back') . "</a>", "Error", 403);
        }
    }
R
root 已提交
1242

Q
qkqpttgf 已提交
1243 1244 1245 1246 1247 1248
    if (isset($_GET['preview'])) {
        $preurl = $_SERVER['PHP_SELF'] . '?preview';
    } else {
        $preurl = path_format($_SERVER['PHP_SELF'] . '/');
    }
    $html .= '
Q
qkqpttgf 已提交
1249 1250
<a href="' . $preurl . '">' . getconstStr('Back') . '</a><br>
';
1251
    if ($_GET['setup']==='platform') {
Q
qkqpttgf 已提交
1252
        $frame .= '
Q
qkqpttgf 已提交
1253
<table border=1 width=100%>
Q
qkqpttgf 已提交
1254
    <form name="common" action="" method="post">';
R
v3  
root 已提交
1255
    foreach ($EnvConfigs as $key => $val) if (isCommonEnv($key) && isShowedEnv($key)) {
Q
qkqpttgf 已提交
1256
        $frame .= '
Q
qkqpttgf 已提交
1257 1258
        <tr>
            <td><label>' . $key . '</label></td>
R
refer  
root 已提交
1259 1260
            <td width=100%>';
        if ($key=='timezone') {
Q
qkqpttgf 已提交
1261
            $frame .= '
Q
qkqpttgf 已提交
1262 1263
                <select name="' . $key .'">';
            foreach (array_keys($timezones) as $zone) {
Q
qkqpttgf 已提交
1264
                $frame .= '
Q
qkqpttgf 已提交
1265
                    <option value="'.$zone.'" '.($zone==getConfig($key)?'selected="selected"':'').'>'.$zone.'</option>';
Q
qkqpttgf 已提交
1266
            }
Q
qkqpttgf 已提交
1267
            $frame .= '
Q
qkqpttgf 已提交
1268
                </select>
R
refer  
root 已提交
1269
                ' . getconstStr('EnvironmentsDescription')[$key];
Q
qkqpttgf 已提交
1270
        } elseif ($key=='theme') {
Q
qkqpttgf 已提交
1271
            $theme_arr = scandir(__DIR__ . $slash . 'theme');
Q
qkqpttgf 已提交
1272
            $frame .= '
Q
qkqpttgf 已提交
1273 1274 1275
                <select name="' . $key .'">
                    <option value=""></option>';
            foreach ($theme_arr as $v1) {
Q
qkqpttgf 已提交
1276
                if ($v1!='.' && $v1!='..') $frame .= '
Q
qkqpttgf 已提交
1277
                    <option value="'.$v1.'" '.($v1==getConfig($key)?'selected="selected"':'').'>'.$v1.'</option>';
Q
qkqpttgf 已提交
1278
            }
Q
qkqpttgf 已提交
1279
            $frame .= '
Q
qkqpttgf 已提交
1280
                </select>
R
refer  
root 已提交
1281
                ' . getconstStr('EnvironmentsDescription')[$key];
Q
qkqpttgf 已提交
1282 1283 1284 1285 1286
        } /*elseif ($key=='domain_path') {
            $tmp = getConfig($key);
            $domain_path = '';
            foreach ($tmp as $k1 => $v1) {
                $domain_path .= $k1 . ':' . $v1 . '|';
Q
qkqpttgf 已提交
1287
            }
Q
qkqpttgf 已提交
1288
            $domain_path = substr($domain_path, 0, -1);
Q
qkqpttgf 已提交
1289
            $frame .= '
Q
qkqpttgf 已提交
1290 1291 1292 1293
        <tr>
            <td><label>' . $key . '</label></td>
            <td width=100%><input type="text" name="' . $key .'" value="' . $domain_path . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
        </tr>';
Q
qkqpttgf 已提交
1294
        }*/ else $frame .= '
R
refer  
root 已提交
1295
                <input type="text" name="' . $key . '" value="' . htmlspecialchars(getConfig($key)) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%">';
Q
qkqpttgf 已提交
1296
        $frame .= '
R
refer  
root 已提交
1297
            </td>
Q
qkqpttgf 已提交
1298 1299
        </tr>';
    }
Q
qkqpttgf 已提交
1300 1301
    $frame .= '
        <tr><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td><td></td></tr>
Q
qkqpttgf 已提交
1302 1303
    </form>
</table><br>';
1304 1305
    } elseif (isset($_GET['disktag'])&&in_array($_GET['disktag'], $disktags)) {
        $disktag = $_GET['disktag'];
Q
qkqpttgf 已提交
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318
        $disk_tmp = null;
        $diskok = driveisfine($disktag, $disk_tmp);
        $frame .= '
<table width=100%>
    <tr>
        <td>
            <form action="" method="post" style="margin: 0" onsubmit="return renametag(this);">
                <input type="hidden" name="disktag_rename" value="' . $disktag . '">
                <input type="text" name="disktag_newname" value="' . $disktag . '" placeholder="' . getconstStr('EnvironmentsDescription')['disktag'] . '">
                <input type="submit" name="submit1" value="' . getconstStr('RenameDisk') . '">
            </form>
        </td>
    </tr>
Q
qkqpttgf 已提交
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
</table><br>
<table>
<tr>
    <td>
        <form action="" method="post" style="margin: 0" onsubmit="return deldiskconfirm(this);">
            <input type="hidden" name="disktag_del" value="' . $disktag . '">
            <input type="submit" name="submit1" value="' . getconstStr('DelDisk') . '">
        </form>
    </td>
    <td>
        <form action="" method="post" style="margin: 0" onsubmit="return cpdiskconfirm(this);">
            <input type="hidden" name="disktag_copy" value="' . $disktag . '">
            <input type="submit" name="submit1" value="' . getconstStr('CopyDisk') . '">
        </form>
    </td>
</tr>
Q
qkqpttgf 已提交
1335 1336
</table>
<table border=1 width=100%>
Q
qkqpttgf 已提交
1337 1338 1339
    <tr>
        <td>Driver</td>
        <td>' . getConfig('Driver', $disktag);
Q
qkqpttgf 已提交
1340 1341
        if ($diskok) $frame .= ' <a href="?AddDisk=' . get_class($disk_tmp) . '&disktag=' . $disktag . '&SelectDrive">' . getconstStr('ChangeDrivetype') . '</a>';
        $frame .= '</td>
Q
qkqpttgf 已提交
1342
    </tr>';
Q
qkqpttgf 已提交
1343
        if ($diskok) {
Q
qkqpttgf 已提交
1344 1345 1346 1347
            $frame .= '
    <tr>
        <td>diskSpace</td><td>' . $disk_tmp->getDiskSpace() . '</td>
    </tr>';
Q
qkqpttgf 已提交
1348
            foreach (extendShow_diskenv($disk_tmp) as $ext_env) {
Q
qkqpttgf 已提交
1349 1350 1351 1352 1353
                $frame .= '
    <tr>
        <td>' . $ext_env . '</td>
        <td>' . getConfig($ext_env, $disktag) . '</td>
    </tr>';
Q
qkqpttgf 已提交
1354
            }
Q
qkqpttgf 已提交
1355

Q
qkqpttgf 已提交
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366
            $frame .= '
<form name="' . $disktag . '" action="" method="post">
    <input type="hidden" name="disk" value="' . $disktag . '">';
            foreach ($EnvConfigs as $key => $val) if (isInnerEnv($key) && isShowedEnv($key)) {
                $frame .= '
    <tr>
        <td><label>' . $key . '</label></td>
        <td width=100%><input type="text" name="' . $key . '" value="' . getConfig($key, $disktag) . '" placeholder="' . getconstStr('EnvironmentsDescription')[$key] . '" style="width:100%"></td>
    </tr>';
            }
            $frame .= '
Q
qkqpttgf 已提交
1367
    <tr><td></td><td><input type="submit" name="submit1" value="' . getconstStr('Setup') . '"></td></tr>
Q
qkqpttgf 已提交
1368 1369 1370 1371 1372 1373 1374 1375 1376
</form>';
        } else {
            $frame .= '
<tr>
    <td colspan="2">' . ($disk_tmp->error['body']?$disk_tmp->error['stat'] . '<br>' . $disk_tmp->error['body']:'Add this disk again.') . '</td>
</tr>';
        }
        $frame .= '
</table>
Q
qkqpttgf 已提交
1377

Q
qkqpttgf 已提交
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
<script>
    function deldiskconfirm(t) {
        var msg="' . getconstStr('Delete') . ' ??";
        if (confirm(msg)==true) return true;
        else return false;
    }
    function cpdiskconfirm(t) {
        var msg="' . getconstStr('Copy') . ' ??";
        if (confirm(msg)==true) return true;
        //else 
        return false;
    }
    function renametag(t) {
        if (t.disktag_newname.value==\'\') {
            alert(\'' . getconstStr('DiskTag') . '\');
            return false;
        }
        if (t.disktag_newname.value==t.disktag_rename.value) {
            return false;
        }
        envs = [' . $envs . '];
        if (envs.indexOf(t.disktag_newname.value)>-1) {
            alert(\'Do not input ' . $envs . '\');
            return false;
        }
        var reg = /^[a-zA-Z]([_a-zA-Z0-9]{1,20})$/;
        if (!reg.test(t.disktag_newname.value)) {
            alert(\'' . getconstStr('TagFormatAlert') . '\');
            return false;
        }
        return true;
    }
</script>';
    } else {
1412
        //$_GET['disktag'] = '';
Q
qkqpttgf 已提交
1413 1414 1415
        $Driver_arr = scandir(__DIR__ . $slash . 'disk');
        if (count($disktags)>1) {
            $frame .= '
R
root 已提交
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
<script src="//cdn.bootcss.com/Sortable/1.8.3/Sortable.js"></script>
<style>
    .sortable-ghost {
        opacity: 0.4;
        background-color: #1748ce;
    }

    #sortdisks td {
        cursor: move;
    }
</style>
<table border=1>
    <form id="sortdisks_form" action="" method="post" style="margin: 0" onsubmit="return dragsort(this);">
    <tr id="sortdisks">
        <input type="hidden" name="disktag_sort" value="">';
Q
qkqpttgf 已提交
1431 1432 1433 1434 1435
            $num = 0;
            foreach ($disktags as $disktag) {
                if ($disktag!='') {
                    $num++;
                    $frame .= '
R
root 已提交
1436
        <td>' . $disktag . '</td>';
Q
qkqpttgf 已提交
1437
                }
R
root 已提交
1438
            }
Q
qkqpttgf 已提交
1439
            $frame .= '
R
root 已提交
1440 1441 1442 1443 1444
    </tr>
    <tr><td colspan="' . $num . '">' . getconstStr('DragSort') . '<input type="submit" name="submit1" value="' . getconstStr('SubmitSortdisks') . '"></td></tr>
    </form>
</table>
<script>
1445
    var disks=' . json_encode($disktags) . ';
R
root 已提交
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470
    function change(arr, oldindex, newindex) {
        //console.log(oldindex + "," + newindex);
        tmp=arr.splice(oldindex-1, 1);
        if (oldindex > newindex) {
            tmp1=JSON.parse(JSON.stringify(arr));
            tmp1.splice(newindex-1, arr.length-newindex+1);
            tmp2=JSON.parse(JSON.stringify(arr));
            tmp2.splice(0, newindex-1);
        } else {
            tmp1=JSON.parse(JSON.stringify(arr));
            tmp1.splice(newindex-1, arr.length-newindex+1);
            tmp2=JSON.parse(JSON.stringify(arr));
            tmp2.splice(0, newindex-1);
        }
        arr=tmp1.concat(tmp, tmp2);
        //console.log(arr);
        return arr;
    }
    function dragsort(t) {
        if (t.disktag_sort.value==\'\') {
            alert(\'' . getconstStr('DragSort') . '\');
            return false;
        }
        envs = [' . $envs . '];
        if (envs.indexOf(t.disktag_sort.value)>-1) {
R
refer  
root 已提交
1471
            alert(\'Do not input ' . $envs . '\');
R
root 已提交
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487
            return false;
        }
        return true;
    }
    Sortable.create(document.getElementById(\'sortdisks\'), {
        animation: 150,
        onEnd: function (evt) { //拖拽完毕之后发生该事件
            //console.log(evt.oldIndex);
            //console.log(evt.newIndex);
            if (evt.oldIndex!=evt.newIndex) {
                disks=change(disks, evt.oldIndex, evt.newIndex);
                document.getElementById(\'sortdisks_form\').disktag_sort.value=JSON.stringify(disks);
            }
        }
    });
</script><br>';
Q
qkqpttgf 已提交
1488
        }
Q
qkqpttgf 已提交
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506
        $frame .= '
<select name="DriveType" onchange="changedrivetype(this.options[this.options.selectedIndex].value)">';
        foreach ($Driver_arr as $v1) {
            if ($v1!='.' && $v1!='..') {
                //$v1 = substr($v1, 0, -4);
                $v2 = splitlast($v1, '.php')[0];
                if ($v2 . '.php'==$v1) $frame .= '
    <option value="' . $v2 . '"' . ($v2=='Onedrive'?' selected="selected"':'') . '>' . $v2 . '</option>';
            }
        }
        $frame .= '
</select>
<a id="AddDisk_link" href="?AddDisk=Onedrive">' . getconstStr('AddDisk') . '</a><br><br>
<script>
    function changedrivetype(d) {
        document.getElementById(\'AddDisk_link\').href="?AddDisk=" + d;
    }
</script>';
Q
qkqpttgf 已提交
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525

        $canOneKeyUpate = 0;
        if (isset($_SERVER['USER'])&&$_SERVER['USER']==='qcloud') {
            $canOneKeyUpate = 1;
        } elseif (isset($_SERVER['HEROKU_APP_DIR'])&&$_SERVER['HEROKU_APP_DIR']==='/app') {
            $canOneKeyUpate = 1;
        } elseif (isset($_SERVER['FC_SERVER_PATH'])&&$_SERVER['FC_SERVER_PATH']==='/var/fc/runtime/php7.2') {
            $canOneKeyUpate = 1;
        } elseif ($_SERVER['BCE_CFC_RUNTIME_NAME']=='php7') {
            $canOneKeyUpate = 1;
        } elseif ($_SERVER['_APP_SHARE_DIR']==='/var/share/CFF/processrouter') {
            $canOneKeyUpate = 1;
        } else {
            $tmp = time();
            if ( mkdir(''.$tmp, 0777) ) {
                rmdir(''.$tmp);
                $canOneKeyUpate = 1;
            }
        }
Q
qkqpttgf 已提交
1526
        $frame .= '<a href="https://github.com/qkqpttgf/OneManager-php" target="_blank">Github</a>';
Q
qkqpttgf 已提交
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
        if (!$canOneKeyUpate) {
            $frame .= '
' . getconstStr('CannotOneKeyUpate') . '<br>';
        } else {
            $frame .= '
<form name="updateform" action="" method="post">
    <input type="text" name="auth" size="6" placeholder="auth" value="qkqpttgf">
    <input type="text" name="project" size="12" placeholder="project" value="OneManager-php">
    <button name="QueryBranchs" onclick="querybranchs();return false;">' . getconstStr('QueryBranchs') . '</button>
    <select name="branch">
        <option value="master">master</option>
    </select>
    <input type="submit" name="updateProgram" value="' . getconstStr('updateProgram') . '">
</form>
<script>
    function querybranchs()
    {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", "https://api.github.com/repos/"+document.updateform.auth.value+"/"+document.updateform.project.value+"/branches");
        //xhr.setRequestHeader("User-Agent","qkqpttgf/OneManager");
        xhr.onload = function(e){
            console.log(xhr.responseText+","+xhr.status);
            if (xhr.status==200) {
                document.updateform.branch.options.length=0;
                JSON.parse(xhr.responseText).forEach( function (e) {
                    document.updateform.branch.options.add(new Option(e.name,e.name));
                    if ("master"==e.name) document.updateform.branch.options[document.updateform.branch.options.length-1].selected = true; 
                });
                document.updateform.QueryBranchs.style.display="none";
Q
qkqpttgf 已提交
1556
            } else {
Q
qkqpttgf 已提交
1557
                alert(xhr.responseText+"\n"+xhr.status);
Q
qkqpttgf 已提交
1558 1559
            }
        }
Q
qkqpttgf 已提交
1560 1561 1562 1563
        xhr.onerror = function(e){
            alert("Network Error "+xhr.status);
        }
        xhr.send(null);
Q
qkqpttgf 已提交
1564
    }
Q
qkqpttgf 已提交
1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
</script>
';
        }
        if ($needUpdate) {
            $frame .= '<div style="position: relative; word-wrap: break-word;">
        ' . str_replace("\r", '<br>', $_SERVER['github_ver_new']) . '
</div>
<button onclick="document.getElementById(\'github_ver_old\').style.display=(document.getElementById(\'github_ver_old\').style.display==\'none\'?\'\':\'none\');">More...</button>
<div id="github_ver_old" style="position: relative; word-wrap: break-word; display: none">
        ' . str_replace("\r", '<br>', $_SERVER['github_ver_old']) . '
</div>';
        }/* else {
            $frame .= getconstStr('NotNeedUpdate');
        }*/
        $frame .= '<br>
Q
qkqpttgf 已提交
1580
<script src="https://cdn.bootcss.com/js-sha1/0.6.0/sha1.min.js"></script>
Q
qkqpttgf 已提交
1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
<table>
    <form id="change_pass" name="change_pass" action="" method="POST" onsubmit="return changePassword(this);">
    <tr>
        <td>old pass:</td><td><input type="password" name="oldPass">
        <input type="hidden" name="timestamp"></td>
    </tr>
    <tr>
        <td>new pass:</td><td><input type="password" name="newPass1"></td>
    </tr>
    <tr>
        <td>reinput:</td><td><input type="password" name="newPass2"></td>
    </tr>
    <tr>
        <td></td><td><button name="changePass" value="changePass">Change Admin Pass</button></td>
    </tr>
    </form>
</table><br>
R
root 已提交
1598 1599 1600
<table>
    <form id="config_f" name="config" action="" method="POST" onsubmit="return false;">
    <tr>
Q
qkqpttgf 已提交
1601 1602
        <td>admin pass:<input type="password" name="pass">
        <button name="config_b" value="export" onclick="exportConfig(this);">export</button></td>
R
root 已提交
1603 1604
    </tr>
    <tr>
Q
qkqpttgf 已提交
1605 1606
        <td>config:<textarea name="config_t"></textarea>
        <button name="config_b" value="import" onclick="importConfig(this);">import</button></td>
R
root 已提交
1607 1608
    </tr>
    </form>
Q
qkqpttgf 已提交
1609
</table><br>
R
root 已提交
1610 1611 1612 1613 1614 1615 1616
<script>
    var config_f = document.getElementById("config_f");
    function exportConfig(b) {
        if (config_f.pass.value=="") {
            alert("admin pass");
            return false;
        }
Q
qkqpttgf 已提交
1617 1618 1619 1620 1621 1622
        try {
            sha1(1);
        } catch {
            alert("sha1.js not loaded.");
            return false;
        }
Q
qkqpttgf 已提交
1623
        var timestamp = new Date().getTime();
R
root 已提交
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "");
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
        xhr.onload = function(e){
            console.log(xhr.responseText+","+xhr.status);
            if (xhr.status==200) {
                var res = JSON.parse(xhr.responseText);
                config_f.config_t.value = xhr.responseText;
                config_f.parentNode.style = "width: 100%";
                config_f.config_t.style = "width: 100%";
                config_f.config_t.style.height = config_f.config_t.scrollHeight + "px";
            } else {
                alert(xhr.status+"\n"+xhr.responseText);
            }
        }
        xhr.onerror = function(e){
            alert("Network Error "+xhr.status);
        }
Q
qkqpttgf 已提交
1642
        xhr.send("pass=" + sha1(config_f.pass.value + "" + timestamp) + "&config_b=" + b.value + "&timestamp=" + timestamp);
R
root 已提交
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
    }
    function importConfig(b) {
        if (config_f.pass.value=="") {
            alert("admin pass");
            return false;
        }
        if (config_f.config_t.value=="") {
            alert("input config");
            return false;
        } else {
            try {
                var tmp = JSON.parse(config_f.config_t.value);
            } catch(e) {
                alert("config error!");
                return false;
            }
        }
Q
qkqpttgf 已提交
1660 1661 1662 1663 1664 1665
        try {
            sha1(1);
        } catch {
            alert("sha1.js not loaded.");
            return false;
        }
Q
qkqpttgf 已提交
1666
        var timestamp = new Date().getTime();
R
root 已提交
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "");
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
        xhr.onload = function(e){
            console.log(xhr.responseText+","+xhr.status);
            if (xhr.status==200) {
                //var res = JSON.parse(xhr.responseText);
                alert("Import success");
            } else {
                alert(xhr.status+"\n"+xhr.responseText);
            }
        }
        xhr.onerror = function(e){
            alert("Network Error "+xhr.status);
        }
Q
qkqpttgf 已提交
1682
        xhr.send("pass=" + sha1(config_f.pass.value + "" + timestamp) + "&config_t=" + encodeURIComponent(config_f.config_t.value) + "&config_b=" + b.value + "&timestamp=" + timestamp);
R
root 已提交
1683
    }
Q
qkqpttgf 已提交
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696
    function changePassword(f) {
        if (f.oldPass.value==""||f.newPass1.value==""||f.newPass2.value=="") {
            alert("Input");
            return false;
        }
        if (f.oldPass.value==f.newPass1.value) {
            alert("Same password");
            return false;
        }
        if (f.newPass1.value!==f.newPass1.value) {
            alert("Input twice new password");
            return false;
        }
Q
qkqpttgf 已提交
1697 1698 1699 1700 1701 1702
        try {
            sha1(1);
        } catch {
            alert("sha1.js not loaded.");
            return false;
        }
Q
qkqpttgf 已提交
1703 1704 1705 1706 1707
        var timestamp = new Date().getTime();
        f.timestamp.value = timestamp;
        f.oldPass.value = sha1(f.oldPass.value + "" + timestamp);
        return true;
    }
Q
qkqpttgf 已提交
1708
</script>';
R
v3  
root 已提交
1709 1710
    }
    $html .= '
Q
qkqpttgf 已提交
1711
<style type="text/css">
Q
qkqpttgf 已提交
1712
    .tabs td { padding: 5px; }
Q
qkqpttgf 已提交
1713
</style>
Q
qkqpttgf 已提交
1714
<table border=0>
Q
qkqpttgf 已提交
1715
    <tr class="tabs">';
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725
    if ($_GET['disktag']=='') {
        if ($_GET['setup']==='platform') $html .= '
        <td><a href="?setup">' . getconstStr('Home') . '</a></td>
        <td>' . getconstStr('PlatformConfig') . '</td>';
        else $html .= '
        <td>' . getconstStr('Home') . '</td>
        <td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>';
    } else $html .= '
        <td><a href="?setup">' . getconstStr('Home') . '</a></td>
        <td><a href="?setup=platform">' . getconstStr('PlatformConfig') . '</a></td>';
Q
qkqpttgf 已提交
1726 1727
    foreach ($disktags as $disktag) {
        if ($disktag!='') {
1728 1729
            if ($_GET['disktag']==$disktag) $html .= '
        <td>' . $disktag . '</td>';
Q
qkqpttgf 已提交
1730
            else $html .= '
1731
        <td><a href="?setup&disktag=' . $disktag . '">' . $disktag . '</a></td>';
Q
qkqpttgf 已提交
1732 1733
        }
    }
Q
qkqpttgf 已提交
1734 1735 1736 1737
    $html .= '
    </tr>
</table><br>';
    $html .= $frame;
Q
qkqpttgf 已提交
1738 1739 1740
    return message($html, getconstStr('Setup'));
}

1741
function render_list($path = '', $files = [])
Q
qkqpttgf 已提交
1742 1743 1744
{
    global $exts;
    global $constStr;
R
v3  
root 已提交
1745
    global $slash;
Q
qkqpttgf 已提交
1746

R
v3  
root 已提交
1747 1748 1749
    if (isset($files['list']['index.html']) && !$_SERVER['admin']) {
        //$htmlcontent = fetch_files(spurlencode(path_format(urldecode($path) . '/index.html'), '/'))['content'];
        $htmlcontent = get_content(spurlencode(path_format(urldecode($path) . '/index.html'), '/'))['content'];
Q
qkqpttgf 已提交
1750 1751 1752 1753 1754 1755 1756 1757 1758
        return output($htmlcontent['body'], $htmlcontent['stat']);
    }
    $path = str_replace('%20','%2520',$path);
    $path = str_replace('+','%2B',$path);
    $path = str_replace('&','&amp;',path_format(urldecode($path))) ;
    $path = str_replace('%20',' ',$path);
    $path = str_replace('#','%23',$path);
    $p_path='';
    if ($path !== '/') {
R
v3  
root 已提交
1759
        if ($files['type']=='file') {
Q
qkqpttgf 已提交
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
            $pretitle = str_replace('&','&amp;', $files['name']);
            $n_path = $pretitle;
            $tmp = splitlast(splitlast($path,'/')[0],'/');
            if ($tmp[1]=='') {
                $p_path = $tmp[0];
            } else {
                $p_path = $tmp[1];
            }
        } else {
            if (substr($path, 0, 1)=='/') $pretitle = substr($path, 1);
            if (substr($path, -1)=='/') $pretitle = substr($pretitle, 0, -1);
            $tmp=splitlast($pretitle,'/');
            if ($tmp[1]=='') {
                $n_path = $tmp[0];
            } else {
                $n_path = $tmp[1];
                $tmp = splitlast($tmp[0],'/');
                if ($tmp[1]=='') {
                    $p_path = $tmp[0];
                } else {
                    $p_path = $tmp[1];
                }
            }
        }
    } else {
      $pretitle = getconstStr('Home');
R
v3  
root 已提交
1786
      $n_path = $pretitle;
Q
qkqpttgf 已提交
1787
    }
R
v3  
root 已提交
1788 1789
    $n_path = str_replace('&amp;','&',$n_path);
    $p_path = str_replace('&amp;','&',$p_path);
Q
qkqpttgf 已提交
1790
    $pretitle = str_replace('%23','#',$pretitle);
R
v3  
root 已提交
1791
    $statusCode = 200;
Q
qkqpttgf 已提交
1792
    date_default_timezone_set(get_timezone($_SERVER['timezone']));
R
v3  
root 已提交
1793 1794
    $authinfo = '
<!--
Q
qkqpttgf 已提交
1795
    OneManager: An index & manager of Onedrive auth by ysun.
Q
qkqpttgf 已提交
1796
    Github: https://github.com/qkqpttgf/OneManager-php
Q
qkqpttgf 已提交
1797
-->';
Q
qkqpttgf 已提交
1798
    //$authinfo = $path . '<br><pre>' . json_encode($files, JSON_PRETTY_PRINT) . '</pre>';
Q
qkqpttgf 已提交
1799

1800 1801 1802
    //if (isset($_COOKIE['theme'])&&$_COOKIE['theme']!='') $theme = $_COOKIE['theme'];
    //if ( !file_exists(__DIR__ . $slash .'theme' . $slash . $theme) ) $theme = '';
    if ($_SERVER['admin']) $theme = 'classic.html';
Q
qkqpttgf 已提交
1803 1804 1805 1806 1807 1808
    if ( $theme=='' ) {
        $tmp = getConfig('customTheme');
        if ( $tmp!='' ) $theme = $tmp;
    }
    if ( $theme=='' ) {
        $theme = getConfig('theme');
Q
qkqpttgf 已提交
1809
        if ( $theme=='' || !file_exists(__DIR__ . $slash .'theme' . $slash . $theme) ) $theme = 'classic.html';
Q
qkqpttgf 已提交
1810
    }
Q
qkqpttgf 已提交
1811 1812
    if (substr($theme,-4)=='.php') {
        @ob_start();
R
v3  
root 已提交
1813
        include 'theme/' . $theme;
Q
qkqpttgf 已提交
1814 1815
        $html = ob_get_clean();
    } else {
Q
qkqpttgf 已提交
1816 1817
        if (file_exists(__DIR__ . $slash .'theme' . $slash . $theme)) {
            $file_path = __DIR__ . $slash .'theme' . $slash . $theme;
Q
qkqpttgf 已提交
1818 1819 1820 1821
            $html = file_get_contents($file_path);
        } else {
            if (!($html = getcache('customTheme'))) {
                $file_path = $theme;
R
root 已提交
1822
                $tmp = curl('GET', $file_path, '', [], 1);
Q
qkqpttgf 已提交
1823
                if ($tmp['stat']==302) {
1824
                    error_log1(json_encode($tmp));
R
v3  
root 已提交
1825
                    $tmp = curl('GET', $tmp["returnhead"]["Location"]);
Q
qkqpttgf 已提交
1826 1827
                }
                if (!!$tmp['body']) $html = $tmp['body'];
Q
qkqpttgf 已提交
1828
                savecache('customTheme', $html, '', 9999);
Q
qkqpttgf 已提交
1829 1830 1831
            }
            
        }
Q
qkqpttgf 已提交
1832 1833 1834 1835 1836 1837 1838 1839 1840

        $tmp = splitfirst($html, '<!--IconValuesStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--IconValuesEnd-->');
        $IconValues = json_decode($tmp[0], true);
        $html .= $tmp[1];

        if (!$files) {
            //$html = '<pre>'.json_encode($files, JSON_PRETTY_PRINT).'</pre>' . $html;
Q
qkqpttgf 已提交
1841 1842 1843 1844 1845 1846 1847
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFileStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
                $html .= $tmp[1];
            }
Q
qkqpttgf 已提交
1848 1849 1850 1851 1852 1853
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFolderStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
                $html .= $tmp[1];
Q
qkqpttgf 已提交
1854
            }
Q
qkqpttgf 已提交
1855 1856 1857 1858 1859 1860
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--ListStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--ListEnd-->');
                $html .= $tmp[1];
Q
qkqpttgf 已提交
1861
            }
Q
qkqpttgf 已提交
1862 1863 1864 1865 1866
            while (strpos($html, '<!--GuestUploadStart-->')) {
                $tmp = splitfirst($html, '<!--GuestUploadStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
                $html .= $tmp[1];
Q
qkqpttgf 已提交
1867
            }
Q
qkqpttgf 已提交
1868 1869
            while (strpos($html, '<!--EncryptedStart-->')) {
                $tmp = splitfirst($html, '<!--EncryptedStart-->');
Q
qkqpttgf 已提交
1870
                $html = $tmp[0];
Q
qkqpttgf 已提交
1871
                $tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
Q
qkqpttgf 已提交
1872
                $html .= $tmp[1];
Q
qkqpttgf 已提交
1873 1874 1875 1876 1877 1878
            }
        }
        if ($_SERVER['admin']) {
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--LoginStart-->');
Q
qkqpttgf 已提交
1879
                $html = $tmp[0];
Q
qkqpttgf 已提交
1880 1881 1882
                $tmp = splitfirst($tmp[1], '<!--LoginEnd-->');
                $html .= $tmp[1];
            }
1883 1884 1885 1886 1887 1888 1889
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--GuestStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--GuestEnd-->');
                $html .= $tmp[1];
            }
Q
qkqpttgf 已提交
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929
            while (strpos($html, '<!--AdminStart-->')) {
                $html = str_replace('<!--AdminStart-->', '', $html);
                $html = str_replace('<!--AdminEnd-->', '', $html);
            }
            while (strpos($html, '<!--constStr@Operate-->')) $html = str_replace('<!--constStr@Operate-->', getconstStr('Operate'), $html);
            while (strpos($html, '<!--constStr@Create-->')) $html = str_replace('<!--constStr@Create-->', getconstStr('Create'), $html);
            while (strpos($html, '<!--constStr@Encrypt-->')) $html = str_replace('<!--constStr@Encrypt-->', getconstStr('Encrypt'), $html);
            while (strpos($html, '<!--constStr@RefreshCache-->')) $html = str_replace('<!--constStr@RefreshCache-->', getconstStr('RefreshCache'), $html);
            while (strpos($html, '<!--constStr@Setup-->')) $html = str_replace('<!--constStr@Setup-->', getconstStr('Setup'), $html);
            while (strpos($html, '<!--constStr@Logout-->')) $html = str_replace('<!--constStr@Logout-->', getconstStr('Logout'), $html);
            while (strpos($html, '<!--constStr@Rename-->')) $html = str_replace('<!--constStr@Rename-->', getconstStr('Rename'), $html);
            while (strpos($html, '<!--constStr@Submit-->')) $html = str_replace('<!--constStr@Submit-->', getconstStr('Submit'), $html);
            while (strpos($html, '<!--constStr@Delete-->')) $html = str_replace('<!--constStr@Delete-->', getconstStr('Delete'), $html);
            while (strpos($html, '<!--constStr@Copy-->')) $html = str_replace('<!--constStr@Copy-->', getconstStr('Copy'), $html);
            while (strpos($html, '<!--constStr@Move-->')) $html = str_replace('<!--constStr@Move-->', getconstStr('Move'), $html);
            while (strpos($html, '<!--constStr@Folder-->')) $html = str_replace('<!--constStr@Folder-->', getconstStr('Folder'), $html);
            while (strpos($html, '<!--constStr@File-->')) $html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
            while (strpos($html, '<!--constStr@Name-->')) $html = str_replace('<!--constStr@Name-->', getconstStr('Name'), $html);
            while (strpos($html, '<!--constStr@Content-->')) $html = str_replace('<!--constStr@Content-->', getconstStr('Content'), $html);
            
        } else {
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--AdminStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--AdminEnd-->');
                $html .= $tmp[1];
            }
            if (getConfig('adminloginpage')=='') {
                while (strpos($html, '<!--LoginStart-->')) $html = str_replace('<!--LoginStart-->', '', $html);
                while (strpos($html, '<!--LoginEnd-->')) $html = str_replace('<!--LoginEnd-->', '', $html);
            } else {
                $tmp[1] = 'a';
                while ($tmp[1]!='') {
                    $tmp = splitfirst($html, '<!--LoginStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--LoginEnd-->');
                    $html .= $tmp[1];
                }
            }
1930 1931
            while (strpos($html, '<!--GuestStart-->')) $html = str_replace('<!--GuestStart-->', '', $html);
            while (strpos($html, '<!--GuestEnd-->')) $html = str_replace('<!--GuestEnd-->', '', $html);
Q
qkqpttgf 已提交
1932 1933
        }

1934
        if ($_SERVER['ishidden']==4) {
1935
            // 加密状态
Q
qkqpttgf 已提交
1936 1937 1938 1939
            if (!getConfig('dontBasicAuth')) {
                // use Basic Auth
                return output('Need password.', 401, ['WWW-Authenticate'=>'Basic realm="Secure Area"']);
            }
1940 1941 1942 1943 1944 1945 1946
            /*$tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--ListStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--ListEnd-->');
                $html .= $tmp[1];
            }*/
Q
qkqpttgf 已提交
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFileStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
                $html .= $tmp[1];
            }
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFolderStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
                $html .= $tmp[1];
            }
1961 1962 1963 1964 1965
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
1966 1967
                $html .= $tmp[1];
            }
1968 1969 1970
            while (strpos($html, '<!--EncryptedStart-->')) {
                $html = str_replace('<!--EncryptedStart-->', '', $html);
                $html = str_replace('<!--EncryptedEnd-->', '', $html);
Q
qkqpttgf 已提交
1971 1972 1973
            }
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
1974
                $tmp = splitfirst($html, '<!--GuestUploadStart-->');
Q
qkqpttgf 已提交
1975
                $html = $tmp[0];
1976 1977 1978 1979 1980 1981 1982 1983 1984
                $tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--IsNotHiddenStart-->')) {
                $tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
                $html .= $tmp[1];
            }
Q
qkqpttgf 已提交
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
            while (strpos($html, '<!--HeadomfStart-->')) {
                $tmp = splitfirst($html, '<!--HeadomfStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--HeadmdStart-->')) {
                $tmp = splitfirst($html, '<!--HeadmdStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--ReadmemdStart-->')) {
                $tmp = splitfirst($html, '<!--ReadmemdStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--FootomfStart-->')) {
                $tmp = splitfirst($html, '<!--FootomfStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--FootomfEnd-->');
                $html .= $tmp[1];
            }
2009 2010 2011 2012 2013
        } else {
            while (strpos($html, '<!--EncryptedStart-->')) {
                $tmp = splitfirst($html, '<!--EncryptedStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
Q
qkqpttgf 已提交
2014 2015
                $html .= $tmp[1];
            }
2016 2017 2018 2019
            while (strpos($html, '<!--IsNotHiddenStart-->')) {
                $html = str_replace('<!--IsNotHiddenStart-->', '', $html);
                $html = str_replace('<!--IsNotHiddenEnd-->', '', $html);
            }
Q
qkqpttgf 已提交
2020
        }
2021 2022 2023
        while (strpos($html, '<!--constStr@Download-->')) $html = str_replace('<!--constStr@Download-->', getconstStr('Download'), $html);

        if ($_SERVER['is_guestup_path']&&!$_SERVER['admin']) {
Q
qkqpttgf 已提交
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFileStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
                $html .= $tmp[1];
            }
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFolderStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
                $html .= $tmp[1];
            }
2038 2039 2040 2041 2042
            while (strpos($html, '<!--GuestUploadStart-->')) {
                $html = str_replace('<!--GuestUploadStart-->', '', $html);
                $html = str_replace('<!--GuestUploadEnd-->', '', $html);
            }
            while (strpos($html, '<!--IsNotHiddenStart-->')) {
Q
qkqpttgf 已提交
2043 2044 2045 2046 2047
                $tmp = splitfirst($html, '<!--IsNotHiddenStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsNotHiddenEnd-->');
                $html .= $tmp[1];
            }
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
        } else {
            while (strpos($html, '<!--GuestUploadStart-->')) {
                $tmp = splitfirst($html, '<!--GuestUploadStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--IsNotHiddenStart-->')) {
                $html = str_replace('<!--IsNotHiddenStart-->', '', $html);
                $html = str_replace('<!--IsNotHiddenEnd-->', '', $html);
            }
        }
Q
qkqpttgf 已提交
2060 2061 2062 2063 2064 2065
        $DriverFile = scandir(__DIR__ . $slash . 'disk');
        $Driver_arr = null;
        foreach ($DriverFile as $v1) {
            if ($v1!='.' && $v1!='..') {
                $v1 = splitlast($v1, '.php')[0];
                $Driver_arr[] = $v1;
R
v3  
root 已提交
2066
            }
Q
qkqpttgf 已提交
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077
        }
        if ($_SERVER['is_guestup_path']||( $_SERVER['admin']&&$files['type']=='folder'&&$_SERVER['ishidden']<4 )) {
            while (strpos($html, '<!--UploadJsStart-->')) $html = str_replace('<!--UploadJsStart-->', '', $html);
            while (strpos($html, '<!--UploadJsEnd-->')) $html = str_replace('<!--UploadJsEnd-->', '', $html);
            $now_driver = baseclassofdrive();
            unset($Driver_arr[$now_driver]);
            while (strpos($html, '<!--' . $now_driver . 'UploadJsStart-->')) $html = str_replace('<!--' . $now_driver . 'UploadJsStart-->', '', $html);
            while (strpos($html, '<!--' . $now_driver . 'UploadJsEnd-->')) $html = str_replace('<!--' . $now_driver . 'UploadJsEnd-->', '', $html);
            foreach ($Driver_arr as $driver) {
                while (strpos($html, '<!--' . $driver . 'UploadJsStart-->')) {
                    $tmp = splitfirst($html, '<!--' . $driver . 'UploadJsStart-->');
R
v3  
root 已提交
2078
                    $html = $tmp[0];
Q
qkqpttgf 已提交
2079
                    $tmp = splitfirst($tmp[1], '<!--' . $driver . 'UploadJsEnd-->');
R
v3  
root 已提交
2080 2081 2082 2083
                    $html .= $tmp[1];
                }
            }
            while (strpos($html, '<!--constStr@Calculate-->')) $html = str_replace('<!--constStr@Calculate-->', getconstStr('Calculate'), $html);
2084
        } else {
2085 2086
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
2087
                $tmp = splitfirst($html, '<!--UploadJsStart-->');
2088
                $html = $tmp[0];
2089
                $tmp = splitfirst($tmp[1], '<!--UploadJsEnd-->');
2090 2091
                $html .= $tmp[1];
            }
Q
qkqpttgf 已提交
2092 2093 2094 2095 2096 2097 2098
            foreach ($Driver_arr as $driver) {
                while (strpos($html, '<!--' . $driver . 'UploadJsStart-->')) {
                    $tmp = splitfirst($html, '<!--' . $driver . 'UploadJsStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--' . $driver . 'UploadJsEnd-->');
                    $html .= $tmp[1];
                }
R
v3  
root 已提交
2099
            }
Q
qkqpttgf 已提交
2100
        }
Q
qkqpttgf 已提交
2101

R
v3  
root 已提交
2102
        if ($files['type']=='file') {
Q
qkqpttgf 已提交
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124
            while (strpos($html, '<!--GuestUploadStart-->')) {
                $tmp = splitfirst($html, '<!--GuestUploadStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
                $html .= $tmp[1];
            }
            $tmp = splitfirst($html, '<!--EncryptedStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
            $html .= $tmp[1];

            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFolderStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFolderEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--IsFileStart-->')) {
                $html = str_replace('<!--IsFileStart-->', '', $html);
                $html = str_replace('<!--IsFileEnd-->', '', $html);
            }
Q
qkqpttgf 已提交
2125 2126 2127
            $html = str_replace('<!--FileEncodeUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path))), $html);
            $html = str_replace('<!--FileUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path))), $html);

Q
qkqpttgf 已提交
2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151
            $ext = strtolower(substr($path, strrpos($path, '.') + 1));
            if (in_array($ext, $exts['img'])) $ext = 'img';
            elseif (in_array($ext, $exts['video'])) $ext = 'video';
            elseif (in_array($ext, $exts['music'])) $ext = 'music';
            //elseif (in_array($ext, $exts['pdf'])) $ext = 'pdf';
            elseif ($ext=='pdf') $ext = 'pdf';
            elseif (in_array($ext, $exts['office'])) $ext = 'office';
            elseif (in_array($ext, $exts['txt'])) $ext = 'txt';
            else $ext = 'Other';
            $previewext = ['img', 'video', 'music', 'pdf', 'office', 'txt', 'Other'];
            $previewext = array_diff($previewext, [ $ext ]);
            foreach ($previewext as $ext1) {
                $tmp[1] = 'a';
                while ($tmp[1]!='') {
                    $tmp = splitfirst($html, '<!--Is'.$ext1.'FileStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--Is'.$ext1.'FileEnd-->');
                    $html .= $tmp[1];
                }
            }
            while (strpos($html, '<!--Is'.$ext.'FileStart-->')) {
                $html = str_replace('<!--Is'.$ext.'FileStart-->', '', $html);
                $html = str_replace('<!--Is'.$ext.'FileEnd-->', '', $html);
            }
Q
qkqpttgf 已提交
2152
            //while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', $files['url'], $html);
Q
qkqpttgf 已提交
2153 2154
            while (strpos($html, '<!--FileDownUrl-->')) $html = str_replace('<!--FileDownUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
            while (strpos($html, '<!--FileEncodeReplaceUrl-->')) $html = str_replace('<!--FileEncodeReplaceUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
Q
qkqpttgf 已提交
2155
            while (strpos($html, '<!--FileName-->')) $html = str_replace('<!--FileName-->', $files['name'], $html);
Q
qkqpttgf 已提交
2156 2157
            while (strpos($html, '<!--FileEncodeDownUrl-->')) $html = str_replace('<!--FileEncodeDownUrl-->', urlencode($files['url']), $html);
            //while (strpos($html, '<!--FileEncodeDownUrl-->')) $html = str_replace('<!--FileEncodeDownUrl-->', urlencode(path_format($_SERVER['base_disk_path'] . '/' . $path)), $html);
Q
qkqpttgf 已提交
2158 2159 2160
            $html = str_replace('<!--constStr@ClicktoEdit-->', getconstStr('ClicktoEdit'), $html);
            $html = str_replace('<!--constStr@CancelEdit-->', getconstStr('CancelEdit'), $html);
            $html = str_replace('<!--constStr@Save-->', getconstStr('Save'), $html);
Q
qkqpttgf 已提交
2161 2162
            //while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(curl('GET', $files['url'], '', [], 0, 1)['body']), $html);
            while (strpos($html, '<!--TxtContent-->')) $html = str_replace('<!--TxtContent-->', htmlspecialchars(get_content(spurlencode(path_format(urldecode($path)), '/'))['content']['body']), $html);
Q
qkqpttgf 已提交
2163 2164 2165
            $html = str_replace('<!--constStr@FileNotSupport-->', getconstStr('FileNotSupport'), $html);

            //$html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
R
v3  
root 已提交
2166
        } elseif ($files['type']=='folder') {
Q
qkqpttgf 已提交
2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
            while (strpos($html, '<!--GuestUploadStart-->')) {
                $tmp = splitfirst($html, '<!--GuestUploadStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--GuestUploadEnd-->');
                $html .= $tmp[1];
            }
            $tmp = splitfirst($html, '<!--EncryptedStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptedEnd-->');
            $html .= $tmp[1];
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--IsFileStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--IsFileEnd-->');
                $html .= $tmp[1];
            }
            while (strpos($html, '<!--IsFolderStart-->')) {
                $html = str_replace('<!--IsFolderStart-->', '', $html);
                $html = str_replace('<!--IsFolderEnd-->', '', $html);
            }
            $html = str_replace('<!--constStr@File-->', getconstStr('File'), $html);
            $html = str_replace('<!--constStr@ShowThumbnails-->', getconstStr('ShowThumbnails'), $html);
            $html = str_replace('<!--constStr@CopyAllDownloadUrl-->', getconstStr('CopyAllDownloadUrl'), $html);
            $html = str_replace('<!--constStr@EditTime-->', getconstStr('EditTime'), $html);
            $html = str_replace('<!--constStr@Size-->', getconstStr('Size'), $html);

            $filenum = 0;

            $tmp = splitfirst($html, '<!--FolderListStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--FolderListEnd-->');
            $FolderList = $tmp[0];
R
v3  
root 已提交
2200 2201
            foreach ($files['list'] as $file) {
                if ($file['type']=='folder') {
Q
qkqpttgf 已提交
2202 2203
                    if ($_SERVER['admin'] or !isHideFile($file['name'])) {
                        $filenum++;
Q
qkqpttgf 已提交
2204
                        $FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path) . '/' . $file['name'])), $FolderList);
R
v3  
root 已提交
2205
                        $FolderListStr = str_replace('<!--FileId-->', $file['id'], $FolderListStr);
2206
                        $FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&amp;', $file['showname']?$file['showname']:$file['name']), $FolderListStr);
R
v3  
root 已提交
2207
                        $FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['time']), $FolderListStr);
Q
qkqpttgf 已提交
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219
                        $FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
                        while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
                        $html .= $FolderListStr;
                    }
                }
            }
            $html .= $tmp[1];

            $tmp = splitfirst($html, '<!--FileListStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--FileListEnd-->');
            $FolderList = $tmp[0];
R
v3  
root 已提交
2220 2221
            foreach ($files['list'] as $file) {
                if ($file['type']=='file') {
Q
qkqpttgf 已提交
2222 2223 2224
                    if ($_SERVER['admin'] or !isHideFile($file['name'])) {
                        $filenum++;
                        $ext = strtolower(substr($file['name'], strrpos($file['name'], '.') + 1));
Q
qkqpttgf 已提交
2225
                        $FolderListStr = $FolderList;
Q
qkqpttgf 已提交
2226
                        while (strpos($FolderListStr, '<!--FileEncodeReplaceUrl-->')) $FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', encode_str_replace(path_format($_SERVER['base_disk_path'] . '/' . str_replace('&amp;', '&', $path) . '/' . $file['name'])), $FolderListStr);
Q
qkqpttgf 已提交
2227 2228 2229 2230
                        $FolderListStr = str_replace('<!--FileExt-->', $ext, $FolderListStr);
                        if (in_array($ext, $exts['music'])) $FolderListStr = str_replace('<!--FileExtType-->', 'audio', $FolderListStr);
                        elseif (in_array($ext, $exts['video'])) $FolderListStr = str_replace('<!--FileExtType-->', 'iframe', $FolderListStr);
                        else $FolderListStr = str_replace('<!--FileExtType-->', '', $FolderListStr);
Q
qkqpttgf 已提交
2231
                        $FolderListStr = str_replace('<!--FileEncodeReplaceName-->', str_replace('&','&amp;', $file['name']), $FolderListStr);
R
v3  
root 已提交
2232
                        $FolderListStr = str_replace('<!--FileId-->', $file['id'], $FolderListStr);
Q
qkqpttgf 已提交
2233
                        //$FolderListStr = str_replace('<!--FileEncodeReplaceUrl-->', path_format($_SERVER['base_disk_path'] . '/' . $path . '/' . str_replace('&','&amp;', $file['name'])), $FolderListStr);
R
v3  
root 已提交
2234
                        $FolderListStr = str_replace('<!--lastModifiedDateTime-->', time_format($file['time']), $FolderListStr);
Q
qkqpttgf 已提交
2235
                        $FolderListStr = str_replace('<!--size-->', size_format($file['size']), $FolderListStr);
Q
qkqpttgf 已提交
2236 2237 2238 2239 2240 2241 2242 2243
                        if (!!$IconValues) {
                            foreach ($IconValues as $key1 => $value1) {
                                if (isset($exts[$key1])&&in_array($ext, $exts[$key1])) {
                                    $FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
                                }
                                if ($ext==$key1) {
                                    $FolderListStr = str_replace('<!--IconValue-->', $value1, $FolderListStr);
                                }
2244
                                //error_log1('file:'.$file['name'].':'.$key1);
Q
qkqpttgf 已提交
2245
                                if (!strpos($FolderListStr, '<!--IconValue-->')) break;
Q
qkqpttgf 已提交
2246
                            }
Q
qkqpttgf 已提交
2247
                            if (strpos($FolderListStr, '<!--IconValue-->')) $FolderListStr = str_replace('<!--IconValue-->', $IconValues['default'], $FolderListStr);
Q
qkqpttgf 已提交
2248 2249 2250 2251 2252 2253 2254 2255 2256
                        }
                        while (strpos($FolderListStr, '<!--filenum-->')) $FolderListStr = str_replace('<!--filenum-->', $filenum, $FolderListStr);
                        $html .= $FolderListStr;
                    }
                }
            }
            $html .= $tmp[1];
            while (strpos($html, '<!--maxfilenum-->')) $html = str_replace('<!--maxfilenum-->', $filenum, $html);

R
v3  
root 已提交
2257
            if ($files['childcount']>200) {
Q
qkqpttgf 已提交
2258 2259 2260
                while (strpos($html, '<!--MorePageStart-->')) $html = str_replace('<!--MorePageStart-->', '', $html);
                while (strpos($html, '<!--MorePageEnd-->')) $html = str_replace('<!--MorePageEnd-->', '', $html);
                
R
v3  
root 已提交
2261
                $pagenum = $files['page'];
Q
qkqpttgf 已提交
2262
                if ($pagenum=='') $pagenum = 1;
R
v3  
root 已提交
2263
                $maxpage = ceil($files['childcount']/200);
Q
qkqpttgf 已提交
2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297

                if ($pagenum!=1) {
                    $html = str_replace('<!--PrePageStart-->', '', $html);
                    $html = str_replace('<!--PrePageEnd-->', '', $html);
                    $html = str_replace('<!--constStr@PrePage-->', getconstStr('PrePage'), $html);
                    $html = str_replace('<!--PrePageNum-->', $pagenum-1, $html);
                } else {
                    $tmp = splitfirst($html, '<!--PrePageStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--PrePageEnd-->');
                    $html .= $tmp[1];
                }
                //$html .= json_encode($files['folder']);
                if ($pagenum!=$maxpage) {
                    $html = str_replace('<!--NextPageStart-->', '', $html);
                    $html = str_replace('<!--NextPageEnd-->', '', $html);
                    $html = str_replace('<!--constStr@NextPage-->', getconstStr('NextPage'), $html);
                    $html = str_replace('<!--NextPageNum-->', $pagenum+1, $html);
                } else {
                    $tmp = splitfirst($html, '<!--NextPageStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--NextPageEnd-->');
                    $html .= $tmp[1];
                }
                $tmp = splitfirst($html, '<!--MorePageListNowStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--MorePageListNowEnd-->');
                $MorePageListNow = str_replace('<!--PageNum-->', $pagenum, $tmp[0]);
                $html .= $tmp[1];

                $tmp = splitfirst($html, '<!--MorePageListStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--MorePageListEnd-->');
                $MorePageList = $tmp[0];
Q
qkqpttgf 已提交
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308
                for ($page=1;$page<=$maxpage;$page++) {
                    if ($page == $pagenum) {
                        $MorePageListStr = $MorePageListNow;
                    } else {
                        $MorePageListStr = str_replace('<!--PageNum-->', $page, $MorePageList);
                        $MorePageListStr = str_replace('<!--PageNum-->', $page, $MorePageListStr);
                    }
                    $html .= $MorePageListStr;
                }
                $html .= $tmp[1];

Q
qkqpttgf 已提交
2309 2310
                while (strpos($html, '<!--MaxPageNum-->')) $html = str_replace('<!--MaxPageNum-->', $maxpage, $html);

Q
qkqpttgf 已提交
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333
            } else {
                while (strpos($html, '<!--MorePageStart-->')) {
                    $tmp = splitfirst($html, '<!--MorePageStart-->');
                    $html = $tmp[0];
                    $tmp = splitfirst($tmp[1], '<!--MorePageEnd-->');
                    $html .= $tmp[1];
                }
            }
            
        }

        $html = str_replace('<!--constStr@language-->', $constStr['language'], $html);

        $title = $pretitle;
        if ($_SERVER['base_disk_path']!=$_SERVER['base_path']) {
            if (getConfig('diskname')!='') $diskname = getConfig('diskname');
            else $diskname = $_SERVER['disktag'];
            $title .= ' - ' . $diskname;
        }
        $title .= ' - ' . $_SERVER['sitename'];
        $html = str_replace('<!--Title-->', $title, $html);

        $keywords = $n_path;
Q
qkqpttgf 已提交
2334 2335 2336
        if ($p_path!='') $keywords .= ', ' . $p_path;
        if ($_SERVER['sitename']!='OneManager') $keywords .= ', ' . $_SERVER['sitename'] . ', OneManager';
        else $keywords .= ', OneManager';
Q
qkqpttgf 已提交
2337 2338
        $html = str_replace('<!--Keywords-->', $keywords, $html);

Q
qkqpttgf 已提交
2339 2340
        if ($_GET['preview']) {
            $description = $n_path.', '.getconstStr('Preview');//'Preview of '.
R
v3  
root 已提交
2341
        } elseif ($files['type']=='folder') {
Q
qkqpttgf 已提交
2342 2343 2344
            $description = $n_path.', '.getconstStr('List');//'List of '.$n_path.'. ';
        }
        //$description .= 'In '.$_SERVER['sitename'];
Q
qkqpttgf 已提交
2345 2346
        $html = str_replace('<!--Description-->', $description, $html);

Q
qkqpttgf 已提交
2347
        while (strpos($html, '<!--base_disk_path-->')) $html = str_replace('<!--base_disk_path-->', (substr($_SERVER['base_disk_path'],-1)=='/'?substr($_SERVER['base_disk_path'],0,-1):$_SERVER['base_disk_path']), $html);
Q
qkqpttgf 已提交
2348
        while (strpos($html, '<!--base_path-->')) $html = str_replace('<!--base_path-->', $_SERVER['base_path'], $html);
Q
qkqpttgf 已提交
2349
        while (strpos($html, '<!--Path-->')) $html = str_replace('<!--Path-->', str_replace('%23', '#', str_replace('&','&amp;', path_format($path.'/'))), $html);
Q
qkqpttgf 已提交
2350
        while (strpos($html, '<!--constStr@Home-->')) $html = str_replace('<!--constStr@Home-->', getconstStr('Home'), $html);
2351

Q
qkqpttgf 已提交
2352 2353 2354
        $html = str_replace('<!--customCss-->', getConfig('customCss'), $html);
        $html = str_replace('<!--customScript-->', getConfig('customScript'), $html);
        
Q
qkqpttgf 已提交
2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373
        while (strpos($html, '<!--constStr@Login-->')) $html = str_replace('<!--constStr@Login-->', getconstStr('Login'), $html);
        while (strpos($html, '<!--constStr@Close-->')) $html = str_replace('<!--constStr@Close-->', getconstStr('Close'), $html);
        while (strpos($html, '<!--constStr@InputPassword-->')) $html = str_replace('<!--constStr@InputPassword-->', getconstStr('InputPassword'), $html);
        while (strpos($html, '<!--constStr@InputPasswordUWant-->')) $html = str_replace('<!--constStr@InputPasswordUWant-->', getconstStr('InputPasswordUWant'), $html);
        while (strpos($html, '<!--constStr@Submit-->')) $html = str_replace('<!--constStr@Submit-->', getconstStr('Submit'), $html);
        while (strpos($html, '<!--constStr@Success-->')) $html = str_replace('<!--constStr@Success-->', getconstStr('Success'), $html);
        while (strpos($html, '<!--constStr@GetUploadLink-->')) $html = str_replace('<!--constStr@GetUploadLink-->', getconstStr('GetUploadLink'), $html);
        while (strpos($html, '<!--constStr@UpFileTooLarge-->')) $html = str_replace('<!--constStr@UpFileTooLarge-->', getconstStr('UpFileTooLarge'), $html);
        while (strpos($html, '<!--constStr@UploadStart-->')) $html = str_replace('<!--constStr@UploadStart-->', getconstStr('UploadStart'), $html);
        while (strpos($html, '<!--constStr@UploadStartAt-->')) $html = str_replace('<!--constStr@UploadStartAt-->', getconstStr('UploadStartAt'), $html);
        while (strpos($html, '<!--constStr@LastUpload-->')) $html = str_replace('<!--constStr@LastUpload-->', getconstStr('LastUpload'), $html);
        while (strpos($html, '<!--constStr@ThisTime-->')) $html = str_replace('<!--constStr@ThisTime-->', getconstStr('ThisTime'), $html);

        while (strpos($html, '<!--constStr@Upload-->')) $html = str_replace('<!--constStr@Upload-->', getconstStr('Upload'), $html);
        while (strpos($html, '<!--constStr@AverageSpeed-->')) $html = str_replace('<!--constStr@AverageSpeed-->', getconstStr('AverageSpeed'), $html);
        while (strpos($html, '<!--constStr@CurrentSpeed-->')) $html = str_replace('<!--constStr@CurrentSpeed-->', getconstStr('CurrentSpeed'), $html);
        while (strpos($html, '<!--constStr@Expect-->')) $html = str_replace('<!--constStr@Expect-->', getconstStr('Expect'), $html);
        while (strpos($html, '<!--constStr@UploadErrorUpAgain-->')) $html = str_replace('<!--constStr@UploadErrorUpAgain-->', getconstStr('UploadErrorUpAgain'), $html);
        while (strpos($html, '<!--constStr@EndAt-->')) $html = str_replace('<!--constStr@EndAt-->', getconstStr('EndAt'), $html);
Q
qkqpttgf 已提交
2374
        
Q
qkqpttgf 已提交
2375 2376 2377 2378 2379 2380
        while (strpos($html, '<!--constStr@UploadComplete-->')) $html = str_replace('<!--constStr@UploadComplete-->', getconstStr('UploadComplete'), $html);
        while (strpos($html, '<!--constStr@CopyUrl-->')) $html = str_replace('<!--constStr@CopyUrl-->', getconstStr('CopyUrl'), $html);
        while (strpos($html, '<!--constStr@UploadFail23-->')) $html = str_replace('<!--constStr@UploadFail23-->', getconstStr('UploadFail23'), $html);
        while (strpos($html, '<!--constStr@GetFileNameFail-->')) $html = str_replace('<!--constStr@GetFileNameFail-->', getconstStr('GetFileNameFail'), $html);
        while (strpos($html, '<!--constStr@UploadFile-->')) $html = str_replace('<!--constStr@UploadFile-->', getconstStr('UploadFile'), $html);
        while (strpos($html, '<!--constStr@UploadFolder-->')) $html = str_replace('<!--constStr@UploadFolder-->', getconstStr('UploadFolder'), $html);
Q
qkqpttgf 已提交
2381
        while (strpos($html, '<!--constStr@FileSelected-->')) $html = str_replace('<!--constStr@FileSelected-->', getconstStr('FileSelected'), $html);
Q
qkqpttgf 已提交
2382
        while (strpos($html, '<!--IsPreview?-->')) $html = str_replace('<!--IsPreview?-->', (isset($_GET['preview'])?'?preview&':'?'), $html);
Q
qkqpttgf 已提交
2383 2384 2385 2386 2387

        $tmp = splitfirst($html, '<!--BackgroundStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--BackgroundEnd-->');
        if (getConfig('background')) {
Q
qkqpttgf 已提交
2388 2389 2390 2391 2392 2393 2394 2395 2396
            $html .= str_replace('<!--BackgroundUrl-->', getConfig('background'), $tmp[0]);
        }
        $html .= $tmp[1];

        $tmp = splitfirst($html, '<!--BackgroundMStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--BackgroundMEnd-->');
        if (getConfig('backgroundm')) {
            $html .= str_replace('<!--BackgroundMUrl-->', getConfig('backgroundm'), $tmp[0]);
Q
qkqpttgf 已提交
2397
        }
Q
qkqpttgf 已提交
2398
        $html .=  $tmp[1];
Q
qkqpttgf 已提交
2399 2400 2401

        $tmp = splitfirst($html, '<!--PathArrayStart-->');
        $html = $tmp[0];
2402 2403 2404 2405 2406 2407 2408 2409 2410
        if ($tmp[1]!='') {
            $tmp = splitfirst($tmp[1], '<!--PathArrayEnd-->');
            $PathArrayStr = $tmp[0];
            $tmp_url = $_SERVER['base_disk_path'];
            $tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
            while ($tmp_path!='') {
                $tmp1 = splitfirst($tmp_path, '/');
                $folder1 = $tmp1[0];
                if ($folder1!='') {
Q
qkqpttgf 已提交
2411
                    $tmp_url .= str_replace('&amp;', '&', $folder1) . '/';
zouyujia1997's avatar
zouyujia1997 已提交
2412
                    $PathArrayStr1 = str_replace('<!--PathArrayLink-->', encode_str_replace($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431
                    $PathArrayStr1 = str_replace('<!--PathArrayName-->', $folder1, $PathArrayStr1);
                    $html .= $PathArrayStr1;
                }
                $tmp_path = $tmp1[1];
            }
            $html .= $tmp[1];
        }

        $tmp = splitfirst($html, '<!--DiskPathArrayStart-->');
        $html = $tmp[0];
        if ($tmp[1]!='') {
            $tmp = splitfirst($tmp[1], '<!--DiskPathArrayEnd-->');
            $PathArrayStr = $tmp[0];
            $tmp_url = $_SERVER['base_path'];
            $tmp_path = str_replace('&','&amp;', substr(urldecode($_SERVER['PHP_SELF']), strlen($tmp_url)));
            while ($tmp_path!='') {
                $tmp1 = splitfirst($tmp_path, '/');
                $folder1 = $tmp1[0];
                if ($folder1!='') {
Q
qkqpttgf 已提交
2432
                    $tmp_url .= str_replace('&amp;', '&', $folder1) . '/';
zouyujia1997's avatar
zouyujia1997 已提交
2433
                    $PathArrayStr1 = str_replace('<!--PathArrayLink-->', encode_str_replace($folder1==$files['name']?'':$tmp_url), $PathArrayStr);
2434 2435 2436 2437 2438 2439
                    $PathArrayStr1 = str_replace('<!--PathArrayName-->', ($folder1==$_SERVER['disktag']?(getConfig('diskname')==''?$_SERVER['disktag']:getConfig('diskname')):$folder1), $PathArrayStr1);
                    $html .= $PathArrayStr1;
                }
                $tmp_path = $tmp1[1];
            }
            $html .= $tmp[1];
Q
qkqpttgf 已提交
2440
        }
Q
qkqpttgf 已提交
2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464
        
        $tmp = splitfirst($html, '<!--SelectLanguageStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--SelectLanguageEnd-->');
        $SelectLanguage = $tmp[0];
        foreach ($constStr['languages'] as $key1 => $value1) {
            $SelectLanguageStr = str_replace('<!--SelectLanguageKey-->', $key1, $SelectLanguage);
            $SelectLanguageStr = str_replace('<!--SelectLanguageValue-->', $value1, $SelectLanguageStr);
            $SelectLanguageStr = str_replace('<!--SelectLanguageSelected-->', ($key1==$constStr['language']?'selected="selected"':''), $SelectLanguageStr);
            $html .= $SelectLanguageStr;
        }
        $html .= $tmp[1];

        $tmp = splitfirst($html, '<!--NeedUpdateStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--NeedUpdateEnd-->');
        $NeedUpdateStr = $tmp[0];
        if (isset($_SERVER['needUpdate'])&&$_SERVER['needUpdate']) $NeedUpdateStr = str_replace('<!--constStr@NeedUpdate-->', getconstStr('NeedUpdate'), $NeedUpdateStr);
        else $NeedUpdateStr ='';
        $html .= $NeedUpdateStr . $tmp[1];
        
        $tmp = splitfirst($html, '<!--BackArrowStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--BackArrowEnd-->');
2465 2466
        $current_url = path_format($_SERVER['PHP_SELF'] . '/');
        if ($current_url !== $_SERVER['base_path']) {
Q
qkqpttgf 已提交
2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483
            while (substr($current_url, -1) === '/') {
                $current_url = substr($current_url, 0, -1);
            }
            if (strpos($current_url, '/') !== FALSE) {
                $parent_url = substr($current_url, 0, strrpos($current_url, '/'));
            } else {
                $parent_url = $current_url;
            }
            $BackArrow = str_replace('<!--BackArrowUrl-->', $parent_url.'/', $tmp[0]);
        }
        $html .= $BackArrow . $tmp[1];

        $tmp[1] = 'a';
        while ($tmp[1]!='') {
            $tmp = splitfirst($html, '<!--ShowThumbnailsStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--ShowThumbnailsEnd-->');
Q
qkqpttgf 已提交
2484 2485
            //if (!(isset($_SERVER['USER'])&&$_SERVER['USER']=='qcloud')) {
            if (!getConfig('disableShowThumb')) {
Q
qkqpttgf 已提交
2486
                $html .= str_replace('<!--constStr@OriginalPic-->', getconstStr('OriginalPic'), $tmp[0]) . $tmp[1];
Q
qkqpttgf 已提交
2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517
            } else $html .= $tmp[1];
        }
        $imgextstr = '';
        foreach ($exts['img'] as $imgext) $imgextstr .= '\''.$imgext.'\', '; 
        $html = str_replace('<!--ImgExts-->', $imgextstr, $html);
        

        $html = str_replace('<!--Sitename-->', $_SERVER['sitename'], $html);

        $tmp = splitfirst($html, '<!--MultiDiskAreaStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--MultiDiskAreaEnd-->');
        $disktags = explode("|",getConfig('disktag'));
        if (count($disktags)>1) {
            $tmp1 = $tmp[1];
            $tmp = splitfirst($tmp[0], '<!--MultiDisksStart-->');
            $MultiDiskArea = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--MultiDisksEnd-->');
            $MultiDisks = $tmp[0];
            foreach ($disktags as $disk) {
                $diskname = getConfig('diskname', $disk);
                if ($diskname=='') $diskname = $disk;
                $MultiDisksStr = str_replace('<!--MultiDisksUrl-->', path_format($_SERVER['base_path'].'/'.$disk.'/'), $MultiDisks);
                $MultiDisksStr = str_replace('<!--MultiDisksNow-->', ($_SERVER['disktag']==$disk?' now':''), $MultiDisksStr);
                $MultiDisksStr = str_replace('<!--MultiDisksName-->', $diskname, $MultiDisksStr);
                $MultiDiskArea .= $MultiDisksStr;
            }
            $MultiDiskArea .= $tmp[1];
            $tmp[1] = $tmp1;
        }
        $html .= $MultiDiskArea . $tmp[1];
R
v3  
root 已提交
2518
        $diskname = getConfig('diskname', $_SERVER['disktag']);
Q
qkqpttgf 已提交
2519
        if ($diskname=='') $diskname = $_SERVER['disktag'];
Q
qkqpttgf 已提交
2520
        //if (strlen($diskname)>15) $diskname = substr($diskname, 0, 12).'...';
Q
qkqpttgf 已提交
2521
        while (strpos($html, '<!--DiskNameNow-->')) $html = str_replace('<!--DiskNameNow-->', $diskname, $html);
Q
qkqpttgf 已提交
2522 2523 2524 2525
        
        $tmp = splitfirst($html, '<!--HeadomfStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--HeadomfEnd-->');
R
v3  
root 已提交
2526 2527
        if (isset($files['list']['head.omf'])) {
            $headomf = str_replace('<!--HeadomfContent-->', get_content(spurlencode(path_format($path . '/head.omf'), '/'))['content']['body'], $tmp[0]);
Q
qkqpttgf 已提交
2528 2529 2530 2531 2532 2533
        }
        $html .= $headomf . $tmp[1];
        
        $tmp = splitfirst($html, '<!--HeadmdStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
R
v3  
root 已提交
2534 2535
        if (isset($files['list']['head.md'])) {
            $headmd = str_replace('<!--HeadmdContent-->', get_content(spurlencode(path_format($path . '/head.md'), '/'))['content']['body'], $tmp[0]);
Q
qkqpttgf 已提交
2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566
            $html .= $headmd . $tmp[1];
            while (strpos($html, '<!--HeadmdStart-->')) {
                $html = str_replace('<!--HeadmdStart-->', '', $html);
                $html = str_replace('<!--HeadmdEnd-->', '', $html);
            }
        } else {
            $html .= $tmp[1];
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--HeadmdStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--HeadmdEnd-->');
                $html .= $tmp[1];
            }
        }

        $tmp[1] = 'a';
        while ($tmp[1]!='') {
            $tmp = splitfirst($html, '<!--ListStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--ListEnd-->');
            $html_aft = $tmp[1];
            if ($files) {
                $listarea = $tmp[0];
            }
            $html .= $listarea . $html_aft;
        }

        $tmp = splitfirst($html, '<!--ReadmemdStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
R
v3  
root 已提交
2567 2568
        if (isset($files['list']['readme.md'])) {
            $Readmemd = str_replace('<!--ReadmemdContent-->', get_content(spurlencode(path_format($path . '/readme.md'),'/'))['content']['body'], $tmp[0]);
Q
qkqpttgf 已提交
2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
            $html .= $Readmemd . $tmp[1];
            while (strpos($html, '<!--ReadmemdStart-->')) {
                $html = str_replace('<!--ReadmemdStart-->', '', $html);
                $html = str_replace('<!--ReadmemdEnd-->', '', $html);
            }
        } else {
            $html .= $tmp[1];
            $tmp[1] = 'a';
            while ($tmp[1]!='') {
                $tmp = splitfirst($html, '<!--ReadmemdStart-->');
                $html = $tmp[0];
                $tmp = splitfirst($tmp[1], '<!--ReadmemdEnd-->');
                $html .= $tmp[1];
            }
        }

        
        $tmp = splitfirst($html, '<!--FootomfStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--FootomfEnd-->');
R
v3  
root 已提交
2589 2590
        if (isset($files['list']['foot.omf'])) {
            $Footomf = str_replace('<!--FootomfContent-->', get_content(spurlencode(path_format($path . '/foot.omf'),'/'))['content']['body'], $tmp[0]);
Q
qkqpttgf 已提交
2591 2592 2593 2594 2595 2596 2597
        }
        $html .= $Footomf . $tmp[1];

        
        $tmp = splitfirst($html, '<!--MdRequireStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--MdRequireEnd-->');
R
v3  
root 已提交
2598
        if (isset($files['list']['head.md'])||isset($files['list']['readme.md'])) {
Q
qkqpttgf 已提交
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632
            $html .= $tmp[0] . $tmp[1];
        } else $html .= $tmp[1];

        if (getConfig('passfile')!='') {
            $tmp = splitfirst($html, '<!--EncryptBtnStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptBtnEnd-->');
            $html .= str_replace('<!--constStr@Encrypt-->', getconstStr('Encrypt'), $tmp[0]) . $tmp[1];
            $tmp = splitfirst($html, '<!--EncryptAlertStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptAlertEnd-->');
            $html .= $tmp[1];
        } else {
            $tmp = splitfirst($html, '<!--EncryptAlertStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptAlertEnd-->');
            $html .= str_replace('<!--constStr@SetpassfileBfEncrypt-->', getconstStr('SetpassfileBfEncrypt'), $tmp[0]) . $tmp[1];
            $tmp = splitfirst($html, '<!--EncryptBtnStart-->');
            $html = $tmp[0];
            $tmp = splitfirst($tmp[1], '<!--EncryptBtnEnd-->');
            $html .= $tmp[1];
        }

        $tmp = splitfirst($html, '<!--MoveRootStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--MoveRootEnd-->');
        if ($path != '/') {
            $html .= str_replace('<!--constStr@ParentDir-->', getconstStr('ParentDir'), $tmp[0]) . $tmp[1];
        } else $html .= $tmp[1];

        $tmp = splitfirst($html, '<!--MoveDirsStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--MoveDirsEnd-->');
        $MoveDirs = $tmp[0];
R
v3  
root 已提交
2633 2634 2635
        if ($files['type']=='folder') {
            foreach ($files['list'] as $file) {
                if ($file['type']=='folder') {
Q
qkqpttgf 已提交
2636 2637 2638 2639 2640 2641 2642 2643
                    $MoveDirsStr = str_replace('<!--MoveDirsValue-->', str_replace('&','&amp;', $file['name']), $MoveDirs);
                    $MoveDirsStr = str_replace('<!--MoveDirsValue-->', str_replace('&','&amp;', $file['name']), $MoveDirsStr);
                    $html .= $MoveDirsStr;
                }
            }
        }
        $html .= $tmp[1];

2644 2645 2646 2647 2648 2649
        $tmp = splitfirst($html, '<!--WriteTimezoneStart-->');
        $html = $tmp[0];
        $tmp = splitfirst($tmp[1], '<!--WriteTimezoneEnd-->');
        if (!isset($_COOKIE['timezone'])) $html .= str_replace('<!--timezone-->', $_SERVER['timezone'], $tmp[0]);
        $html .= $tmp[1];
        while (strpos($html, '<!--timezone-->')) $html = str_replace('<!--timezone-->', $_SERVER['timezone'], $html);
Q
qkqpttgf 已提交
2650

Q
qkqpttgf 已提交
2651 2652 2653
        while (strpos($html, '{{.RawData}}')) {
            $str = '[';
            $i = 0;
R
v3  
root 已提交
2654
            foreach ($files['list'] as $file) if ($_SERVER['admin'] or !isHideFile($file['name'])) {
Q
qkqpttgf 已提交
2655 2656 2657 2658 2659
                $tmp = [];
                $tmp['name'] = $file['name'];
                $tmp['size'] = size_format($file['size']);
                $tmp['date'] = time_format($file['lastModifiedDateTime']);
                $tmp['@time'] = $file['date'];
R
v3  
root 已提交
2660
                $tmp['@type'] = ($file['type']=='folder')?'folder':'file';
Q
qkqpttgf 已提交
2661 2662 2663 2664 2665 2666 2667 2668
                $str .= json_encode($tmp).',';
            }
            if ($str == '[') {
                $str = '';
            } else $str = substr($str, 0, -1).']';
            $html = str_replace('{{.RawData}}', base64_encode($str), $html);
        }

Q
qkqpttgf 已提交
2669 2670
        // 最后清除换行
        while (strpos($html, "\r\n\r\n")) $html = str_replace("\r\n\r\n", "\r\n", $html);
2671 2672
        //while (strpos($html, "\r\r")) $html = str_replace("\r\r", "\r", $html);
        while (strpos($html, "\n\n")) $html = str_replace("\n\n", "\n", $html);
Q
qkqpttgf 已提交
2673 2674 2675
        //while (strpos($html, PHP_EOL.PHP_EOL)) $html = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $html);

        $exetime = round(microtime(true)-$_SERVER['php_starttime'],3);
R
v3  
root 已提交
2676 2677 2678
        //$ip2city = json_decode(curl('GET', 'http://ip.taobao.com/outGetIpInfo?ip=' . $_SERVER['REMOTE_ADDR'] . '&accessKey=alibaba-inc')['body'], true);
        //if ($ip2city['code']===0) $city = ' ' . $ip2city['data']['city'];
        $html = str_replace('<!--FootStr-->', date("Y-m-d H:i:s") . " " . getconstStr('Week')[date("w")] . " " . $_SERVER['REMOTE_ADDR'] . $city . ' Runningtime:' . $exetime . 's Mem:' . size_format(memory_get_usage()), $html);
Q
qkqpttgf 已提交
2679 2680
    }

2681
    /*if ($_SERVER['admin']||!getConfig('disableChangeTheme')) {
Q
qkqpttgf 已提交
2682
        $theme_arr = scandir(__DIR__ . $slash . 'theme');
R
v3  
root 已提交
2683 2684 2685 2686
        $selecttheme = '
    <div style="position: fixed;right: 10px;bottom: 10px;">
        <select name="theme" onchange="changetheme(this.options[this.options.selectedIndex].value)">
            <option value="">'.getconstStr('Theme').'</option>';
2687
        foreach ($theme_arr as $v1) {
R
v3  
root 已提交
2688 2689
            if ($v1!='.' && $v1!='..') $selecttheme .= '
            <option value="' . $v1 . '"' . ($v1==$theme?' selected="selected"':'') . '>' . $v1 . '</option>';
2690
        }
R
v3  
root 已提交
2691 2692 2693 2694 2695
        $selecttheme .= '
        </select>
    </div>
';
        $selectthemescript ='
Q
qkqpttgf 已提交
2696 2697 2698
<script type="text/javascript">
    function changetheme(str)
    {
Q
qkqpttgf 已提交
2699 2700 2701 2702
        var expd = new Date();
        expd.setTime(expd.getTime()+(2*60*60*1000));
        var expires = "expires="+expd.toGMTString();
        document.cookie=\'theme=\'+str+\'; path=/; \'+expires;
Q
qkqpttgf 已提交
2703 2704 2705
        location.href = location.href;
    }
</script>';
R
v3  
root 已提交
2706 2707
        $tmp = splitfirst($html, '</body>');
        $html = $tmp[0] . $selecttheme . '</body>' . $selectthemescript . $tmp[1];
2708
    }*/
Q
qkqpttgf 已提交
2709

R
v3  
root 已提交
2710 2711
    $tmp = splitfirst($html, '</title>');
    $html = $tmp[0] . '</title>' . $authinfo . $tmp[1];
R
refer  
root 已提交
2712
    //if (isset($_SERVER['Set-Cookie'])) return output($html, $statusCode, [ 'Set-Cookie' => $_SERVER['Set-Cookie'], 'Content-Type' => 'text/html' ]);
R
v3  
root 已提交
2713
    return output($html, $statusCode);
Q
qkqpttgf 已提交
2714
}