FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
index.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************
3  Copyright (C) 2017-2018 Siemens AG
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***************************************************************/
24 namespace Fossology\UI\Api;
25 
26 $GLOBALS['apiCall'] = true;
27 
28 // setup autoloading
29 require_once dirname(dirname(dirname(__DIR__))) . "/vendor/autoload.php";
30 require_once dirname(dirname(dirname(dirname(__FILE__)))) .
31  "/lib/php/bootstrap.php";
32 
46 use Slim\App;
47 
48 const REST_VERSION_SLUG = "restVersion";
49 
50 const VERSION_1 = "/v{" . REST_VERSION_SLUG . ":1}/";
51 
52 const AUTH_METHOD = "JWT_TOKEN";
53 
54 $startTime = microtime(true);
55 
56 /* Set SYSCONFDIR and set global (for backward compatibility) */
57 $SysConf = bootstrap();
58 
59 global $container;
61 $timingLogger = $container->get("log.timing");
62 $timingLogger->logWithStartTime("bootstrap", $startTime);
63 
64 /* Load UI templates */
65 $loader = $container->get('twig.loader');
66 $loader->addPath(dirname(dirname(__FILE__)).'/template');
67 
68 /* Initialize global system configuration variables $SysConfig[] */
69 $timingLogger->tic();
70 ConfigInit($GLOBALS['SYSCONFDIR'], $SysConf);
71 $timingLogger->toc("setup init");
72 
73 $timingLogger->tic();
74 plugin_load();
75 
76 $app = new App($GLOBALS['container']);
77 
78 /*
79  * To check the order of middlewares, refer
80  * https://www.slimframework.com/docs/v3/concepts/middleware.html
81  *
82  * FOSSology Init is the first middleware and Rest Auth is second.
83  *
84  * 1. The call enters from Rest Auth and initialize session variables.
85  * 2. It then goes to FOSSology Init and initialize all plugins
86  * 3. The normal flow continues.
87  * 4. The call now enteres FOSSology Init again and plugins are unloaded.
88  * 5. Then call then enters Rest Auth and leaves as is.
89  */
90 
91 // Middleware for plugin initialization
92 $app->add(new FossologyInitMiddleware());
93 // Middleware for authentication
94 $app->add(new RestAuthMiddleware());
95 
97 $app->get(VERSION_1 . 'auth', AuthController::class . ':getAuthHeaders');
98 $app->post(VERSION_1 . 'tokens', AuthController::class . ':createNewJwtToken');
99 
101 $app->group(VERSION_1 . 'uploads',
102  function (){
103  $this->get('[/{id:\\d+}]', UploadController::class . ':getUploads');
104  $this->delete('/{id:\\d+}', UploadController::class . ':deleteUpload');
105  $this->patch('/{id:\\d+}', UploadController::class . ':moveUpload');
106  $this->put('/{id:\\d+}', UploadController::class . ':copyUpload');
107  $this->post('', UploadController::class . ':postUpload');
108  $this->get('/{id:\\d+}/summary', UploadController::class . ':getUploadSummary');
109  $this->get('/{id:\\d+}/licenses', UploadController::class . ':getUploadLicenses');
110  $this->any('/{params:.*}', BadRequestController::class);
111  });
112 
114 $app->group(VERSION_1 . 'users',
115  function (){
116  $this->get('[/{id:\\d+}]', UserController::class . ':getUsers');
117  $this->delete('/{id:\\d+}', UserController::class . ':deleteUser');
118  $this->any('/{params:.*}', BadRequestController::class);
119  });
120 
122 $app->group(VERSION_1 . 'jobs',
123  function (){
124  $this->get('[/{id:\\d+}]', JobController::class . ':getJobs');
125  $this->post('', JobController::class . ':createJob');
126  $this->any('/{params:.*}', BadRequestController::class);
127  });
128 
130 $app->group(VERSION_1 . 'search',
131  function (){
132  $this->get('', SearchController::class . ':performSearch');
133  });
134 
136 $app->group(VERSION_1 . 'folders',
137  function (){
138  $this->get('[/{id:\\d+}]', FolderController::class . ':getFolders');
139  $this->post('', FolderController::class . ':createFolder');
140  $this->delete('/{id:\\d+}', FolderController::class . ':deleteFolder');
141  $this->patch('/{id:\\d+}', FolderController::class . ':editFolder');
142  $this->put('/{id:\\d+}', FolderController::class . ':copyFolder');
143  $this->any('/{params:.*}', BadRequestController::class);
144  });
145 
147 $app->group(VERSION_1 . 'report',
148  function (){
149  $this->get('', ReportController::class . ':getReport');
150  $this->get('/{id:\\d+}', ReportController::class . ':downloadReport');
151  $this->any('/{params:.*}', BadRequestController::class);
152  });
153 
155 $app->group(VERSION_1 . 'version',
156  function (){
157  $this->get('', VersionController::class . ':getVersion');
158  });
159 
160 $app->run();
161 
162 $GLOBALS['container']->get("db.manager")->flushStats();
163 return 0;
164 
plugin_load()
Load every module ui found in mods-enabled.
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
Definition: migratetest.php:93
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().