|
|
@@ -1,12 +1,13 @@
|
|
|
-#!/usr/bin/php
|
|
|
+#!/usr/bin/env php
|
|
|
<?php
|
|
|
-$update_only = 0;
|
|
|
-if( $argv[1] && stripos( $argv[1], "update") !== false ) $update_only = 1;
|
|
|
-
|
|
|
$user_info = posix_getpwuid(posix_geteuid());
|
|
|
$wd = realpath( dirname( __FILE__ ) . "/../" );
|
|
|
|
|
|
-if( !$update_only ) {
|
|
|
+// Look for the $private_base and $public_base. Assume /var/www/ if no homedir.
|
|
|
+$homedir = ( $user_info['dir'] ? $user_info['dir'] : '/var/www/' );
|
|
|
+$private_base = ( file_exists( "$homedir/.tCMS_basedir" ) ) ? file_get_contents( "$homedir/.tCMS_basedir" ) : "";
|
|
|
+
|
|
|
+if( empty( $private_base ) ) {
|
|
|
echo "[NOTE] Make sure the directories you install to are R+W accessible by your web server.\n";
|
|
|
echo " On most shared hosts (cPanel, etc.) this is fine to leave in your home directory.\n\n";
|
|
|
echo "Please enter the directory you wish for tCMS' private data files to be stored under.\n";
|
|
|
@@ -19,6 +20,7 @@ if( !$update_only ) {
|
|
|
$private_base = realpath( dirname( $input ) ) . "/" . basename( $input );
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
echo "Please enter the directory you for tCMS' public data files.\n";
|
|
|
echo "Default [" . $user_info['dir'] . "/public_html]: ";
|
|
|
$input = get_string_from_stdin();
|
|
|
@@ -27,55 +29,41 @@ if( empty( $input ) ) {
|
|
|
} else {
|
|
|
$public_base = realpath( dirname( $input ) ) . "/" . basename( $input );
|
|
|
}
|
|
|
+
|
|
|
+echo "[INFO] Installing private data to $private_base now...\n";
|
|
|
+$files = [ 'lib', 'templates' ];
|
|
|
+install( $private_base, $wd, $files );
|
|
|
+ensure_directories_exist( [ "$private_base/blog", "$private_base/microblog", "$private_base/conf" ] );
|
|
|
+
|
|
|
# Make sure our webserver (and my horrible code) knows how to find your custom directory
|
|
|
-if( !$update_only ) {
|
|
|
- if( $private_base != $user_info['dir'] . "/.tCMS" ) {
|
|
|
- echo "[WARN]: For tCMS to know where this directory we install to is, we will write the following\n";
|
|
|
- echo " into your document root for the default/virtual host you control on your Web Server:\n";
|
|
|
- echo " '$public_base/basedir'\n";
|
|
|
- echo " Please add an HTACCESS or similar blocker to prevent public acess to this file if you\n";
|
|
|
- echo " wish to prevent this information disclosure. Please press [enter] to continue.";
|
|
|
- get_string_from_stdin(); # Mostly just to make the user confirm they read this.
|
|
|
- }
|
|
|
+if( !file_exists($user_info['dir'] . "/.tCMS_basedir") ) {
|
|
|
+ echo "[INFO]: For tCMS to know where the directory we installed to was, we will write the following\n";
|
|
|
+ echo " into your home directory:\n";
|
|
|
+ echo " '" . $user_info["dir"] . "/.tCMS_basedir'\n";
|
|
|
+ echo " Please press [enter] to continue.";
|
|
|
+ get_string_from_stdin(); # Mostly just to make the user confirm they read this.
|
|
|
+ file_put_contents( $user_info['dir'] . "/.tCMS_basedir", $private_base );
|
|
|
+}
|
|
|
+
|
|
|
+# Create admin user
|
|
|
+if( !file_exists("$private_base/conf/users.json") ) {
|
|
|
while( empty($username) ) {
|
|
|
- echo "Please enter in the name you'd like to login to tCMS as (you can add more users later): ";
|
|
|
+ echo "Please enter in the name you'd like to login to tCMS as administrator (you can add more users later): ";
|
|
|
$username = get_string_from_stdin();
|
|
|
}
|
|
|
while( empty($password) ) {
|
|
|
echo "Please enter a password for the user: ";
|
|
|
$password = get_string_from_stdin(1);
|
|
|
+ $auth_hash = password_hash( $password, PASSWORD_DEFAULT );
|
|
|
}
|
|
|
-
|
|
|
- echo "[INFO] Installing private data to $private_base now...\n";
|
|
|
- $files = [ 'lib', 'templates' ];
|
|
|
- install( $private_base, $wd, $files );
|
|
|
- ensure_directories_exist( [ "$private_base/blog", "$private_base/microblog", "$private_base/conf" ] );
|
|
|
-
|
|
|
- echo "[INFO] Writing user configuration and generating 4096 bit RSA keypair now...\n";
|
|
|
- $openssl_config = [
|
|
|
- 'private_key_bits' => 4096,
|
|
|
- 'digest_alg' => "sha512",
|
|
|
- 'private_key_type' => OPENSSL_KEYTYPE_RSA,
|
|
|
- ];
|
|
|
- $cryptkeeper = openssl_pkey_new( $openssl_config );
|
|
|
- openssl_pkey_export( $cryptkeeper, $privkey, $password );
|
|
|
- $pubkey = openssl_pkey_get_details($cryptkeeper);
|
|
|
- $pubkey = $pubkey["key"];
|
|
|
- file_put_contents( "$private_base/conf/users.json", json_encode( [ $username => [ 'pubkey' => $pubkey ] ] ) );
|
|
|
- echo "*** PLEASE COPY THE BELOW PRIVATE KEY AND SAVE IT SOMEWHERE SAFE!!!! ***\n";
|
|
|
- echo "*** THIS IS IMPORTANT AS THIS KEY WILL BE USED FOR YOUR LOGIN! ***\n\n";
|
|
|
- echo "$privkey\n\n";
|
|
|
- echo "Please press [ENTER] to continue.";
|
|
|
- get_string_from_stdin();
|
|
|
+ echo "\n[INFO] Writing user configuration now...\n";
|
|
|
+ file_put_contents( "$private_base/conf/users.json", json_encode( [ $username => [ 'auth_hash' => $auth_hash ] ] ) );
|
|
|
}
|
|
|
|
|
|
echo "[INFO] Installing public data to $public_base now...\n";
|
|
|
$files = [ 'css', 'fileshare', 'img', 'index.php', 'sys' ];
|
|
|
install( $public_base, $wd, $files );
|
|
|
ensure_directories_exist( [ "$public_base/css/custom", "$public_base/img/icon/custom" ] );
|
|
|
-if( !$update_only && $private_base != $user_info['dir'] . "/.tCMS" ) {
|
|
|
- file_put_contents( "$public_base/basedir", $private_base );
|
|
|
-}
|
|
|
|
|
|
echo "[INFO] Done.\n";
|
|
|
exit(0);
|