-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
cli.php
executable file
·145 lines (112 loc) · 4.11 KB
/
cli.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Vvveb
*
* Copyright (C) 2022 Ziadin Givan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Vvveb;
$msg = <<<MSG
Usage cli.php [app] [parameters...]
where app can be admin, app or install and parameters are a list of name=value that will be used as Http GET/POST parameters when calling controllers.
You can call any module and action by passing the corresponding module and action parameters.
Note:For admin app super admin is used as user.
Examples:
#disable plugin
php cli.php admin module=plugin/plugins action=deactivate plugin=markdown-import
#activate plugin
php cli.php admin module=plugin/plugins action=checkPluginAndActivate plugin=markdown-import
#delete post
php cli.php admin module=content/posts action=delete post_id=1
#fresh install MySQL
php cli.php install host=127.0.0.1 user=root password= database=vvveb admin[email][email protected] admin[password]=admin
#fresh install PgSQL
php cli.php install engine=pgsql host=127.0.0.1 user=postgres password= database=vvveb admin[email][email protected] admin[password]=admin
#fresh install SQLite
php cli.php install engine=sqlite admin[email][email protected] admin[password]=admin
#import markdown posts from folder /docs/user into site with id 5
php cli.php admin module=plugins/markdown-import/settings action=import site_id=5 settings[path]=/docs/user
#import markdown posts from folder /docs/developer into site with id 6
php cli.php admin module=plugins/markdown-import/settings action=import site_id=6 settings[path]=/docs/developer
#import content
php cli.php admin module=tools/import action=upload file[]=pages.xml file[]=menus.xml
php cli.php admin module=tools/import action=upload file[]='/home/www/vvveb/pages.xml' file[]='/home/www/vvveb/landing-menu-export.xml' file[]='/home/www/vvveb/plugins.xml' file[]='/home/www/vvveb/themes.xml' file[]='/home/www/vvveb/plugins-posts.xml'
# run cron jobs
php cli.php app module=cron
# simulate a page request and get page json as output
php cli.php app request_uri=/hello-world
\n
MSG;
define('V_VERSION', '0.0.1');
function is_installed() {
return file_exists(DIR_ROOT . 'config' . DS . 'db.php');
}
$params = implode('&', array_slice($argv, 2));
parse_str($params, $_GET);
parse_str($params, $_POST);
//simulate a page request
if (isset($_GET['request_uri'])) {
$_SERVER['REQUEST_URI'] = $_GET['request_uri'];
} else {
define('CLI',true);
}
$app = 'app';
$appDir = '';
if (isset($argv[1])) {
switch ($argv[1]) {
case 'install':
$app = 'install';
$appDir = 'install';
break;
case 'admin':
$app = 'admin';
$appDir = 'admin';
break;
}
} else {
die($msg);
}
define('DS', DIRECTORY_SEPARATOR);
define('DIR_ROOT', __DIR__ . DS);
define('DIR_SYSTEM', DIR_ROOT . 'system' . DS);
define('PUBLIC_PATH', DS . 'public' . DS);
defined('PAGE_CACHE_DIR') || define('PAGE_CACHE_DIR', 'page-cache' . DS);
define('PUBLIC_THEME_PATH', DS . 'public' . DS);
define('APP', $app);
//common constants
include DIR_ROOT . 'env.php';
include DIR_SYSTEM . '/core/startup.php';
function superAdminLogin() {
$login =
[
'admin_id' => 1,
'username' => 'admin',
'email' => 'cli@vvveb',
'url' => '',
'registered' => '',
'token' => '',
'status' => 1,
'display_name' => 'Super Admin',
'role_id' => 1,
'permissions' => ['allow' => ['*'], 'deny' => ['']],
];
return session(['admin' => $login]);
}
if ($app == 'admin') {
superAdminLogin();
}
System\Core\Response::getInstance()->setType('json');
System\Core\start();