Code Duplication    Length = 8-19 lines in 9 locations

install/install.queries.php 5 locations

@@ 380-387 (lines=8) @@
377
378
                        // prepare config file
379
                        $tp_config_file = "../includes/config/tp.config.php";
380
                        if (file_exists($tp_config_file)) {
381
                            if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
382
                                echo '[{"error" : "includes/config/tp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
383
                                break;
384
                            } else {
385
                                unlink($tp_config_file);
386
                            }
387
                        }
388
                        $file_handler = fopen($tp_config_file, 'w');
389
                        $config_text = "<?php
390
global \$SETTINGS;
@@ 1028-1035 (lines=8) @@
1025
                    // 0- check if exists
1026
                    $filename_seckey = $securePath."/teampass-seckey.txt";
1027
1028
                    if (file_exists($filename_seckey)) {
1029
                        if (!copy($filename_seckey, $filename_seckey.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1030
                            echo '[{"error" : "File `$filename_seckey` already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1031
                            break;
1032
                        } else {
1033
                            unlink($filename);
1034
                        }
1035
                    }
1036
1037
                    // 1- generate saltkey
1038
                    require_once '../includes/libraries/Encryption/Encryption/Crypto.php';
@@ 1060-1067 (lines=8) @@
1057
                    // Now create settings file
1058
                    $filename = "../includes/config/settings.php";
1059
1060
                    if (file_exists($filename)) {
1061
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1062
                            echo '[{"error" : "Setting.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1063
                            break;
1064
                        } else {
1065
                            unlink($filename);
1066
                        }
1067
                    }
1068
1069
                    // Encrypt the DB password
1070
                    $encrypted_text = encryptFollowingDefuse(
@@ 1109-1116 (lines=8) @@
1106
                    }
1107
                } elseif ($task === "sk.php") {
1108
//Create sk.php file
1109
                    if (file_exists($skFile)) {
1110
                        if (!copy($skFile, $skFile.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1111
                            echo '[{"error" : "sk.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1112
                            break;
1113
                        } else {
1114
                            unlink($skFile);
1115
                        }
1116
                    }
1117
                    $file_handler = fopen($skFile, 'w');
1118
1119
                    $result = fwrite(
@@ 1163-1170 (lines=8) @@
1160
                    // update CSRFP TOKEN
1161
                    $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
1162
                    $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
1163
                    if (file_exists($csrfp_file)) {
1164
                        if (!copy($csrfp_file, $csrfp_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1165
                            echo '[{"error" : "csrfp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
1166
                            break;
1167
                        } else {
1168
                            $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
1169
                        }
1170
                    }
1171
                    unlink($csrfp_file); // delete existing csrfp.config file
1172
                    copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
1173
                    $data = file_get_contents($csrfp_file);

sources/admin.queries.php 1 location

@@ 1618-1636 (lines=19) @@
1615
            }
1616
1617
            // before perform a copy of sk.php file
1618
            if (file_exists($tmp_skfile)) {
1619
                //Do a copy of the existing file
1620
                if (!copy(
1621
                    $tmp_skfile,
1622
                    $tmp_skfile.'.'.date(
1623
                        "Y_m_d",
1624
                        mktime(0, 0, 0, date('m'), date('d'), date('y'))
1625
                    )
1626
                )) {
1627
                    echo '[{"result" : "" , "error" : "Could NOT perform a copy of file: '.$tmp_skfile.'"}]';
1628
                    break;
1629
                } else {
1630
                    fileDelete($tmp_skfile);
1631
                }
1632
            } else {
1633
                // send back an error
1634
                echo '[{"result" : "" , "error" : "Could NOT access file: '.$tmp_skfile.'"}]';
1635
                break;
1636
            }
1637
        }
1638
1639
        // Write back values in sk.php file

install/upgrade_ajax.php 1 location

@@ 813-820 (lines=8) @@
810
                // update CSRFP TOKEN
811
                $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
812
                $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
813
                if (file_exists($csrfp_file) === true) {
814
                    if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
815
                        echo '[{"error" : "csrfp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
816
                        break;
817
                    } else {
818
                        $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
819
                    }
820
                }
821
                unlink($csrfp_file); // delete existing csrfp.config file
822
                copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
823
                $data = file_get_contents("../includes/libraries/csrfp/libs/csrfp.config.php");

install/upgrade_run_final.php 1 location

@@ 207-214 (lines=8) @@
204
* UPDATE CONFIG file
205
*/
206
$tp_config_file = "../includes/config/tp.config.php";
207
if (file_exists($tp_config_file)) {
208
    if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
209
        echo '[{"error" : "includes/config/tp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
210
        return false;
211
    } else {
212
        unlink($tp_config_file);
213
    }
214
}
215
$file_handler = fopen($tp_config_file, 'w');
216
$config_text = "";
217
$any_settings = false;

install/upgrade_run_2.1.27.php 1 location

@@ 695-702 (lines=8) @@
692
* Introduce new CONFIG file
693
*/
694
$tp_config_file = "../includes/config/tp.config.php";
695
if (file_exists($tp_config_file)) {
696
    if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
697
        echo '[{"error" : "includes/config/tp.config.php file already exists and cannot be renamed. Please do it by yourself and click on button Launch.", "result":"", "index" : "'.$post_index.'", "multiple" : "'.$post_multiple.'"}]';
698
        return false;
699
    } else {
700
        unlink($tp_config_file);
701
    }
702
}
703
$file_handler = fopen($tp_config_file, 'w');
704
$config_text = "";
705
$any_settings = false;