Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('_cLog.php');
- class cConfiguration {
- private $oLog;
- public $aConfig,$cfgNum,$iMailErrToNum;
- public function __construct($aConfiguration) {
- $this->oLog= new cLog();
- // ako postoji file zapisuje ga u $aConfiguration
- /*if (file_exists('cfg.xml')) {
- $aConfiguration = simplexml_load_file('cfg.xml');
- }*/
- $this->aConfig=array();
- // broj configuracija u pojedinom file-u
- //$this->cfgNum=isset($aConfiguration->config) ? count($aConfiguration->config) : 0;
- //var_dump($this->cfgNum);
- // ako postoji konfiguracija
- //detaljno logiranje stanja skripte: 0 (iskljuÄeno), 1 (ukljuÄeno)-->
- $this->aConfig['scriptLog']= isset($aConfiguration->scriptLog) ? $aConfiguration->scriptLog : 0;
- //mapiranje externog diska
- $this->aConfig['mountFolder']['extern'] = isset($aConfiguration->mountFolder->extern) ? $aConfiguration->mountFolder->extern : NULL;
- $this->aConfig['mountFolder']['local'] = isset($aConfiguration->mountFolder->local) ? $aConfiguration->mountFolder->local : NULL;
- $this->aConfig['mountFolder']['user'] = isset($aConfiguration->mountFolder->user) ? $aConfiguration->mountFolder->user : NULL;
- $this->aConfig['mountFolder']['pass'] = isset($aConfiguration->mountFolder->pass) ? $aConfiguration->mountFolder->pass : NULL;
- $this->aConfig['mountFolder']['options'] = isset($aConfiguration->mountFolder->options) ? $aConfiguration->mountFolder->options : NULL;
- $this->aConfig['unmountFolder']['local'] = isset($aConfiguration->unmountFolder->local) ? $aConfiguration->unmountFolder->lcoal : NULL;
- //kopiranje samo datoteka stvorenih na posljednji dan iz src u dest
- //kompresiranje dest foldera u file i brisanje svega u dest folderu osim kompresirane datoteke
- $this->aConfig['newestSrc'] = isset($aConfiguration->newestSrc) ? $aConfiguration->newestSrc : '';
- $this->aConfig['newestDest'] = isset($aConfiguration->newestDest) ? $aConfiguration->newestDest : '';
- $this->aConfig['newestFileName'] = isset($aConfiguration->newestFileName) ? $aConfiguration->newestFileName : '';
- //tip izrade backupa: '0' (ne radi se backup), 'rsync'
- $this->aConfig['backupType'] = isset($aConfiguration->backupType) ? $aConfiguration->backupType : '';
- $this->aConfig['rsync']['cycle'] = isset($aConfiguration->rsync->cycle) ? $aConfiguration->rsync->cycle : '';
- $this->aConfig['rsync']['server'] = isset($aConfiguration->rsync->server) ? $aConfiguration->rsync->server : '';
- $this->aConfig['rsync']['userName'] = isset($aConfiguration->rsync->userName) ? $aConfiguration->rsync->userName : '';
- $this->aConfig['rsync']['userPass'] = isset($aConfiguration->rsync->userPass) ? $aConfiguration->rsync->userPass : '';
- $this->aConfig['rsync']['remoteFolder'] = isset($aConfiguration->rsync->remoteFolder) ? $aConfiguration->rsync->remoteFolder : '';
- $this->aConfig['rsync']['localData'] = isset($aConfiguration->rsync->localData) ? $aConfiguration->rsync->localData : '';
- $this->aConfig['rsync']['localExclude'] = isset($aConfiguration->rsync->localExclude) ? $aConfiguration->rsync->localExclude : '';
- //podaci o SMTP serveru i pošiljatelju izvještaja
- $this->aConfig['smtpServer'] = isset($aConfiguration->smtpServer) ? $aConfiguration->smtpServer : '';
- $this->aConfig['mailFrom'] = isset($aConfiguration->mailFrom) ? $aConfiguration->mailFrom : '';
- //podaci o slanju poruka prilikom greške
- $this->aConfig['mailErrors'] = isset($aConfiguration->mailErrors) ? $aConfiguration->mailErrors : '';
- foreach( ($aConfiguration->mailErrorsTo) as $sMailErrTo){
- $sEmail = filter_var($sMailErrTo->email, FILTER_SANITIZE_EMAIL);
- if (!filter_var($sEmail, FILTER_VALIDATE_EMAIL) === false) {
- $this->aConfig['mailErrorsTo'][] = $sEmail;
- }
- else {
- $this->oLog->add('Upisan je neispravan mail na '.$i.'slotu',3003);
- }
- }
- $this->aConfig['mailErrorsSubject'] = isset($aConfiguration->mailErrorsSubject) ? $aConfiguration->mailErrorsSubject : '';
- $this->aConfig['mailReportsOnError'] = isset($aConfiguration->mailReportsOnError) ? $aConfiguration->mailReportsOnError : '';
- //podaci o slanju poruka bez greške
- $this->aConfig['mailReports'] = isset($aConfiguration->mailReports) ? $aConfiguration->mailReports : '';
- foreach(($aConfiguration->mailReportsTo) as $sMailRepTo){
- $sEmail = filter_var($sMailRepTo->email, FILTER_SANITIZE_EMAIL);
- if (!filter_var($sEmail, FILTER_VALIDATE_EMAIL) === false) {
- $this->aConfig['mailReportsTo'][] = $sEmail;
- }
- else {
- $this->oLog->add('Upisan je neispravan mail na '.$i.'slotu',3004);
- }
- }
- /*for($j=0;$j<$this->iMailRepToNum;$j++){
- $this->aConfig['mailReportsTo'][$j] = isset($aConfiguration->mailReportsTo) ? $aConfiguration->mailReportsTo[$j]->email : '';
- }*/
- $this->aConfig['mailReportsSubject'] = isset($aConfiguration->mailReportsSubject) ? $aConfiguration->mailReportsSubject : '';
- //RAID polja za koja se trazi izvjestaj
- foreach($aConfiguration->reportRaid as $sReportRaid){
- if($sReportRaid){
- $this->aConfig['reportRaid'][] = $sReportRaid->raid;
- }
- }
- //particije za koje se traži izvještaj
- foreach($aConfiguration->reportPartition as $sRepPartition){
- if($sRepPartition){
- $this->aConfig['reportPartition'][] = $sRepPartition->partition;
- }
- }
- //folderi za koje se trazi izvjestaj
- /*for($j=0;$j<$this->iRepFolderNum;$j++){
- $this->aConfig['reportFolder'][$j] = isset($aConfiguration->reportFolder) ? $aConfiguration->reportFolder[$j]->folder : '';
- }*/
- foreach($aConfiguration->reportFolder as $sRepFolder){
- if($sRepFolder){
- $this->aConfig['reportFolder'][] = $sRepFolder->folder;
- }
- }
- $this->aConfig['reportFolderListParameters'] = isset($aConfiguration->reportFolderListParameters) ? $aConfiguration->reportFolderListParameters : '';
- // lokalni folderi za koje se trazi velicina zauzetog prostora
- foreach($aConfiguration->locFolderSize as $sLocFolderSize){
- if($sLocFolderSize){
- $this->aConfig['locFolderSize'][] = $sLocFolderSize->size;
- }
- }
- /*for($j=0;$j<$this->iLocFolSizeNum;$j++){
- $this->aConfig['locFolderSize'][$j] = isset($aConfiguration->locFolderSize) ? $aConfiguration->locFolderSize[$j]->size : '';
- }*/
- // udaljeni folderi za koje se trazi velicina zauzetog prostora
- foreach($aConfiguration->sshFolderSize as $sSshFolderSize){
- if($sSshFolderSize){
- $this->aConfig['sshFolderSize'][]['server'] = isset ($sSshFolderSize->server) ? $sSshFolderSize->server : NULL ;
- $this->aConfig['sshFolderSize'][]['userName'] = isset ($sSshFolderSize->userName) ? $sSshFolderSize->userName : NULL;
- $this->aConfig['sshFolderSize'][]['userPass'] = isset($sSshFolderSize->userPass) ? $sSshFolderSize->userPass: NULL ;
- $this->aConfig['sshFolderSize'][]['remoteFolder'] = isset($sSshFolderSize->remoteFolder) ? $sSshFolderSize->remoteFolder :NULL;
- }
- }
- $this->aConfig['pauseFactor'] = isset($aConfiguration->pauseFactor) ? $aConfiguration->pauseFactor : '';
- $this->aConfig['disconnectUsb'] = isset($aConfiguration->disconnectUsb) ? $aConfiguration->disconnectUsb : '';
- $this->aConfig['turnOffPc'] = isset($aConfiguration->turnOffPc) ? $aConfiguration->turnOffPc : '';
- $this->aConfig['restartPc'] = isset($aConfiguration->restartPc) ? $aConfiguration->restartPc : '';
- }
- public function getAny($param=''){
- if($param=='mailErrTo'){
- return $this->aConfig['mailErrorsTo'];
- }
- else if($param=='mountFolderExtern'){
- return $this->aConfig['mountFolder']['extern'];
- }
- else if($param=='mountFolderLocal'){
- return $this->aConfig['mountFolder']['local'];
- }
- else if($param=='mountFolderOptions'){
- return $this->aConfig['mountFolder']['options'];
- }
- else if($param=='mountFolderUser'){
- return $this->aConfig['mountFolder']['user'];
- }
- else if($param=='mountFolderPass'){
- return $this->aConfig['mountFolder']['pass'];
- }
- else if ($param=='newestSrc'){
- return $this->aConfig['newestSrc'];
- }
- else if ($param=='newestDest'){
- return $this->aConfig['newestDest'];
- }
- else if ($param=='newestFileName'){
- return $this->aConfig['newestFileName'];
- }
- else if ($param=='backupType'){
- return $this->aConfig['backupType'];
- }
- else if ($param=='rsyncCycle'){
- return $this->aConfig['rsync']['cycle'];
- }
- else if ($param=='rsyncServer'){
- return $this->aConfig['rsync']['server'];
- }
- else if ($param=='rsyncUsername'){
- return $this->aConfig['rsync']['userName'];
- }
- else if ($param=='rsyncUserPass'){
- return $this->aConfig['rsync']['userPass'];
- }
- else if ($param=='rsyncRemoteFolder'){
- return $this->aConfig['rsync']['remoteFolder'];
- }
- else if ($param=='rsyncLocalData'){
- return $this->aConfig['rsync']['localData'];
- }
- else if ($param=='rsyncLocalExclude'){
- return $this->aConfig['rsync']['localExclude'];
- }
- else if ($param=='reportRaid'){
- return $this->aConfig['reportRaid'];
- }
- else if ($param=='reportPartition'){
- return $this->aConfig['reportPartition'];
- }
- else if ($param=='reportFolder'){
- return $this->aConfig['reportFolder'];
- }
- else if ($param=='reportFolderListParameters'){
- return $this->aConfig['reportFolderListParameters'];
- }
- else if ($param=='sshFolderSize'){
- return $this->aConfig['sshFolderSize'];
- }
- }
- public function getOs(){
- $sOs = substr(php_uname(),0,3);
- if($sOs=='Win'){
- $sOs='win';
- $this->oLog->add('Operacijski sustav: '. $sOs);
- return $sOs;
- }
- else if($sOs == 'Lin'){
- $sOs='lin';
- return $sOs;
- }
- else {
- $this->oLog->add('Operacijski sustav nije identificiran',5002);
- $sOs = NULL;
- return $sOs;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement