Skip to content

Commit

Permalink
v3.0.3 - Add backupCore, enable on-demand backups
Browse files Browse the repository at this point in the history
-v3.0.3.
-Fix typo in commonCore.php
-Add manual backup feature to Admin settings page.
-Add backupCore.
-Still working on a Cron script for auto backups (cron will call backupCore using a shell script).
-Still working on instructions to include auto backup information.
-Added GUI elements to settingsCore for changing backup settings & performing on-demand backups.
-Existing users will need to update their config.php file to contain an $EnableBackups = '1'; line and a $BackupLoc = '/path/to/backup/dir'; line.
  • Loading branch information
zelon88 committed Jan 5, 2019
1 parent 38b592f commit bc1d291
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 5 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.txt
@@ -1,3 +1,16 @@
COMMIT 1/3/2019
v3.0.3 - Add backupCore, enable on-demand user data backups.

-v3.0.3.
-Fix typo in commonCore.php
-Add manual backup feature to Admin settings page.
-Add backupCore.
-Still working on a Cron script for auto backups (cron will call backupCore using a shell script).
-Still working on instructions to include auto backup information.
-Added GUI elements to settingsCore for changing backup settings & performing on-demand backups.
-Existing users will need to update their config.php file to contain an $EnableBackups = '1'; line and a $BackupLoc = '/path/to/backup/dir'; line.

----------
COMMIT 12/17/2018 COMMIT 12/17/2018
v3.0.2 - Fix log generation issue. v3.0.2 - Fix log generation issue.


Expand Down
1 change: 1 addition & 0 deletions HRCloud2_Backup_Cron.sh
@@ -0,0 +1 @@
#!/usr/bin/php -f /var/www/html/HRProprietary/HRCloud2/backupCore.php execute
92 changes: 92 additions & 0 deletions backupCore.php
@@ -0,0 +1,92 @@
<?php
// / This file represents the HRCloud2 Backup Core. It is responsible for backing up all Cloud User Data to whatever location is specified in the config.php file.
// / If no $BackupLocation is set in config.php this file will produce a backupWarning.log file in the root HRCloud2 directory which triggers the HRCloud2 Settings Core to display a warning to the administrator.
// / It can safely be run from a local terminal or cron at any time, however large Cloud instances can take A LONG TIME to sync.
// / Therefore, this file WILL NOT start a new instance while a sync is in process.

// / -----------------------------------------------------------------------------------
// / The following code sets variables for the session.
$ExecuteBackup = FALSE;
$BackupDate = date("m_d_y");
$BackupTime = date("F j, Y, g:i a");
$BackupConfigFile = realpath(dirname(__FILE__)).'/config.php';
$backupWarningLogFile = realpath(dirname(__FILE__)).'/backupWARNING.log';
$backupWarningLogData = 'This file was generated on '.$BackupDate.' at '.$BackupTime.' by backupCore.php to notify you that automatic backups cannot run until the $BackupLoc is set in '.$BackupConfigFile.'.';
$BackupScannedFilesCloud = $BackupScannedFilesBackup = $BackupCreatedFiles = $BackupRemovedFiles = $BackupCreatedFolders = $BackupRemovedFolders = $BackupReplacedFiles = 0;
// / -----------------------------------------------------------------------------------

// / -----------------------------------------------------------------------------------
// / The following code loads the HRCloud2 configuration file.
if (!file_exists($BackupConfigFile)) die('ERROR!!! HRC2BackupCore15, Cannot process the HRCloud2 Config file ('.$BackupConfigFile.') on '.$BackupTime.'!'.PHP_EOL);
else require_once($BackupConfigFile);
// / -----------------------------------------------------------------------------------

// / -----------------------------------------------------------------------------------
// / The following code checks if the script is being run as a cron task or shell script.
if (!isset($_POST['backupUserDataNow']) && !isset($_POST['backupNowToken']) && !isset($UserID)) {
if (!isset($EnableBackups) or $EnableBackups !== '1') die();
// / The following code checks if the $BackupLoc is defined in config.php and creates a $backupWarningLogFile if not. Also kills the script.
if ((!isset($BackupLoc) or $BackupLoc == '') && !file_exists($backupWarningLogFile)) {
file_put_contents($backupWarningLogFile, $backupWarningLogData);
die(); }
// / The following code checks if the $backupWarningLogFile is still needed and deletes it if not.
if (isset($BackupLoc) && file_exists($backupWarningLogFile)) unlink($backupWarningLogFile);
// / The following code checks if any CLI arguments are set and sets the execution flag if all checks have passed.
if (isset($argv)) {
if ($argv[1] == 'execute') $ExecuteBackup = TRUE; } }
// / -----------------------------------------------------------------------------------

