11 $monLibrary= dirname(__FILE__) .
"/../library";
12 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
15 require_once(
"$monLibrary/cu_top.i");
16 require_once(
"$monLibrary/ck_hticket.i");
17 require_once(
"$sharedLibrary/hcuCommon.i");
18 require_once(
"$sharedLibrary/cu_flagconst.i");
20 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
21 header(
"Location: /hcuadm/hcu_noperm.prg");
26 $AUDIT_LOG_TRANSACTION = bin2hex(openssl_random_pseudo_bytes(8));
36 function GetSecret() {
37 return "n3c3s1t@m0\$Mud@rT0d@\$L@\$C0\$@\$!";
44 function CreateHash($action, $cu) {
45 return sha1(
"${action}${cu}" . GetSecret());
48 $passed_arguments =
"";
49 $secret_key = GetSecret();
50 putenv(
"ODY_MIGR_SECRET_KEY=$secret_key");
52 $response = array(
"success"=> False,
"message" =>
"");
60 function GetLogsDir($cu) {
61 return "/home/" . strtolower($cu) .
"/logs";
70 function GetTmpDir($cu) {
71 return "/home/" . strtolower($cu) .
"/tmp";
82 function getWIPFile($cu, $category, $operation) {
83 return GetTmpDir($cu) .
"/.ody_migr_" . $operation .
"_" . $category .
".wip";
93 function getSwitchAccountsSettingFile($cu) {
94 return GetTmpDir($cu) .
"/.ody_migr_include_switchaccounts_in_final_migr";
105 function getDoneFile($cu, $category, $operation) {
106 return GetTmpDir($cu) .
"/.ody_migr_" . $operation .
"_" . $category .
".done";
117 function deleteWIPFile($cu, $category, $operation) {
118 $wip_file = getWIPFile($cu, $category, $operation);
120 if (unlink($wip_file)) {
121 return array(
"success"=> True,
"message" =>
"Lock ('wip') file deleted successfully.");
123 return array(
"success"=> False,
"message" =>
"Something went wrong while deleting lock ('wip') file: " . $wip_file);
135 function markWIPAsComplete($cu, $category, $operation) {
136 $wip_file = getWIPFile($cu, $category, $operation);
137 $done_file = getDoneFile($cu, $category, $operation);
139 if (file_exists($wip_file)) {
140 $cmd =
"mv $wip_file $done_file";
142 $results = system($cmd);
144 if ($results ===
false) {
145 return array(
"success"=> False,
"message" =>
"Marking WIP file as Done failed.");
148 if ($category ==
"memdata" || $category ==
"memhist") {
150 $final_migr_memcount_file = getFinalMigrationConfigFile($cu);
151 if(file_exists($final_migr_memcount_file) && (($fileStr = file_get_contents($final_migr_memcount_file)) != False)) {
152 $mem_count_arr = explode(
",", explode(
"\n", $fileStr)[1]);
153 $memdata_count = (int)$mem_count_arr[0];
154 $memhist_count = (int)$mem_count_arr[1];
155 if ($category ==
"memdata") {
158 if ($category ==
"memhist") {
161 $new_vals =
"memdata_count,memhist_count\n" . $memdata_count .
"," . $memhist_count .
"\n";
162 file_put_contents($final_migr_memcount_file, $new_vals);
165 return array(
"success"=> True,
"message" =>
"WIP marked as Done." . $wip_file);
168 return array(
"success"=> False,
"message" =>
"WIP file does not exist." . $wip_file);
181 function getLogFile($cu, $operation, $category) {
182 return GetLogsDir($cu) .
"/ody_migr_" . $operation .
"_" . $category .
".log";
192 function getMonitorLockFile($cu) {
193 return GetTmpDir($cu) .
"/.ody_migr_monitor_lock";
204 function getPublicHtmlPath($cu) {
205 return "/home/" . strtolower($cu) .
"/public_html";
215 function getLockFileForPreventingFurtherMigration($cu, $cat_group) {
216 if($cat_group ==
"Settings") {
217 return GetTmpDir($cu) .
"/.ody_migr_prevent_further_settings_migration";
219 return GetTmpDir($cu) .
"/.ody_migr_prevent_further_admin_migration";
232 function updateProgress($line, $category) {
233 if ($category ==
"memdata") {
234 $res_progress_arr = explode(
"/", trim(explode(
"|", trim(explode(
"[PROGRESS] Members imported:", $line)[1]))[0]));
235 return $res_progress_arr;
249 function getAccCrossRefFile($cu) {
250 return GetTmpDir($cu) .
"/ody_migr_user_id_cross_reference.csv";
260 function getFinalMigrationMainLock($cu) {
261 return GetTmpDir($cu) .
"/.ody_migr_final";
271 function getFinalMigrationDoneLock($cu) {
272 return GetTmpDir($cu) .
"/.ody_migr_final.complete";
282 function getOrphanMemberListFile($cu) {
283 return GetTmpDir($cu) .
"/ody_migr_mammoth_orphaned_members.csv";
293 function getFinalMigrationConfigFile($cu) {
294 return GetTmpDir($cu) .
"/.ody_migr_members_exec_count";
309 function readContent($file, $operation, $category, $cu) {
313 $progress_current = 0;
316 if (!file_exists($file)) {
317 $progress_status = array(
"current"=>$progress_current,
"total"=>$progress_total);
318 $file_status =
"Log file '" .$file .
"' does not exist.";
319 return array(
"does_not_exist" => True,
"log_content" => $logContent,
"end_of_log"=> $endOfLog,
"file_status" => $file_status,
"progress_status"=>$progress_status);
322 $fileHandle = fopen($file,
'r');
323 $file_status =
"Log file '" . $file .
"' exists.";
325 while (!feof($fileHandle)) {
326 $line = fgets($fileHandle);
327 if ($line ==
false) {
331 if (strpos($line,
"[PROGRESS] ") !==
false && $operation ==
"migrate") {
332 $progress_update = updateProgress($line, $category);
333 $progress_current = $progress_update[0];
334 $progress_total = $progress_update[1];
337 $logContent[] = $line;
339 if (strpos($line,
"MIGRATION DONE") !==
false) {
341 auditLogMigrationExecution($cu,
"", $operation, $category,
"Migration completed. Marked by browser auto-refresh.");
347 $progress_status = array(
"current"=>$progress_current,
"total"=>$progress_total);
348 return array(
"does_not_exist" => False,
"log_content" => $logContent,
"end_of_log"=> $endOfLog,
"file_status" => $file_status,
"progress_status"=>$progress_status);
372 function deleteOdysseyTemporaryFiles($cu) {
374 $memhist_file =
"memhist";
375 $memhist_acc_file =
"memhist_accounthistory";
376 $memhist_loan_file =
"memhist_loanhistory";
378 $lowercaseCu = strtolower($cu);
380 $dir =
"/home/$lowercaseCu/tmp";
381 $memhist_file =
"$dir/${memhist_file}";
382 $memhist_acc_file =
"$dir/${memhist_acc_file}";
383 $memhist_loan_file =
"$dir/${memhist_loan_file}";
388 if (file_exists($memhist_file)) {
389 $all_success = $all_success && unlink($memhist_file);
392 if (file_exists($memhist_acc_file)) {
393 $all_success = $all_success && unlink($memhist_acc_file);
396 if (file_exists($memhist_loan_file)) {
397 $all_success = $all_success && unlink($memhist_loan_file);
401 return "[Cleanup ODY] Temporary files deleted.";
404 return "[Cleanup ODY] Something went wrong while deleting temporary files.";
407 return "[Cleanup ODY] No such directory '$dir'.";
423 function makeMammothEndpointCall($server, $cu, $action, $hash, $parameters = array()) {
425 if (!isset($parameters) || !is_array($parameters)) {
426 $parameters = array();
428 $parameters[
"passphrase"] = $hash;
429 $parameters[
"action"] = $action;
432 $parameters = http_build_query($parameters);
433 $url =
"${server}.homecu.net/hcuadm/mOdysseyMigrExp.prg?cu=" . urlencode($cu) .
"&" . $parameters;
435 $ch = curl_init($url);
437 curl_setopt($ch, CURLOPT_USERPWD,
"nobody:no1home");
438 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
439 curl_setopt($ch, CURLOPT_FOLLOWLOCATION,
true);
440 curl_setopt($ch, CURLOPT_FORBID_REUSE,
true);
441 curl_setopt($ch, CURLOPT_FRESH_CONNECT,
true);
443 $response = curl_exec($ch);
445 $response = isset($response) && trim($response) !=
"" ? HCU_JsonDecode($response)
446 : array(
"action" => $action,
"error" =>
"CURL call didn't return anything. (" . __FILE__ .
":" . __LINE__ .
")",
"data" => array());
460 function validateOptionsBeforeScriptExecution($cu, $operation, $category) {
461 $valid_response = array(
"success"=> True,
"message" =>
"Options validated.");
463 if ($operation ==
"clean") {
465 $preventSettingsLockFile = getLockFileForPreventingFurtherMigration($cu,
"Settings");
466 if(file_exists($preventSettingsLockFile) && $category ==
"settings") {
467 return array(
"success"=> False,
"message" =>
"Data category '$category' ALREADY MIGRATED and (possibly) MODIFIED on the target system. 'clean' operations for 'settings' is LOCKED to PREVENT ACCIDENTAL DELETIONS.");
470 $preventAdminLockFile = getLockFileForPreventingFurtherMigration($cu,
"Admin");
471 if(file_exists($preventAdminLockFile) && $category ==
"admin") {
472 return array(
"success"=> False,
"message" =>
"Data category '$category' ALREADY MIGRATED. 'clean' operation 'admin' is LOCKED to PREVENT ACCIDENTAL DELETIONS.");
476 if($category ==
"switchaccounts") {
477 return array(
"success"=> False,
"message" =>
"INVALID migration operation '$operation'" .
"-" .
"'$category' for direct deletion.");
481 $wip_file_migrate = getWIPFile($cu, $category,
"migrate");
482 if(file_exists($wip_file_migrate)) {
483 return array(
"success"=> False,
"message" =>
"Cannot clean up in-progress work 'migrate-$category'");
487 return $valid_response;
502 function executeMigrationScript($server, $operation, $cu, $category, $username, $password, $bg=True) {
504 $PYTHON_EXEC =
"/usr/bin/python3";
505 $rootScriptsDir =
"/opt/odyssey/tools/bin";
506 if (getenv(
"DEVMODE") ==
"1") {
507 $rootScriptsDir =
"/project/app/tools/bin";
510 $cmd = $PYTHON_EXEC .
" " . $rootScriptsDir .
"/ody_migr_executor.py " 511 . escapeshellarg($server) .
" " 512 . escapeshellarg($operation) .
" " 513 . escapeshellarg(strtoupper($cu)) .
" " 514 . escapeshellarg($category) .
" " 515 . escapeshellarg($username) .
" " 516 . escapeshellarg($password) .
" " 524 auditLogMigrationExecution($cu, $username, $operation, $category,
"Started.");
527 if ($operation ==
"migrate" || $operation ==
"summary") {
528 $migrate_summary_log_file = getLogFile($cu, $operation, $category);
529 if (file_exists($migrate_summary_log_file)) {
530 unlink($migrate_summary_log_file);
535 exec($cmd, $scriptOutput, $returnStatus);
537 if ($returnStatus > 0) {
538 return array(
"success"=> False,
539 "message" =>
"(" . $rootScriptsDir .
") " .
" ".join($scriptOutput));
541 return array(
"success"=> True,
542 "message" =>
" Migration operation ('" . $operation .
" - " . $category .
"') STARTED successfully. <br>(" . $rootScriptsDir .
") " .
" ".join($scriptOutput));
556 function auditLogMigrationExecution($cu, $attempted_username, $migr_operation, $migr_category, $comment=
"") {
557 global $AUDIT_LOG_TRANSACTION, $Hu;
558 $current_monitor_user = $Hu;
559 $date_now =
new DateTime(
'now',
new DateTimeZone(
'America/Boise'));
560 $date_log= $date_now->format(
'Y-m-d:H-i-s:T');
561 $audit_log_file =
"/home/${cu}/tmp/ody_migr_execution_logs.csv";
562 $audit_log_record = array($AUDIT_LOG_TRANSACTION,
565 $current_monitor_user,
566 strtoupper($attempted_username),
571 # should only be created once, and not to be deleted 572 if (!file_exists($audit_log_file)) {
573 $audit_log_header = array(
"SessionId",
581 touch($audit_log_file);
582 $fp = fopen($audit_log_file,
"a");
583 fputcsv($fp, $audit_log_header);
585 $fp = fopen($audit_log_file,
"a");
588 fputcsv($fp, $audit_log_record);
603 function cleanupAfterClean($cu, $category, $operation) {
604 if ($operation ==
"clean") {
606 $done_file = getDoneFile($cu, $category,
"migrate");
607 if(file_exists($done_file)) {
612 $migrate_log_file = getLogFile($cu,
"migrate", $category);
613 if(file_exists($migrate_log_file)) {
614 unlink($migrate_log_file);
617 $summary_log_file = getLogFile($cu,
"summary", $category);
618 if(file_exists($summary_log_file)) {
619 unlink($summary_log_file);
622 if ($category ==
"memdata") {
624 $sa_migrate_done_file = getDoneFile($cu,
"switchaccounts",
"migrate");
625 if(file_exists($sa_migrate_done_file)) {
627 unlink($sa_migrate_done_file);
630 $sa_migrate_log_file = getLogFile($cu,
"migrate",
"switchaccounts");
631 if(file_exists($sa_migrate_log_file)) {
632 unlink($sa_migrate_log_file);
636 $sa_summary_log_file = getLogFile($cu,
"summary",
"switchaccounts");
637 if(file_exists($sa_summary_log_file)) {
638 unlink($sa_summary_log_file);
642 $loanapp_migrate_done_file = getDoneFile($cu,
"loanapp",
"migrate");
643 if(file_exists($loanapp_migrate_done_file)) {
645 unlink($loanapp_migrate_done_file);
648 $loanapp_migrate_log_file = getLogFile($cu,
"migrate",
"loanapp");
649 if(file_exists($loanapp_migrate_log_file)) {
650 unlink($loanapp_migrate_log_file);
654 $loanapp_summary_log_file = getLogFile($cu,
"summary",
"loanapp");
655 if(file_exists($loanapp_summary_log_file)) {
656 unlink($loanapp_summary_log_file);
663 if($category ==
"settings") {
664 $preventSettingsLockFile = getLockFileForPreventingFurtherMigration($cu,
"Settings");
665 if(file_exists($preventSettingsLockFile)) {
666 unlink($preventSettingsLockFile);
671 if($category ==
"admin") {
672 $preventAdminLockFile = getLockFileForPreventingFurtherMigration($cu,
"Admin");
673 if(file_exists($preventAdminLockFile)) {
674 unlink($preventAdminLockFile);
690 function executeFinalMigration($server, $cu, $username, $password) {
692 if (file_exists(getFinalMigrationDoneLock($cu))) {
693 return array(
"success"=> False,
694 "message" =>
"<b>Final migration (migrate-{memdata,memhist}) already executed once." 695 .
" Re-migration is not advised. If you really need to run this again, speak to a" 696 .
" develolper to reset final migration before trying again. </b>");
699 $python_exec =
"/usr/bin/python3";
700 $root_script_dir =
"/opt/odyssey/tools/bin";
701 if (getenv(
"DEVMODE") ==
"1") {
702 $root_script_dir =
"/project/app/tools/bin";
704 $developer_help_msg =
" Please contact a developer to look into it.";
706 $final_migr_lck = getFinalMigrationMainLock($cu);
709 if (file_exists($final_migr_lck)) {
710 return array(
"success"=> False,
711 "message" =>
"Final migration (members data) already IN PROGRESS." 712 . $developer_help_msg);
716 elseif (file_exists(getWIPFile($cu,
"memdata",
"migrate"))
717 || file_exists(getWIPFile($cu,
"switchaccounts",
"migrate"))
718 || file_exists(getWIPFile($cu,
"loanapp",
"migrate"))
719 || file_exists(getWIPFile($cu,
"memhist",
"migrate"))) {
721 return array(
"success"=> False,
722 "message" =>
"Final migration (members data) cannot be executed." 723 . $developer_help_msg);
726 $executing_categories =
"memdata";
727 $cmd_memdata = $python_exec .
" " . $root_script_dir .
"/ody_migr_executor.py " 728 . escapeshellarg($server) .
" " 729 . escapeshellarg(
"migrate") .
" " 730 . escapeshellarg(strtoupper($cu)) .
" " 731 . escapeshellarg(
"memdata") .
" " 732 . escapeshellarg($username) .
" " 733 . escapeshellarg($password) .
" " 737 if (file_exists(getSwitchAccountsSettingFile($cu))) {
738 $cmd_switchaccounts = $python_exec .
" " . $root_script_dir .
"/ody_migr_executor.py " 739 . escapeshellarg($server) .
" " 740 . escapeshellarg(
"migrate") .
" " 741 . escapeshellarg(strtoupper($cu)) .
" " 742 . escapeshellarg(
"switchaccounts") .
" " 743 . escapeshellarg($username) .
" " 744 . escapeshellarg($password) .
" " 747 $cmd_memdata = $cmd_memdata .
" && " . $cmd_switchaccounts;
748 $executing_categories .=
", switchaccounts";
753 $cmd_loanapp = $python_exec .
" " . $root_script_dir .
"/ody_migr_executor.py " 754 . escapeshellarg($server) .
" " 755 . escapeshellarg(
"migrate") .
" " 756 . escapeshellarg(strtoupper($cu)) .
" " 757 . escapeshellarg(
"loanapp") .
" " 758 . escapeshellarg($username) .
" " 759 . escapeshellarg($password) .
" " 762 $cmd_memdata = $cmd_memdata .
" && " . $cmd_loanapp;
763 $executing_categories .=
", loanapp";
765 $cmd_memhist = $python_exec .
" " . $root_script_dir .
"/ody_migr_executor.py " 766 . escapeshellarg($server) .
" " 767 . escapeshellarg(
"migrate") .
" " 768 . escapeshellarg(strtoupper($cu)) .
" " 769 . escapeshellarg(
"memhist") .
" " 770 . escapeshellarg($username) .
" " 771 . escapeshellarg($password) .
" " 774 $cmd =
"(" . $cmd_memdata .
" && " . $cmd_memhist .
") > /dev/null 2>&1 &";
775 $executing_categories .=
", memhist";
778 if (touch(getWIPFile($cu,
"memdata",
"migrate")) && touch($final_migr_lck)) {
780 auditLogMigrationExecution($cu, $username,
"migrate",
"Final",
"Started.");
782 exec($cmd, $script_output, $return_status);
785 if(file_exists($final_migr_lck)) {
786 unlink($final_migr_lck);
788 if(file_exists(getWIPFile($cu,
"memdata",
"migrate"))) {
789 unlink(getWIPFile($cu,
"memdata",
"migrate"));
791 return array(
"success"=> True,
792 "message" =>
" Failed creating initial WIP lock file (memdata) for Final migration. " 793 . $developer_help_msg);
796 if ($return_status > 0) {
798 if(file_exists($final_migr_lck)) {
799 unlink($final_migr_lck);
801 if(file_exists(getWIPFile($cu,
"memdata",
"migrate"))) {
802 unlink(getWIPFile($cu,
"memdata",
"migrate"));
804 return array(
"success"=> False,
805 "message" =>
"Final migration (" + $executing_categories +
") execution returned non-zero exit code. (" 806 . $root_script_dir .
") " .
" ".join($script_output) .
"." 807 . $developer_help_msg);
809 return array(
"success"=> True,
810 "message" =>
" Final migration ('migrate-{" . $executing_categories .
"}'') STARTED successfully. (" 811 . $root_script_dir .
") ");
826 function deleteMultipleCategories($cu, $cat_del_list, $is_forced_cleanup=False) {
828 if (count($cat_del_list) == 0 && $is_forced_cleanup == False) {
829 return array(
"success"=> True,
"message" =>
"No categories selected for deletion.");
832 $success_categories = array();
833 $failed_categories = array();
835 auditLogMigrationExecution($cu,
"",
"attempted-multiple-clean", implode(
":", $cat_del_list));
836 foreach($cat_del_list as $category) {
838 if ($is_forced_cleanup == True) {
840 $validationResponseStatus = True;
843 $validationResponse = validateOptionsBeforeScriptExecution($cu,
"clean", $category);
844 $validationResponseStatus = $validationResponse[
"success"];
847 if ($validationResponseStatus == True) {
850 $response_category = executeMigrationScript(
"www4",
"clean", $cu, $category,
"",
"", $bg=False);
852 if ($response_category[
"success"]) {
855 cleanupAfterClean($cu, $category,
"clean");
857 $success_categories[] = $category;
859 $failed_categories[] = $category;
862 $response_category = $validationResponse;
863 $failed_categories[] = $category;
866 $all_success = $response_category[
"success"] && $all_success;
867 $response_category[
"category"] = $category;
870 auditLogMigrationExecution($cu,
"",
"successful-multiple-clean", implode(
":", $success_categories));
871 if($is_forced_cleanup == False) {
873 return array(
"success"=> True,
"message" =>
"Successfully cleaned up all SELECTED (and UNLOCKED) categories. [ " . implode(
", ", $success_categories) .
" ] were cleaned. ");
875 return array(
"success"=> False,
"message" =>
"Cleaned categories: [ " . implode(
", ", $success_categories) .
" ]. Categories not cleaned (probably set LOCKED): [ " .implode(
",", $failed_categories) .
" ]. ");
888 function getCurrentDoneCategoryList($cu) {
889 $done_list = array();
890 foreach (glob(GetTmpDir($cu) .
"/.ody_migr_migrate_*.done") as $filename) {
891 $filename_pieces = explode(
"_", $filename);
892 $category_frm_filename = explode(
".", $filename_pieces[count($filename_pieces) - 1])[0];
893 $done_list[] = $category_frm_filename;
905 function getCurrentWIPCategoryList($cu, $migrate_only=False) {
907 $glob_collection = array();
909 $glob_collection = glob(GetTmpDir($cu) .
"/.ody_migr_migrate*.wip");
911 $glob_collection = glob(GetTmpDir($cu) .
"/.ody_migr_*.wip");
913 foreach ($glob_collection as $filename) {
914 $filename_only = explode(
".", $filename)[1];
915 $cat_operation_str = explode(
"ody_migr_", $filename_only)[1];
916 $wip_list[] = str_replace(
"_",
"-", $cat_operation_str);
928 function getCurrentLogsList($cu) {
931 foreach (glob(GetLogsDir($cu) .
"/ody_migr_*.log") as $log_file) {
932 $filename_only = explode(
".", $log_file)[0];
933 $cat_operation_str = explode(
"ody_migr_", $filename_only)[1];
935 list($op, $cat) = explode(
"_", $cat_operation_str);
940 if ($op ==
"migrate") {
941 if (file_exists(getDoneFile($cu, $cat, $op))) {
942 $logs_list[] = str_replace(
"_",
"-", $cat_operation_str);
959 function executeFixPublicHtmlScript($cu, $from, $to) {
960 $perl_exec =
"/usr/bin/env perl";
961 $root_script_dir =
"/opt/odyssey/tools/bin";
962 if (getenv(
"DEVMODE") ==
"1") {
963 $root_script_dir =
"/project/app/tools/bin";
966 $cmd = $perl_exec .
" " . $root_script_dir .
"/fix_public_html.pl " . escapeshellarg($cu) .
" " . escapeshellarg($from) .
" " . escapeshellarg($to) .
" " .
" > /dev/null";
968 exec($cmd, $script_output, $return_status);
970 if ($return_status > 0) {
971 return array(
"success"=> False,
"message" =>
"(" . $root_script_dir .
") " .
" ".join($script_output));
973 return array(
"success"=> True,
"message" =>
"public_html embedded links updated successfully. (" . $root_script_dir .
") " .
" ".join($script_output));
986 function GetCuList($dbh) {
988 global $SYS_TYPE_CLOSED, $SYS_TYPE_LIVE, $SYS_TYPE_BATCH, $SYS_TYPE_WEBONLY;
989 $sql =
"select user_name, www_server, case when (coalesce(system_options, 0)" .
990 " & $SYS_TYPE_LIVE) <> 0 then 'Live'" .
991 " when (coalesce(system_options, 0) & $SYS_TYPE_BATCH) <> 0 then 'Batch'" .
992 " when (coalesce(system_options, 0) & $SYS_TYPE_WEBONLY) <> 0 then 'Web Only'" .
993 " else 'Other' end as cutype from cuinfo" .
994 " where (coalesce(system_options, 0) & $SYS_TYPE_CLOSED) = 0" .
995 " order by user_name";
997 $sth = db_query($sql, $dbh);
999 throw new exception (
"Select query failed.", 2);
1002 $results = db_fetch_all($sth);
1003 $results = $results ===
false ? array() : $results;
1005 $returnArray = array(
"error" =>
"",
"cuinfo" => $results);
1006 }
catch (exception $e) {
1007 $returnArray = array(
"error" => $e->getMessage());
1009 return $returnArray;
1046 function serveMigrationPurpose() {
1050 if ( isset($_GET[
"get_purpose"]) ) {
1052 if ($_GET[
"get_purpose"] ==
"acc_cross_ref") {
1054 if ( isset($_GET[
"cu"]) ) {
1057 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1060 $accountCrossRefFile = getAccCrossRefFile($cu);
1062 if (!file_exists($accountCrossRefFile)) {
1063 $response = array(
"success"=> False,
"message" =>
"'$accountCrossRefFile' file does not exist.");
1066 header(
"Content-type: text/plain");
1067 header(
"Content-disposition: inline; filename=$accountCrossRefFile");
1070 @readfile($accountCrossRefFile);
1075 } elseif ( isset($_POST[
"post_purpose"]) ) {
1081 if ($_POST[
"post_purpose"] ==
"execute_script") {
1083 if ( isset($_POST[
"server"]) ) {
1084 $server = $_POST[
"server"];
1086 throw new exception(
"'server' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1089 if ( isset($_POST[
"cu"]) ) {
1092 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1095 if ( isset($_POST[
"operation"]) ) {
1096 $operation = $_POST[
"operation"];
1098 throw new exception(
"'operation' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 6);
1101 if ( isset($_POST[
"category"]) ) {
1102 $category = $_POST[
"category"];
1104 throw new exception(
"'category' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1107 if ( isset($_POST[
"username"]) ) {
1108 $username = $_POST[
"username"];
1110 throw new exception(
"'username' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 3);
1113 if ( isset($_POST[
"password"]) ) {
1114 $password = $_POST[
"password"];
1116 throw new exception(
"'password' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 4);
1121 if (file_exists(getFinalMigrationDoneLock($cu))) {
1122 return array(
"success"=> False,
1123 "message" =>
"<b>Operation NOT ALLOWED. Final migration ('migrate-{memdata,memhist}') already COMPLETED. </b>");
1127 if (file_exists(getFinalMigrationMainLock($cu))) {
1128 return array(
"success"=> False,
1129 "message" =>
"<b>Operation NOT ALLOWED. Final migration step ('migrate-{memdata,memhist}') is IN PROGRESS. </b>");
1132 $validationResponse = validateOptionsBeforeScriptExecution($cu, $operation, $category);
1133 if (!$validationResponse[
"success"]) {
1134 return $validationResponse;
1137 $migration_started_lock = getWIPFile($cu, $category, $operation);
1138 $migration_done_lock = getDoneFile($cu, $category, $operation);
1140 if (file_exists($migration_started_lock)) {
1141 $response = array(
"success"=> False,
1142 "message" =>
"[WIP] Migration process is already IN PROGRESS for '$operation-$category'.");
1143 } elseif (file_exists($migration_done_lock)) {
1144 $response = array(
"success"=> False,
1145 "message" =>
"[Done] Migration already COMPLETED for '$operation-$category'.");
1147 if (touch($migration_started_lock)) {
1148 $response = executeMigrationScript($server, $operation, $cu,
1149 $category, $username, $password);
1151 $response = array(
"success"=> False,
1152 "message" =>
"Failed to create WIP lock file.");
1160 elseif ($_POST[
"post_purpose"] ==
"execute_final_migration") {
1162 if ( isset($_POST[
"server"]) ) {
1163 $server = $_POST[
"server"];
1165 throw new exception(
"'server' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1168 if ( isset($_POST[
"cu"]) ) {
1171 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1174 if ( isset($_POST[
"username"]) ) {
1175 $username = $_POST[
"username"];
1177 throw new exception(
"'username' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 3);
1180 if ( isset($_POST[
"password"]) ) {
1181 $password = $_POST[
"password"];
1183 throw new exception(
"'password' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 4);
1186 $response = executeFinalMigration($server, $cu, $username, $password);
1193 elseif ($_POST[
"post_purpose"] ==
"start_memhist_sa_wip_for_final_migration") {
1194 if ( isset($_POST[
"cu"]) ) {
1197 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1200 if ( isset($_POST[
"category"]) ) {
1201 $category = $_POST[
"category"];
1203 throw new exception(
"'category' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1206 $memhist_sa_wip = getWIPFile($cu, $category,
"migrate");
1207 if (touch($memhist_sa_wip)) {
1208 $response = array(
"success"=> True,
"message" =>
"[Final Migration] WIP file created for " . $category .
" category.");
1210 $response = array(
"success"=> False,
"message" =>
"[Final Migration] WIP file could not be created for " . $category .
" category.");
1218 elseif ($_POST[
"post_purpose"] ==
"reset_migration_state") {
1219 if ( isset($_POST[
"cu"]) ) {
1222 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1225 auditLogMigrationExecution($cu,
"",
"Reset (Final) Migration State",
"memdata:memhist",
"Button clicked");
1227 $final_migr_lck = getFinalMigrationMainLock($cu);
1228 $final_migr_lck_done = getFinalMigrationDoneLock($cu);
1230 if (file_exists($final_migr_lck)) {
1231 unlink($final_migr_lck);
1234 if (file_exists($final_migr_lck_done)) {
1235 unlink($final_migr_lck_done);
1238 $categories_toclean = array(
"memdata",
"memhist");
1239 deleteMultipleCategories($cu, $categories_toclean, $is_forced_cleanup=True);
1240 $categories_toclean[] =
"switchaccounts";
1243 foreach ($categories_toclean as $category) {
1244 foreach(array(
"migrate",
"summary") as $op) {
1245 $lg_file = getLogFile($cu, $op, $category);
1246 if(file_exists($lg_file)) {
1250 $wip_file = getWIPFile($cu, $category, $op);
1251 if(file_exists($wip_file)) {
1254 $done_file = getDoneFile($cu, $category, $op);
1255 if(file_exists($done_file)) {
1260 $response = array(
"success" => True,
"message" =>
"Migration state (members data and history) has been reset and cleaned. You may proceed with the members migration normally now. ");
1268 elseif ($_POST[
"post_purpose"] ==
"manage_migration_state") {
1269 if ( isset($_POST[
"cu"]) ) {
1272 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1275 if ( isset($_POST[
"final_migration_when"]) ) {
1276 $final_migration_when = $_POST[
"final_migration_when"];
1278 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1281 $final_lck_file = getFinalMigrationMainLock($cu);
1282 $final_lck_file_complete = getFinalMigrationDoneLock($cu);
1284 if ($final_migration_when ==
"on_completion") {
1285 $final_migr_completion_msg =
"";
1286 if (file_exists($final_lck_file)) {
1287 if (touch($final_lck_file_complete)) {
1288 $final_migr_completion_msg =
"[Final Migration] All Migrations COMPLETED. Altering settings and over-writing migrations is not advised. ";
1289 $response = array(
"success"=> True,
1290 "message" => $final_migr_completion_msg);
1292 $final_migr_completion_msg =
"[Error] Final Migration could not be completed (migration completed but error creating completed lock file.) ";
1293 $response = array(
"success"=> False,
1294 "message" => $final_migr_completion_msg);
1298 $final_migr_completion_msg =
"[Error] Final Migration seem to be completed, but required internal migration state violated (not started, but trying to complete? Please consult issue with a developer.) ";
1299 $response = array(
"success"=> False,
1300 "message" => $final_migr_completion_msg);
1303 auditLogMigrationExecution($cu,
"",
"migrate",
"final", $final_migr_completion_msg);
1307 if (file_exists($final_lck_file_complete) && file_exists($final_lck_file)) {
1308 $response = array(
"success"=> True,
1309 "message" =>
"[Final Migration] All Migrations COMPLETED. Altering settings and over-writing migrations is not advised. ",
1310 "migr_status" =>
"completed",
1311 "migr_type" =>
"final");
1313 if (file_exists($final_lck_file)) {
1314 $migr_type =
"final";
1315 $msg_prefix =
"[Final Migration] ";
1317 $migr_type =
"regular";
1318 $msg_prefix =
"[Regular Migration] ";
1321 $wips = getCurrentWIPCategoryList($cu);
1323 if (count($wips) > 1) {
1324 $response = array(
"success"=> False,
1325 "message" =>
"[Invalid] Unexpected multiple in-progress migrations found. Please reset migration states from Settings and re-run migration. ",
1326 "migr_status" =>
"invalid");
1327 } elseif (count($wips) == 1){
1328 $category = $wips[0];
1329 $response = array(
"success"=> True,
1330 "message" =>
"Migration in progress: " . $category,
1331 "migr_status" =>
"inprogress",
1332 "inprogress_category" => $category);
1334 if($migr_type ==
"final") {
1335 $response = array(
"success"=> False,
1336 "message" =>
"No in-progress migration operation found. Please consult issue with a developer. ",
1337 "migr_status" =>
"invalid");
1339 $response = array(
"success"=> True,
1340 "message" =>
"Normal start up. Good to proceed with the migration steps. ",
1341 "migr_status" =>
"normalstart");
1344 $response[
"migr_type"] = $migr_type;
1345 $response[
"message"] = $msg_prefix . $response[
"message"];
1355 elseif ($_POST[
"post_purpose"] ==
"handle_switchaccounts_setting") {
1356 if ( isset($_POST[
"cu"]) ) {
1359 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1362 if ( isset($_POST[
"action"]) ) {
1363 $action = $_POST[
"action"];
1365 throw new exception(
"'action' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1368 if ( isset($_POST[
"entity"]) ) {
1369 $entity = $_POST[
"entity"];
1371 throw new exception(
"'entity' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1375 if ($entity ==
"switchaccounts") {
1376 $config_file= getSwitchAccountsSettingFile($cu);
1379 if ($action ==
"get_setting") {
1380 $response = array(
"success"=> True,
"include_or_not" => (file_exists($config_file)));
1384 if(file_exists($config_file)) {
1385 $response = array(
"success"=> (unlink($config_file)));
1387 $response = array(
"success"=> (touch($config_file)));
1396 elseif ($_POST[
"post_purpose"] ==
"fetch_log") {
1398 if ( isset($_POST[
"cu"]) ) {
1401 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1404 if ( isset($_POST[
"operation"]) ) {
1405 $operation = $_POST[
"operation"];
1407 throw new exception(
"'operation' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 6);
1410 if ( isset($_POST[
"category"]) ) {
1411 $category = $_POST[
"category"];
1413 throw new exception(
"'category' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1416 $log_path = getLogFile($cu, $operation, $category);
1417 $result = readContent($log_path, $operation, $category, $cu);
1420 $lastline =end($result[
"log_content"]);
1421 if (strpos($lastline,
"Error") !==
false) {
1422 auditLogMigrationExecution($cu,
"", $operation, $category,
"Log Fetch Error: " . trim(preg_split(
"/::/", $lastline)[1]));
1425 $success_msg_prefix =
"";
1426 if ($result[
"does_not_exist"]) {
1427 $msg =
"Log file does not exist: " . $log_path .
". ";
1429 elseif ($result[
"end_of_log"]) {
1430 if ($operation !=
"migrate") {
1433 if($operation ==
"clean") {
1434 cleanupAfterClean($cu, $category, $operation);
1436 $msg =
"<b>Operation ('$operation - $category') COMPLETED.</b> Displayed log is COMPLETE. ";
1439 $success_msg_prefix =
"<b>Migration ('$operation - $category') COMPLETED.</b> Displayed log is COMPLETE. ";
1442 if ($operation ==
"migrate") {
1443 $handle_wip_response = markWIPAsComplete($cu, $category, $operation);
1445 $handle_wip_response = deleteWIPFile($cu, $category, $operation);
1448 if ($handle_wip_response[
"success"] == False) {
1449 $msg = $success_msg_prefix .
" WIP file COULD NOT be marked as Done or Deleted. ";
1451 $msg = $success_msg_prefix;
1455 if ($operation ==
"migrate") {
1456 $msg =
"<b>Migration ('$operation - $category') is IN PROGRESS.</b> Displayed log is NOT COMPLETE. ";
1458 $msg =
"<b>Operation ('$operation - $category') is IN PROGRESS.</b> Displayed log is NOT COMPLETE. ";
1462 $response = array(
"success"=> True,
"message" => $msg,
"category"=>$category,
"log_report" => $result);
1468 elseif ($_POST[
"post_purpose"] ==
"fetch_log_history_only") {
1470 if ( isset($_POST[
"cu"]) ) {
1473 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1476 if ( isset($_POST[
"operation"]) ) {
1477 $operation = $_POST[
"operation"];
1479 throw new exception(
"'operation' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 6);
1482 if ( isset($_POST[
"category"]) ) {
1483 $category = $_POST[
"category"];
1485 throw new exception(
"'category' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1488 $log_path = getLogFile($cu, $operation, $category);
1489 $response = readContent($log_path, $operation, $category, $cu);
1491 if ($response[
"does_not_exist"]) {
1492 $response[
"success"] = False;
1493 $response[
"message"] =
"[Log History] Log file does not exist for '$operation-$category'";
1495 $response[
"success"] = True;
1496 $response[
"message"] =
"[Log History] Displaying logs: '$operation-$category'";
1504 elseif ($_POST[
"post_purpose"] ==
"disable_monitor") {
1506 if ( isset($_POST[
"cu"]) ) {
1509 throw new exception(
"Empty 'cucode' name provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1512 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1515 if ( isset($_POST[
"server"]) ) {
1516 $server = $_POST[
"server"];
1517 if ($server ==
"") {
1518 throw new exception(
"Empty 'server' name provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1521 throw new exception(
"'server' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1525 auditLogMigrationExecution($cu,
"",
"Disable Migration Menu.",
"Temporary files cleanup.",
"Button clicked.");
1527 $monitor_lock_file = getMonitorLockFile($cu);
1529 if (file_exists($monitor_lock_file)) {
1530 $response = array(
"success"=> True,
"message" =>
"Monitor UI already disabled.");
1533 if (touch($monitor_lock_file)) {
1541 $cleanup_hash = CreateHash(
"cleanup", $cu);
1542 $cleanup_response = makeMammothEndpointCall($server, $cu,
"cleanup", $cleanup_hash);
1544 $temp_file_deletion_msg_append =
"";
1546 if ($cleanup_response[
"error"] ==
"") {
1547 # temporary files are deleted successfully 1548 $temp_file_deletion_msg_append =
"[Cleanup MMTH] " . $cleanup_response[
"info"] .
".";
1550 $temp_file_deletion_msg_append =
"[Cleanup MMTH] " . $cleanup_response[
"error"] .
".";
1554 $ody_cleanup_msg = deleteOdysseyTemporaryFiles($cu);
1556 $response = array(
"success"=> True,
"message" =>
"[Monitor Disable] Migration Monitor UI disabled. $temp_file_deletion_msg_append $ody_cleanup_msg");
1559 $response = array(
"success"=> False,
"message" =>
"[Monitor Disable] Something went wrong, could not disable Monitor UI. $temp_file_deletion_msg_append");
1569 elseif ($_POST[
"post_purpose"] ==
"check_monitor_lock") {
1571 if ( isset($_POST[
"cu"]) ) {
1574 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1577 $monitor_lock_file = getMonitorLockFile($cu);
1579 if (file_exists($monitor_lock_file)) {
1580 $response = array(
"exists"=> True,
"lock_file" => $monitor_lock_file);
1582 $response = array(
"exists"=> False,
"lock_file" => $monitor_lock_file);
1590 elseif ($_POST[
"post_purpose"] ==
"delete_wip") {
1593 if ( isset($_POST[
"cu"]) ) {
1596 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1599 if ( isset($_POST[
"category"]) ) {
1600 $category = $_POST[
"category"];
1602 throw new exception(
"'category' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1605 if ( isset($_POST[
"operation"]) ) {
1606 $operation = $_POST[
"operation"];
1608 throw new exception(
"'operation' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1611 if ( isset($_POST[
"is_final_migr"]) ) {
1612 $is_final_migr = $_POST[
"is_final_migr"];
1614 throw new exception(
"'operation' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 21);
1617 $response = deleteWIPFile($cu, $category, $operation);
1619 if($is_final_migr) {
1620 $final_migr_main_lock = getFinalMigrationMainLock($cu);
1621 if (file_exists($final_migr_main_lock)) {
1622 $final_migr_unlink_response = unlink($final_migr_main_lock);
1623 if($final_migr_unlink_response) {
1624 $response[
"message"] .=
" Successfully removed final migration lock file. ";
1626 $response[
"message"] .=
" Removing final migration lock file FAILED. ";
1628 $response[
"success"] = ($response[
"success"] && $final_migr_unlink_response);
1638 elseif ($_POST[
"post_purpose"] ==
"get_wip_done_list") {
1641 if ( isset($_POST[
"cu"]) ) {
1644 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1647 $wip_list = getCurrentWIPCategoryList($cu);
1648 $done_list = getCurrentDoneCategoryList($cu);
1649 $final_migr_done = file_exists(getFinalMigrationDoneLock($cu));
1651 $response = array(
"success"=> True,
1652 "message" =>
"Successfully fetched list of wip and done migrations.",
1653 "wip_list" => $wip_list,
1654 "done_list"=>$done_list,
1655 "final_migr_done" => $final_migr_done);
1662 elseif ($_POST[
"post_purpose"] ==
"get_logs_list") {
1664 if ( isset($_POST[
"cu"]) ) {
1667 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1670 $logs_list = getCurrentLogsList($cu);
1672 $response = array(
"success"=> True,
"message" =>
"Successfully fetched all existing log files.",
"logs_list" => $logs_list);
1679 elseif ($_POST[
"post_purpose"] ==
"clean_all_categories") {
1681 if ( isset($_POST[
"cu"]) ) {
1684 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1687 if (file_exists(getFinalMigrationMainLock($cu)) || file_exists(getFinalMigrationDoneLock($cu))) {
1688 $response = array(
"success"=> False,
"message" =>
"Deletion NOT ALLOWED. Final migration already executed or is in progress. ");
1691 $delete_done_list = array();
1692 if ( isset($_POST[
"delete_done_list"]) ) {
1693 $delete_done_list = $_POST[
"delete_done_list"];
1695 throw new exception(
"'delete_done_list' not provided (must be a list of categories to run clean operation.). (" . __FILE__ .
":" . __LINE__ .
")", 1);
1697 $response = deleteMultipleCategories($cu, $delete_done_list);
1705 elseif ($_POST[
"post_purpose"] ==
"update_server_list") {
1707 if ( isset($_POST[
"cu"]) ) {
1710 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1713 $associated_servers = array();
1714 $cu_info_arr = array();
1716 if (in_array(strtoupper($cu), array(
"SCRUBCU",
"CRUISECU"))) {
1718 $associated_servers[] =
"www4";
1721 $cu_info_response = GetCuList($dbh);
1722 if (HCU_array_key_exists(
"cuinfo", $cu_info_response)) {
1723 $cu_info_arr = $cu_info_response[
"cuinfo"];
1724 foreach($cu_info_arr as $cuinfo) {
1725 if (in_array(trim($cuinfo[
"cutype"]), array(
"Live")) && strtoupper(trim($cuinfo[
"user_name"])) == strtoupper($cu)) {
1726 $associated_servers[] = trim($cuinfo[
"www_server"]);
1732 if(count($associated_servers) > 0) {
1733 $response = array(
"success"=> True,
"message" =>
"Successfully obtained server list for CU '$cu'.",
"server_list" => $associated_servers);
1735 $response = array(
"success"=> False,
"message" =>
"CU '$cu' does not exist in any of the Mammoth Servers.");
1743 elseif ($_POST[
"post_purpose"] ==
"update_categories_list") {
1745 if ( isset($_POST[
"cu"]) ) {
1748 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1750 $categories_list = array();
1752 $memdata_done_file = getDoneFile($cu,
"memdata",
"migrate");
1753 $switchaccount_done_file = getDoneFile($cu,
"switchaccounts",
"migrate");
1755 $include_switchaccount_settings_file = getSwitchAccountsSettingFile($cu);
1758 $general_list = array(
"settings",
"admin",
"memdata");
1760 if (file_exists($memdata_done_file)) {
1761 $categories_list = $general_list;
1764 if (file_exists($include_switchaccount_settings_file)) {
1765 if (!file_exists(getDoneFile($cu,
"switchaccounts",
"migrate"))
1766 && !file_exists(getWIPFile($cu,
"switchaccounts",
"migrate"))) {
1767 $categories_list[] =
"switchaccounts";
1772 if (file_exists($include_switchaccount_settings_file)){
1773 if (file_exists(getDoneFile($cu,
"switchaccounts",
"migrate"))) {
1774 $categories_list[] =
"loanapp";
1777 $categories_list[] =
"loanapp";
1782 $categories_list = $general_list;
1786 $categories_list[] =
"memhist";
1788 $response = array(
"success"=> True,
1789 "message" =>
"Updated categories list for CU '$cu'.",
1790 "categories_list" => $categories_list);
1797 elseif ($_POST[
"post_purpose"] ==
"display_accref_download") {
1799 if ( isset($_POST[
"cu"]) ) {
1802 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1806 $accCrossRefFile = getAccCrossRefFile($cu);
1808 $memdataDoneFile = getDoneFile($cu,
"memdata",
"migrate");
1810 if (file_exists($accCrossRefFile) && file_exists($memdataDoneFile)) {
1811 $response = array(
"success"=> True,
"message" =>
"Show account reference download button.",
"show_btn" => True );
1813 $response = array(
"success"=> True,
"message" =>
"'migrate-memdata' not completed. Disable account reference download button.",
"show_btn" => False );
1821 elseif ($_POST[
"post_purpose"] ==
"display_hb_info_text") {
1823 if ( isset($_POST[
"cu"]) ) {
1826 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1833 $sql =
"select count(*) from cuadmin where cu='" . strtoupper($cu) .
"';";
1834 if($qr_result = db_query($sql, $dbh)) {
1835 $result_arr = db_fetch_array($qr_result);
1837 $cuadmin_count = $result_arr[0];
1840 if($cuadmin_count ==
"1") {
1842 $sql_flagset2 =
"select flagset2, offlinestat, livebatch from cuadmin where cu='" . strtoupper($cu) .
"';";
1843 $query_result_record = db_query($sql_flagset2, $dbh);
1844 $row = db_fetch_array($query_result_record);
1846 $livebatch = trim($row[
"livebatch"]);
1847 $offlinestat = trim($row[
"offlinestat"]);
1848 $flagset2 = $row[
"flagset2"];
1851 if ($flagset2 & GetFlagsetValue(
"CU2_ALLOW_MBR_ALERTS")) $flag2_33554432_ck =
"CHECKED";
else $flag2_33554432_ck =
"";
1854 if ($flagset2 & GetFlagsetValue(
"CU2_PROCRECUR")) $flag2_32_ck =
"CHECKED";
else $flag2_32_ck =
"";
1857 if ($livebatch ==
'L') {
1858 $show_offline_status = True;
1861 if ($offlinestat ==
'N' || $offlinestat ==
"") {
1862 $return_offlinestat =
"Active";
1864 elseif ($offlinestat ==
'U') {
1865 $return_offlinestat =
"Offline (Auto Up)";
1867 elseif ($offlinestat ==
'Y') {
1868 $return_offlinestat =
"Offline (Stay Down)";
1871 $return_offlinestat =
"Undefined (Live)";
1875 $show_offline_status = False;
1876 $return_offlinestat =
"Not Applicable (Batch)";
1880 $response = array(
"success"=> True,
"message" =>
"Settings flags retrieved successfully.",
"CU2_ALLOW_MBR_ALERTS" => $flag2_33554432_ck,
"CU2_PROCRECUR" => $flag2_32_ck,
"show_offline_status" => $show_offline_status,
"offlinestat" => $return_offlinestat);
1884 $response = array(
"success"=> False,
"message" =>
"No 'cuadmin' record exist for " . strtoupper($cu) .
". Run 'migrate-settings'?");
1893 elseif ($_POST[
"post_purpose"] ==
"fix_public_html") {
1895 if ( isset($_POST[
"cu"]) ) {
1898 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1901 if ( isset($_POST[
"from"]) ) {
1902 $from = $_POST[
"from"];
1904 throw new exception(
"'from domain' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1907 if ( isset($_POST[
"to"]) ) {
1910 throw new exception(
"'to domain' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1913 auditLogMigrationExecution($cu,
"",
"public_html update ($from->$to)",
"public_html directory contents",
"Button clicked.");
1915 $publichtmlPath = getPublicHtmlPath($cu);
1917 if (file_exists($publichtmlPath)) {
1918 $response = executeFixPublicHtmlScript($cu, $from, $to);
1920 $response = array(
"success"=> False,
"message" =>
"'public_html' directory does not exist.");
1928 elseif ($_POST[
"post_purpose"] ==
"display_lock_unlock_preventive_buttons") {
1930 if ( isset($_POST[
"cu"]) ) {
1933 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1936 if ( isset($_POST[
"cat_group"]) ) {
1937 $cat_group = $_POST[
"cat_group"];
1939 throw new exception(
"'cat_group' (Settings or Admin) not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1942 if($cat_group ==
"Admin" or $cat_group ==
"Settings") {
1944 if ($cat_group ==
"Settings") {
1946 if (file_exists(getDoneFile($cu,
"settings",
"migrate"))) {
1947 $msg =
"'settings' data category migration has completed. Show Lock/Unlock Settings button.";
1950 $msg =
"'settings' data category migration has not completed. Disable Lock/Unlock Settings button.";
1955 if (file_exists(getDoneFile($cu,
"admin",
"migrate"))) {
1956 $msg =
"'admin' data category migration has completed completed. Show Lock/Unlock Admin button.";
1959 $msg =
"'admin' data category migration has not completed. Disable Lock/Unlock Admin button.";
1963 if(file_exists(getLockFileForPreventingFurtherMigration($cu, $cat_group))) {
1969 $response = array(
"success"=> True,
"message" => $msg,
"show_btn" => $show_btn,
"locked" => $locked );
1971 throw new exception(
"Invalid 'cat_group': must be either Settings or Admin. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1979 elseif ($_POST[
"post_purpose"] ==
"lock_unlock_cat_group") {
1981 if ( isset($_POST[
"cu"]) ) {
1984 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1987 if ( isset($_POST[
"cat_group"]) ) {
1988 $cat_group = $_POST[
"cat_group"];
1990 throw new exception(
"'cat_group' (Admin or Settings) not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1993 if ( isset($_POST[
"lock_or_unlock"])) {
1994 $lock_or_unlock = $_POST[
"lock_or_unlock"];
1996 throw new exception(
"'lock_or_unlock' (lock or unlock) not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
1999 if ($lock_or_unlock ==
"lock" or $lock_or_unlock ==
"unlock") {
2001 if($cat_group ==
"Settings" || $cat_group ==
"Admin") {
2002 if ($cat_group ==
"Settings") {
2003 $settingsDoneFile = getDoneFile($cu,
"settings",
"migrate");
2005 if (file_exists($settingsDoneFile)) {
2006 $preventSettingsLockFile = getLockFileForPreventingFurtherMigration($cu, $cat_group);
2007 if($lock_or_unlock ==
"lock") {
2008 touch($preventSettingsLockFile);
2012 if(file_exists($preventSettingsLockFile)) {
2013 unlink($preventSettingsLockFile);
2019 $adminDoneFile = getDoneFile($cu,
"admin",
"migrate");
2021 if (file_exists($adminDoneFile)) {
2022 $preventAdminLockFile = getLockFileForPreventingFurtherMigration($cu, $cat_group);
2023 if($lock_or_unlock ==
"lock") {
2024 touch($preventAdminLockFile);
2028 if(file_exists($preventAdminLockFile)) {
2029 unlink($preventAdminLockFile);
2036 throw new exception(
"Invalid 'cat_group': must be Admin or Settings. (" . __FILE__ .
":" . __LINE__ .
")", 1);
2039 throw new exception(
"Invalid 'lock_or_unlock': must be lock or unlock. (" . __FILE__ .
":" . __LINE__ .
")", 1);
2041 $lock_unlock_msg =
"'". $cat_group .
"' is '" . $lock_or_unlock .
"ed'.";
2043 auditLogMigrationExecution($cu,
"",
"Toggle lock-unlock", $cat_group, $lock_unlock_msg);
2044 $response = array(
"success"=> True,
"message" => $lock_unlock_msg);
2051 elseif ($_POST[
"post_purpose"] ==
"get_final_migr_flag") {
2053 if ( isset($_POST[
"cu"]) ) {
2056 throw new exception(
"'CU' not provided. (" . __FILE__ .
":" . __LINE__ .
")", 1);
2060 $final_migr_memcount_file = getFinalMigrationConfigFile($cu);
2061 $show_final_migr_button = False;
2066 if (!file_exists($final_migr_memcount_file)) {
2067 if(touch($final_migr_memcount_file)) {
2068 file_put_contents($final_migr_memcount_file,
"memdata_count,memhist_count\n$memdata_count".
",".
"$memhist_count\n");
2071 if (($fileStr = file_get_contents($final_migr_memcount_file)) != False) {
2072 $mem_count_arr = explode(
",", explode(
"\n", $fileStr)[1]);
2073 $memdata_count = (int)$mem_count_arr[0];
2074 $memhist_count = (int)$mem_count_arr[1];
2079 $SettingsLocked = (file_exists(getLockFileForPreventingFurtherMigration($cu,
"Settings")));
2080 $AdminLocked = (file_exists(getLockFileForPreventingFurtherMigration($cu,
"Admin")));
2083 $memdataIsClean = (!file_exists(getDoneFile($cu,
"memdata",
"migrate")));
2084 $memhistIsClean = (!file_exists(getDoneFile($cu,
"memhist",
"migrate")));
2086 $wip_list = getCurrentWIPCategoryList($cu);
2087 $noWIP = (count($wip_list) == 0);
2090 if($memdata_count > 0 && $memhist_count > 0 && $SettingsLocked && $AdminLocked && $memdataIsClean && $memhistIsClean && $noWIP) {
2091 $show_final_migr_button = True;
2093 $response_options = array();
2094 $response_options[
"memdata_gt0"] = ($memdata_count >0);
2095 $response_options[
"memhist_gt0"] = ($memhist_count >0);
2096 $response_options[
"SettingsAdminLocked"] = ($SettingsLocked && $AdminLocked);
2097 $response_options[
"memdata_is_clean"] = $memdataIsClean;
2098 $response_options[
"memhist_is_clean"] = $memhistIsClean;
2099 $response_options[
"no_wip_exists"] = $noWIP;
2100 $response_options[
"show_final_migr_button"] = $show_final_migr_button;
2103 $response = array(
"success"=> True,
"message" =>
"",
"final_migr_resp" => $response_options );
2111 unset($_POST[
"password"]);
2112 $passed_arguments = http_build_query($_POST,
'',
', ') .
" (password not displayed.)";
2113 $response = array(
"success"=> False,
"message" =>
"Unknown request. Passed arguments: " . $passed_arguments );
2118 if (isset($_POST[
"password"])) {
2119 unset($_POST[
"password"]);
2120 $passed_arguments = http_build_query($_POST,
'',
', ') .
" (password not displayed.)";
2121 $msg_suffix =
"Passed arguments: " . $passed_arguments;
2123 $response = array(
"success"=> False,
"message" =>
"[HTTP parameters error] Not a valid request." . $msg_suffix );
2126 }
catch (exception $e) {
2128 if (isset($_POST[
"password"])) {
2129 unset($_POST[
"password"]);
2130 $passed_arguments = http_build_query($_POST,
'',
', ') .
" (password not displayed.)";
2131 $msg_suffix =
"Passed arguments: " . $passed_arguments;
2133 $response = array(
"success"=> False,
"message" =>
"[HTTP parameters error]" . $e->getMessage()) . $msg_suffix;
2140 echo HCU_JsonEncode(serveMigrationPurpose());