{= # # # # setup.cfv # # # include "templates.util.authentication_util"; include "templates.util.base_util"; include "templates.util.encoding"; include "templates.util.licensing_util"; include "templates.setup_pages.build_setup_page"; debug_message("\n\n#### setup.cfv \n\n"); # # # Make sure that nobody accesses the setup page after setup completed # # # Check if setup_done already exists bool setup_done = false; if (?("system") and ?("system.setup_done") and @("system.setup_done")) then ( setup_done = true; ); # Check if one or more users already exist bool users_exist = (?("users") and (num_subnodes("users") > 0)); # Check if a licenses already exists bool license_exists = (?("licenses") and (num_subnodes("licenses") > 0)); # Check if the user is authenticated bool is_authenticated_user = false; string user_node_name = ""; if (?("volatile.authenticated_user_node_path")) then ( user_node_name = node_name(volatile.authenticated_user_node_path); is_authenticated_user = (?("users." . user_node_name)); ); debug_message("#### setup_done: " . setup_done . "\n"); debug_message("#### users_exist: " . users_exist . "\n"); debug_message("#### license_exists: " . license_exists . "\n"); debug_message("#### is_authenticated_user: " . is_authenticated_user . "\n"); if (!setup_done and !users_exist and !license_exists and !is_authenticated_user) then ( if (!?("v.fp.setup_directive")) then ( # # # # Handle setup HTML # # # debug_message("#### Handle setup HTML \n"); # Set default_language string default_language = "english"; if (?("preferences.miscellaneous.language") and @("preferences.miscellaneous.language") ne "") then ( default_language = @("preferences.miscellaneous.language"); ); build_setup_page(default_language); ) else ( # # # # Handle setup server background call # # # debug_message("#### Handle setup server background call \n"); debug_message("\n" . node_as_string("v.fp") . "\n"); string setup_directive = v.fp.setup_directive; string language; string license_key; node license_as_node; node license_validation; bool is_valid_license; string license_error_message; string username; string password; string password_checksum; string trial_licensing_tier; string smtp_password; string dat; if (setup_directive eq "set_language") then ( string language = v.fp.language; # Set language in preferences debug_message("#### set language: " . language . "\n"); preferences.miscellaneous.language = language; save_node("preferences"); debug_message("#### set language done \n"); 'setup.setLanguageResponse()\n'; ) else if (setup_directive eq "get_trial_license_key") then ( # # # # get_trial_license_key # # # # We first check if a trial license key already exists in system.trial_license_key and if it is valid. # If the existing key is valid then we use the existing key, else we create a new one and save the key in # system.trial_license_key. bool create_new_license_key = true; if (?("system.trial_license_key") and (@("system.trial_license_key") ne "")) then ( license_key = @("system.trial_license_key"); # Check if the key is valid. license_as_node = license_string_to_license_node(license_key); license_validation = get_license_validation_from_license_node(license_as_node); is_valid_license = @license_validation{"is_valid"}; if (is_valid_license) then ( create_new_license_key = false; ); ); debug_message("#### create_new_license_key: " . create_new_license_key . "\n"); # # Handle create_new_license_key # if (create_new_license_key) then ( license_key = create_trial_license(); debug_message("#### new license_key: " . license_key . "\n"); # if the license_key has no value then trial is not anymore possible, though # give it a value so that the license_key node is not empty when validating! if (license_key eq "") then ( license_key = "-"; ) else ( # Save the trial license key in setup.trial_license_key system.trial_license_key = license_key; save_node("system"); ); # Convert the license key to a license node license_as_node = license_string_to_license_node(license_key); debug_message("#### license_as_node:\n" . node_as_string(license_as_node) . "\n"); license_validation = get_license_validation_from_license_node(license_as_node); is_valid_license = @license_validation{"is_valid"}; # license_error_message = @license_validation{"error_message"}; ); dat = "{"; dat .= add_json("trialLicenseKey", license_key, "string"); dat .= add_json("isValidTrialLicenseKey", is_valid_license, "bool"); dat = close_json(dat); 'setup.getTrialLicenseKeyResponse(' . dat . ')\n'; ) else if (setup_directive eq "check_license_key") then ( # # # # check_license_key # # # license_key = v.fp.license_key; # Convert the license key to a license node license_as_node = convert_license_key_to_license_node(license_key); debug_message("#### license_as_node:\n" . node_as_string(license_as_node) . "\n"); license_validation = get_license_validation_from_license_node(license_as_node); is_valid_license = @license_validation{"is_valid"}; license_error_message = @license_validation{"error_message"}; dat = "{"; dat .= add_json("licenseKey", license_key, "string"); dat .= add_json("isValidLicenseKey", is_valid_license, "bool"); dat .= add_json("licenseErrorMessage", license_error_message, "string"); dat = close_json(dat); 'setup.checkLicenseKeyResponse(' . dat . ')\n'; ) else if (setup_directive eq "finish") then ( # # # # Finish # # # license_key = v.fp.license_key; username = v.fp.username; password = v.fp.password; trial_licensing_tier = v.fp.trial_licensing_tier; debug_message("#### trial_licensing_tier: " . trial_licensing_tier . "\n"); # # # Set license # # # If license_key has no value then we have a pre-installed license! if (license_key ne "") then ( license_as_node = convert_license_key_to_license_node(license_key); clone_node(license_as_node, "licenses.license"); save_node("licenses"); ); # # # Set username/password_checksum # # # If username has no value then we have a pre-defined username and password if (username eq "") then ( # Get pre-defined username and password username = @("users.root_admin.username"); password = @("users.root_admin.password"); # Delete the pre-defined password node delete_node("users.root_admin.password"); ); password_checksum = md5_digest(password); users.root_admin.username = username; users.root_admin.password_checksum = password_checksum; users.root_admin.email_address = v.fp.email_address; users.root_admin.language = ""; save_node("users"); # # # Set preferences # # if (trial_licensing_tier ne "") then ( preferences.miscellaneous.trial_licensing_tier = trial_licensing_tier; ); # Encrypt smtp_password smtp_password = v.fp.smtp_password; if (smtp_password ne "") then ( smtp_password = format(smtp_password, "!encrypt"); ); preferences.email.smtp_server = v.fp.smtp_server; preferences.email.smtp_username = v.fp.smtp_username; preferences.email.smtp_password = smtp_password; preferences.miscellaneous.talkback = v.fp.talkback; save_node("preferences"); # # # Set system # # system.setup_done = true; # Added show_before_you_start_info in version 8.7.3 system.show_before_you_start_info.profiles = true; save_node("system"); # # KHP 20/Oct/2011 # Authenticate the user (auto_login by calling authenticate() directly) # debug_message("\n #### Auto authenticate the user in setup.cfv \n"); # Doe we have a session_id? #if (?("volatile.session_id")) then ( # debug_message("#### volatile.session_id exists: " . volatile.session_id . "\n"); #) #else ( # debug_message("#### volatile.session_id DOES NOT EXIST \n"); #); authenticate_with_valid_username_and_password(username, password, true); 'setup.finishSetupResponse()\n'; ); ); ) else ( display_no_permission_html(); ); debug_message("#### setup.cfv END \n\n"); =}