| // Gateways.js | ||
| import chalk from 'chalk'; | ||
| export function handleGateways() { | ||
| console.log(chalk.yellow('Interacting with Gateways...')); | ||
| // NetGetX logic here | ||
| } |
| // Gets.js | ||
| import chalk from 'chalk'; | ||
| export function handleGets() { | ||
| console.log(chalk.yellow('Interacting with Gets...')); | ||
| // NetGetX logic here | ||
| } |
| // netget_MainMenu.js | ||
| import inquirer from 'inquirer'; | ||
| import chalk from 'chalk'; | ||
| import { NetGetX } from './NetGetX/NetGetX.cli.js'; | ||
| import { i_DefaultNetGetX } from './NetGetX/config/i_DefaultNetGetX.js'; | ||
| import { handleGateways } from './Gateways/Gateways.js'; | ||
| import { handleGets } from './Gets/Gets.js'; | ||
| console.log(` | ||
| Welcome to: | ||
| ╔╗╔┌─┐┌┬┐╔═╗┌─┐┌┬┐ | ||
| ║║║├┤ │ ║ ╦├┤ │ | ||
| ╝╚╝└─┘ ┴ ╚═╝└─┘ ┴ | ||
| `); | ||
| export async function NetGetMainMenu() { | ||
| /* | ||
| ╔╗╔┌─┐┌┬┐╔═╗┌─┐┌┬┐ | ||
| ║║║├┤ │ ║ ╦├┤ │ | ||
| ╝╚╝└─┘ ┴ ╚═╝└─┘ ┴ | ||
| */ | ||
| const answers = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'action', | ||
| message: 'Choose an action:', | ||
| choices: ['NetGetX', 'Gateways', 'Gets', new inquirer.Separator(), 'Exit'], | ||
| }, | ||
| ]); | ||
| switch (answers.action) { | ||
| case 'NetGetX': | ||
| console.log(chalk.blue('Initializing NetGetX...')); | ||
| try { | ||
| const setupVerified = await i_DefaultNetGetX(); | ||
| if (setupVerified) { | ||
| console.log(chalk.green('Setup verification successful.')); | ||
| console.log(` | ||
| ██╗ ██╗ | ||
| ╚██╗██╔╝ | ||
| ╚███╔╝ | ||
| ██╔██╗ | ||
| ██╔╝ ██╗ | ||
| ╚═╝ ╚═╝ | ||
| `); | ||
| await NetGetX(); // Proceed to the interactive menu if setup is verified | ||
| } else { | ||
| console.log(chalk.red('Setup verification failed. Please resolve any issues before proceeding.')); | ||
| // Optionally, return to the main menu or provide options to retry | ||
| } | ||
| } catch (error) { | ||
| console.log(chalk.red(`An error occurred during setup verification: ${error.message}`)); | ||
| // Error handling or further actions can be defined here | ||
| } | ||
| break; | ||
| case 'Gateways': | ||
| console.log(chalk.yellow('Selected Gateways')); | ||
| // Call Gateways functionality here | ||
| break; | ||
| case 'Gets': | ||
| console.log(chalk.yellow('Selected Gets')); | ||
| // Call Gets functionality here | ||
| break; | ||
| case 'Exit': | ||
| console.log(chalk.green('Exiting NetGet CLI.')); | ||
| process.exit(); | ||
| } | ||
| } | ||
| //configureDefaultServerBlock.js | ||
| import fs from 'fs'; | ||
| import chalk from 'chalk'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname } from 'path'; | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const userConfigPath = path.join(__dirname, 'userConfig.json'); | ||
| async function loadUserConfig() { | ||
| try { | ||
| const data = await fs.promises.readFile(userConfigPath, 'utf8'); | ||
| return JSON.parse(data); | ||
| } catch (error) { | ||
| console.error(chalk.red(`Failed to load user configuration: ${error.message}`)); | ||
| return {}; | ||
| } | ||
| } | ||
| const defaultConfigContent = `server { | ||
| listen 80 default_server; | ||
| server_name _; | ||
| root /var/www/html; | ||
| location / { | ||
| return 200 'NGINX Default Response. Server is running.'; | ||
| } | ||
| }`; | ||
| export const configureDefaultServerBlock = async () => { | ||
| const userConfig = await loadUserConfig(); | ||
| const nginxPath = userConfig.nginxPath || '/etc/nginx/sites-available/default'; // Fallback to default if not set | ||
| try { | ||
| fs.writeFileSync(nginxPath, defaultConfigContent); | ||
| console.log(chalk.green('NGINX default server block has been configured to match NetGetX requirements.')); | ||
| } catch (error) { | ||
| console.error(chalk.red(`Failed to write NGINX default server block config at ${nginxPath}: ${error.message}`)); | ||
| } | ||
| }; |
| // configureCustomPath.js | ||
| /** | ||
| * A placeholder function for configuring a custom path for NGINX. | ||
| * Currently, it only logs a message to indicate its invocation. | ||
| */ | ||
| export function configureCustomPath() { | ||
| console.log("Configuring custom path for NGINX..."); | ||
| // Placeholder for future implementation | ||
| } |
| //i_DefaultNetGetX.js | ||
| import chalk from 'chalk'; | ||
| import { verifyNginxInstallation } from './verifyNginxInstallation.js'; | ||
| import { nginxInstallationOptions } from './nginxInstallationOptions.cli.js'; | ||
| import { verifyServerBlock } from './verifyServerBlock.js'; | ||
| import checkPublicIP from '../../utils/checkPublicIP.js'; | ||
| export async function i_DefaultNetGetX() { | ||
| console.log(chalk.blue('Running Enviroment Check...')); | ||
| // Check for public IP first | ||
| const publicIP = await checkPublicIP(); | ||
| if (publicIP) { | ||
| console.log(chalk.green(`Public IP detected: ${publicIP}`)); | ||
| // You can implement logic based on having a public IP here | ||
| } else { | ||
| console.log(chalk.red('No public IP detected. Some features may be limited.')); | ||
| // Handle the case where no public IP is available if necessary | ||
| } | ||
| // Verify NGINX installation and configuration | ||
| let nginxVerified = await verifyNginxInstallation(); | ||
| if (!nginxVerified) { | ||
| console.log(chalk.yellow('NGINX is not correctly installed or configured.')); | ||
| await nginxInstallationOptions(); | ||
| // Recheck after installation options might have changed the state | ||
| nginxVerified = await verifyNginxInstallation(); | ||
| if (!nginxVerified) { | ||
| console.log(chalk.red('NGINX installation or configuration still incorrect after attempted fixes.')); | ||
| return false; // Exit after rechecking and still failing | ||
| } | ||
| } | ||
| console.log(chalk.blue('Verifying NGINX server block...')); | ||
| const serverBlockVerified = await verifyServerBlock(); | ||
| if (!serverBlockVerified) { | ||
| console.log(chalk.yellow('NGINX server block is not correctly configured.')); | ||
| return false; // Exit if server block cannot be verified or fixed | ||
| } | ||
| console.log(chalk.green('All configurations are correct.')); | ||
| // Proceed to main functionality | ||
| return true; | ||
| } |
| import os from 'os'; | ||
| import chalk from 'chalk'; | ||
| import { exec } from 'child_process'; | ||
| import { execShellCommand } from '../../utils/execShellCommand.js'; | ||
| import { verifyNginxInstallation } from './verifyNginxInstallation.js'; | ||
| const checkForChoco = async () => { | ||
| return new Promise((resolve, reject) => { | ||
| exec('choco', (error, stdout, stderr) => { | ||
| if (error && stderr.includes('is not recognized as an internal or external command')) { | ||
| resolve(false); // Chocolatey is not installed. | ||
| } else { | ||
| resolve(true); // Chocolatey is installed or other error. | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
| const determineInstallCommand = (version, customVersion) => { | ||
| switch (os.platform()) { | ||
| case 'darwin': | ||
| return 'brew install nginx'; // Homebrew on macOS | ||
| case 'linux': | ||
| return 'sudo apt-get install nginx -y'; // Debian-based Linux | ||
| case 'win32': | ||
| return 'choco install nginx'; // Chocolatey on Windows | ||
| default: | ||
| console.error(chalk.red('Unsupported operating system for automatic installation.')); | ||
| return null; | ||
| } | ||
| }; | ||
| export const installNginx = async (version, customVersion) => { | ||
| if (os.platform() === 'win32' && !await checkForChoco()) { | ||
| console.error(chalk.yellow('Chocolatey is not installed. Please install Chocolatey or install NGINX manually.')); | ||
| return { success: false, message: 'Chocolatey not installed' }; | ||
| } | ||
| const installCmd = determineInstallCommand(version, customVersion); | ||
| if (!installCmd) return { success: false, message: 'Unsupported OS for automatic installation' }; | ||
| console.log(chalk.blue(`Using command: ${installCmd}`)); | ||
| try { | ||
| await execShellCommand(installCmd); | ||
| const isNginxVerified = await verifyNginxInstallation(); | ||
| console.log(isNginxVerified ? chalk.green('NGINX is installed and verified successfully.') : chalk.yellow('NGINX is installed but could not be verified.')); | ||
| } catch (error) { | ||
| console.error(chalk.red(`${error.message}`)); | ||
| handleInstallationError(error); | ||
| } | ||
| }; | ||
| const handleInstallationError = async (error) => { | ||
| if (error.message.toLowerCase().includes('permission denied')) { | ||
| console.log(chalk.yellow('Please check the permissions or try running the command with elevated privileges.')); | ||
| } | ||
| // Here, you can decide to prompt the user with options to retry, adjust permissions, or exit instead of automatically rerunning checks. | ||
| }; | ||
| const suggestPermissionFix = (filePath) => { | ||
| const permissionAdvice = os.platform() === 'win32' ? | ||
| `Consider adjusting the file permissions manually in the file properties of ${filePath}, or use the 'icacls' command.` : | ||
| `Consider running 'sudo chmod +rw ${filePath}' to fix permission issues.`; | ||
| console.log(chalk.cyan(permissionAdvice)); | ||
| }; |
| //nginxInstallationOptions.cli.js | ||
| import inquirer from 'inquirer'; | ||
| import { installNginx } from './installNginx.js'; | ||
| import { nxConfigMenu } from './nx_install_Options.cli.js'; | ||
| export async function nginxInstallationOptions() { | ||
| console.log("NGINX installation options are available. We recommend installing NGINX solely for NetGet and doing the configurations through the NetGet tools to avoid conflicts. If you want to use NGINX for other configurations and services please do so at your own risk and refer to both NGINX and NetGet manuals for help."); | ||
| const installConfirmation = await inquirer.prompt([ | ||
| { | ||
| type: 'confirm', | ||
| name: 'confirmInstall', | ||
| message: 'NGINX is not installed. Would you like to install it now?', | ||
| default: true | ||
| }, | ||
| { | ||
| type: 'list', | ||
| name: 'version', | ||
| message: 'Choose which version of NGINX you want to install:', | ||
| choices: ['Stable', 'Mainline', 'Custom version', 'Back to previous menu'], | ||
| when: (answers) => answers.confirmInstall | ||
| }, | ||
| { | ||
| type: 'input', | ||
| name: 'customVersion', | ||
| message: 'Enter the custom version you wish to install:', | ||
| when: (answers) => answers.version === 'Custom version' | ||
| } | ||
| ]); | ||
| switch (installConfirmation.version) { | ||
| case 'Stable': | ||
| case 'Mainline': | ||
| case 'Custom version': | ||
| await installNginx(installConfirmation.version, installConfirmation.customVersion); | ||
| break; | ||
| case 'Back to previous menu': | ||
| await nxConfigMenu(); // Call the main configuration menu again | ||
| break; | ||
| default: | ||
| console.log(chalk.yellow('Installation aborted by the user.')); | ||
| await nxConfigMenu(); // Optionally return to config menu | ||
| } | ||
| } |
| //nginxConfig.js | ||
| import inquirer from 'inquirer'; | ||
| import chalk from 'chalk'; | ||
| import { i_DefaultNetGetX } from './i_DefaultNetGetX.js'; | ||
| import { NetGetMainMenu } from '../../netget_MainMenu.cli.js'; | ||
| export async function nxConfigMenu() { | ||
| const answers = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'action', | ||
| message: 'Options:', | ||
| choices: [ | ||
| 'Install NetGetX Default Configuration (Recommended)', | ||
| 'Costum NetGetX Configuration', | ||
| 'About NetGetX', | ||
| new inquirer.Separator(), | ||
| 'Return to Main Menu', | ||
| 'Exit' | ||
| ], | ||
| }, | ||
| ]); | ||
| switch (answers.action) { | ||
| case 'Install NetGetX Default Configuration (Recommended)': | ||
| await i_DefaultNetGetX(); | ||
| break; | ||
| case 'About NetGetX': | ||
| console.log(chalk.blue('NetGetX manages network gateways efficiently...')); | ||
| // Add more informational content or link to documentation | ||
| break; | ||
| case 'Return to Main Menu': | ||
| await NetGetMainMenu(); | ||
| break; | ||
| case 'Exit': | ||
| console.log(chalk.green('Exiting NetGet CLI.')); | ||
| process.exit(); | ||
| break; | ||
| default: | ||
| console.log(chalk.red('Invalid option, please try again.')); | ||
| await nginxConfigMenu(); | ||
| } | ||
| } | ||
| import inquirer from 'inquirer'; | ||
| import chalk from 'chalk'; | ||
| import { configureDefaultServerBlock } from './configureDefaultServerBlock.js'; | ||
| export const serverBlockConfigOptions = async () => { | ||
| const answers = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'action', | ||
| message: 'How would you like to proceed with the server block configuration?', | ||
| choices: [ | ||
| 'Restore NGINX Default to Recommended Settings', | ||
| 'Proceed with Current Configuration', | ||
| 'Exit and Adjust Manually' | ||
| ] | ||
| } | ||
| ]); | ||
| switch (answers.action) { | ||
| case 'Restore NGINX Default to Recommended Settings': | ||
| await configureDefaultServerBlock(); | ||
| break; | ||
| case 'Proceed with Current Configuration': | ||
| console.log(chalk.yellow('Proceeding with existing NGINX configuration.')); | ||
| break; | ||
| case 'Exit and Adjust Manually': | ||
| console.log(chalk.green('Please adjust your NGINX configuration manually as needed.')); | ||
| process.exit(0); | ||
| break; | ||
| } | ||
| }; |
| import fs from 'fs'; | ||
| import chalk from 'chalk'; | ||
| import inquirer from 'inquirer'; | ||
| import path from 'path'; | ||
| import os from 'os'; | ||
| import { dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const userConfigPath = path.join(__dirname, 'userConfig.json'); | ||
| async function loadUserConfig() { | ||
| try { | ||
| const data = await fs.promises.readFile(userConfigPath, 'utf8'); | ||
| return JSON.parse(data); | ||
| } catch (error) { | ||
| console.error(chalk.red(`Failed to load user configuration: ${error.message}`)); | ||
| return {}; | ||
| } | ||
| } | ||
| async function saveUserConfig(userConfig) { | ||
| await fs.promises.writeFile(userConfigPath, JSON.stringify(userConfig, null, 2)); | ||
| } | ||
| async function detectNginxPath() { | ||
| // Determine the operating system to suggest more accurate default paths | ||
| const osType = os.type(); | ||
| let potentialPaths = []; | ||
| if (osType === 'Linux') { | ||
| potentialPaths.push('/etc/nginx/nginx.conf'); | ||
| } else if (osType === 'Darwin') { // macOS | ||
| potentialPaths.push('/usr/local/etc/nginx/nginx.conf', '/opt/homebrew/etc/nginx/nginx.conf'); // Paths for Homebrew installs | ||
| } else if (osType === 'Windows_NT') { | ||
| potentialPaths.push('C:\\nginx\\nginx.conf'); | ||
| } | ||
| for (const potentialPath of potentialPaths) { | ||
| if (fs.existsSync(potentialPath)) { | ||
| return potentialPath; | ||
| } | ||
| } | ||
| return ''; | ||
| } | ||
| async function setNginxPath() { | ||
| const detectedPath = await detectNginxPath(); | ||
| let finalPath = detectedPath; | ||
| if (!detectedPath) { | ||
| console.log(chalk.yellow('Unable to automatically detect the NGINX configuration path.')); | ||
| // Provide guidance based on OS if automatic detection fails | ||
| console.log(chalk.blue(`Please specify the path manually. Typical locations include:`)); | ||
| console.log(chalk.blue(`- Linux: /etc/nginx/nginx.conf`)); | ||
| console.log(chalk.blue(`- macOS: /usr/local/etc/nginx/nginx.conf or /opt/homebrew/etc/nginx/nginx.conf`)); | ||
| console.log(chalk.blue(`- Windows: C:\\nginx\\nginx.conf`)); | ||
| } | ||
| const responses = await inquirer.prompt([ | ||
| { | ||
| type: 'confirm', | ||
| name: 'confirm', | ||
| message: `Use the detected path: ${detectedPath}?`, | ||
| default: true, | ||
| when: () => !!detectedPath | ||
| }, | ||
| { | ||
| type: 'input', | ||
| name: 'customPath', | ||
| message: 'Please enter the custom path for your NGINX configuration:', | ||
| when: ({ confirm }) => !confirm | ||
| } | ||
| ]); | ||
| if (responses.customPath) { | ||
| finalPath = responses.customPath; | ||
| } | ||
| // Verify the final path | ||
| if (!fs.existsSync(finalPath)) { | ||
| console.log(chalk.red('The specified NGINX configuration path does not exist.')); | ||
| return ''; | ||
| } | ||
| // Save the verified path to user config | ||
| const userConfig = await loadUserConfig(); | ||
| userConfig.nginxPath = finalPath; | ||
| await saveUserConfig(userConfig); | ||
| console.log(chalk.green(`NGINX configuration path set to: ${finalPath}`)); | ||
| return finalPath; | ||
| } | ||
| export { setNginxPath }; |
| { | ||
| "nginxConfigurationProceed": false, | ||
| "netgetXConfigurationProceed": false, | ||
| "nginxPath": "/opt/homebrew/etc/nginx/nginx.conf" | ||
| } |
| // verifyNginxInstallation.js | ||
| import chalk from 'chalk'; | ||
| import { execShellCommand } from '../../utils/execShellCommand.js'; | ||
| export const verifyNginxInstallation = async () => { | ||
| try { | ||
| const result = await execShellCommand('nginx -v'); | ||
| console.log(chalk.green(`NGINX successfully verified...`)); | ||
| return true; // Call the callback function with true indicating success | ||
| } catch (error) { | ||
| console.error(chalk.red(`Verification of NGINX installation failed: ${error.message}`)); | ||
| return false; // Call the callback function with false indicating failure | ||
| } | ||
| }; |
| //verifyServerBlock.js | ||
| import fs from 'fs'; | ||
| import chalk from 'chalk'; | ||
| import inquirer from 'inquirer'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname } from 'path'; | ||
| import { configureDefaultServerBlock } from './configureDefaultServerBlock.js'; | ||
| import { setNginxPath } from './setNginxPath.js'; | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const userConfigPath = path.join(__dirname, 'userConfig.json'); | ||
| async function loadUserConfig() { | ||
| try { | ||
| const data = await fs.promises.readFile(userConfigPath, { encoding: 'utf8' }); | ||
| return JSON.parse(data); | ||
| } catch (error) { | ||
| console.error(chalk.red(`Failed to load user configuration: ${error.message}`)); | ||
| return { nginxConfigurationProceed: false, nginxPath: '' }; | ||
| } | ||
| } | ||
| async function saveUserConfig(userConfig) { | ||
| await fs.promises.writeFile(userConfigPath, JSON.stringify(userConfig, null, 2), { encoding: 'utf8' }); | ||
| } | ||
| async function verifyServerBlock() { | ||
| console.log(chalk.blue('Running verifyServerBlock...')); | ||
| let userConfig = await loadUserConfig(); | ||
| if (!userConfig.nginxPath) { | ||
| await setNginxPath(); | ||
| userConfig = await loadUserConfig(); // Reload config after setting path | ||
| } | ||
| if (userConfig.nginxPath) { | ||
| try { | ||
| const defaultConfigData = await fs.promises.readFile(userConfig.nginxPath, 'utf8'); | ||
| if (!defaultConfigData.includes("return 200 'NGINX Default Response. Server is running.';")) { | ||
| console.log(chalk.yellow('Default server block configuration does not match the expected setup. Visit Default Server Block Configuration.')); | ||
| if (!userConfig.nginxConfigurationProceed) { | ||
| const action = await askUserForAction('NGINX'); | ||
| if (action === 'restore') { | ||
| await configureDefaultServerBlock(); | ||
| //userConfig.nginxConfigurationProceed = true; | ||
| //await saveUserConfig(userConfig); | ||
| } else if (action === 'proceed') { | ||
| userConfig.nginxConfigurationProceed = true; | ||
| await saveUserConfig(userConfig); | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| console.log(chalk.green('NGINX server block is configured correctly.')); | ||
| return true; | ||
| } catch (error) { | ||
| console.error(chalk.red(`Error reading NGINX config: ${error.message}`)); | ||
| return false; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| async function askUserForAction(type) { | ||
| const response = await inquirer.prompt([{ | ||
| type: 'list', | ||
| name: 'action', | ||
| message: `How would you like to proceed with the ${type} server block configuration?`, | ||
| choices: [ | ||
| { name: 'Set/Restore to Recommended Default Settings', value: 'restore' }, | ||
| { name: 'Proceed with current configuration', value: 'proceed' } | ||
| ] | ||
| }]); | ||
| return response.action; | ||
| } | ||
| export { verifyServerBlock }; |
| // NetGetX.cli.js | ||
| import inquirer from 'inquirer'; | ||
| import { showNGXBlocks } from './src/showXBlocks.js'; | ||
| import chalk from 'chalk'; | ||
| //import { addNewNGXBlock } from './src/addNewNGXBlock.js'; | ||
| //import { showNGXBlocks, addNewNGXBlock, showNGXDiscoveryNode, addNewNGXDiscoveryNode, netGetXSettings, aboutNetGetX } from './netGetXOptions.js'; | ||
| export async function NetGetX() { | ||
| const answers = await inquirer.prompt({ | ||
| type: 'list', | ||
| name: 'option', | ||
| message: 'Select an action:', | ||
| choices: [ | ||
| 'Show NGXBlocks', | ||
| 'Add New NGXBlock', | ||
| 'Show NGXDiscoveryNodes', | ||
| 'Add New NGXDiscoveryNode', | ||
| 'NetGetX Settings', | ||
| 'About NetGetX', | ||
| 'Exit' | ||
| ] | ||
| }); | ||
| switch (answers.option) { | ||
| case 'Show NGXBlocks': | ||
| await showNGXBlocks(); | ||
| console.log('Show NGXBlocks'); | ||
| break; | ||
| case 'Add New NGXBlock': | ||
| // await addNewNGXBlock(); | ||
| console.log('Add New NGXBlock'); | ||
| break; | ||
| // Continue handling other cases similarly | ||
| case 'Exit': | ||
| console.log(chalk.blue('Exiting NetGetX...')); | ||
| break; | ||
| default: | ||
| await NetGetXMenu(); // Recurse back to the menu unless exiting | ||
| break; | ||
| } | ||
| } |
| // netGetXOptions.js | ||
| import fs from 'fs'; | ||
| import chalk from 'chalk'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
| import { dirname } from 'path'; | ||
| import { NetGetX} from '../NetGetX.cli.js'; | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
| const blocksPath = path.join(__dirname, 'NGXBlocks.json'); | ||
| async function loadNGXBlocks() { | ||
| try { | ||
| const data = await fs.promises.readFile(blocksPath, { encoding: 'utf8' }); | ||
| return JSON.parse(data); | ||
| } catch (error) { | ||
| console.error(chalk.red(`Failed to load NGXBlocks: ${error.message}`)); | ||
| return []; // Return an empty array in case of error | ||
| } | ||
| } | ||
| export async function showNGXBlocks() { | ||
| console.log(chalk.blue('Loading NGXBlocks...')); | ||
| const blocks = await loadNGXBlocks(); | ||
| if (blocks.length === 0) { | ||
| console.log(chalk.yellow('No NGXBlocks Found.')); | ||
| await NetGetX(); // Return to main menu after showing this message | ||
| } else { | ||
| console.log(chalk.green('List of NGXBlocks:')); | ||
| blocks.forEach((block, index) => { | ||
| console.log(`${index + 1}. ${block.name} - ${block.description}`); | ||
| }); | ||
| await NetGetX(); // Also return to the main menu after listing blocks | ||
| } | ||
| } |
| import fetch from 'node-fetch'; | ||
| async function checkPublicIP() { | ||
| try { | ||
| const response = await fetch('https://api.ipify.org?format=json'); | ||
| if (response.ok) { | ||
| const data = await response.json(); | ||
| const publicIP = data.ip; | ||
| console.log(`Current public IP: ${publicIP}`); | ||
| return publicIP; | ||
| } else { | ||
| throw new Error('Failed to retrieve IP address'); | ||
| } | ||
| } catch (error) { | ||
| console.error(`Error checking public IP: ${error.message}`); | ||
| return null; // Return null if there is an error or no public IP found | ||
| } | ||
| } | ||
| export default checkPublicIP; |
| //src/modules/utils/execShellCommand.js | ||
| import { exec } from 'child_process'; | ||
| /** | ||
| * Executes a shell command and returns the result as a promise. | ||
| * @param {string} cmd - The command to run, with space-separated arguments. | ||
| * @returns {Promise<string>} - A promise that resolves with the command output. | ||
| */ | ||
| export function execShellCommand(cmd) { | ||
| return new Promise((resolve, reject) => { | ||
| exec(cmd, (error, stdout, stderr) => { | ||
| if (error) { | ||
| reject(new Error(stderr)); | ||
| } else { | ||
| resolve(stdout); | ||
| } | ||
| }); | ||
| }); | ||
| } |
+3
-2
| { | ||
| "name": "netget", | ||
| "version": "2.3.54", | ||
| "version": "2.3.55", | ||
| "description": "Rette Adepto/ Recibido Directamente.", | ||
@@ -34,3 +34,4 @@ "type": "module", | ||
| "inquirer": "^9.2.17", | ||
| "morgan": "^1.10.0" | ||
| "morgan": "^1.10.0", | ||
| "node-fetch": "^3.3.2" | ||
| }, | ||
@@ -37,0 +38,0 @@ "repository": { |
+0
-1
@@ -30,3 +30,2 @@ <img src="https://suign.github.io/assets/imgs/netget.png" alt="netget.me" width="244" height="203"> | ||
| ``` | ||
| Now you can: | ||
@@ -33,0 +32,0 @@ ```bash |
| #!/usr/bin/env node | ||
| import { program } from 'commander'; | ||
| import { handleNetGetX } from './CLI/NetGetX.js'; | ||
| import { handleGateways } from './CLI/Gateways.js'; | ||
| import { handleGets } from './CLI/Gets.js'; | ||
| import { NetGetMainMenu } from './CLI/netget_MainMenu.js'; | ||
| import { NetGetX } from './modules/NetGetX/NetGetX.cli.js'; | ||
| import { handleGateways } from './modules/Gateways/Gateways.js'; | ||
| import { handleGets } from './modules/Gets/Gets.js'; | ||
| import { NetGetMainMenu } from './modules/netget_MainMenu.cli.js'; | ||
@@ -16,3 +15,3 @@ program | ||
| .description('Directly interact with NetGetX') | ||
| .action(handleNetGetX); | ||
| .action(NetGetX); | ||
@@ -19,0 +18,0 @@ program.command('gateways') |
+35
-24
| // src/netget.js | ||
| import Gateway from './Gateway.js'; | ||
| /** | ||
| * Represents the main entry point for NetGet functionalities. | ||
| * Handles the instantiation of gateways and configuration loading. | ||
| */ | ||
| class NetGet { | ||
| constructor() { | ||
| // Initialization code, if necessary | ||
| /** | ||
| * Constructs the NetGet service, initializing any necessary base configurations. | ||
| */ | ||
| constructor() { | ||
| // Initialization code, if necessary | ||
| } | ||
| /** | ||
| * Creates a Gateway instance with specified configuration. | ||
| * @param {Object} config - Configuration options for the Gateway. | ||
| * @returns {Gateway} An instance of the Gateway configured with the provided options. | ||
| */ | ||
| Gateway(config) { | ||
| const gateway = new Gateway(config); | ||
| return gateway; | ||
| } | ||
| /** | ||
| * Loads and parses the domain configuration from a specified file. | ||
| * @param {string} domainConfigPath - The path to the domain configuration file. | ||
| * @returns {Object|null} The parsed domain configuration object or null if an error occurs. | ||
| */ | ||
| static loadDomainConfig(domainConfigPath) { | ||
| try { | ||
| const data = fs.readFileSync(domainConfigPath, 'utf8'); | ||
| const domainConfig = JSON.parse(data); | ||
| console.log('Loaded Domain Configuration:', domainConfig); | ||
| return domainConfig; | ||
| } catch (err) { | ||
| console.error('Error loading domain configuration:', err); | ||
| return null; | ||
| } | ||
| Gateway(config) { | ||
| // Gateway is now an instance method that returns a new Gateway instance. | ||
| const gateway = new Gateway(config); | ||
| return gateway; | ||
| } | ||
| static loadDomainConfig(domainConfigPath) { | ||
| try { | ||
| const data = fs.readFileSync(domainConfigPath, 'utf8'); | ||
| const domainConfig = JSON.parse(data); | ||
| console.log('Loaded Domain Configuration:', domainConfig); | ||
| // Additional processing or setup based on the domainConfig | ||
| return domainConfig; | ||
| } catch (err) { | ||
| console.error('Error loading domain configuration:', err); | ||
| return null; // Or throw an error, depending on your preference | ||
| } | ||
| } | ||
| // NetGet related functionalities | ||
| } | ||
| export default NetGet; | ||
| } | ||
| export default NetGet; |
| // Gateways.js | ||
| import chalk from 'chalk'; | ||
| export function handleGateways() { | ||
| console.log(chalk.yellow('Interacting with Gateways...')); | ||
| // NetGetX logic here | ||
| } |
| // Gets.js | ||
| import chalk from 'chalk'; | ||
| export function handleGets() { | ||
| console.log(chalk.yellow('Interacting with Gets...')); | ||
| // NetGetX logic here | ||
| } |
| // netget_MainMenu.js | ||
| import inquirer from 'inquirer'; | ||
| import chalk from 'chalk'; | ||
| export async function NetGetMainMenu() { | ||
| const answers = await inquirer.prompt([ | ||
| { | ||
| type: 'list', | ||
| name: 'action', | ||
| message: 'Choose an action:', | ||
| choices: ['NetGetX', 'Gateways', 'Gets', new inquirer.Separator(), 'Exit'], | ||
| }, | ||
| ]); | ||
| switch (answers.action) { | ||
| case 'NetGetX': | ||
| console.log(chalk.yellow('Selected NetGetX')); | ||
| // Call NetGetX functionality here | ||
| break; | ||
| case 'Gateways': | ||
| console.log(chalk.yellow('Selected Gateways')); | ||
| // Call Gateways functionality here | ||
| break; | ||
| case 'Gets': | ||
| console.log(chalk.yellow('Selected Gets')); | ||
| // Call Gets functionality here | ||
| break; | ||
| case 'Exit': | ||
| console.log(chalk.green('Exiting NetGet CLI.')); | ||
| process.exit(); | ||
| } | ||
| } |
| // NetGetX.js | ||
| import chalk from 'chalk'; | ||
| export function handleNetGetX() { | ||
| console.log(chalk.yellow('Interacting with NetGetX...')); | ||
| // NetGetX logic here | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
861030
2.82%45
60.71%892
180.5%5
25%115
-0.86%11
57.14%6
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added