From d69960a6c19d31a473e93fd3ca3dd06465f32e42 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 2 Jan 2026 13:02:17 +0530 Subject: [PATCH] FEAT_CHECK_EN_SCRIPT --- .env.sample | 185 +++++++++++++++++++++++++++ app/Config/Routes.php | 1 + app/Controllers/MasterController.php | 75 +++++++++++ 3 files changed, 261 insertions(+) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..b7ce361 --- /dev/null +++ b/.env.sample @@ -0,0 +1,185 @@ +#-------------------------------------------------------------------- +# ENVIRONMENT +#-------------------------------------------------------------------- + +CI_ENVIRONMENT = development + +#-------------------------------------------------------------------- +# APP +#-------------------------------------------------------------------- + +app.baseURL = +app.appTimezone = 'Asia/Kolkata' +# If you have trouble with `.`, you could also use `_`. +# app_baseURL = '' +# app.forceGlobalSecureRequests = false +# app.CSPEnabled = false + +#-------------------------------------------------------------------- +# DATABASE +#-------------------------------------------------------------------- +DB_SSL_ENABLE = false +database.default.hostname = +database.default.database = +database.default.username = +database.default.password = +# database.default.DBDriver = MySQLi +# database.default.DBPrefix = +# database.default.port = 3306 + +#-------------------------------------------------------------------- +# CONTENT SECURITY POLICY +#-------------------------------------------------------------------- + +# contentsecuritypolicy.reportOnly = false +# contentsecuritypolicy.defaultSrc = 'none' +# contentsecuritypolicy.scriptSrc = 'self' +# contentsecuritypolicy.styleSrc = 'self' +# contentsecuritypolicy.imageSrc = 'self' +# contentsecuritypolicy.baseURI = null +# contentsecuritypolicy.childSrc = null +# contentsecuritypolicy.connectSrc = 'self' +# contentsecuritypolicy.fontSrc = null +# contentsecuritypolicy.formAction = null +# contentsecuritypolicy.frameAncestors = null +# contentsecuritypolicy.frameSrc = null +# contentsecuritypolicy.mediaSrc = null +# contentsecuritypolicy.objectSrc = null +# contentsecuritypolicy.pluginTypes = null +# contentsecuritypolicy.reportURI = null +# contentsecuritypolicy.sandbox = false +# contentsecuritypolicy.upgradeInsecureRequests = false +# contentsecuritypolicy.styleNonceTag = '{csp-style-nonce}' +# contentsecuritypolicy.scriptNonceTag = '{csp-script-nonce}' +# contentsecuritypolicy.autoNonce = true + +#-------------------------------------------------------------------- +# COOKIE +#-------------------------------------------------------------------- + +# cookie.prefix = '' +# cookie.expires = 0 +# cookie.path = '/' +# cookie.domain = '' +# cookie.secure = false +# cookie.httponly = false +# cookie.samesite = 'Lax' +# cookie.raw = false + +#-------------------------------------------------------------------- +# ENCRYPTION +#-------------------------------------------------------------------- + +# encryption.key = +# encryption.driver = OpenSSL +# encryption.blockSize = 16 +# encryption.digest = SHA512 + +#-------------------------------------------------------------------- +# HONEYPOT +#-------------------------------------------------------------------- + +# honeypot.hidden = 'true' +# honeypot.label = 'Fill This Field' +# honeypot.name = 'honeypot' +# honeypot.template = '' +# honeypot.container = '
{template}
' + +#-------------------------------------------------------------------- +# SECURITY +#-------------------------------------------------------------------- + +# security.csrfProtection = 'cookie' +# security.tokenRandomize = false +# security.tokenName = 'csrf_token_name' +# security.headerName = 'X-CSRF-TOKEN' +# security.cookieName = 'csrf_cookie_name' +# security.expires = 7200 +# security.regenerate = true +# security.redirect = false +# security.samesite = 'Lax' + +#-------------------------------------------------------------------- +# SESSION +#-------------------------------------------------------------------- + +# session.driver = 'CodeIgniter\Session\Handlers\FileHandler' +# session.cookieName = 'ci_session' +session.expiration = 28800 +# session.savePath = null +# session.matchIP = false +# session.timeToUpdate = 300 +# session.regenerateDestroy = false + +#-------------------------------------------------------------------- +# LOGGER +#-------------------------------------------------------------------- + +logger.threshold = 4 + +#-------------------------------------------------------------------- +# CURLRequest +#-------------------------------------------------------------------- + +# curlrequest.shareOptions = true + +GOOGLE_OAUTH_APP_NAME = +#GOOGLE_OAUTH_CLIENT_ID = +#GOOGLE_OAUTH_CLIENT_SECRET = + +GOOGLE_OAUTH_CLIENT_ID = +GOOGLE_OAUTH_CLIENT_SECRET = +GOOGLE_OAUTH_REDIRECT_URI = +GOOGLE_OAUTH_SCOPES = +App_Url = +NHANCE_LOGO = +helpdeskURL = +TOKENTIMEOUT = +POST_ENROLLMENT_APP_LINK = +GDRIVE_ROOT_FOLDER_ID = + + +email.fromEmail = +email.fromName = +ZEPTO_API_KEY = +email.SMTPPass = + +#-------------------------------------------------------------------- +# SET COOKIE DATA +#-------------------------------------------------------------------- +cookie.Path = '/'; +cookie.Domain = '.nhanceindia.in'; //Enter Domain Name with preceding .(dot) -> .nhanceindia.in +cookie.secure = 'true';// if https set as true or if http set as false + +unlayer.projectID = +email.enquiryMail = + +POST_ENROLLMENT_BASEURL = + +database.postDB.hostname = +database.postDB.database = +database.postDB.username = +database.postDB.password = +database.postDB.DBDriver = +database.postDB.DBPrefix = +database.postDB.port = + +POST_ENROLLMENT_BASEURL = + +#SMS +SMS_API_KEY = +SMS_SENDER_ID = +SMS_TEMPLATE_ID = +SMS_SERVICE_NAME = +SMS_APP_NAME = + +# CORS Configuration +CORS_ALLOWED_ORIGINS=https://app.nhanceindia.in,https://benefits.nhanceindia.in,https://hr.nhanceindia.in +CORS_ALLOW_CREDENTIALS=true +CORS_ALLOWED_METHODS=GET,POST,PUT,PATCH,DELETE,OPTIONS +CORS_ALLOWED_HEADERS=Content-Type,Authorization,X-Requested-With,Accept,Origin,App-Signature +CORS_EXPOSE_HEADERS=X-Total-Count,X-Page-Count,X-RateLimit-Remaining +CORS_MAX_AGE=7200 +CORS_DEBUG=true + +APP_SIGNATURE = nhance-2025-signature-T8f6gV9k5fK2wf5V5c4vId3b0J8z6cAm2x8Y diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d8d2548..e124472 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -438,6 +438,7 @@ $routes->cli('cli/sendZeptoMail', 'MasterController::testZeptoSMTP'); $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMails'); $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); +$routes->cli('cli/check_env', 'MasterController::checkEnv'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index c1722ad..e7751e5 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -37,6 +37,7 @@ use App\Models\SettingsModel; use App\Models\VehicleModel; use CodeIgniter\CLI\CLI; +use CodeIgniter\CLI\BaseCommand; class MasterController extends AdminController { @@ -1822,4 +1823,78 @@ class MasterController extends AdminController echo "################################################################\n\n"; } + + public function checkEnv() + { + $root = ROOTPATH; + + $sample_file_name = '.env.sample'; + $sample_file_path = $root . $sample_file_name; + + $envFile = $root . '.env'; + // echo ($exampleFile);//die(); + if (!file_exists($sample_file_path)) { + echo ("$sample_file_path file not found"); + exit(); + } + + if (!file_exists($envFile)) { + echo('.env file not found'); + exit(); + } + + $example = $this->parseEnv($sample_file_path); + $actual = $this->parseEnv($envFile); + + $missing = array_diff_key($example, $actual); + $extra = array_diff_key($actual, $example); + + CLI::write("#################### CHECKING ENV ##############################\n"); + if ($extra) { + CLI::write('⚠️ Extra ENV keys (not in .env.example)', 'yellow'); + foreach (array_keys($extra) as $key) { + CLI::write(" - $key", 'yellow'); + } + } + + CLI::newLine(); + if ($missing) { + CLI::error('❌ Missing ENV keys'); + foreach (array_keys($missing) as $key) { + CLI::write(" - $key", 'red'); + } + } + + CLI::newLine(); + if (!$missing && !$extra) { + CLI::write('✅ ENV configuration is clean', 'green'); + return CLI::EXIT_SUCCESS; + } + + CLI::write("#################### END OF CHECKING ENV ############################\n"); + + + } + + private function parseEnv(string $file): array + { + $lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + $env = []; + + foreach ($lines as $line) { + $line = trim($line); + + if ($line === '' || str_starts_with($line, '#')) { + continue; + } + + if (strpos($line, '=') !== false) { + [$key] = explode('=', $line, 2); + $env[trim($key)] = true; + } + } + + return $env; + } + } \ No newline at end of file