forked from sendya/shadowsocks-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
109 lines (101 loc) · 3.47 KB
/
index.php
File metadata and controls
109 lines (101 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
98
99
100
101
102
103
104
105
106
107
108
109
#!env php
<?php
/**
* Project Titor
* Author: kookxiang <r18@ikk.me>
*/
if (php_sapi_name() != 'cli') {
exit('Sorry, This page is not available due to incorrect server configuration.');
}
// Initialize constants
define('ROOT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('LIBRARY_PATH', ROOT_PATH . 'Library/');
define('DATA_PATH', ROOT_PATH . 'Data/');
define('TIMESTAMP', time());
@ini_set('display_errors', 'on');
@ini_set('expose_php', false);
@ini_set('date.timezone','Asia/Shanghai');
set_time_limit(0);
function command_exists($command)
{
$whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'which';
$process = proc_open(
"$whereIsCommand $command",
array(
0 => array("pipe", "r"), //STDIN
1 => array("pipe", "w"), //STDOUT
2 => array("pipe", "w"), //STDERR
),
$pipes
);
if ($process !== false) {
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $stdout != '';
}
return false;
}
switch ($argv[1]) {
case 'install':
if (!file_exists(ROOT_PATH . 'composer.phar')) {
echo 'Downloading composer...';
$ch = curl_init("http://getcomposer.org/composer.phar");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$binary = curl_exec($ch);
if (curl_errno($ch)) {
echo 'FAILED!' . PHP_EOL . curl_error($ch);
curl_close($ch);
break;
}
$fp = fopen(ROOT_PATH . 'composer.phar', 'wb');
fputs($fp, $binary);
fclose($fp);
curl_close($ch);
echo 'Done!' . PHP_EOL;
}
echo 'Now installing dependencies...' . PHP_EOL;
system(PHP_BINARY . ' ' . ROOT_PATH . 'composer.phar install');
if (!file_exists(ROOT_PATH . 'Package/autoload.php')) {
echo 'It seems composer failed to install package';
break;
}
echo 'Now reloading packages and config...';
$configFile = DATA_PATH . 'Config.php';
if (!file_exists($configFile)) {
echo 'Config Unknown... copying..' . PHP_EOL;
copy(DATA_PATH . 'Config.simple.php', $configFile);
echo 'Please modify ./Data/Config.php and try again';
break;
}
@include ROOT_PATH . 'Package/autoload.php';
@include DATA_PATH . 'Config.php';
echo 'Done!' . PHP_EOL;
echo 'Now migrating database...' . PHP_EOL;
// $phinxCommand = PHP_BINARY . ' ' . ROOT_PATH . 'Package/bin/phinx migrate';
$phinxCommand = ROOT_PATH . 'Package/bin/phinx migrate';
if(PATH_SEPARATOR!=':') {
$phinxCommand = ROOT_PATH . 'Package\bin\phinx.bat migrate';
}
system($phinxCommand);
/*
临时屏蔽 npm 自动构建
if (!command_exists('npm')) {
echo 'It seems like you don\'t have a valid npm installation. Please refer to http://nodejs.org';
break;
}
echo 'Installing front-end packages...';
system('npm install');
echo 'Building front-end resources...'.PHP_EOL;
system('npm run build');
echo 'All done~ Cheers!';
*/
echo 'All done~ Cheers!';
break;
default:
echo 'Unknown command';
}
echo PHP_EOL;