-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self update #1097
Self update #1097
Changes from 23 commits
bfebff8
0aee63c
07257c1
a0399fa
a65324f
720ce83
f542a89
07fb247
1c1f5e6
a2062a7
a00572c
28f2449
0f3a4cf
919c6fa
4e514ea
21a9369
b299280
0251942
b913c26
686d3a7
529b1e1
0f24dd8
31165a3
ce312db
7ea7df0
24da903
c56879f
4f0a63d
fd582fd
4830907
41d99c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
#Vagrant | ||
.vagrant/ | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
*.iml | ||
## Directory-based project format: | ||
.idea/ | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
#Exclude composer vendor folders | ||
vendor | ||
composer.lock | ||
|
||
# Uploaded Images | ||
thumbnails | ||
|
||
# SASS | ||
.sass-cache | ||
|
||
#skins | ||
adminlte | ||
font-awesome | ||
ionicons | ||
|
||
# Configuration files with passwords | ||
src/Include/Config.php | ||
|
||
target | ||
/src/orm/model/ChurchCRM/Base/ | ||
/src/orm/model/ChurchCRM/Map/ | ||
#Vagrant | ||
.vagrant/ | ||
|
||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm | ||
*.iml | ||
## Directory-based project format: | ||
.idea/ | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
#Exclude composer vendor folders | ||
vendor | ||
composer.lock | ||
|
||
# Uploaded Images | ||
thumbnails | ||
|
||
# SASS | ||
.sass-cache | ||
|
||
#skins | ||
adminlte | ||
font-awesome | ||
ionicons | ||
|
||
# Configuration files with passwords | ||
src/Include/Config.php | ||
|
||
target | ||
/src/orm/model/ChurchCRM/Base/ | ||
/src/orm/model/ChurchCRM/Map/ | ||
/src/signatures.json | ||
/src/integrityCheck.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
$CRMRoot = $argv[1]; | ||
$CRMRootLen = strlen($CRMRoot); | ||
$signatureFile = $CRMRoot."/signatures.json"; | ||
$composerFile = file_get_contents(__DIR__. "/src/composer.json"); | ||
$composerJson = json_decode($composerFile, true); | ||
|
||
echo "Creating Signature Definition at: ".$signatureFile."\r\n"; | ||
|
||
$signatureData = new stdClass(); | ||
$signatureData->version = $composerJson["version"]; | ||
$signatureData->files = array(); | ||
|
||
$projectFiles = new RecursiveDirectoryIterator($CRMRoot); | ||
$Iterator = new RecursiveIteratorIterator($projectFiles); | ||
$Regex = new RegexIterator($Iterator, '/^.+\.(php|js)$/i', RecursiveRegexIterator::GET_MATCH); | ||
foreach ($Regex as $obj ) | ||
{ | ||
$file = new stdClass(); | ||
$file->filename = substr($obj[0], $CRMRootLen+1); | ||
$file->sha1 = sha1_file($CRMRoot."/".$file->filename); | ||
array_push($signatureData->files, $file); | ||
} | ||
|
||
ksort($signatureData->files); | ||
|
||
$signatureData->sha1 = sha1(json_encode($signatureData->files)); | ||
file_put_contents($signatureFile, json_encode($signatureData)); | ||
|
||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/******************************************************************************* | ||
* | ||
* filename : GroupList.php | ||
* website : http://www.churchcrm.io | ||
* copyright : Copyright 2001, 2002 Deane Barker | ||
* | ||
* | ||
* Additional Contributors: | ||
* 2006 Ed Davis | ||
* 2016 Charles Crossan | ||
* | ||
* | ||
* Copyright Contributors | ||
* | ||
* ChurchCRM is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This file best viewed in a text editor with tabs stops set to 4 characters | ||
* | ||
******************************************************************************/ | ||
//Include the function library | ||
require 'Include/Config.php'; | ||
require 'Include/Functions.php'; | ||
|
||
|
||
//Set the page title | ||
$sPageTitle = gettext('Integrity Check Results'); | ||
if (!$_SESSION['bFinance']) | ||
{ | ||
Redirect("index.php"); | ||
exit; | ||
} | ||
require 'Include/Header.php'; | ||
$CRMInstallRoot = __DIR__; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for the var |
||
$integrityCheckFile = $CRMInstallRoot."/integrityCheck.json"; | ||
$IntegrityCheckDetails = json_decode(file_get_contents($integrityCheckFile)); | ||
|
||
?> | ||
|
||
<div class="box box-body"> | ||
<p><?= gettext("Previous Integrity Check Result:") ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the callout warning css to get read or green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in a commit coming soon to a Repo near you |
||
<?php | ||
if ($IntegrityCheckDetails->status == "failure") | ||
{ | ||
?> | ||
<span style="color:red"><?= gettext("Failure") ?></span> | ||
<?php | ||
} | ||
else | ||
{ | ||
?> | ||
<span style="color:green"><?= gettext("Success") ?></span> | ||
<?php | ||
} | ||
?> | ||
</p> | ||
<?php | ||
if (isset($IntegrityCheckDetails->message)) | ||
{ | ||
?> | ||
<p><?= gettext("Details:")?> <?= $IntegrityCheckDetails->message ?></p> | ||
|
||
<?php | ||
} | ||
if(count($IntegrityCheckDetails->files) > 0 ) | ||
{ | ||
?> | ||
<p><?= gettext("Files failing integrity check:") ?> | ||
<ul> | ||
<?php | ||
foreach ($IntegrityCheckDetails->files as $file) | ||
{ | ||
?> | ||
<li>FileName: <?= $file->filename ?> | ||
<ul> | ||
<li>Expected Hash: <?= $file->expectedhash ?></li> | ||
<li>Actual Hash: <?= $file->actualhash ?></li> | ||
</ul> | ||
</li> | ||
<?php | ||
} | ||
?> | ||
</ul> | ||
<?php | ||
} | ||
?> | ||
</div> | ||
|
||
<?php | ||
require 'Include/Footer.php'; | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,24 +363,119 @@ function reportIssue($data) | |
|
||
function runTimerJobs() | ||
{ | ||
global $sEnableExternalBackupTarget, $sExternalBackupAutoInterval, $sLastBackupTimeStamp; | ||
global $sEnableIntegrityCheck, $sIntegrityCheckInterval, $sLastIntegrityCheckTimeStamp; | ||
//start the external backup timer job | ||
if ($sEnableExternalBackupTarget && $sExternalBackupAutoInterval > 0) //if remote backups are enabled, and the interval is greater than zero | ||
{ | ||
try { | ||
$now = new DateTime(); //get the current time | ||
$previous = new DateTime($sLastBackupTimeStamp); // get a DateTime object for the last time a backup was done. | ||
$now = new \DateTime(); //get the current time | ||
$previous = new \DateTime($sLastBackupTimeStamp); // get a DateTime object for the last time a backup was done. | ||
$diff = $previous->diff($now); // calculate the difference. | ||
if (!$sLastBackupTimeStamp || $diff->h >= $sExternalBackupAutoInterval) // if there was no previous backup, or if the interval suggests we do a backup now. | ||
{ | ||
$systemService->copyBackupToExternalStorage(); // Tell system service to do an external storage backup. | ||
$now = new DateTime(); // update the LastBackupTimeStamp. | ||
$now = new \DateTime(); // update the LastBackupTimeStamp. | ||
$sSQL = "UPDATE config_cfg SET cfg_value='" . $now->format('Y-m-d H:i:s') . "' WHERE cfg_name='sLastBackupTimeStamp'"; | ||
$rsUpdate = RunQuery($sSQL); | ||
} | ||
} catch (Exception $exc) { | ||
// an error in the auto-backup shouldn't prevent the page from loading... | ||
} | ||
} | ||
if ($sEnableIntegrityCheck && $sIntegrityCheckInterval > 0) | ||
{ | ||
$now = new \DateTime(); //get the current time | ||
$previous = new \DateTime($sLastIntegrityCheckTimeStamp); // get a DateTime object for the last time a backup was done. | ||
$diff = $previous->diff($now); // calculate the difference. | ||
if (!$sLastIntegrityCheckTimeStamp || $diff->h >= $sIntegrityCheckInterval) // if there was no previous backup, or if the interval suggests we do a backup now. | ||
{ | ||
$CRMInstallRoot = dirname(__DIR__); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. temp var not used else where |
||
$integrityCheckFile = $CRMInstallRoot."/integrityCheck.json"; | ||
$appIntegrity = $this->verifyApplicationIntegrity(); | ||
file_put_contents($integrityCheckFile, json_encode($appIntegrity)); | ||
$now = new \DateTime(); // update the LastBackupTimeStamp. | ||
$sSQL = "UPDATE config_cfg SET cfg_value='" . $now->format('Y-m-d H:i:s') . "' WHERE cfg_name='sLastIntegrityCheckTimeStamp'"; | ||
$rsUpdate = RunQuery($sSQL); | ||
} | ||
} | ||
} | ||
|
||
function downloadLatestRelease() | ||
{ | ||
$release = $this->getLatestRelese(); | ||
$CRMInstallRoot = dirname(__DIR__); | ||
$UpgradeDir = $CRMInstallRoot."/Upgrade"; | ||
$url = $release['assets'][0]['browser_download_url']; | ||
mkdir($UpgradeDir); | ||
file_put_contents($UpgradeDir."/".basename($url), file_get_contents($url)); | ||
$returnFile= array(); | ||
$returnFile['fileName'] = basename($url); | ||
$returnFile['fullPath'] = $UpgradeDir."/".basename($url); | ||
$returnFile['sha1'] = sha1_file($UpgradeDir."/".basename($url)); | ||
return $returnFile; | ||
} | ||
|
||
function doUpgrade($zipFilename,$sha1) | ||
{ | ||
ini_set('max_execution_time',60); | ||
$CRMInstallRoot = dirname(__DIR__); | ||
if($sha1 == sha1_file($zipFilename)) | ||
{ | ||
$zip = new \ZipArchive(); | ||
if ($zip->open($zipFilename) == TRUE) | ||
{ | ||
for($i = 0; $i < $zip->numFiles; $i++) | ||
{ | ||
$archivedFileName = $zip->getNameIndex($i); | ||
$targetFilename = str_replace("churchcrm/","/",$archivedFileName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are you trying to do here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't want to maintain the "churchcrm" folder inside of the zip archive when we extract it. |
||
if ($targetFilename != "/Service/SystemService.php") // save the best for last. | ||
{ | ||
copy("zip://".$zipFilename."#".$archivedFileName, $CRMInstallRoot.$targetFilename); | ||
} | ||
} | ||
$zip->close(); | ||
} | ||
return "It is done"; | ||
} | ||
else | ||
{ | ||
return "hashes dont match. don't touch it!"; | ||
} | ||
|
||
} | ||
|
||
function verifyApplicationIntegrity() | ||
{ | ||
$CRMInstallRoot = dirname(__DIR__); | ||
$signatureFile = $CRMInstallRoot."/signatures.json"; | ||
$signatureData = json_decode(file_get_contents($signatureFile)); | ||
$signatureFailures = array(); | ||
|
||
if (sha1(json_encode($signatureData->files)) == $signatureData->sha1) | ||
{ | ||
foreach ($signatureData->files as $file) | ||
{ | ||
$actualHash = sha1_file($CRMInstallRoot."/".$file->filename); | ||
if ( $actualHash != $file->sha1 ) | ||
{ | ||
array_push($signatureFailures, array("filename"=>$file->filename,"expectedhash"=>$file->sha1,"actualhash"=>$actualHash)); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
return array("status"=>"failure","message"=>"Signature Definition file signature failed validation"); | ||
} | ||
|
||
if(count($signatureFailures) > 0 ) | ||
{ | ||
return array("status"=>"failure","files"=>$signatureFailures); | ||
} | ||
else | ||
{ | ||
return array("status"=>"success"); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whooopss.. That's what i get for copying / pasting a page. I should get rid of the header too...