Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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