forked from liexusong/php-beast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt_project.php
71 lines (58 loc) · 1.66 KB
/
encrypt_project.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
<?php
function getext($file) {
$list = explode('.', $file);
return strtolower($list[count($list)-1]);
}
function encrypt_project($project, $new_project) {
$project = rtrim($project, '/');
$new_project = rtrim($new_project, '/');
if (!file_exists($new_project)) {
if (!mkdir($new_project)) {
printf("[failed] failed to call `mkdir()' function\n");
return false;
}
}
$hdl_o = opendir($project);
$hdl_n = opendir($new_project);
if (!$hdl_o || !$hdl_n) {
if ($hdl_o) closedir($hdl_o);
if ($hdl_n) closedir($hdl_n);
printf("[failed] failed to call `opendir()' function\n");
return false;
}
while (($file = readdir($hdl_o)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$path = $project.'/'.$file;
if (is_dir($path)) {
encrypt_project($path, $new_project.'/'.$file);
} elseif (is_file($path) && getext($file) == 'php') {
beast_encode_file($path, $new_project.'/'.$file);
} else {
copy($path, $new_project.'/'.$file);
}
}
closedir($hdl_o);
closedir($hdl_n);
return true;
}
$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");
if (!$stdin || !$stdout) {
if ($stdin) fclose($stdin);
if ($stdout) fclose($stdout);
exit("[failed] failed to open I/O stream\n");
}
fwrite($stdout, "Please enter project path: ");
$project = fgets($stdin);
$project = trim($project);
fwrite($stdout, "Please enter output project path: ");
$new_project = fgets($stdin);
$new_project = trim($new_project);
$start = time();
fwrite($stdout, "Encrypting...\n");
encrypt_project($project, $new_project); /* encrypt project */
$spend = time() - $start;
fwrite($stdout, "Finish encrypt, spend {$spend} seconds.\n");
?>