Advertisement
Guest User

Untitled

a guest
Jun 20th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.83 KB | None | 0 0
  1. <?php
  2.  
  3. include_once('_cLog.php');
  4.  
  5.  
  6. class cConfiguration {
  7.  
  8. private $oLog;
  9.  
  10.  
  11. public $aConfig,$cfgNum,$iMailErrToNum;
  12.  
  13. public function __construct($aConfiguration) {
  14.  
  15.  
  16.  
  17.  
  18. $this->oLog= new cLog();
  19.  
  20.  
  21.  
  22. // ako postoji file zapisuje ga u $aConfiguration
  23.  
  24. /*if (file_exists('cfg.xml')) {
  25.  
  26. $aConfiguration = simplexml_load_file('cfg.xml');
  27.  
  28. }*/
  29.  
  30.  
  31. $this->aConfig=array();
  32.  
  33. // broj configuracija u pojedinom file-u
  34.  
  35. //$this->cfgNum=isset($aConfiguration->config) ? count($aConfiguration->config) : 0;
  36.  
  37. //var_dump($this->cfgNum);
  38.  
  39.  
  40.  
  41.  
  42. // ako postoji konfiguracija
  43.  
  44.  
  45.  
  46.  
  47. //detaljno logiranje stanja skripte: 0 (isključeno), 1 (uključeno)-->
  48.  
  49. $this->aConfig['scriptLog']= isset($aConfiguration->scriptLog) ? $aConfiguration->scriptLog : 0;
  50.  
  51.  
  52. //mapiranje externog diska
  53.  
  54. $this->aConfig['mountFolder']['extern'] = isset($aConfiguration->mountFolder->extern) ? $aConfiguration->mountFolder->extern : NULL;
  55. $this->aConfig['mountFolder']['local'] = isset($aConfiguration->mountFolder->local) ? $aConfiguration->mountFolder->local : NULL;
  56. $this->aConfig['mountFolder']['user'] = isset($aConfiguration->mountFolder->user) ? $aConfiguration->mountFolder->user : NULL;
  57. $this->aConfig['mountFolder']['pass'] = isset($aConfiguration->mountFolder->pass) ? $aConfiguration->mountFolder->pass : NULL;
  58. $this->aConfig['mountFolder']['options'] = isset($aConfiguration->mountFolder->options) ? $aConfiguration->mountFolder->options : NULL;
  59. $this->aConfig['unmountFolder']['local'] = isset($aConfiguration->unmountFolder->local) ? $aConfiguration->unmountFolder->lcoal : NULL;
  60.  
  61. //kopiranje samo datoteka stvorenih na posljednji dan iz src u dest
  62. //kompresiranje dest foldera u file i brisanje svega u dest folderu osim kompresirane datoteke
  63.  
  64. $this->aConfig['newestSrc'] = isset($aConfiguration->newestSrc) ? $aConfiguration->newestSrc : '';
  65. $this->aConfig['newestDest'] = isset($aConfiguration->newestDest) ? $aConfiguration->newestDest : '';
  66. $this->aConfig['newestFileName'] = isset($aConfiguration->newestFileName) ? $aConfiguration->newestFileName : '';
  67.  
  68. //tip izrade backupa: '0' (ne radi se backup), 'rsync'
  69.  
  70. $this->aConfig['backupType'] = isset($aConfiguration->backupType) ? $aConfiguration->backupType : '';
  71. $this->aConfig['rsync']['cycle'] = isset($aConfiguration->rsync->cycle) ? $aConfiguration->rsync->cycle : '';
  72. $this->aConfig['rsync']['server'] = isset($aConfiguration->rsync->server) ? $aConfiguration->rsync->server : '';
  73. $this->aConfig['rsync']['userName'] = isset($aConfiguration->rsync->userName) ? $aConfiguration->rsync->userName : '';
  74. $this->aConfig['rsync']['userPass'] = isset($aConfiguration->rsync->userPass) ? $aConfiguration->rsync->userPass : '';
  75. $this->aConfig['rsync']['remoteFolder'] = isset($aConfiguration->rsync->remoteFolder) ? $aConfiguration->rsync->remoteFolder : '';
  76. $this->aConfig['rsync']['localData'] = isset($aConfiguration->rsync->localData) ? $aConfiguration->rsync->localData : '';
  77. $this->aConfig['rsync']['localExclude'] = isset($aConfiguration->rsync->localExclude) ? $aConfiguration->rsync->localExclude : '';
  78.  
  79.  
  80. //podaci o SMTP serveru i pošiljatelju izvještaja
  81.  
  82. $this->aConfig['smtpServer'] = isset($aConfiguration->smtpServer) ? $aConfiguration->smtpServer : '';
  83. $this->aConfig['mailFrom'] = isset($aConfiguration->mailFrom) ? $aConfiguration->mailFrom : '';
  84.  
  85. //podaci o slanju poruka prilikom greške
  86.  
  87. $this->aConfig['mailErrors'] = isset($aConfiguration->mailErrors) ? $aConfiguration->mailErrors : '';
  88.  
  89.  
  90.  
  91. foreach( ($aConfiguration->mailErrorsTo) as $sMailErrTo){
  92.  
  93. $sEmail = filter_var($sMailErrTo->email, FILTER_SANITIZE_EMAIL);
  94.  
  95. if (!filter_var($sEmail, FILTER_VALIDATE_EMAIL) === false) {
  96.  
  97. $this->aConfig['mailErrorsTo'][] = $sEmail;
  98. }
  99. else {
  100.  
  101. $this->oLog->add('Upisan je neispravan mail na '.$i.'slotu',3003);
  102. }
  103. }
  104.  
  105.  
  106.  
  107. $this->aConfig['mailErrorsSubject'] = isset($aConfiguration->mailErrorsSubject) ? $aConfiguration->mailErrorsSubject : '';
  108. $this->aConfig['mailReportsOnError'] = isset($aConfiguration->mailReportsOnError) ? $aConfiguration->mailReportsOnError : '';
  109.  
  110.  
  111. //podaci o slanju poruka bez greške
  112.  
  113. $this->aConfig['mailReports'] = isset($aConfiguration->mailReports) ? $aConfiguration->mailReports : '';
  114.  
  115.  
  116. foreach(($aConfiguration->mailReportsTo) as $sMailRepTo){
  117.  
  118. $sEmail = filter_var($sMailRepTo->email, FILTER_SANITIZE_EMAIL);
  119.  
  120. if (!filter_var($sEmail, FILTER_VALIDATE_EMAIL) === false) {
  121.  
  122. $this->aConfig['mailReportsTo'][] = $sEmail;
  123. }
  124. else {
  125.  
  126. $this->oLog->add('Upisan je neispravan mail na '.$i.'slotu',3004);
  127. }
  128. }
  129.  
  130. /*for($j=0;$j<$this->iMailRepToNum;$j++){
  131.  
  132. $this->aConfig['mailReportsTo'][$j] = isset($aConfiguration->mailReportsTo) ? $aConfiguration->mailReportsTo[$j]->email : '';
  133. }*/
  134.  
  135. $this->aConfig['mailReportsSubject'] = isset($aConfiguration->mailReportsSubject) ? $aConfiguration->mailReportsSubject : '';
  136.  
  137. //RAID polja za koja se trazi izvjestaj
  138.  
  139. foreach($aConfiguration->reportRaid as $sReportRaid){
  140.  
  141. if($sReportRaid){
  142.  
  143. $this->aConfig['reportRaid'][] = $sReportRaid->raid;
  144.  
  145. }
  146. }
  147.  
  148. //particije za koje se traži izvještaj
  149.  
  150. foreach($aConfiguration->reportPartition as $sRepPartition){
  151.  
  152. if($sRepPartition){
  153.  
  154. $this->aConfig['reportPartition'][] = $sRepPartition->partition;
  155. }
  156. }
  157.  
  158. //folderi za koje se trazi izvjestaj
  159.  
  160. /*for($j=0;$j<$this->iRepFolderNum;$j++){
  161.  
  162. $this->aConfig['reportFolder'][$j] = isset($aConfiguration->reportFolder) ? $aConfiguration->reportFolder[$j]->folder : '';
  163. }*/
  164.  
  165. foreach($aConfiguration->reportFolder as $sRepFolder){
  166.  
  167. if($sRepFolder){
  168.  
  169. $this->aConfig['reportFolder'][] = $sRepFolder->folder;
  170. }
  171. }
  172.  
  173.  
  174. $this->aConfig['reportFolderListParameters'] = isset($aConfiguration->reportFolderListParameters) ? $aConfiguration->reportFolderListParameters : '';
  175.  
  176. // lokalni folderi za koje se trazi velicina zauzetog prostora
  177.  
  178. foreach($aConfiguration->locFolderSize as $sLocFolderSize){
  179.  
  180. if($sLocFolderSize){
  181.  
  182. $this->aConfig['locFolderSize'][] = $sLocFolderSize->size;
  183. }
  184. }
  185.  
  186. /*for($j=0;$j<$this->iLocFolSizeNum;$j++){
  187.  
  188.  
  189. $this->aConfig['locFolderSize'][$j] = isset($aConfiguration->locFolderSize) ? $aConfiguration->locFolderSize[$j]->size : '';
  190.  
  191. }*/
  192.  
  193. // udaljeni folderi za koje se trazi velicina zauzetog prostora
  194.  
  195.  
  196. foreach($aConfiguration->sshFolderSize as $sSshFolderSize){
  197.  
  198. if($sSshFolderSize){
  199.  
  200. $this->aConfig['sshFolderSize'][]['server'] = isset ($sSshFolderSize->server) ? $sSshFolderSize->server : NULL ;
  201. $this->aConfig['sshFolderSize'][]['userName'] = isset ($sSshFolderSize->userName) ? $sSshFolderSize->userName : NULL;
  202. $this->aConfig['sshFolderSize'][]['userPass'] = isset($sSshFolderSize->userPass) ? $sSshFolderSize->userPass: NULL ;
  203. $this->aConfig['sshFolderSize'][]['remoteFolder'] = isset($sSshFolderSize->remoteFolder) ? $sSshFolderSize->remoteFolder :NULL;
  204. }
  205. }
  206.  
  207. $this->aConfig['pauseFactor'] = isset($aConfiguration->pauseFactor) ? $aConfiguration->pauseFactor : '';
  208. $this->aConfig['disconnectUsb'] = isset($aConfiguration->disconnectUsb) ? $aConfiguration->disconnectUsb : '';
  209. $this->aConfig['turnOffPc'] = isset($aConfiguration->turnOffPc) ? $aConfiguration->turnOffPc : '';
  210. $this->aConfig['restartPc'] = isset($aConfiguration->restartPc) ? $aConfiguration->restartPc : '';
  211.  
  212.  
  213. }
  214.  
  215. public function getAny($param=''){
  216.  
  217. if($param=='mailErrTo'){
  218. return $this->aConfig['mailErrorsTo'];
  219. }
  220. else if($param=='mountFolderExtern'){
  221. return $this->aConfig['mountFolder']['extern'];
  222. }
  223. else if($param=='mountFolderLocal'){
  224. return $this->aConfig['mountFolder']['local'];
  225. }
  226. else if($param=='mountFolderOptions'){
  227. return $this->aConfig['mountFolder']['options'];
  228. }
  229. else if($param=='mountFolderUser'){
  230. return $this->aConfig['mountFolder']['user'];
  231. }
  232. else if($param=='mountFolderPass'){
  233. return $this->aConfig['mountFolder']['pass'];
  234. }
  235. else if ($param=='newestSrc'){
  236. return $this->aConfig['newestSrc'];
  237. }
  238. else if ($param=='newestDest'){
  239. return $this->aConfig['newestDest'];
  240. }
  241. else if ($param=='newestFileName'){
  242. return $this->aConfig['newestFileName'];
  243. }
  244. else if ($param=='backupType'){
  245. return $this->aConfig['backupType'];
  246. }
  247. else if ($param=='rsyncCycle'){
  248. return $this->aConfig['rsync']['cycle'];
  249. }
  250. else if ($param=='rsyncServer'){
  251. return $this->aConfig['rsync']['server'];
  252. }
  253. else if ($param=='rsyncUsername'){
  254. return $this->aConfig['rsync']['userName'];
  255. }
  256. else if ($param=='rsyncUserPass'){
  257. return $this->aConfig['rsync']['userPass'];
  258. }
  259. else if ($param=='rsyncRemoteFolder'){
  260. return $this->aConfig['rsync']['remoteFolder'];
  261. }
  262. else if ($param=='rsyncLocalData'){
  263. return $this->aConfig['rsync']['localData'];
  264. }
  265. else if ($param=='rsyncLocalExclude'){
  266. return $this->aConfig['rsync']['localExclude'];
  267. }
  268. else if ($param=='reportRaid'){
  269. return $this->aConfig['reportRaid'];
  270. }
  271. else if ($param=='reportPartition'){
  272. return $this->aConfig['reportPartition'];
  273. }
  274.  
  275. else if ($param=='reportFolder'){
  276. return $this->aConfig['reportFolder'];
  277. }
  278.  
  279. else if ($param=='reportFolderListParameters'){
  280. return $this->aConfig['reportFolderListParameters'];
  281. }
  282. else if ($param=='sshFolderSize'){
  283. return $this->aConfig['sshFolderSize'];
  284. }
  285.  
  286.  
  287. }
  288.  
  289. public function getOs(){
  290.  
  291. $sOs = substr(php_uname(),0,3);
  292.  
  293. if($sOs=='Win'){
  294.  
  295. $sOs='win';
  296. $this->oLog->add('Operacijski sustav: '. $sOs);
  297. return $sOs;
  298. }
  299.  
  300. else if($sOs == 'Lin'){
  301.  
  302. $sOs='lin';
  303. return $sOs;
  304. }
  305.  
  306. else {
  307.  
  308. $this->oLog->add('Operacijski sustav nije identificiran',5002);
  309. $sOs = NULL;
  310. return $sOs;
  311. }
  312. }
  313.  
  314.  
  315.  
  316.  
  317. }
  318.  
  319.  
  320.  
  321.  
  322. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement