コード例 #1
0
ファイル: Request.php プロジェクト: trickyplan/codeine
<?php

/* Codeine
 * @author bergstein@trickyplan.com
 * @description  
 * @package Codeine
 * @version 8.x
 */
setFn('Do', function ($Call) {
    if (isset($Call['Request'])) {
        foreach ($Call['HTTP']['Filter']['Request']['Rules'] as $FilterName => $Filter) {
            foreach ($Filter['Match'] as $Match) {
                if (F::Diff($Match, $Call['Request']) === null) {
                    if ($Filter['Decision']) {
                    } else {
                        F::Log('HTTP Request Filter *' . $FilterName . '* matched', LOG_WARNING, 'Security');
                        return false;
                    }
                }
            }
        }
    }
    return true;
});
コード例 #2
0
ファイル: Static.php プロジェクト: trickyplan/codeine
setFn('Route', function ($Call) {
    if (isset($Call['Static'])) {
    } else {
        $Call['Static'] = $Call['Links'];
        // FIXME
        F::Log('«Links» now «Static», please replace', LOG_WARNING);
    }
    if (strpos($Call['Run'], '?')) {
        list($Call['Run']) = explode('?', $Call['Run']);
    }
    if (isset($Call['Static'])) {
        if (is_string($Call['Run']) && isset($Call['Static'][$Call['Run']])) {
            if (isset($Rule['Debug']) && $Rule['Debug'] === true) {
                d(__FILE__, __LINE__, $Rule);
            }
            $Call['Run'] = $Call['Static'][$Call['Run']];
        }
    }
    unset($Call['Static']);
    return $Call;
});
setFn('Reverse', function ($Call) {
    if (isset($Call['Static'])) {
        foreach ($Call['Static'] as $Link => $Run) {
            if (F::Diff($Call['Run'], $Run) == null) {
                $Call['Link'] = $Link;
            }
        }
    }
    return $Call;
});
コード例 #3
0
ファイル: Differentiated.php プロジェクト: trickyplan/codeine
<?php

/* Codeine
 * @author bergstein@trickyplan.com
 * @description  
 * @package Codeine
 * @version 8.x
 */
setFn('Start', function ($Call) {
    foreach ($Call['QoS']['Rules'] as $Name => $Rule) {
        if ($Rule['Weight'] >= $Call['QoS']['Weight']) {
            if (isset($Rule['Run']) && F::Diff($Rule['Run'], $Call) === null) {
                $Call['QoS']['Class'] = $Rule['Class'];
                $Call['QoS']['Weight'] = $Rule['Weight'];
            }
        }
    }
    return $Call;
});
setFn('Finish', function ($Call) {
    return $Call;
});
コード例 #4
0
ファイル: Rule.php プロジェクト: trickyplan/codeine
             }
         }
         if (!isset($Rule['Weight'])) {
             $Rule['Weight'] = $Call['Weight'];
         }
         if ($Rule['Weight'] >= $Call['Weight']) {
             if (isset($Rule['Run']) && F::Diff($Rule['Run'], $Call) === null) {
                 if (!isset($Rule['Expression']) || F::Live($Rule['Expression'], $Call)) {
                     F::Log('Rule ' . $Name . ' applied', LOG_DEBUG, 'Security');
                     $Call['Decision'] = $Rule['Decision'];
                     $Call['Weight'] = $Rule['Weight'];
                     $Call['Rule'] = $Name;
                 }
             } else {
                 if (isset($Rule['Debug'])) {
                     F::Log('Diff ' . $Name . ' (Rule, Call)' . j(F::Diff($Rule['Run'], $Call)), LOG_INFO, 'Security');
                 }
             }
             if (isset($Call['Service']) && isset($Rule['Run']['Service']) && isset($Rule['Run']['Method']) && isset($Rule['Message'])) {
                 if ($Call['Service'] == $Rule['Run']['Service'] && $Call['Method'] == $Rule['Run']['Method']) {
                     $Call['Message'] = $Rule['Message'];
                 }
             }
         }
     }
 } else {
     F::Log('No rules loaded', LOG_WARNING);
 }
 if (isset($Call['Rule'])) {
     F::Log('Rule *' . $Call['Rule'] . '* decision *' . $Call['Decision'] . '* with weight ' . $Call['Weight'], LOG_INFO, 'Security');
 }
コード例 #5
0
ファイル: Role.php プロジェクト: trickyplan/codeine
<?php

/* Codeine
 * @author bergstein@trickyplan.com
 * @description  
 * @package Codeine
 * @version 8.x
 */
setFn('Check', function ($Call) {
    // Определить право
    foreach ($Call['Rights'] as $RID => $Right) {
        if (F::Diff($Right, $Call) === null) {
            $Call['Right'] = $RID;
            break;
        }
    }
    // Определить роль
    if (isset($Call['Session']['User']['Role'])) {
        $Call['Role'] = F::Merge($Call['Role'], $Call['Session']['User']['Role']);
    }
    // Проверить, если доступно
    if (isset($Call['Right'])) {
        foreach ($Call['Role'] as $Role) {
            if (isset($Call['Roles'][$Role])) {
                if (isset($Call['Roles'][$Role]['Rights'][$Call['Right']])) {
                    $Call['Decision'] = $Call['Roles'][$Role]['Rights'][$Call['Right']];
                } else {
                    F::Log('Permission for ' . $Call['Right'] . ' not configured', LOG_WARNING);
                }
            } else {
                F::Log('Unknown role', LOG_WARNING);
コード例 #6
0
ファイル: Rights.php プロジェクト: trickyplan/codeine
<?php

/* Codeine
 * @author bergstein@trickyplan.com
 * @description  
 * @package Codeine
 * @version 8.x
 */
setFn('Check', function ($Call) {
    if (isset($Call['Session']['User']['Rights'])) {
        $UserRights = (array) explode(',', $Call['Session']['User']['Rights']);
    } else {
        $UserRights = [];
    }
    if (!empty($UserRights)) {
        foreach ($Call['Access']['Rights'] as $Name => $Rule) {
            if (($Diff = F::Diff($Rule, $Call['Run'])) === null) {
                $Call['Decision'] = in_array($Name, $UserRights);
                F::Log('Right applied: ' . $Name, LOG_INFO);
                break;
            }
        }
        F::Log('Final decision:' . ($Call['Decision'] ? 'Allow' : 'Deny'), LOG_INFO);
    }
    return $Call;
});