Пример #1
0
function AuthenticateApplication($appName, $UserID, $searchGroups = false)
{
    global $SqlDatabase;
    if (!$searchGroups) {
        $groups = $SqlDatabase->FetchObjects('SELECT ug.Name FROM FUserGroup ug, FUserToGroup utg WHERE utg.UserID=\'' . $UserID . '\' AND utg.UserGroupID = ug.ID');
        if (!$groups) {
            return 'fail<!--separate-->User with no group can not use apps.';
        }
        $searchGroups = array();
        foreach ($groups as $g) {
            $searchGroups[] = $g->Name;
        }
    }
    $fn = FindAppInSearchPaths($appName);
    if (!file_exists($fn . '/Config.conf')) {
        return 'fail<!--separate-->{"Error":"No config for this app."}';
    }
    if (!($conf = json_decode(file_get_contents($fn . '/Config.conf')))) {
        return 'fail<!--separate-->{"Error":"Bad config for this app."}';
    }
    // Can we run it?
    $found = false;
    if (isset($conf->UserGroups)) {
        foreach ($conf->UserGroups as $ug) {
            if (in_array($ug, $searchGroups)) {
                $found = true;
                break;
            }
        }
        if (!$found) {
            return 'fail<!--separate-->{"Error":"Has no permission for this app."}';
        }
    }
    return 'ok';
}
Пример #2
0
function AuthenticateApplication($appName, $UserID, $searchGroups = false)
{
    global $SqlDatabase;
    if (!$searchGroups) {
        $groups = $SqlDatabase->FetchObjects('SELECT ug.Name FROM FUserGroup ug, FUserToGroup utg WHERE utg.UserID=\'' . $UserID . '\' AND utg.UserGroupID = ug.ID');
        if (!$groups) {
            return 'fail<!--separate-->User with no group can not use apps.';
        }
        $searchGroups = array();
        foreach ($groups as $g) {
            $searchGroups[] = $g->Name;
        }
    }
    // Do we have a project?
    if (strtolower(substr($appName, -4, 4)) == '.apf') {
        include_once 'php/classes/file.php';
        $f = new File($appName);
        $f->Load();
        $content = $f->GetContent();
        return 'ok<!--separate-->' . $content;
    } else {
        $fn = FindAppInSearchPaths($appName);
        if (!file_exists($fn . '/Config.conf')) {
            return 'fail<!--separate-->{"Error":"No config for this app."}';
        }
        if (!($conf = json_decode(file_get_contents($fn . '/Config.conf')))) {
            return 'fail<!--separate-->{"Error":"Bad config for this app."}';
        }
        // Can we run it?
        $conf->ConfFilename = $fn . '/Config.conf';
        $found = false;
        if (isset($conf->UserGroups)) {
            foreach ($conf->UserGroups as $ug) {
                if (in_array($ug, $searchGroups)) {
                    $found = true;
                    break;
                }
            }
            if (!$found) {
                return 'fail<!--separate-->{"Error":"Has no permission for this app."}';
            }
        }
        return 'ok<!--separate-->' . json_encode($conf);
    }
    return 'fail<!--separate-->{"Error":"Can not understand query."}';
}