Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1693-1740 (lines=48) @@
1690
1691
    if (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "1" && isset($filename_status) && ($filename_status === "clear" || $filename_status === "0")) {
1692
        // file needs to be encrypted
1693
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
1694
            // make a copy of file
1695
            if (!copy(
1696
                $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1697
                $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1698
            )) {
1699
                exit;
1700
            } else {
1701
                // do a bck
1702
                copy(
1703
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1704
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1705
                );
1706
            }
1707
1708
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework);
1709
1710
            // Now encrypt the file with saltkey
1711
            $err = '';
1712
            try {
1713
                \Defuse\Crypto\File::encryptFile(
1714
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1715
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1716
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1717
                );
1718
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1719
                $err = "An attack! Either the wrong key was loaded, or the ciphertext has changed since it was created either corrupted in the database or intentionally modified by someone trying to carry out an attack.";
1720
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1721
                $err = $ex;
1722
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1723
                $err = $ex;
1724
            }
1725
            if (empty($err) === false) {
1726
                echo $err;
1727
            }
1728
1729
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1730
1731
            // update table
1732
            DB::update(
1733
                prefix_table('files'),
1734
                array(
1735
                    'status' => 'encrypted'
1736
                    ),
1737
                "id=%i",
1738
                substr($_POST['uri'], 1)
1739
            );
1740
        }
1741
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1742
        // file needs to be decrypted
1743
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
@@ 1743-1790 (lines=48) @@
1740
        }
1741
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1742
        // file needs to be decrypted
1743
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
1744
            // make a copy of file
1745
            if (!copy(
1746
                $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1747
                $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1748
            )) {
1749
                exit;
1750
            } else {
1751
                // do a bck
1752
                copy(
1753
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1754
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1755
                );
1756
            }
1757
1758
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework);
1759
1760
            // Now encrypt the file with saltkey
1761
            $err = '';
1762
            try {
1763
                \Defuse\Crypto\File::decryptFile(
1764
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1765
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1766
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1767
                );
1768
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1769
                $err = "An attack! Either the wrong key was loaded, or the ciphertext has changed since it was created either corrupted in the database or intentionally modified by someone trying to carry out an attack.";
1770
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1771
                $err = $ex;
1772
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1773
                $err = $ex;
1774
            }
1775
            if (empty($err) === false) {
1776
                echo $err;
1777
            }
1778
1779
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1780
1781
            // update table
1782
            DB::update(
1783
                prefix_table('files'),
1784
                array(
1785
                    'status' => 'clear'
1786
                    ),
1787
                "id=%i",
1788
                substr($_POST['uri'], 1)
1789
            );
1790
        }
1791
    }
1792
}
1793