Code Duplication    Length = 48-48 lines in 2 locations

sources/main.functions.php 2 locations

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