Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

@@ 1800-1847 (lines=48) @@
1797
                || $filename_status === "0")
1798
        ) {
1799
            // File needs to be encrypted
1800
            if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1801
                // Make a copy of file
1802
                if (!copy(
1803
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1804
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1805
                )) {
1806
                    exit;
1807
                } else {
1808
                    // Do a bck
1809
                    copy(
1810
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1811
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1812
                    );
1813
                }
1814
1815
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1816
1817
                // Now encrypt the file with saltkey
1818
                $err = '';
1819
                try {
1820
                    \Defuse\Crypto\File::encryptFile(
1821
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1822
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1823
                        \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1824
                    );
1825
                } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1826
                    $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.";
1827
                } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1828
                    $err = $ex;
1829
                } catch (Defuse\Crypto\Exception\IOException $ex) {
1830
                    $err = $ex;
1831
                }
1832
                if (empty($err) === false) {
1833
                    echo $err;
1834
                }
1835
1836
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1837
1838
                // update table
1839
                DB::update(
1840
                    prefix_table('files'),
1841
                    array(
1842
                        'status' => 'encrypted'
1843
                        ),
1844
                    "id = %i",
1845
                    $fileInfo['id']
1846
                );
1847
            }
1848
        } elseif (isset($SETTINGS['enable_attachment_encryption'])
1849
            && $SETTINGS['enable_attachment_encryption'] === "0"
1850
            && isset($filename_status)
@@ 1854-1901 (lines=48) @@
1851
            && $filename_status === "encrypted"
1852
        ) {
1853
            // file needs to be decrypted
1854
            if (file_exists($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework)) {
1855
                // make a copy of file
1856
                if (!copy(
1857
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1858
                    $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy"
1859
                )) {
1860
                    exit;
1861
                } else {
1862
                    // do a bck
1863
                    copy(
1864
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1865
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".bck"
1866
                    );
1867
                }
1868
1869
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework);
1870
1871
                // Now encrypt the file with saltkey
1872
                $err = '';
1873
                try {
1874
                    \Defuse\Crypto\File::decryptFile(
1875
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy",
1876
                        $SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework,
1877
                        \Defuse\Crypto\Key::loadFromAsciiSafeString($ascii_key)
1878
                    );
1879
                } catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
1880
                    $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.";
1881
                } catch (Defuse\Crypto\Exception\EnvironmentIsBrokenException $ex) {
1882
                    $err = $ex;
1883
                } catch (Defuse\Crypto\Exception\IOException $ex) {
1884
                    $err = $ex;
1885
                }
1886
                if (empty($err) === false) {
1887
                    echo $err;
1888
                }
1889
1890
                unlink($SETTINGS['path_to_upload_folder'].'/'.$filename_to_rework.".copy");
1891
1892
                // update table
1893
                DB::update(
1894
                    prefix_table('files'),
1895
                    array(
1896
                        'status' => 'clear'
1897
                        ),
1898
                    "id = %i",
1899
                    $fileInfo['id']
1900
                );
1901
            }
1902
        }
1903
    }
1904