diff --git a/.env.test b/.env.test index 1abba9df1..2eba605af 100644 --- a/.env.test +++ b/.env.test @@ -3,5 +3,6 @@ PATHS_STATES=$(pwd)/../core/test/fixtures/states PATHS_PLUGINS=$(pwd)/../core/test/fixtures/plugins PATHS_UNRAID_VERSION=$(pwd)/../core/test/fixtures/etc/unraid-version PATHS_DYNAMIX_CONFIG=$(pwd)/../core/test/fixtures/boot/config/plugins/dynamix/dynamix.cfg +PATHS_MY_SERVERS_CONFIG=$(pwd)/../core/test/fixtures/boot/config/plugins/Unraid.net/myservers.cfg NCHAN=false PORT=5000 \ No newline at end of file diff --git a/README.md b/README.md index 7b99b0b9a..011170cf7 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Debug logs can be enabled via stdout while running with `start-debug`. ## Playground The playground can be access via `http://tower.local/graphql` while `PLAYGROUND=true` and `INTROSPECTION=true`. These values can be set in the `ecosystem.config.js` file in `/usr/local/bin/node/unraid-api`. -To get your API key open a terminal on your server and run `cat /boot/config/plugins/dynamix/dynamix.cfg | grep apikey= | cut -d '"' -f2`. Add that api key in the "HTTP headers" panel of the playground. +To get your API key open a terminal on your server and run `cat /boot/config/plugins/Unraid.net/myservers.cfg | grep apikey= | cut -d '"' -f2`. Add that api key in the "HTTP headers" panel of the playground. ```json { diff --git a/app/core/api-manager.ts b/app/core/api-manager.ts index f8933c2ed..60228ba4b 100644 --- a/app/core/api-manager.ts +++ b/app/core/api-manager.ts @@ -3,6 +3,7 @@ * Written by: Alexis Tyler */ +import path from 'path'; import chokidar from 'chokidar'; import { EventEmitter } from 'events'; import toMillisecond from 'ms'; @@ -116,12 +117,11 @@ export class ApiManager extends EventEmitter { // Create singleton ApiManager.instance = this; - // Watch for changes to the dynamix.cfg file + // Watch for changes to the myservers.cfg file // @todo Move API keys to their own file - const basePath = paths.get('dynamix-base')!; - const configPath = paths.get('dynamix-config')!; + const configPath = paths.get('myservers-config')!; if (options.watch) { - chokidar.watch(basePath, { + chokidar.watch(path.basename(configPath), { ignoreInitial: true }).on('all', async (_eventName, filePath) => { if (filePath === configPath) { diff --git a/app/core/paths.ts b/app/core/paths.ts index 2e13d866c..6ab300a49 100644 --- a/app/core/paths.ts +++ b/app/core/paths.ts @@ -16,6 +16,7 @@ export interface Paths { 'emhttpd-socket': string; 'dynamix-base': string; 'dynamix-config': string; + 'myservers-config': string; 'nginx-origin': string; 'machine-id': string; } @@ -46,6 +47,7 @@ export const defaultPaths = new Map([ ['states', '/usr/local/emhttp/state/'], ['dynamix-base', '/boot/config/plugins/dynamix/'], ['dynamix-config', '/boot/config/plugins/dynamix/dynamix.cfg'], + ['myservers-config', '/boot/config/plugins/Unraid.net/myservers.cfg'], ['nginx-origin', '/var/run/nginx.origin'], ['machine-id', '/etc/machine-id'] ]); diff --git a/ava.config.cjs b/ava.config.cjs index 4efe05fc1..1335311bb 100644 --- a/ava.config.cjs +++ b/ava.config.cjs @@ -8,6 +8,7 @@ const config = { PATHS_STATES: path.resolve(__dirname, './dev/states'), PATHS_DYNAMIX_BASE: path.resolve(__dirname, './dev/dynamix'), PATHS_DYNAMIX_CONFIG: path.resolve(__dirname, './dev/dynamix/dynamix.cfg'), + PATHS_MY_SERVERS_CONFIG: path.resolve(__dirname, './dev/Unraid.net/myservers.cfg'), API_KEY: 'TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST' }, files: [ diff --git a/dev/Unraid.net/myservers.cfg b/dev/Unraid.net/myservers.cfg new file mode 100644 index 000000000..c4564ae1e --- /dev/null +++ b/dev/Unraid.net/myservers.cfg @@ -0,0 +1,11 @@ +[remote] +apikey="_______________________BIG_API_KEY_HERE_________________________" +email="test@example.com" +wanaccess="no" +wanport="0" +username="zspearmint" +avatar="https://via.placeholder.com/200" +regWizTime="1611175408732_0951-1653-3509-FBA155FA23C0" +event="REG_WIZARD" +keyfile="_____________________EVEN_BIGGER_KEY_HERE_________________________" +license="" \ No newline at end of file diff --git a/dev/dynamix/dynamix.cfg b/dev/dynamix/dynamix.cfg index 305745cb9..8fe95fabe 100644 --- a/dev/dynamix/dynamix.cfg +++ b/dev/dynamix/dynamix.cfg @@ -18,20 +18,6 @@ critical="90" hot="45" max="55" sysinfo="/Tools/SystemProfiler" -[remote] -apikey="TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST_TEST" -wanaccess="yes" -wanport="0" -sshprivkey="-----BEGIN OPENSSH PRIVATE KEY----- -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ------END OPENSSH PRIVATE KEY----- -" -sshpubkey="ssh-ed25519 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -" [notify] entity="1" normal="1" @@ -46,6 +32,4 @@ date="d-m-Y" time="H:i" position="top-right" path="/tmp/notifications" -system="*/1 * * * *" -[wizard] -hideWizard="1" +system="*/1 * * * *" \ No newline at end of file diff --git a/dynamix.unraid.net.plg b/dynamix.unraid.net.plg index 9f7654728..71928dfb2 100644 --- a/dynamix.unraid.net.plg +++ b/dynamix.unraid.net.plg @@ -30,7 +30,7 @@ if [ -e /etc/rc.d/rc.unraid-api ]; then rm -f /etc/rc.d/rc.unraid-api rm -f /etc/rc.d/rc.flash_backup mv -f /usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php- /usr/local/emhttp/plugins/dynamix/include/UpdateDNS.php - mv -f /usr/local/emhttp/plugins/dynamix/Registration.page- /usr/local/emhttp/plugins/dynamix/Registration.page + mv -f /usr/local/emhttp/plugins/dynamix.unraid.net/Registration.page- /usr/local/emhttp/plugins/dynamix/Registration.page mv -f /usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php- /usr/local/emhttp/plugins/dynamix/include/DefaultPageLayout.php mv -f /usr/local/emhttp/plugins/dynamix/DisplaySettings.page- /usr/local/emhttp/plugins/dynamix/DisplaySettings.page rm -rf /boot/config/plugins/Unraid.net/wc @@ -73,9 +73,8 @@ require_once "$docroot/webGui/include/Translations.php"; $var = (array)parse_ini_file('state/var.ini'); $license_state = strtoupper(empty($var['regCheck']) ? $var['regTy'] : $var['regCheck']); $key_contents = str_replace(['+','/','='], ['-','_',''], trim(base64_encode(@file_get_contents($var['regFILE'])))); - -if (file_exists('/boot/config/plugins/dynamix/dynamix.cfg')) { - extract(parse_ini_file('/boot/config/plugins/dynamix/dynamix.cfg',true)); +if (file_exists('/boot/config/plugins/Unraid.net/myservers.cfg')) { + extract(parse_ini_file('/boot/config/plugins/Unraid.net/myservers.cfg',true)); } $arr = []; @@ -622,7 +621,7 @@ Tag="globe" ?> _(Unraid.net Status)_: -: +: _(Allow Remote Access)_: @@ -920,7 +919,7 @@ function response_complete($httpcode, $result, $cli_success_msg='') { } // remoteaccess, externalport, (if registering) username, password -extract(parse_ini_file('/boot/config/plugins/dynamix/dynamix.cfg',true)); +extract(parse_ini_file('/boot/config/plugins/Unraid.net/myservers.cfg',true)); if (empty($remote)) { $remote = [ "apikey" => "", @@ -1153,8 +1152,8 @@ $cli = php_sapi_name()=='cli'; $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'; -if (file_exists('/boot/config/plugins/dynamix/dynamix.cfg')) { - extract(parse_ini_file('/boot/config/plugins/dynamix/dynamix.cfg',true)); +if (file_exists('/boot/config/plugins/Unraid.net/myservers.cfg')) { + extract(parse_ini_file('/boot/config/plugins/Unraid.net/myservers.cfg',true)); } if (empty($remote)) { $remote = [ @@ -1592,7 +1591,7 @@ function handleMessage(e) { case "REG_WIZARD": if (data.apikey) { var postargs = { - '#file': 'dynamix/dynamix.cfg', + '#file': 'Unraid.net/myservers.cfg', '#section': 'remote', apikey: data.apikey, regWizTime: `${Date.now()}_${data.guid}`, // set when signing in the first time and never unset for the sake of displaying Sign In/Up in the UPC without needing to validate guid every time @@ -1607,7 +1606,7 @@ function handleMessage(e) { postargs['avatar'] = data.avatar; } $.post('/update.php', postargs, function() { - console.log('dynamix/dynamix.cfg: Updated apikey under [remote] section'); + console.log('Unraid.net/myservers.cfg: Updated apikey under [remote] section'); // send a ping back to the regwiz const payload = { event: 'ACCOUNT_PINGBACK', success: true, type: 'signIn', webGuiPathname: window.location.pathname }; e.source.postMessage(JSON.stringify(payload), e.origin); @@ -1643,14 +1642,14 @@ function handleMessage(e) { break; case "MYSERVERS_UNREGISTER": $.post('/update.php', { - '#file': 'dynamix/dynamix.cfg', + '#file': 'Unraid.net/myservers.cfg', '#section': 'remote', apikey: '', avatar: '', email: '', username: '', }, function() { - console.log('dynamix/dynamix.cfg: Unregistered myservers, cleared apikey under [remote] section'); + console.log('Unraid.net/myservers.cfg: Unregistered myservers, cleared apikey under [remote] section'); // send a ping back to the regwiz const payload = { event: 'ACCOUNT_PINGBACK', success: true, type: 'signOut', webGuiPathname: window.location.pathname }; e.source.postMessage(JSON.stringify(payload), e.origin); @@ -2338,6 +2337,285 @@ _(Header show description)_: + + + + + + + + + +_(Thank you for trying Unraid OS)_! + + + +_(Thank you for choosing Unraid OS)_! + + + + + +
+:registration_1_plug: +Your server will not be usable until you purchase a Registration key or install a free 30-day *Trial* key. A *Trial* +key provides all the functionality of a *Pro* Registration key. + +Registration keys are bound to your USB Flash boot device serial number (GUID). Please use a high quality name brand device +at least 1GB in size. + +Note: USB memory card readers are generally **not** supported because most do not present unique serial numbers. +:end +_(Important)_: + +:registration_2_plug: ++ Please make sure your [server time](DateTime) is accurate to within 5 minutes. ++ Please make sure there is a [DNS server](NetworkSettings) specified. +:end +
+ + + + + +
+:registration_3_plug: +Your *Trial* key includes all the functionality and device support of a *Pro* Registration key. + +After your *Trial* key has reached expiration, your server **still functions normally** until the next time you **Stop** the array. + +At that point, you may either purchase a Registration key, or request a *Trial* extension. +:end +
+ + + + + +
+_(Cannot connect to key-server)_! + +_(Your *Trial* key requires an internet connection)_. _(Please check your)_ [_(Network Settings)_](NetworkSettings). +
+ + + + + +
+_(Release has been withdrawn)_! + +_(This release has been withdrawn for use with *Trial* keys)_. +
+ + + + + +
+_(Your *Trial* key has expired)_. +:registration_4_plug: +To continue using Unraid OS you may purchase a Registration key. Alternately, you may request a *Trial* extension key. + +Most *Trial* extension requests are processed immediately but please allow up to one business day to receive your *Trial* extension key. +:end +
+ + + + + +_(Invalid *Trial* Installation)_ +
+:registration_5_plug: +It is not possible to use a *Trial* key with an existing Unraid OS installation. + +You may purchase a Registration key corresponding to this USB Flash device to continue using this installation. + +For more information, please [Contact Support](https://lime-technology.com/contact). +:end +
+ + + + + +_(Missing Key File)_ +
+:registration_6_plug: +It appears that your Registration key file is corrupted or missing. The key file should be located in the +[config](/Registration/Browse?dir=/boot/config) directory on your USB Flash boot device. + +If you do not have a backup copy of your Registration key file, [Contact Support](https://lime-technology.com/contact). + +If this was a *Trial* installation, you may purchase a Registration key. +:end +
+ + + + + +_(The registered GUID does not match the USB Flash boot device GUID)_ + + + +
+:registration_7_plug: +*Trial* installations are only valid with the originally registered USB Flash device. + +To continue using this installation with this USB Flash device, you may purchase a Registration key. +:end +
+ + + +
+:registration_8_plug: +The Registration key file does not correspond to the USB Flash boot device. +Please copy the correct key file to the [config](/Registration/Browse?dir=/boot/config) directory +on your USB Flash boot device. If you do not have a backup copy of your key file, [Contact Support](https://lime-technology.com/contact). + +If you want to replace your Registration key with a new key bound to this USB Flash device, click Replace Key below. An original key may be +replaced anytime. Thereafter, a replacement key may be replaced again after one year has passed. If you require +another replacement key sooner, [Contact Support](https://lime-technology.com/contact). + +**Note:** Replacing a Registration key results in permanently *blacklisting* the previous USB Flash GUID. +:end +
+ + + + + + +_(Blacklisted USB Flash GUID)_ +
+:registration_9_plug: +This USB Flash boot device has been *blacklisted*. This can occur as a result of transfering your Registration key to +a replacement USB Flash device, and you are currently booted from your old USB Flash device. + +A USB Flash device may also be *blacklisted* if there is no serial number, or if we discover the serial number +is not unique (this is common with USB card readers). + +For more information, please [Contact Support](https://lime-technology.com/contact). +:end +
+ + + + + +_(***Trial*** key expires on)_: +: + + + + + +_(Expiration)_: +: + + + + + +_(Registered to)_: +: + +_(Registered on)_: +: + + + + + +_(Registered GUID)_: +: + + + + + +_(Error accessing your physical USB Flash boot device)_ +
+_(There is a physical problem accessing your USB Flash boot device)_. _(Please)_ [Contact Support](https://lime-technology.com/contact). + +_(Flash GUID)_: +: _(Error code)_: + + + +_(Flash GUID)_: +: + + + +_(Flash Vendor)_: +: + +_(Flash Product)_: +: + + + +_(Replaceable)_: +: + + + + + +
+ + + + + +]]> + + + + + + + + @@ -2373,6 +2651,115 @@ rm /usr/local/emhttp/plugins/dynamix/DisplaySettings.page-splice1 + + + + $var['csrf_token'], + '#file' => $mys_cfg, + '#section' => 'remote' + ]; + foreach($orig['remote'] as $key => $value) { + $fields_mys_remote[$key] = $value; + } + update($url, http_build_query($fields_mys_remote)); + } + /* + // write [wizard] section to myservers.cfg + if(!empty($orig['wizard'])) { + $fields_mys_wizard = [ + 'csrf_token' => $var['csrf_token'], + '#file' => $mys_cfg, + '#section' => 'wizard' + ]; + foreach($orig['wizard'] as $key => $value) { + $fields_mys_wizard[$key] = $value; + } + update($url, http_build_query($fields_mys_wizard)); + } + */ + // remove [remote] section from dynamix.cfg + if(!empty($orig['remote'])) { + $fields_dyn_remote = [ + 'csrf_token' => $var['csrf_token'], + '#file' => $dyn_cfg, + '#section' => 'remote', + '#cleanup' => 'true' + ]; + foreach($orig['remote'] as $key => $value) { + $fields_dyn_remote[$key] = ''; + } + update($url, http_build_query($fields_dyn_remote)); + } + // remove [wizard] section from dynamix.cfg + if(!empty($orig['wizard'])) { + $fields_dyn_wizard = [ + 'csrf_token' => $var['csrf_token'], + '#file' => $dyn_cfg, + '#section' => 'wizard', + '#cleanup' => 'true' + ]; + foreach($orig['wizard'] as $key => $value) { + $fields_dyn_wizard[$key] = ''; + } + update($url, http_build_query($fields_dyn_wizard)); + } + // remove [remote] and [wizard] section headings from dyn_cfg file + $oldtext = file_get_contents($dyn_cfg); + $newtext = preg_replace ('/\[(remote|wizard)\]\n/', '', $oldtext); + if (strcmp($oldtext, $newtext) !== 0) { + file_put_contents($dyn_cfg, $newtext); + } +} +if (!file_exists($mys_cfg)) touch($mys_cfg); + +?> + +]]> + + + + + + + + +