Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1676-1723 (lines=48) @@
1673
1674
    if (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "1" && isset($filename_status) && ($filename_status === "clear" || $filename_status === "0")) {
1675
        // file needs to be encrypted
1676
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
1677
            // make a copy of file
1678
            if (!copy(
1679
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1680
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1681
            )) {
1682
                exit;
1683
            } else {
1684
                // do a bck
1685
                copy(
1686
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1687
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1688
                );
1689
            }
1690
1691
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework);
1692
1693
            // Now encrypt the file with saltkey
1694
            $err = '';
1695
            try {
1696
                \Defuse\Crypto\File::encryptFile(
1697
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1698
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1699
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1700
                );
1701
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1702
                $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.";
1703
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1704
                $err = $ex;
1705
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1706
                $err = $ex;
1707
            }
1708
            if (empty($err) === false) {
1709
                echo $err;
1710
            }
1711
1712
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1713
1714
            // update table
1715
            DB::update(
1716
                prefix_table('files'),
1717
                array(
1718
                    'status' => 'encrypted'
1719
                    ),
1720
                "id=%i",
1721
                substr($_POST['uri'], 1)
1722
            );
1723
        }
1724
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1725
        // file needs to be decrypted
1726
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
@@ 1726-1773 (lines=48) @@
1723
        }
1724
    } elseif (isset($_SESSION['settings']['enable_attachment_encryption']) && $_SESSION['settings']['enable_attachment_encryption'] === "0" && isset($filename_status) && $filename_status === "encrypted") {
1725
        // file needs to be decrypted
1726
        if (file_exists($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework)) {
1727
            // make a copy of file
1728
            if (!copy(
1729
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1730
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1731
            )) {
1732
                exit;
1733
            } else {
1734
                // do a bck
1735
                copy(
1736
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1737
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1738
                );
1739
            }
1740
1741
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework);
1742
1743
            // Now encrypt the file with saltkey
1744
            $err = '';
1745
            try {
1746
                \Defuse\Crypto\File::decryptFile(
1747
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1748
                    $_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework,
1749
                    \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1750
                );
1751
            } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1752
                $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.";
1753
            } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1754
                $err = $ex;
1755
            } catch (Defuse\Crypto\Exception\IOException $ex) {
1756
                $err = $ex;
1757
            }
1758
            if (empty($err) === false) {
1759
                echo $err;
1760
            }
1761
1762
            unlink($_SESSION['settings']['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1763
1764
            // update table
1765
            DB::update(
1766
                prefix_table('files'),
1767
                array(
1768
                    'status' => 'clear'
1769
                    ),
1770
                "id=%i",
1771
                substr($_POST['uri'], 1)
1772
            );
1773
        }
1774
    }
1775
}
1776