#!/usr/bin/php 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 "[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); function get_string_from_stdin($noecho=0) { if( $noecho ) system('stty -echo'); $STDIN = fopen( "php://stdin", "r" ); $input = fgets( $STDIN, 4096 ); # Not gonna read something longer than the maximum path length for ext $input = rtrim( $input ); # Trim any trailing spaces fclose( $STDIN ); if( $noecho ) system('stty echo'); return $input; } function install( $to, $from, $files2copy ) { if( file_exists( $to ) && !is_dir( $to ) ) { echo "[FATAL] $to already exists but is not a directory! Stopping here.\n"; exit(1); } if ( !file_exists( $to ) ) mkdir( $to ); # XXX Prolly won't work on directories foreach ( $files2copy as $file ) { # Referencing it by path as some systems have aliases on this command $cmd = "/bin/cp -rf '$from/$file' '$to/'"; echo "exec `$cmd`\n"; $out = shell_exec($cmd); echo $out; } return; } function ensure_directories_exist( $dirs ) { foreach ( $dirs as $dir ) { if ( !file_exists( $dir ) ) { echo "exec `/bin/mkdir '$dir'`\n"; mkdir( $dir ); } } return; } ?>