예제 #1
0
    }
    $app->redirect(ROOT_URI . '/login');
});
/* include predefined routes */
$path = array_filter(explode('/', $app->request->getPath()));
$path = array_shift($path);
$routesFilePath = 'routes' . DS . $path . '.php';
if (file_exists($routesFilePath)) {
    require_once $routesFilePath;
}
/* REST API Routes */
$app->get('/:package', 'API', 'CHECKTOKEN', 'RATELIMITER', function ($package) use($r) {
    if (!$r->packageOK($package)) {
        return $r->respond(400, 'BAD REQUEST', true);
    }
    $listOfTables = R::inspect();
    $data = array_filter($listOfTables, function ($table) use($package) {
        return substr($table, 0, strlen($package)) == $package;
    });
    $data = array_map(function ($table) use($package) {
        return substr($table, strlen($package));
    }, $data);
    return $r->respond(200, array_values($data));
});
$app->get('/:package/:name', 'API', 'CHECKTOKEN', 'RATELIMITER', function ($package, $name) use($r, $app, $config) {
    $tableName = $r->genTableName($package, $name);
    try {
        if (!$r->packageOK($package, 'list') && $tableName !== 'managepackages') {
            return $r->respond(400, 'BAD REQUEST', true);
        }
        $query = R::$f->begin()->select('*')->from($tableName);
예제 #2
0
        if (isset($data['routes'])) {
            file_put_contents($routeFileName, $data['routes']);
        }
    }
});
$r->registerHook('manage', 'packages', 'beforeRemove', function ($data) {
    if (!$_SESSION['authenticated']) {
        return false;
    }
    return true;
});
$r->registerHook('manage', 'packages', 'afterRemove', function ($data) {
    $package = $data['name'];
    /* remove hooks */
    $hookFileName = 'hooks' . DS . $package . '.php';
    if (file_exists($hookFileName)) {
        unlink($hookFileName);
    }
    $routeFileName = 'routes' . DS . $data['name'] . '.php';
    if (file_exists($routeFileName)) {
        unlink($routeFileName);
    }
    /* remove tables */
    $allTables = R::inspect();
    $tableList = array_filter($allTables, function ($table) use($package) {
        return substr($table, 0, strlen($package)) == $package;
    });
    foreach ($tableList as $table) {
        R::$f->begin()->drop_table($table)->get();
    }
});