// / -----------------------------------------------------------------------------------
// / The following code checks if the script is being run via the API and checks that the session is authentic.
if (isset($_POST['backupUserDataNow']) && isset($_POST['backupNowToken']) && isset($UserID) && isset($UserIDRAW)) {
$BackupTokenHASH = hash('ripemd160', $Salts.$BackupLoc.$BackupDate.$UserID.$UserIDRAW);
if ($_POST['backupNowToken'] !== $BackupTokenHASH or $UserIDRAW !== 1) die('ERROR!!! HRC2BackupCore31, The backup token was not valid on '.$BackupTime.'!'.PHP_EOL);
$ExecuteBackup = TRUE; }
// / -----------------------------------------------------------------------------------

// / -----------------------------------------------------------------------------------
// / The following code sync's the user data between the CloudLoc and the BackupLoc.
if ($ExecuteBackup == TRUE) {
// / The following code checks to be sure that the required directories exist before attempting to copy anything.
if (!file_exists($BackupLoc)) @mkdir($BackupLoc);
if (!file_exists($BackupLoc)) die('ERROR!!! HRC2BackupCore48, There was a problem creating a new BackupLoc on '.$BackupTime.'!'.PHP_EOL);
if (!file_exists($CloudLoc)) die('ERROR!!! HRC2BackupCore49, There was a problem creating a sync\'d copy of the Cloud directory in the BackupLoc on '.$BackupTime.'!'.PHP_EOL);
// / The following loop is what actually creates the sync'd copy of folders and files.
foreach ($iterator = new \RecursiveIteratorIterator (
new \RecursiveDirectoryIterator ($CloudLoc, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST) as $item) {
$BUL = $BackupLoc.DIRECTORY_SEPARATOR.$iterator->getSubPathName();
$BackupScannedFilesCloud++;
// / The following code checks if the selected item is a directory, and creates a backup copy if it is.
if (is_dir($item)) {
if (!is_dir($BUL)) {
mkdir($BUL);
$BackupCreatedFolders++;
continue; } }
// / The following code checks if the selected item is a file, and creates a backup copy if it is.
else if (!is_link($item) && !file_exists($BUL)) {
copy($item, $BUL);
$BackupCreatedFiles++; } }
// / The following loop makes sure that the backup contains only the latest copy of files, and only files that still exist in the CloudLoc.
foreach ($iterator = new \RecursiveIteratorIterator (
new \RecursiveDirectoryIterator ($BackupLoc, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST) as $item) {
$CUL = $CloudLoc.DIRECTORY_SEPARATOR.$iterator->getSubPathName();
$BackupScannedFilesBackup++;
// / The following code checks if the selected item is a folder.
if (!file_exists($CUL) && !is_dir($item)) {
$CULFiles = @scandir($item);
// / The following code checks if the folder is empty, and deletes it if so.
if (count($CULFiles) <= 2) {
rmdir($item);
$BackupRemovedFolders++; }
// / The following code checks if the original user file was deleted and deletes the backup if needed.
if (!file_exists($CUL) && is_dir($item) && count(scandir($item)) == 2) {
unlink($item);
$BackupRemovedFiles++; }
// / The following code checks if the Cloud file is newer than the Backup file, and replaces the backup if so.
if (!is_link($CUL) && filemtime($CUL) > filemtime($item)) {
unlink($item);
copy($CUL, $item);
$BackupReplacedFiles++; } } } }
// / -----------------------------------------------------------------------------------
5 changes: 3 additions & 2 deletions commonCore.php
Expand Up @@ -148,6 +148,7 @@
if (!is_numeric($defaultPPEnableURL) or $defaultPPEnableURL > '1') $defaultPPEnableURL = '0'; if (!is_numeric($defaultPPEnableURL) or $defaultPPEnableURL > '1') $defaultPPEnableURL = '0';
if (!isset($defaultTOSEnableURL) or $defaultTOSEnableURL == '') $defaultTOSEnableURL = '0'; if (!isset($defaultTOSEnableURL) or $defaultTOSEnableURL == '') $defaultTOSEnableURL = '0';
if (!is_numeric($defaultTOSEnableURL) or $defaultTOSEnableURL > '1') $defaultTOSEnableURL = '0'; if (!is_numeric($defaultTOSEnableURL) or $defaultTOSEnableURL > '1') $defaultTOSEnableURL = '0';
if (!isset($BackupLoc)) $BackupLoc = '';
if (!isset($defaultPrivacyPolicyURL) or $defaultPrivacyPolicyURL == '') $defaultPrivacyPolicyURL = 'https://www.honestrepair.net/index.php/privacy-policy'; if (!isset($defaultPrivacyPolicyURL) or $defaultPrivacyPolicyURL == '') $defaultPrivacyPolicyURL = 'https://www.honestrepair.net/index.php/privacy-policy';
if (!isset($defaultTermsOfServiceURL) or $defaultTermsOfServiceURL == '') $defaultTermsOfServiceURL = 'https://www.honestrepair.net/index.php/terms-of-service'; if (!isset($defaultTermsOfServiceURL) or $defaultTermsOfServiceURL == '') $defaultTermsOfServiceURL = 'https://www.honestrepair.net/index.php/terms-of-service';
if (!isset($ShowHRAI) or $ShowHRAI == '') $ShowHRAI = $defaultShowHRAI; if (!isset($ShowHRAI) or $ShowHRAI == '') $ShowHRAI = $defaultShowHRAI;
Expand Down Expand Up @@ -348,7 +349,7 @@
// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------
// / The following code sync's the users AppData between the InstLoc and the CloudLoc. // / The following code sync's the users AppData between the InstLoc and the CloudLoc.
if (!file_exists($appDataCloudDir)) { if (!file_exists($appDataCloudDir)) {
$txt = 'WARNING!!! HRC2CommonCore238, There was a problem creating the a sync\'d copy of the AppData directory in the CloudLoc on '.$Time.'!'; $txt = 'WARNING!!! HRC2CommonCore238, There was a problem creating a sync\'d copy of the AppData directory in the CloudLoc on '.$Time.'!';
$MAKELogFile = file_put_contents($LogFile, $txt.PHP_EOL, FILE_APPEND); $MAKELogFile = file_put_contents($LogFile, $txt.PHP_EOL, FILE_APPEND);
die($txt.PHP_EOL.'Most likely the server\'s permissions are incorrect. Make sure the www-data usergroup and user have R/W access to ALL folders in the Cloud directory.'); } die($txt.PHP_EOL.'Most likely the server\'s permissions are incorrect. Make sure the www-data usergroup and user have R/W access to ALL folders in the Cloud directory.'); }
$dirs = array_filter(glob($appDataInstDir.'/*'), 'is_dir'); $dirs = array_filter(glob($appDataInstDir.'/*'), 'is_dir');
Expand All @@ -370,7 +371,7 @@
// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------
// / The following code sync's the users AppData between the CloudLoc and the InstLoc. // / The following code sync's the users AppData between the CloudLoc and the InstLoc.
if (!file_exists($appDataInstDir)) { if (!file_exists($appDataInstDir)) {
$txt = 'WARNING!!! HRC2CommonCore238, There was a problem creating the a sync\'d copy of the AppData directory in the InstLoc on '.$Time.'!'; $txt = 'WARNING!!! HRC2CommonCore238, There was a problem creating a sync\'d copy of the AppData directory in the InstLoc on '.$Time.'!';
$MAKELogFile = file_put_contents($LogFile, $txt.PHP_EOL, FILE_APPEND); $MAKELogFile = file_put_contents($LogFile, $txt.PHP_EOL, FILE_APPEND);
die($txt.PHP_EOL.'Most likely the server\'s permissions are incorrect. Make sure the www-data usergroup and user have R/W access to ALL folders in the Installation directory. '); } die($txt.PHP_EOL.'Most likely the server\'s permissions are incorrect. Make sure the www-data usergroup and user have R/W access to ALL folders in the Installation directory. '); }
foreach ($iterator = new \RecursiveIteratorIterator ( foreach ($iterator = new \RecursiveIteratorIterator (
Expand Down
4 changes: 2 additions & 2 deletions compatibilityCore.php
Expand Up @@ -2,8 +2,8 @@


/* /*
HRCLOUD2 VERSION INFORMATION HRCLOUD2 VERSION INFORMATION
THIS VERSION : v3.0.2 THIS VERSION : v3.0.3
WRITTEN ON : 12/17/2018 WRITTEN ON : 1/4/2019
*/ */


// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions settingsCore.php
Expand Up @@ -17,6 +17,7 @@ function selectChanged(id1, id2) {
else require(realpath(dirname(__FILE__)).'/securityCore.php'); else require(realpath(dirname(__FILE__)).'/securityCore.php');
if (!file_exists(realpath(dirname(__FILE__)).'/compatibilityCore.php')) die ('</head><body>ERROR!!! HRC2SettingsCore107, Cannot process the HRCloud2 Compatibility Core file (compatibilityCore.php)!<br /></body></html>'); if (!file_exists(realpath(dirname(__FILE__)).'/compatibilityCore.php')) die ('</head><body>ERROR!!! HRC2SettingsCore107, Cannot process the HRCloud2 Compatibility Core file (compatibilityCore.php)!<br /></body></html>');
else require(realpath(dirname(__FILE__)).'/compatibilityCore.php'); else require(realpath(dirname(__FILE__)).'/compatibilityCore.php');
$BackupToken = hash('ripemd160', $Salts.$BackupLoc.$Date.$UserID.$UserIDRAW);
// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------


?> ?>
Expand Down Expand Up @@ -350,6 +351,22 @@ function selectChanged(id1, id2) {
echo('Generated a Client App Installation package to your Cloud Drive! | <a href="'.$URL.'/HRProprietary/HRCloud2/DATA/'.$UserID.'/HRCloud2-Client_'.$GenClientOS.'_'.$GenClientCPU.'_'.$Date.'.zip"><strong>Download Now</strong></a>.'.$br.'</hr>'); } } echo('Generated a Client App Installation package to your Cloud Drive! | <a href="'.$URL.'/HRProprietary/HRCloud2/DATA/'.$UserID.'/HRCloud2-Client_'.$GenClientOS.'_'.$GenClientCPU.'_'.$Date.'.zip"><strong>Download Now</strong></a>.'.$br.'</hr>'); } }
// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------


// / -----------------------------------------------------------------------------------
// / The following code loads the backupCore to perform an admin on-demand backup,
if (isset($_POST['backupNowToken'])) {
if (!file_exists(realpath(dirname(__FILE__)).'/backupCore.php')) die ('</head><body>ERROR!!! HRC2SettingsCore355, Cannot process the HRCloud2 Backup Core file (backupCore.php)!<br /></body></html>');
else require(realpath(dirname(__FILE__)).'/backupCore.php');
echo('Backup Complete!'.$br);
echo('Cloud Items Scanned: '.$BackupScannedFilesCloud.$br);
echo('Backup Items Scanned: '.$BackupScannedFilesBackup.$br);
echo('Files Created: '.$BackupCreatedFiles.$br);
echo('Directories Created: '.$BackupCreatedFolders.$br);
echo('Files Removed: '.$BackupRemovedFiles.$br);
echo('Directories Removed: '.$BackupRemovedFolders.$br);
echo('Modified Files Replaced: '.$BackupReplacedFiles.$hr); }
// / -----------------------------------------------------------------------------------


// / ----------------------------------------------------------------------------------- // / -----------------------------------------------------------------------------------
// / Set the echo value for the "Data Comrpession" option. // / Set the echo value for the "Data Comrpession" option.
if ($DataCompression == '0' or $DataCompression == '' or !isset($DataCompression)) $DCURL = 'Disabled'; if ($DataCompression == '0' or $DataCompression == '' or !isset($DataCompression)) $DCURL = 'Disabled';
Expand Down Expand Up @@ -617,6 +634,10 @@ function selectChanged(id1, id2) {
<input type='submit' name='CheckCompatibility' id='CheckCompatibility' value='Compat Check' style="padding: 2px; border: 1px solid black" onclick="toggle_visibility('loading');"/> <input type='submit' name='CheckCompatibility' id='CheckCompatibility' value='Compat Check' style="padding: 2px; border: 1px solid black" onclick="toggle_visibility('loading');"/>
</p> </p>


<p alt="Backup all user submitted data." title="Backup all user submitted data." style="padding-left:15px;"> Backup User Data: </p>
<p style="float:center; padding-left:10%;"><input type='submit' name='backupUserDataNow' id='backupUserDataNow' value='Backup Now' style="padding-left:30px; padding: 2px; border: 1px solid black" onclick="toggle_visibility('loading');"/></p>
<input type='hidden' id='backupNowToken' name='backupNowToken' value='<?php echo $BackupToken; ?>'/>

<p alt="Verify the permissions level, owner, and group of HRCloud2 controlled directories." title="Verify the permissions level, owner, and group of HRCloud2 controlled directories." style="padding-left:15px;"> Permissions Check:</p> <p alt="Verify the permissions level, owner, and group of HRCloud2 controlled directories." title="Verify the permissions level, owner, and group of HRCloud2 controlled directories." style="padding-left:15px;"> Permissions Check:</p>
<p style="float:center; padding-left:10%;"> <p style="float:center; padding-left:10%;">
<input type='submit' name='CheckPermissions' id='CheckPermissions' value='Perms Check' style="padding: 2px; border: 1px solid black" onclick="toggle_visibility('loading');"/> <input type='submit' name='CheckPermissions' id='CheckPermissions' value='Perms Check' style="padding: 2px; border: 1px solid black" onclick="toggle_visibility('loading');"/>
Expand Down
2 changes: 1 addition & 1 deletion versionInfo.php
@@ -1,4 +1,4 @@
<?php <?php
// / This file contains the current HRCloud2 version for auto-update purposes. // / This file contains the current HRCloud2 version for auto-update purposes.
// / // /
$Version = 'v3.0.2'; $Version = 'v3.0.3';

0 comments on commit bc1d291

Please sign in to comment.