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;
@@ 1029-1036 (lines=8) @@
1026
                    // 0- check if exists
1027
                    $filename_seckey = $securePath."/teampass-seckey.txt";
1028
1029
                    if (file_exists($filename_seckey)) {
1030
                        if (!copy($filename_seckey, $filename_seckey.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1031
                            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.'"}]';
1032
                            break;
1033
                        } else {
1034
                            unlink($filename);
1035
                        }
1036
                    }
1037
1038
                    // 1- generate saltkey
1039
                    require_once '../includes/libraries/Encryption/Encryption/Crypto.php';
@@ 1061-1068 (lines=8) @@
1058
                    // Now create settings file
1059
                    $filename = "../includes/config/settings.php";
1060
1061
                    if (file_exists($filename)) {
1062
                        if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1063
                            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.'"}]';
1064
                            break;
1065
                        } else {
1066
                            unlink($filename);
1067
                        }
1068
                    }
1069
1070
                    // Encrypt the DB password
1071
                    $encrypted_text = encryptFollowingDefuse(
@@ 1110-1117 (lines=8) @@
1107
                    }
1108
                } elseif ($task === "sk.php") {
1109
//Create sk.php file
1110
                    if (file_exists($skFile)) {
1111
                        if (!copy($skFile, $skFile.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1112
                            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.'"}]';
1113
                            break;
1114
                        } else {
1115
                            unlink($skFile);
1116
                        }
1117
                    }
1118
                    $file_handler = fopen($skFile, 'w');
1119
1120
                    $result = fwrite(
@@ 1164-1171 (lines=8) @@
1161
                    // update CSRFP TOKEN
1162
                    $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
1163
                    $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
1164
                    if (file_exists($csrfp_file)) {
1165
                        if (!copy($csrfp_file, $csrfp_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
1166
                            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.'"}]';
1167
                            break;
1168
                        } else {
1169
                            $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
1170
                        }
1171
                    }
1172
                    unlink($csrfp_file); // delete existing csrfp.config file
1173
                    copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
1174
                    $data = file_get_contents($csrfp_file);

sources/admin.queries.php 1 location

@@ 1594-1612 (lines=19) @@
1591
            }
1592
1593
            // before perform a copy of sk.php file
1594
            if (file_exists($tmp_skfile)) {
1595
                //Do a copy of the existing file
1596
                if (!copy(
1597
                    $tmp_skfile,
1598
                    $tmp_skfile.'.'.date(
1599
                        "Y_m_d",
1600
                        mktime(0, 0, 0, date('m'), date('d'), date('y'))
1601
                    )
1602
                )) {
1603
                    echo '[{"result" : "" , "error" : "Could NOT perform a copy of file: '.$tmp_skfile.'"}]';
1604
                    break;
1605
                } else {
1606
                    fileDelete($tmp_skfile);
1607
                }
1608
            } else {
1609
                // send back an error
1610
                echo '[{"result" : "" , "error" : "Could NOT access file: '.$tmp_skfile.'"}]';
1611
                break;
1612
            }
1613
        }
1614
1615
        // Write back values in sk.php file

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_ajax.php 1 location

@@ 812-819 (lines=8) @@
809
                // update CSRFP TOKEN
810
                $csrfp_file_sample = "../includes/libraries/csrfp/libs/csrfp.config.sample.php";
811
                $csrfp_file = "../includes/libraries/csrfp/libs/csrfp.config.php";
812
                if (file_exists($csrfp_file) === true) {
813
                    if (!copy($filename, $filename.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
814
                        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.'"}]';
815
                        break;
816
                    } else {
817
                        $events .= "The file $csrfp_file already exist. A copy has been created.<br />";
818
                    }
819
                }
820
                unlink($csrfp_file); // delete existing csrfp.config file
821
                copy($csrfp_file_sample, $csrfp_file); // make a copy of csrfp.config.sample file
822
                $data = file_get_contents("../includes/libraries/csrfp/libs/csrfp.config.php");

install/upgrade_run_2.1.27.php 1 location

@@ 732-739 (lines=8) @@
729
* Introduce new CONFIG file
730
*/
731
$tp_config_file = "../includes/config/tp.config.php";
732
if (file_exists($tp_config_file)) {
733
    if (!copy($tp_config_file, $tp_config_file.'.'.date("Y_m_d", mktime(0, 0, 0, date('m'), date('d'), date('y'))))) {
734
        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.'"}]';
735
        return false;
736
    } else {
737
        unlink($tp_config_file);
738
    }
739
}
740
$file_handler = fopen($tp_config_file, 'w');
741
$config_text = "";
742
$any_settings = false;