koresp hardlink PROJEKTY/ID..../_PISMA/{HL:pismo.pdf} * TODO: PROJEKTY/ID..../_PISMA/ permy tylko read/listing * TODO: hardlink druki: mkdir DRUKI/ID.{DESC}/_PROJEKT/{proj_folder}/{HL:pliki z proj bez podkatalogʈw} * TODO: DRUKI/ID.{DESC}/_PROJEKT/{proj_folder} permy tylko read/listing * -- TODO: DRUKI/ID.{DESC}/ - permy z bazy danych A_ADM_COMPANY, A_CLASSIFIED * * * DONE: Trigger po update/insert Koresp po aktualizacji permʈw plikʈw projektu */ ini_set('max_execution_time', 300); ini_set('memory_limit', '512M'); define('DS', DIRECTORY_SEPARATOR); define('APP_PATH_ROOT', dirname(__FILE__)); define('APP_PATH_WWW', dirname(__FILE__)); define('APP_PATH_CONFIG', APP_PATH_ROOT . DS . 'config'); // set ini to log errors into error log file ini_set('display_startup_errors', '0'); ini_set('log_errors', '1'); ini_set('error_log', '/var/log/apache2/error_log');// TODO: php.ini ? require_once APP_PATH_ROOT . DS . 'se-lib' . DS . 'Lib.php'; Lib::loadClass('V'); Lib::loadClass('Config'); Lib::loadClass('DB'); Lib::loadClass('User'); Lib::loadClass('FoldersConfig'); Lib::loadClass('FileUploader'); if (isset($_SERVER["argv"][1])) { $_SERVER['SERVER_NAME'] = $_SERVER["argv"][1]; } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'info') { $info = array(); $info['max_execution_time'] = ini_get('max_execution_time'); $info['memory_limit'] = ini_get('memory_limit'); echo'
info (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'
'; ini_set('max_execution_time', 300); ini_set('memory_limit', '512M'); $info = array(); $info['max_execution_time'] = ini_get('max_execution_time'); $info['memory_limit'] = ini_get('memory_limit'); echo'
info (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($info);echo'
'; } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'users') { SyncPerms::run(null, null, 'users', null); } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'usersAll') { SyncPerms::run(null, null, 'usersAll', null); } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'task') { SyncPerms::run(null, null, 'nextTask', null); } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'newFiles') { SyncPerms::run(null, null, 'newFiles', null); } else if (empty($_SERVER["argv"]) && V::get('task', '', $_GET) == 'testParse') { $cmd = " ls -Rlea . "; //exec("cd \"/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/1970.Rekrutacja_z_dnia_2013-02-22_na_stanowisko_Specjalista_ds_pozyskiwania_klientow/6/\"; {$cmd} ", $filesWithPerms); //exec("cd \"/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/1983.Rekrutacja_z_dnia_2013-03-12_na_stanowisko_Przedstawiciel_Handlowy_(D2D)/24/\"; {$cmd} ", $filesWithPerms); //exec("cd '/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/816.2012-01-01.INNE.Siec_Szerokopasmowa_w_ramach_dofinansowania_unii_dla_woj_pomorskiego__Sprint/2013-06-14.Dokumenty_do_wysylki_po_wysylce_usunac!_AB_co_to_za_katlog_TODO/Zalacznik 1 Studium wykonalnosci/'; {$cmd} ", $filesWithPerms); exec("cd '/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/1657.Rekrutacja_z_dnia_2012-06_25_na_stanowisko_Przedstawiciel_Handlowy/1/'; {$cmd} ", $filesWithPerms); //$line = "-rwxrwx---+ 1 _www workgroup 212367 Feb 25 2013 Cv Malwina Szczepaniec.docx"; echo'
$filesWithPerms (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($filesWithPerms);echo'
'; $filesWithPermsTree = array(); $lastName = ''; $folderParent = ''; foreach ($filesWithPerms as $line) { if (substr($line, 0, 1) == '-' || substr($line, 0, 1) == 'd') {// file name $fileParts = array(); $filePartsArr = explode(' ', $line); $lastInd = 0; foreach ($filePartsArr as $vPart) { if ($lastInd > 7) {// file name $fileParts[8] = ($lastInd > 8)? "{$fileParts[8]} {$vPart}" : $vPart; $lastInd++; } else if (!empty($vPart) || $vPart === '0') { $fileParts[] = $vPart; $lastInd++; } } if (end($fileParts) == '..' || (end($fileParts) == '.' && $folderParent)) { $lastName = '..'; continue; } $file = new stdClass(); if (!isset($fileParts[8])) { echo'
Error parse file name (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('line'=>$line, 'fileParts'=>$fileParts));echo'
'; //continue; } else { // fix file name from bad chars // [8] => CV_Kowalski Mariusz`.pdf // "-$Model Bialnet .xlsm" in /Users/plabudda/se-dev-pl/SE/bash_sync_perms.php on line 1518 // [11-Oct-2013 21:00:28 UTC] PHP Notice: Error-cmd: chmod -a# 3 "/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/500.2009-12-01.INNE.DOFINANSOWANIE_PROJEKT_KOLBUDY/2013-02-26_harmonogram_EDORADCA_Aktualny/-$harmonogram 01.2013.xlsx" in /Users/plabudda/se-dev-pl/SE/bash_sync_perms.php on line 1518 // [11-Oct-2013 21:00:27 UTC] PHP Notice: Error-cmd: chmod -a# 3 "/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/500.2009-12-01.INNE.DOFINANSOWANIE_PROJEKT_KOLBUDY/2012-04-19_oferta_gpon_sprint_po_poprawkach/-$Wycena GPON 2012 Biall-Net_spr v1.xlsx" in /Users/plabudda/se-dev-pl/SE/bash_sync_perms.php on line 1518 // [11-Oct-2013 20:56:25 UTC] PHP Notice: Error-cmd: chmod +a "user:prejsi allow write,append,writeattr,writeextattr,writesecurity,chown,read,execute,readattr,readextattr,readsecurity" "/Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY/1695.Projekt_glowny_dzialu_rozwoju_biznesu_oraz_dystrybucji_informacji/HANDLOWY/HANDLOWY_2012/OTOMIN/-$Otomin.xlsx" in /Users/plabudda/se-dev-pl/SE/bash_sync_perms.php on line 1517 //$fileParts[8] = str_replace('\\', '\\\\', $fileParts[8]); //$fileParts[8] = str_replace(array('`', '$'), array('\`', '\$'), $fileParts[8]); } echo'
line/$fileParts/$filePartsArr (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array($line, $fileParts, $filePartsArr));echo'
'; $file->name = end($fileParts); $file->path = array(); if ($folderParent) $file->path[] = $folderParent; $file->path[] = end($fileParts); $file->path = implode('/', $file->path); //$file->owner = $fileParts[2]; //$file->group = $fileParts[3]; //$file->perms = $fileParts[0]; $file->isDir = (substr($line, 0, 1) == 'd'); $file->permsExt = array(); $filesWithPermsTree[$file->name] = $file; $lastName = $file; } else if (substr($line, 0, 1) == ' ') {// extended perm line if ($lastName == '..') { continue; } $filesWithPermsTree[$file->name]->permsExt[] = trim($line); } else if (substr($line, 0, 2) == './' && substr($line, -1) == ':') {// folder $folderParent = substr($line, 2, -1); } else if (substr($line, 0, 5) == 'total') { continue; } else if (empty($line)) { $folderParent = ''; continue; } } echo'
$filesWithPermsTree (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($filesWithPermsTree);echo'
'; } else if (empty($_SERVER["argv"]) && V::get('DBG', '', $_GET, 'int') > 0) { SyncPerms::run(null, null); } else { die("\n The second argument should be server domain - e.g. biuro.kike.pl \n"); } if (!empty($_SERVER["argv"][0]) && !empty($_SERVER["argv"][1])) { $arg2 = (!empty($_SERVER["argv"][2]))? $_SERVER["argv"][2] : null; $arg3 = (!empty($_SERVER["argv"][3]))? $_SERVER["argv"][3] : null; //bash_perms_make_se($_SERVER["argv"][0], $_SERVER["argv"][1], $arg2, $arg3); SyncPerms::run($_SERVER["argv"][0], $_SERVER["argv"][1], $arg2, $arg3); } //require(APP_PATH_ROOT."/superedit-SEF.php"); class SyncPerms { public static function installTable() { $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } // @due to bug in medical trigger install we now install tables using function SQIX_STRUCTURE_SYNC @2014-01-22 $sql = " CREATE TABLE IF NOT EXISTS `_SYNC_FILE_PERMS` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `ID_PROJECT` int(11) NOT NULL, `L_APPOITMENT_USER` varchar(64) DEFAULT '', `A_ADM_COMPANY` varchar(64) NOT NULL DEFAULT '', `A_CLASSIFIED` varchar(64) NOT NULL DEFAULT '', `PARENT_L_APPOITMENT_USER` varchar(64) NOT NULL DEFAULT '', `A_LAST_SYNC` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `A_SYNCHRONIZED` tinyint(4) NOT NULL DEFAULT '0', `A_SYNC_RESULT` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`ID`), UNIQUE KEY `ID_PROJECT` (`ID_PROJECT`) ) ENGINE=MyISAM DEFAULT CHARSET=latin2 ; "; $db->query($sql); $sql = " DROP TRIGGER IF EXISTS `KORESP_change_ID_PROJECT`; "; $db->query($sql); $sql = " CREATE TRIGGER `KORESP_change_ID_PROJECT` AFTER UPDATE ON `IN7_DZIENNIK_KORESP` FOR EACH ROW BEGIN IF (NEW.`ID_PROJECT` != OLD.`ID_PROJECT` and NEW.`ID_PROJECT` > 0) or OLD.`M_DIST_FILES`!=NEW.`M_DIST_FILES` THEN update `_SYNC_FILE_PERMS` as s set s.`A_SYNCHRONIZED`=0 where s.`ID_PROJECT`=NEW.`ID_PROJECT` or s.`ID_PROJECT`=OLD.`ID_PROJECT`; END IF; END "; $db->query($sql); $sql = " DROP TRIGGER IF EXISTS `KORESP_add_ID_PROJECT`; "; $db->query($sql); $sql = " CREATE TRIGGER `KORESP_add_ID_PROJECT` AFTER INSERT ON `IN7_DZIENNIK_KORESP` FOR EACH ROW BEGIN IF NEW.`ID_PROJECT` > 0 THEN update `_SYNC_FILE_PERMS` as s set s.`A_SYNCHRONIZED`=0 where s.`ID_PROJECT`=NEW.`ID_PROJECT`; END IF; END "; $db->query($sql); if (V::get('DBG', '', $_GET, 'int') > 0) { if ($db->has_errors()) { echo'
DB errors (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($db->get_errors());echo'
'; } } } public static function run($script_name, $domain, $arg2 = null, $arg3 = null) { if ($arg2 == 'addToLaunchctl') { system("echo \" Disabled Label pl.biallnet.sync_perms.php UserName root ProgramArguments php {$_SERVER["argv"][0]} {$_SERVER["argv"][1]} StartInterval 60 \" > /Library/LaunchDaemons/pl.biallnet.sync_perms.php.plist"); echo "Run By Root: launchctl load /Library/LaunchDaemons/pl.biallnet.sync_perms.php.plist\n"; } else if ($arg2 == 'newFiles') { $time = new stdClass(); $time->start = time(); self::newFilesAction(); $time->end = time(); // TODO: print operation time if DBG } else if ($arg2 == 'nextTask') { $time = new stdClass(); $time->start = time(); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
nextTask
';} self::installTable(); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
installTable DONE
';} self::generateTasksNewRecords(); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
generateTasksNewRecords DONE
';} self::generateTasksUpdated(); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
generateTasksUpdated DONE
';} $limit = V::get('_limit', 1, $_GET, 'int'); for ($i = 0; $i < $limit; $i++) { $time->cur = time(); if ($time->cur - $time->start > 60 * 5) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
Force-break time('.($time->cur - $time->start).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';echo'
';} break; } $task = self::nextTaskAction(); if (!$task) { break; } } } else if ($arg2 == 'testErrorLog') { echo "display_errors: " . ini_get("display_errors") . "\n"; echo "display_startup_errors: " . ini_get("display_startup_errors") . "\n"; echo "log_errors: " . ini_get("log_errors") . "\n"; echo "error_reporting: " . ini_get("error_reporting") . "\n"; echo "error_log: " . ini_get("error_log") . "\n"; trigger_error("Notice: Test Error Log", E_USER_NOTICE); } else if ($arg2 == 'users') { self::usersAction(); } else if ($arg2 == 'usersAll') { self::usersAllAction(); } else { $DBG_MEMORY = false; $time = new stdClass(); $time->start = time(); self::installTable(); self::generateTasksNewRecords(); if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksNewRecords " . memory_get_usage(true) . ".", E_USER_NOTICE); self::generateTasksUpdated(); if($DBG_MEMORY)trigger_error("DBG:mem usage after-generateTasksUpdated " . memory_get_usage(true) . ".", E_USER_NOTICE); $time->cur = time(); if ($time->cur - $time->start > 60 * 5) { trigger_error("Error: time end after-init " . ($time->cur - $time->start) . " !", E_USER_NOTICE); return; } self::newFilesAction(); if($DBG_MEMORY)trigger_error("DBG:mem usage after-newFilesAction " . memory_get_usage(true) . ".", E_USER_NOTICE); $limit = 100; for ($i = 0; $i < $limit; $i++) { $time->cur = time(); if ($time->cur - $time->start > 60 * 5) { trigger_error("Error: time end after-nextTaskAction(loop:{$i}) " . ($time->cur - $time->start) . " !", E_USER_NOTICE); return; } $task = self::nextTaskAction(); if($DBG_MEMORY)trigger_error("DBG:mem usage after-nextTaskAction (loop:{$i}) " . memory_get_usage(true) . ".", E_USER_NOTICE); if (!$task) { $time->cur = time(); trigger_error("Notice: sync end OK no-task " . ($time->cur - $time->start) . "", E_USER_WARNING); return; } } $time->cur = time(); trigger_error("Notice: sync end OK " . ($time->cur - $time->start) . " !", E_USER_NOTICE); } } public static function newFilesAction() { $task = self::getTaskNewFiles(); $taskResult = self::fixLastModifiedFiles($task); self::saveTask(-1); } public static function nextTaskAction() { $task = self::getTask(); if (!$task) { return false; } self::executeTask($task); /* if (isset($task->A_SYNC_RESULT->total) && isset($task->A_SYNC_RESULT->lastDone) && $task->A_SYNC_RESULT->lastDone < $task->A_SYNC_RESULT->total ) { self::saveTask($task->ID_PROJECT, 0, $task->A_SYNC_RESULT); } else { self::saveTask($task->ID_PROJECT); } */ self::saveTask($task->ID_PROJECT); return $task; } public static function generateTasksUpdated() { $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sqlTest = "select p.ID, p.`L_APPOITMENT_USER`, p.`A_ADM_COMPANY`, p.`A_CLASSIFIED`, s. * from `_SYNC_FILE_PERMS` as s, `IN7_MK_BAZA_DYSTRYBUCJI` as p, `IN7_MK_BAZA_DYSTRYBUCJI` as pp where s.`ID_PROJECT`=p.`ID` and pp.`ID`=p.`P_ID` and ( s.`L_APPOITMENT_USER`!=p.`L_APPOITMENT_USER` or s.`A_ADM_COMPANY`!=p.`A_ADM_COMPANY` or s.`A_CLASSIFIED`!=p.`A_CLASSIFIED` or s.`PARENT_L_APPOITMENT_USER`!=pp.`L_APPOITMENT_USER` ) "; $sql = "update `_SYNC_FILE_PERMS` as s, `IN7_MK_BAZA_DYSTRYBUCJI` as p, `IN7_MK_BAZA_DYSTRYBUCJI` as pp set s.`L_APPOITMENT_USER`=p.`L_APPOITMENT_USER` , s.`A_ADM_COMPANY`=p.`A_ADM_COMPANY` , s.`A_CLASSIFIED`=p.`A_CLASSIFIED` , s.`PARENT_L_APPOITMENT_USER`=pp.`L_APPOITMENT_USER` , s.`A_SYNCHRONIZED`=0 where s.`ID_PROJECT`=p.`ID` and pp.`ID`=p.`P_ID` and ( s.`L_APPOITMENT_USER`!=p.`L_APPOITMENT_USER` or s.`A_ADM_COMPANY`!=p.`A_ADM_COMPANY` or s.`A_CLASSIFIED`!=p.`A_CLASSIFIED` or s.`PARENT_L_APPOITMENT_USER`!=pp.`L_APPOITMENT_USER` ) "; $res = $db->query($sql); } public static function generateTasksNewRecords() { $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sql = "insert ignore into `_SYNC_FILE_PERMS` (`ID_PROJECT`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`) values (-1, '', '', '', ''); "; $res = $db->query($sql); $sql = "insert ignore into `_SYNC_FILE_PERMS` (`ID_PROJECT`, `L_APPOITMENT_USER`, `A_ADM_COMPANY`, `A_CLASSIFIED`, `PARENT_L_APPOITMENT_USER`) select p.`ID`, p.`L_APPOITMENT_USER`, p.`A_ADM_COMPANY`, p.`A_CLASSIFIED`, pp.`L_APPOITMENT_USER` from `IN7_MK_BAZA_DYSTRYBUCJI` as p left join `IN7_MK_BAZA_DYSTRYBUCJI` as pp on (pp.`ID`=p.`P_ID`) where p.`A_STATUS`!='DELETED' "; $res = $db->query($sql); } /** * Znajd‘­ najstarszy aktualizowany projekt. */ public static function getTask() { $task = null; $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sqlWhereProjID = " s.`A_SYNCHRONIZED`=0 "; if (($projID = V::get('PROJ_ID', '', $_GET, 'int')) > 0){ $sqlWhereProjID = " s.`ID_PROJECT`='{$projID}' "; } $sql = "select s.* , p.`L_APPOITMENT_USER` as p__L_APPOITMENT_USER , p.`A_ADM_COMPANY` as p__A_ADM_COMPANY , p.`A_CLASSIFIED` as p__A_CLASSIFIED , pp.`L_APPOITMENT_USER` as p__PARENT_L_APPOITMENT_USER , p.`M_DIST_DESC` as p__M_DIST_DESC , p.`M_DISTRIBUTOR` as p__M_DISTRIBUTOR , p.`CRM_LISTA_ZASOBOW_ID` as p__CRM_LISTA_ZASOBOW_ID from `_SYNC_FILE_PERMS` as s left join `IN7_MK_BAZA_DYSTRYBUCJI` as p on(p.`ID`=s.`ID_PROJECT`) left join `IN7_MK_BAZA_DYSTRYBUCJI` as pp on(pp.`ID`=p.`P_ID`) where {$sqlWhereProjID} order by s.`A_LAST_SYNC` asc, s.`ID` asc limit 1 "; $res = $db->query($sql); if ($r = $db->fetch($res)) { $r->A_SYNC_RESULT = (!$r->A_SYNC_RESULT)? new stdClass() : json_decode($r->A_SYNC_RESULT); $task = $r; } return $task; } public static function getTaskNewerUsers() { $task = null; $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sql = "select s.* from `_SYNC_FILE_PERMS` as s where s.`ID_PROJECT`=-2 "; $res = $db->query($sql); if ($r = $db->fetch($res)) { $task = $r; } if (!$task) { $task = new stdClass(); $task->ID_PROJECT = -2; $task->A_SYNC_RESULT = new stdClass(); $task->A_LAST_SYNC = '';//mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y")); //$task->A_LAST_SYNC = date("Y-m-d H:i", $task->A_LAST_SYNC); } return $task; } public static function getTaskNewFiles() { $task = null; $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sql = "select s.* from `_SYNC_FILE_PERMS` as s where s.`ID_PROJECT`=-1 "; $res = $db->query($sql); if ($r = $db->fetch($res)) { $task = $r; } if (!$task) { $task = new stdClass(); $task->ID_PROJECT = -1; $task->A_SYNC_RESULT = new stdClass(); $task->A_LAST_SYNC = mktime(date("H"), date("i") - 10, date("s"), date("n"), date("j"), date("Y")); $task->A_LAST_SYNC = date("Y-m-d H:i", $task->A_LAST_SYNC); } return $task; } public static function saveTask($idProject, $taskDone = 1, $result = null) { $task = null; $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sqlResult = ''; if ($result) { $resultJson = json_encode($result); $resultJson = $db->_($resultJson); $sqlResult .= " , s.`A_SYNC_RESULT`='{$resultJson}' "; } $sql = "update `_SYNC_FILE_PERMS` as s set s.`A_LAST_SYNC`=NOW() , s.`A_SYNCHRONIZED`={$taskDone} {$sqlResult} where s.`ID_PROJECT`={$idProject} "; $res = $db->query($sql); return $task; } public static function executeTask(&$task) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
executeTask (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($task);echo'
';} $confTblName = 'IN7_MK_BAZA_DYSTRYBUCJI_COLUMN'; $PROJ_mount_point = FoldersConfig::get($confTblName, 'mount_point'); $project = new stdClass(); $project->ID = $task->ID_PROJECT; $project->L_APPOITMENT_USER = $task->p__L_APPOITMENT_USER; $project->A_ADM_COMPANY = $task->p__A_ADM_COMPANY; $project->A_CLASSIFIED = $task->p__A_CLASSIFIED; $project->PARENT_L_APPOITMENT_USER = $task->p__PARENT_L_APPOITMENT_USER; $project->M_DIST_DESC = $task->p__M_DIST_DESC; $project->M_DISTRIBUTOR = $task->p__M_DISTRIBUTOR; $project->CRM_LISTA_ZASOBOW_ID = $task->p__CRM_LISTA_ZASOBOW_ID; $folderConf = FoldersConfig::getAll($confTblName); $uploader = new FileUploader($confTblName, $project); $errMsg = ''; if (!$uploader->setConfig($folderConf, $errMsg)) { trigger_error("Error: folders config!", E_USER_NOTICE); die("Error: folders config!"); } $uploader->findFolder(); $mainFolder = $uploader->getDestFolder(); if(V::get('DBG', '', $_GET, 'int') > 2){echo'
generated folderName('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';var_dump($uploader);echo'
';} if (!$mainFolder) { $mainFolder = $uploader->generateFolderName(); $mainFolderPath = rtrim($PROJ_mount_point, '/') . '/' . $mainFolder; if(V::get('DBG', '', $_GET, 'int') > 2){echo'
generated folderName('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array($mainFolder, $mainFolderPath));echo'
';} mkdir($mainFolderPath, 0770, true); @chmod($mainFolderPath, 0770); if (!file_exists($mainFolderPath)) { trigger_error("Error: Nie uda‘?o siŽ? utworzyŽ? folderu! ({$mainFolder})", E_USER_NOTICE); return false; } $requirePermsExt = self::getRequiredPermsExtByRecord($project); $file = new stdClass(); $file->name = '.'; $file->path = '.'; //$file->owner = ''; //$file->group = ''; //$file->perms = ''; $file->isDir = true; $file->permsExt = array(); $cmdList = self::fixFilePerms($file, $requirePermsExt, "{$PROJ_mount_point}/{$mainFolder}", $project); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
cmdList-P('.$project->ID.') fixFilePerms (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdList);echo'
';} } else { $cmdList = self::fixProject($project, $mainFolder, $PROJ_mount_point, $task); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
cmdList-P('.$project->ID.') fixProject (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdList);echo'
';} $mainFolderPath = rtrim($PROJ_mount_point, '/') . '/' . $mainFolder; $folderPismaPath = "{$mainFolderPath}/_PISMA"; // if folder _PISMA not exists then create $cmdList[] = "if [ ! -d '{$folderPismaPath}' ] ; then mkdir '{$folderPismaPath}'; chmod 0770 '{$folderPismaPath}'; fi;"; $cmdKorepList = self::fixProjectKoresp($project, $folderPismaPath); if (!empty($cmdKorepList)) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
cmdList-P('.$project->ID.') fixProjectKoresp (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdKorepList);echo'
';} foreach ($cmdKorepList as $vCmd) { $cmdList[] = $vCmd; } } if (V::get('TEST_DRUKI', '', $_GET, 'int') > 0) { // $project->CRM_LISTA_ZASOBOW_ID if ($project->CRM_LISTA_ZASOBOW_ID > 0) { } // TODO: $cmdDrukiList = self::fixProjectDruki($project, $mainFolder, $PROJ_mount_point); } } if (!empty($cmdList)) { foreach ($cmdList as $vCmd) { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
Exec-cmdList-P('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCmd);echo'
';} exec($vCmd, $out, $outValue); if(V::get('DBG', '', $_GET, 'int') > 1){echo'
Done-cmdList-P('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array($outValue, $out));echo'
';} if ($outValue != 0) { trigger_error("Error-cmd: {$vCmd}", E_USER_NOTICE); } } } if(V::get('DBG', '', $_GET, 'int') > 0){echo'
';print_r("executeTask finished OK");echo'
';} } public static function getActiveLoginList() { static $activeLoginList; if (!is_array($activeLoginList)) { $activeLoginList = array(); $db = DB::getDB(); if (!$db) { die('DB Error!'); } $sql = "select u.`ADM_ACCOUNT` from `ADMIN_USERS` as u where u.`A_STATUS` = 'NORMAL' "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $activeLoginList[] = $r->ADM_ACCOUNT; } } return $activeLoginList; } public static function isActiveUser($login) { $activeLoginList = self::getActiveLoginList(); return in_array($login, $activeLoginList); } public static function getRequiredPermsExtByRecord($project) { // TODO: need to check if user is correct in field L_APPOITMENT_USER $requirePermsExt = array(); if (!$project->L_APPOITMENT_USER && !$project->A_ADM_COMPANY) {// no owner, no write group // TODO: group PODMIOT $requirePermsExt["group:workgroup"] = array('write', 'read'); } else { if ($project->L_APPOITMENT_USER) { if (self::isActiveUser($project->L_APPOITMENT_USER)) { $requirePermsExt["user:{$project->L_APPOITMENT_USER}"] = array('write', 'read'); } else { // TODO: trigger error $project->L_APPOITMENT_USER is not active user! } } if (!empty($project->A_ADM_COMPANY) && $project->A_ADM_COMPANY == $project->A_CLASSIFIED) { $requirePermsExt["group:{$project->A_ADM_COMPANY}"] = array('read', 'write'); } else if (empty($project->A_ADM_COMPANY) && empty($project->A_CLASSIFIED)) { $requirePermsExt["group:workgroup"] = array('write', 'read'); } else { if ($project->A_ADM_COMPANY) { $requirePermsExt["group:{$project->A_ADM_COMPANY}"] = array('write'); } if ($project->A_CLASSIFIED) { $requirePermsExt["group:{$project->A_CLASSIFIED}"] = array('read'); } } } // add parent owner if (!empty($project->PARENT_L_APPOITMENT_USER) && $project->PARENT_L_APPOITMENT_USER != $project->L_APPOITMENT_USER) { if (self::isActiveUser($project->PARENT_L_APPOITMENT_USER)) { $requirePermsExt["user:{$project->PARENT_L_APPOITMENT_USER}"] = array('write', 'read'); } else { // TODO: trigger error $project->PARENT_L_APPOITMENT_USER is not active user! } } // add user:_www perms read, write $requirePermsExt["user:_www"] = array('write', 'read'); return $requirePermsExt; } /** * Used for files added/modified by samba/afp. * * @return TODO: object to store in task->A_SYNC_RESULT */ public static function fixLastModifiedFiles($task) { $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } if(V::get('DBG', '', $_GET, 'int') > 0){echo'
fixLastModifiedFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedFiles");echo'
';} $PROJ_mount_point = FoldersConfig::get('IN7_MK_BAZA_DYSTRYBUCJI_COLUMN', 'mount_point'); $PISMA_mount_point = FoldersConfig::get('IN7_DZIENNIK_KORESP_COLUMN', 'mount_point'); $foundProjectFiles = array(); if(V::get('DBG', '', $_GET, 'int') > 0){echo'
$lastRunDate (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($task->A_LAST_SYNC);echo'
';} //exec("cd {$PROJ_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' ", $foundPaths); exec("cd {$PROJ_mount_point}; find . -newermt '{$task->A_LAST_SYNC}' -type f -exec ls -le '{}' \;", $filesWithPerms);// TODO: head -{$lastTotal + 10000}| tail if (!empty($filesWithPerms)) { $filesWithPermsTree = array(); $lastName = ''; foreach ($filesWithPerms as $line) { if (substr($line, 0, 1) == '-') {// file name $fileParts = array(); $filePartsArr = explode(' ', $line); $lastInd = 0; foreach ($filePartsArr as $vPart) { if ($lastInd > 7) {// file name $fileParts[8] = ($lastInd > 8)? "{$fileParts[8]} {$vPart}" : $vPart; $lastInd++; } else if (!empty($vPart) || $vPart === '0') { $fileParts[] = $vPart; $lastInd++; } } $file = new stdClass(); if (!isset($fileParts[8])) { echo'
Error parse file name (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('line'=>$line, 'fileParts'=>$fileParts));echo'
'; //continue; } $file->name = end($fileParts); $file->path = end($fileParts); //$file->owner = $fileParts[2]; //$file->group = $fileParts[3]; //$file->perms = $fileParts[0]; $file->isDir = (substr($line, 0, 1) == 'd'); $file->permsExt = array(); $filesWithPermsTree[$file->name] = $file; $lastName = $file->name; } else if (substr($line, 0, 1) == ' ') {// extended perm line if ($lastName == '..') { continue; } $filesWithPermsTree[$file->name]->permsExt[] = trim($line); } else {// parse error $lastName = '..'; } } foreach ($filesWithPermsTree as $vFile) { $vFile->path = ltrim($vFile->path, './'); $vFile->path = explode('/', $vFile->path); $vFile->projectFolder = array_shift($vFile->path); $vFile->path = implode('/', $vFile->path); $projId = explode('.', $vFile->projectFolder); $projId = reset($projId); if (is_numeric($projId) && $projId > 0) { $foundProjectFiles[$projId][] = $vFile; } } } if(V::get('DBG', '', $_GET, 'int') > 1){echo'
filesWithPerms (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($filesWithPerms);echo'
';} if(V::get('DBG', '', $_GET, 'int') > 0){echo'
foundProjectFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($foundProjectFiles);echo'
';} if (!empty($foundProjectFiles)) { $sql = "select p.`ID` , p.`L_APPOITMENT_USER` , p.`A_ADM_COMPANY` , p.`A_CLASSIFIED` , pp.`L_APPOITMENT_USER` as PARENT_L_APPOITMENT_USER from IN7_MK_BAZA_DYSTRYBUCJI as p left join IN7_MK_BAZA_DYSTRYBUCJI as pp on (pp.ID=p.P_ID) where p.`ID` in (" . implode(',', array_keys($foundProjectFiles)) . ") "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $requirePermsExt = self::getRequiredPermsExtByRecord($r); foreach ($foundProjectFiles[$r->ID] as $vFile) { $cmdList = self::fixFilePerms($vFile, $requirePermsExt, "{$PROJ_mount_point}/{$vFile->projectFolder}", $r); if (!empty($cmdList)) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
$cmdList P('.$r->ID.') total('.count($cmdList).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdList);echo'
';} foreach ($cmdList as $vCmd) { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
Exec-cmdList-P('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vCmd);echo'
';} exec($vCmd, $out, $outValue); if(V::get('DBG', '', $_GET, 'int') > 1){echo'
Done-cmdList-P('.$project->ID.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array($outValue, $out));echo'
';} if ($outValue != 0) { trigger_error("Error-cmd: {$vCmd}", E_USER_NOTICE); } } } else { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
$cmdList is empty P('.$r->ID.') total('.count($cmdList).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("empty");echo'
';} } } } } } public static function fixProjectDruki() { if ($project->CRM_LISTA_ZASOBOW_ID <= 0) { return false; } $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } } public static function fixProjectKoresp($project, $folderPismaPath) { $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $PISMA_mount_point = FoldersConfig::get('IN7_DZIENNIK_KORESP_COLUMN', 'mount_point'); $PISMA_mount_point = rtrim($PISMA_mount_point, '/'); $pismaList = array(); // $PISMA_mount_point / {TYP_KORESP} / {ID} . * $sql = "select k.`ID` , k.`K_TYP_KORESP` from `IN7_DZIENNIK_KORESP` as k where k.`ID_PROJECT`={$project->ID} order by k.`ID` DESC limit 100 "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $pismaList[$r->ID] = $r->K_TYP_KORESP;// TODO: K_TYP_KORESP not used } if (empty($pismaList)) { return false; } $lsCmd = array(); $lsCmd[] = "0.*/";// if only one folder then it doesnt show folder name, only files foreach ($pismaList as $kID => $vTyp) { $lsCmd[] = "{$kID}.*/"; } if (empty($lsCmd)) { return false; } $lsCmd = 'ls -le ' . implode($lsCmd, ' ') . ' 2>>/dev/null '; if(V::get('DBG', '', $_GET, 'int') > 0){echo'
Koreps lsCmd (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($lsCmd);echo'
';} exec("cd {$PISMA_mount_point}; {$lsCmd} ", $filesWithPerms); $filesWithPermsTree = array(); if (!empty($filesWithPerms)) { $lastName = ''; $folderParent = ''; foreach ($filesWithPerms as $line) { if (substr($line, 0, 1) == '-') {// file name $fileParts = array(); $filePartsArr = explode(' ', $line); $lastInd = 0; foreach ($filePartsArr as $vPart) { if ($lastInd > 7) {// file name $fileParts[8] = ($lastInd > 8)? "{$fileParts[8]} {$vPart}" : $vPart; $lastInd++; } else if (!empty($vPart) || $vPart === '0') { $fileParts[] = $vPart; $lastInd++; } } $file = new stdClass(); if (!isset($fileParts[8])) { echo'
Error parse file name (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('line'=>$line, 'fileParts'=>$fileParts));echo'
'; //continue; } $file->name = end($fileParts); $file->path = array(); if ($folderParent) $file->path[] = $folderParent; $file->path[] = end($fileParts); $file->path = implode('/', $file->path); //$file->owner = $fileParts[2]; //$file->group = $fileParts[3]; //$file->perms = $fileParts[0]; $file->isDir = (substr($line, 0, 1) == 'd'); $file->permsExt = array(); $filesWithPermsTree[$file->name] = $file; $lastName = $file->name; } else if (substr($line, 0, 1) == ' ') {// extended perm line if ($lastName == '..') { continue; } $filesWithPermsTree[$file->name]->permsExt[] = trim($line); } else if (substr($line, -1) == ':') {// folder $folderParent = trim(substr($line, 0, -1), '/'); } else if (substr($line, 0, 5) == 'total') { continue; } else if (empty($line)) { $folderParent = ''; continue; } else {// parse error $lastName = '..'; } } } if(V::get('DBG', '', $_GET, 'int') > 2){echo'
filesWithPerms (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PISMA_mount_point}\n";print_r($filesWithPerms);echo'
';} if(V::get('DBG', '', $_GET, 'int') > 1){echo'
filesWithPermsTree (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PISMA_mount_point}\n";print_r($filesWithPermsTree);echo'
';} $cmdList = array(); $requirePermsExt = self::getRequiredPermsExtByRecord($project); foreach ($filesWithPermsTree as $kFileName => $vFile) { $cmdFile = self::fixFilePerms($vFile, $requirePermsExt, "{$PISMA_mount_point}", $project); if (!empty($cmdFile)) { foreach ($cmdFile as $vCmd) { $cmdList[] = $vCmd; } } // if folder _PISMA not exists then create $fname = end(explode('/', $vFile->path)); $cmdList []= "if [ ! -f '{$folderPismaPath}/{$fname}' ] ; then ln '{$PISMA_mount_point}/{$vFile->path}' '{$folderPismaPath}'/; fi; "; } return $cmdList; } /* * Not used. */ public static function preloadFixProject(&$task, $mainFolder, $PROJ_mount_point) { if ($task->ID_PROJECT == 1695) {// TODO: biall-net - 8853 pliki w katalog - stary HANDLOWY if (isset($task->A_SYNC_RESULT->total)) { exec("cd '{$PROJ_mount_point}/{$mainFolder}' && find . -type f | wc -l ", $filesTotal); if (!empty($filesTotal)) { $filesTotal = reset($filesTotal); $filesTotal = intval(trim($filesTotal)); $task->A_SYNC_RESULT->total = $filesTotal; self::saveTask($task->ID_PROJECT, 0, $task->A_SYNC_RESULT); } } } } public static function fixProject($r, $mainFolder, $PROJ_mount_point, &$task) { $time = time(); if ($r->ID == 1695) {// TODO: biall-net - 8853 pliki w katalog - stary HANDLOWY if(V::get('DBG', '', $_GET, 'int') > 0){echo'
TODO: pomin - za du‘«o plikʈw ('.$r->ID.'/'.$mainFolder.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($r);echo'
';} //return false; } if(V::get('DBG', '', $_GET, 'int') > 1){echo'
r('.$r->ID.'/'.$mainFolder.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($r);echo'
';} $requirePermsExt = self::getRequiredPermsExtByRecord($r); $filesWithPerms = array(); $cmd = " ls -Rlea . "; if (false) {//$r->ID == 1695) {// TODO: biall-net - 8853 pliki w katalog - stary HANDLOWY if (isset($task->A_SYNC_RESULT->total)) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
A_SYNC_RESULT (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("A_SYNC_RESULT[total]={$task->A_SYNC_RESULT->total}");echo'
';} if ($task->A_SYNC_RESULT->total > 1000) { $lastDone = V::get('lastDone', 0, $task->A_SYNC_RESULT, 'int'); if ($lastDone > 0) { $task->A_SYNC_RESULT->lastDone = $lastDone + 1000; $cmd = " find . -type f | head -" . ($lastDone + 1000) . " | tail -1000 | xargs ls -le "; } else { $task->A_SYNC_RESULT->lastDone = 1000; $cmd = " find . -type f | head -1000 | xargs ls -le "; } } } } if(V::get('DBG', '', $_GET, 'int') > 0){echo'
cmd (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("cd '{$PROJ_mount_point}/{$mainFolder}' && {$cmd} ");echo'
';} exec("cd '{$PROJ_mount_point}/{$mainFolder}' && {$cmd} ", $filesWithPerms); if(V::get('DBG', '', $_GET, 'int') > 2){echo'
$filesWithPerms (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($filesWithPerms);echo'
';} $filesWithPermsTree = array(); $lastName = ''; $folderParent = ''; foreach ($filesWithPerms as $line) { if (substr($line, 0, 1) == '-' || substr($line, 0, 1) == 'd') {// file name $fileParts = array(); $filePartsArr = explode(' ', $line); $lastInd = 0; foreach ($filePartsArr as $vPart) { if ($lastInd > 7) {// file name $fileParts[8] = ($lastInd > 8)? "{$fileParts[8]} {$vPart}" : $vPart; $lastInd++; } else if (!empty($vPart) || $vPart === '0') { $fileParts[] = $vPart; $lastInd++; } } if (end($fileParts) == '..' || (end($fileParts) == '.' && $folderParent)) { $lastName = '..'; continue; } $file = new stdClass(); if (!isset($fileParts[8])) { echo'
Error parse file name (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('line'=>$line, 'fileParts'=>$fileParts));echo'
'; //continue; } $file->name = end($fileParts); $file->path = array(); if ($folderParent) $file->path[] = $folderParent; $file->path[] = end($fileParts); $file->path = implode('/', $file->path); //$file->owner = $fileParts[2]; //$file->group = $fileParts[3]; //$file->perms = $fileParts[0]; $file->isDir = (substr($line, 0, 1) == 'd'); $file->permsExt = array(); $filesWithPermsTree[$file->name] = $file; $lastName = $file; } else if (substr($line, 0, 1) == ' ') {// extended perm line if ($lastName == '..') { continue; } $filesWithPermsTree[$file->name]->permsExt[] = trim($line); } else if (substr($line, 0, 2) == './' && substr($line, -1) == ':') {// folder $folderParent = substr($line, 2, -1); } else if (substr($line, 0, 5) == 'total') { continue; } else if (empty($line)) { $folderParent = ''; continue; } } if(V::get('DBG', '', $_GET, 'int') > 1){echo'
$filesWithPermsTree (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($filesWithPermsTree);echo'
';} // check perms /* files: W read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown W read,write,execute,append,readattr,writeattr,readextattr,writeextattr,readsecurity R read, execute, readattr, readextattr, readsecurity dir: W list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,writesecurity,chown,file_inherit,directory_inherit W list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity, file_inherit,directory_inherit R list, search, readattr, readextattr, readsecurity, file_inherit,directory_inherit */ $cmdList = array(); foreach ($filesWithPermsTree as $kFileName => $vFile) { if (false) { // TODO: $kFileName == '_PISMA' - readonly // TODO: $vFile->path => _PISMA/... } else { $cmdFile = self::fixFilePerms($vFile, $requirePermsExt, "{$PROJ_mount_point}/{$mainFolder}", $r); if (!empty($cmdFile)) { foreach ($cmdFile as $vCmd) { $cmdList[] = $vCmd; } } } } return $cmdList; } public static function fixFilePerms($vFile, $requirePermsExt, $mainPath, $r) { //trigger_error("fixFilePerms: " . json_encode($vFile), E_USER_NOTICE); $cmdList = array(); $vReqPermsExt = array(); foreach ($requirePermsExt as $kPermObj => $vPerms) { $vReqPermsExt[$kPermObj] = array(); foreach ($vPerms as $vPerm) { if ($vFile->isDir) { if ($vPerm == 'read') { $vReqPermsExt[$kPermObj]['list'] = 0; $vReqPermsExt[$kPermObj]['search'] = 0; $vReqPermsExt[$kPermObj]['readattr'] = 0; $vReqPermsExt[$kPermObj]['readextattr'] = 0; $vReqPermsExt[$kPermObj]['readsecurity'] = 0; $vReqPermsExt[$kPermObj]['file_inherit'] = 0; $vReqPermsExt[$kPermObj]['directory_inherit'] = 0; } else if ($vPerm == 'write') { $vReqPermsExt[$kPermObj]['add_file'] = 0; $vReqPermsExt[$kPermObj]['add_subdirectory'] = 0; $vReqPermsExt[$kPermObj]['delete_child'] = 0; $vReqPermsExt[$kPermObj]['writeattr'] = 0; $vReqPermsExt[$kPermObj]['writeextattr'] = 0; $vReqPermsExt[$kPermObj]['writesecurity'] = 0; $vReqPermsExt[$kPermObj]['chown'] = 0; } } else { if ($vPerm == 'read') { $vReqPermsExt[$kPermObj]['read'] = 0; $vReqPermsExt[$kPermObj]['execute'] = 0; $vReqPermsExt[$kPermObj]['readattr'] = 0; $vReqPermsExt[$kPermObj]['readextattr'] = 0; $vReqPermsExt[$kPermObj]['readsecurity'] = 0; } else if ($vPerm == 'write') { $vReqPermsExt[$kPermObj]['write'] = 0; $vReqPermsExt[$kPermObj]['append'] = 0; $vReqPermsExt[$kPermObj]['writeattr'] = 0; $vReqPermsExt[$kPermObj]['writeextattr'] = 0; $vReqPermsExt[$kPermObj]['writesecurity'] = 0; $vReqPermsExt[$kPermObj]['chown'] = 0; } } } } $permsToRemove = array(); foreach ($vFile->permsExt as $vPermExtLine) { $vPermExtArr = explode(' ', $vPermExtLine); $vPermExt = new stdClass(); $vPermExt->nr = trim($vPermExtArr[0], ' :'); $vPermExt->permObj = $vPermExtArr[1]; $vPermExt->perms = ''; if (count($vPermExtArr) == 4) { $vPermExt->perms = explode(',', $vPermExtArr[3]); } else if (count($vPermExtArr) == 5 && $vPermExtArr[2] == 'inherited') { $vPermExt->perms = explode(',', $vPermExtArr[4]); } else { echo "Error: Perm Ext Line format! ({$vPermExtLine})"; continue; } $permFound = false; foreach ($vReqPermsExt as $kPermObj => $vPerms) { if (false !== strpos($vPermExtLine, $kPermObj)) { foreach ($vPerms as $kPerm => $vPermChecked) { if (in_array($kPerm, $vPermExt->perms)) { $vReqPermsExt[$kPermObj][$kPerm] = 1; $permFound = true; } } } } if (!$permFound) { $permsToRemove[] = $vPermExt->nr; } //echo'
$vReqPermsExt('.$vFile->name.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($vReqPermsExt);echo'
'; } if (!empty($permsToRemove)) { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
TO-rm('.$r->ID.'): $permsToRemove('.$vFile->name.') isDir('.$vFile->isDir.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('permsToRemove'=>$permsToRemove, 'vFile->permsExt'=>$vFile->permsExt, 'r'=>$r));echo'
';} $permsToRemove = array_reverse($permsToRemove); foreach ($permsToRemove as $vPermInd) { $cmdList []= "chmod -a# {$vPermInd} '{$mainPath}/{$vFile->path}' "; } } $permsToAdd = array(); foreach ($vReqPermsExt as $kPermObj => $vPerms) { foreach ($vPerms as $kPerm => $vPermChecked) { if (!$vPermChecked) { $permsToAdd[$kPermObj][$kPerm] = 1; } } } if (!empty($permsToAdd)) { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
TO-add('.$r->ID.'): $permsToAdd('.$vFile->name.') isDir('.$vFile->isDir.') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r(array('permsToAdd'=>$permsToAdd, 'vFile->permsExt'=>$vFile->permsExt, 'r'=>$r));echo'
';} foreach ($permsToAdd as $kPermObj => $vPerms) { $cmdList []= "chmod +a \"{$kPermObj} allow " . implode(',', array_keys($vPerms)) . "\" '{$mainPath}/{$vFile->path}' "; } } return $cmdList; } /** * @returns array - last modified project ids. */ public static function fixLastModifiedByFiles() {// TODO: RMME $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } if(V::get('DBG', '', $_GET, 'int') > 0){echo'
fixLastModifiedByFiles (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedByFiles");echo'
';} /* * $ man find: -newer file True if the current file has a more recent last modification time than file. -newerXY file True if the current file has a more recent last access time (X=a), inode creation time (X=B), change time (X=c), or modification time (X=m) than the last access time (Y=a), inode creation time (Y=B), change time (Y=c), or mod- ification time (Y=m) of file. In addition, if Y=t, then file is instead interpreted as a direct date specifica- tion of the form understood by cvs(1). Note that -newermm is equivalent to -newer. * * $ man chmod: -i Removes the 'inherited' bit from all entries in the named file(s) ACLs. * * chmod -a "admin allow write" file1 # remove line * chmod -a# 1 file1 # remove line at position 1 * * chmod +a nie zmienia modify date: find . -newermt '2013-10-07 ...' */ // find /Library/Server/Web/Data/Sites/Default/PLIKI/PROJEKTY -newermt '2013-10-07 16:20' $PROJ_mount_point = FoldersConfig::get('IN7_MK_BAZA_DYSTRYBUCJI_COLUMN', 'mount_point'); $PISMA_mount_point = FoldersConfig::get('IN7_DZIENNIK_KORESP_COLUMN', 'mount_point'); $foundProjectIds = array(); $lastRunDate = self::getLastRunDate(); exec("cd {$PROJ_mount_point}; find . -newermt '{$lastRunDate}' ", $foundPaths); if (!empty($foundPaths)) { foreach ($foundPaths as $path) { $path = ltrim($path, './'); $folder = explode('/', $path); $folder = reset($folder); $projId = explode('.', $folder); $projId = reset($projId); if (is_numeric($projId)) { $foundProjectIds[$projId] = $folder; } } } if(V::get('DBG', '', $_GET, 'int') > 1){echo'
foundPaths (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($foundPaths);echo'
';} if(V::get('DBG', '', $_GET, 'int') > 0){echo'
foundProjectIds (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): '."path: {$PROJ_mount_point}\n";print_r($foundProjectIds);echo'
';} if (!empty($foundProjectIds)) { $sql = "select p.`ID` , p.`L_APPOITMENT_USER` , p.`A_ADM_COMPANY` , p.`A_CLASSIFIED` , pp.`L_APPOITMENT_USER` as PARENT_L_APPOITMENT_USER from IN7_MK_BAZA_DYSTRYBUCJI as p left join IN7_MK_BAZA_DYSTRYBUCJI as pp on (pp.ID=p.P_ID) where p.`ID` in (" . implode(',', array_keys($foundProjectIds)) . ") "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $mainFolder = $foundProjectIds[$r->ID]; $cmdList = self::fixProject($r, $mainFolder, $PROJ_mount_point); if (!empty($cmdList)) { if(V::get('DBG', '', $_GET, 'int') > 0){echo'
$cmdList P('.$r->ID.') total('.count($cmdList).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdList);echo'
';} } else { if(V::get('DBG', '', $_GET, 'int') > 1){echo'
$cmdList P('.$r->ID.') total('.count($cmdList).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($cmdList);echo'
';} } } } return array_keys($foundProjectIds); } public static function fixLastModifiedByDB($fixedProjIds) {// TODO: RMME $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } if(V::get('DBG', '', $_GET, 'int') > 0){echo'
fixLastModifiedByDB (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("fixLastModifiedByDB");echo'
';} $sqlWhereAdd = ''; if (!empty($fixedProjIds)) { $sqlWhereAdd = " and p.`ID` not in (" . implode(',', $fixedProjIds) . ") "; } $projectList = array(); $lastRunDate = self::getLastRunDate(); $sql = "select p.`ID` , p.`L_APPOITMENT_USER` , p.`A_ADM_COMPANY` , p.`A_CLASSIFIED` , pp.`L_APPOITMENT_USER` as PARENT_L_APPOITMENT_USER from IN7_MK_BAZA_DYSTRYBUCJI as p left join IN7_MK_BAZA_DYSTRYBUCJI as pp on (pp.ID=p.P_ID) where ( p.`A_RECORD_UPDATE_DATE`>'{$lastRunDate}' or p.`A_RECORD_CREATE_DATE`>'{$lastRunDate}' ) {$sqlWhereAdd} "; if(V::get('DBG', '', $_GET, 'int') > 0){echo'
sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'
';} $res = $db->query($sql); while ($r = $db->fetch($res)) { $projectList[$r->ID] = $r; } if(V::get('DBG', '', $_GET, 'int') > 1){echo'
projectList (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($projectList);echo'
';} } public static function getLastRunDate() {// TODO: RMME if (($argFromDate = V::get('_fromDate', '', $_GET)) != '') { // Format: 2013-10-07 23:46 if (strlen($argFromDate) == 16 && substr($argFromDate, 4, 1) == '-' && substr($argFromDate, 7, 1) == '-' && substr($argFromDate, 10, 1) == '-' && substr($argFromDate, 13, 1) == ':' && is_numeric(str_replace(array('-', ':'), '', $argFromDate)) ) { $lastRunDate = mktime(substr($argFromDate, 11, 2), substr($argFromDate, 14, 2), 0, substr($argFromDate, 5, 2), substr($argFromDate, 8, 2), substr($argFromDate, 0, 4)); $lastRunDate = date("Y-m-d H:i", $lastRunDate); } } if (!$lastRunDate) { $lastRunDate = mktime(date("H") - 1, date("i"), date("s"), date("n"), date("j"), date("Y")); $lastRunDate = date("Y-m-d H:i", $lastRunDate); } //$lastRunDate = '2013-09-01 01:00'; echo'
lastRunDate (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($lastRunDate);echo'
'; return $lastRunDate; } public static function usersAction() { $task = self::getTaskNewerUsers(); $users = self::getUsersNewerThen($task->A_LAST_SYNC); echo'
$users (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($users);echo'
'; self::saveTask(-2); } public static function usersAllAction() { /* * DBU - DB User LDU - LDAP User * DBG - DB Group LDG - LDAP Group * * DBU - ADMIN_USERS * DBG - CRM_LISTA_ZASOBOW where TYPE in('STANOWISKO','PODMIOT','DZIAL')// TODO: GRUPA_PROJEKTOWA - ldap nested group? * * 1. fetch DB Users * ? only active users (A_STATUS == 'NORMAL') * 2. fetch LDAP Users * * DBU.ADM_ACCOUNT == LDU.uid * DBG.A_LDAP_GID == LDG.gidNumber * * TODO: $group createLdapGroup() * */ Lib::loadClass('UsersHelper'); $users = self::getUsersAll(); echo'
users count('.count($users).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($users);echo'
'; $allLdapUsers = UsersHelper::getLDAPUsersAll(); $ldapUsers = array(); foreach ($allLdapUsers as $vLdapUser) { $ldapUsers[$vLdapUser->uid] = $vLdapUser; } unset($allLdapUsers); echo'
ldapUsers count('.count($ldapUsers).') (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($ldapUsers);echo'
'; foreach ($users as $kLogin => $vUser) { if ($vUser->A_STATUS == 'NORMAL') { if (array_key_exists($vUser->ADM_ACCOUNT, $ldapUsers)) { echo '
'.$vUser->ADM_ACCOUNT.': OK? account exists in LDAP
'; } else { echo '
'.$vUser->ADM_ACCOUNT.': TODO: create account in LDAP
'; } } else if ($vUser->A_STATUS == 'DELETED') { if (array_key_exists($vUser->ADM_ACCOUNT, $ldapUsers)) { echo '
'.$vUser->ADM_ACCOUNT.': TODO: disable account
'; } else { //echo '
'.$vUser->ADM_ACCOUNT.': WARNING: account not exists in LDAP
'; } } } } public static function getUsersNewerThen($datetime) { $users = array(); $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sqlWhereAdd = ""; if ($datetime) { $sqlWhereAdd = " and ( u.`A_RECORD_CREATE_DATE`>'{$datetime}' or u.`A_RECORD_UPDATE_DATE`>'{$datetime}' )"; } else { // TODO: error datetime not set } $sql = "select u.ID , u.`ADM_ACCOUNT` , u.`ADM_NAME` , u.`A_STATUS` from `ADMIN_USERS` as u where u.`A_STATUS` in('NORMAL', 'DELETED') "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $users[$r->ADM_ACCOUNT] = $r; } return $users; } public static function getUsersAll() { $users = array(); $db = DB::getDB(); if (!$db) { die("DB Error: No DB!"); } $sql = "select u.ID , u.`ADM_ACCOUNT` , u.`ADM_NAME` , u.`A_STATUS` from `ADMIN_USERS` as u where u.`A_STATUS` in('NORMAL', 'DELETED') "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $users[$r->ADM_ACCOUNT] = $r; } return $users; } } //dodatkowo synchronizacja automatyczna uprawnien //SEF('KIKE_MIGRACJA_KIKE_AUTH'); //if(strstr($_SESSION['SYSTEM_PROFILE_STRING'],'KIKE' )) KIKE_MIGRACJA_KIKE_AUTH($LAST_TIMESTAMP); ?>