Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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