16 use GuzzleHttp\Client;
17 use GuzzleHttp\Exception\RequestException;
18 use GuzzleHttp\Exception\ClientException;
19 use GuzzleHttp\Exception\ServerException;
21 include_once(dirname(__DIR__) .
"/agent/version.php");
50 $this->Name =
"spashtbrowser";
51 $this->Title = _(
"Spasht Browser");
52 $this->Dependency = array(
"browse",
"view");
55 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
56 $this->spashtDao = $GLOBALS[
'container']->get(
'dao.spasht');
57 $this->agentDao = $GLOBALS[
'container']->get(
'dao.agent');
58 $this->viewName =
"view";
59 $this->renderer = $GLOBALS[
'container']->get(
'twig.environment');
60 $this->agentName =
"spasht";
63 parent::__construct();
73 "show",
"format",
"page",
"upload",
"item"));
76 if (! empty($Item) && ! empty($Upload)) {
78 $tooltipText = _(
"View in clearlydefined");
84 menu_insert(
"Browse::$menuText", $menuPosition, $URI, $tooltipText);
85 menu_insert(
"View::$menuText", $menuPosition, $URI, $tooltipText);
104 if ($this->
State != PLUGIN_STATE_INVALID) {
107 if ($this->Name !==
"") {
109 $this->
State=PLUGIN_STATE_VALID;
112 return($this->
State == PLUGIN_STATE_VALID);
123 $statusbody =
"definition_not_found";
133 $this->vars[
'storeStatus'] =
"false";
134 $this->vars[
'pageNo'] =
"definition_not_found";
139 if (empty($uploadId)) {
140 return 'no item selected';
141 } elseif (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
142 $text = _(
"Permission Denied");
143 return "<h2>$text</h2>";
146 $upload_name = preg_replace(
147 '/(?i)(?:\.(?:tar\.xz|tar\.bz2|tar\.gz|zip|tgz|tbz|txz|tar))/',
"",
149 $uri = preg_replace(
"/&item=([0-9]*)/",
"",
Traceback());
152 $agentId = $this->agentDao->getCurrentAgentId(
"spasht");
154 $this->vars[
'micromenu'] =
Dir2Browse($this->Name, $uploadtree_pk,
null,
155 false,
"Browse", -1,
'',
'', $uploadtree_tablename);
157 if (!empty($optionSelect)) {
161 if ($patternName !=
null && !empty($patternName)) {
163 $client =
new Client([
165 'base_uri' => $SysConf[
'SYSCONFIG'][
"ClearlyDefinedURL"]
169 if (array_key_exists(
'http_proxy', $SysConf[
'FOSSOLOGY']) &&
170 ! empty($SysConf[
'FOSSOLOGY'][
'http_proxy'])) {
171 $proxy[
'http'] = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
173 if (array_key_exists(
'https_proxy', $SysConf[
'FOSSOLOGY']) &&
174 ! empty($SysConf[
'FOSSOLOGY'][
'https_proxy'])) {
175 $proxy[
'https'] = $SysConf[
'FOSSOLOGY'][
'https_proxy'];
177 if (array_key_exists(
'no_proxy', $SysConf[
'FOSSOLOGY']) &&
178 ! empty($SysConf[
'FOSSOLOGY'][
'no_proxy'])) {
179 $proxy[
'no'] = explode(
',', $SysConf[
'FOSSOLOGY'][
'no_proxy']);
184 $res = $client->request(
'GET',
'definitions', [
185 'query' => [
'pattern' => $patternName],
188 }
catch (RequestException $e) {
189 $this->vars[
'message'] =
"Unable to reach " .
190 $SysConf[
'SYSCONFIG'][
"ClearlyDefinedURL"] .
". Code: " .
192 return $this->
render(
'agent_spasht.html.twig', $this->vars);
193 }
catch (ClientException $e) {
194 $this->vars[
'message'] =
"Request failed. Status: " .
196 return $this->
render(
'agent_spasht.html.twig', $this->vars);
197 }
catch (ServerException $e) {
198 $this->vars[
'message'] =
"Request failed. Status: " .
200 return $this->
render(
'agent_spasht.html.twig', $this->vars);
203 if ($res->getStatusCode()==200) {
204 $findings = json_decode($res->getBody()->getContents());
206 if (count($findings) == 0) {
207 $statusbody =
"definition_not_found";
212 foreach ($findings as $finding) {
213 $obj = Coordinate::generateFromString($finding);
216 $typeName, $providerName)) {
217 $uri =
"definitions/" . $obj->generateUrlString();
221 $res_details = $client->request(
'GET', $uri, [
227 }
catch (RequestException $e) {
228 $this->vars[
'message'] =
"Unable to reach " .
229 $SysConf[
'SYSCONFIG'][
"ClearlyDefinedURL"] .
". Code: " .
231 return $this->
render(
'agent_spasht.html.twig', $this->vars);
232 }
catch (ClientException $e) {
233 $this->vars[
'message'] =
"Request failed. Status: " .
235 return $this->
render(
'agent_spasht.html.twig', $this->vars);
236 }
catch (ServerException $e) {
237 $this->vars[
'message'] =
"Request failed. Status: " .
239 return $this->
render(
'agent_spasht.html.twig', $this->vars);
242 $detail_body = json_decode($res_details->getBody()->getContents(),
246 $obj->setScore($details_temp->getScore());
249 $details[] = $details_temp;
252 if (!empty($details)) {
253 $this->vars[
'details'] = $details;
254 $this->vars[
'body'] = $matches;
255 $statusbody =
"definition_found";
257 $statusbody =
"definition_not_found";
262 if ($statusbody ==
"definition_found") {
263 $this->vars[
'pageNo'] =
"show_definitions";
265 $this->vars[
'pageNo'] =
"definition_not_found";
267 $upload_name = $patternName;
269 $this->vars[
'pageNo'] =
"Please Search and Select Revision";
271 $searchUploadId = $this->spashtDao->getComponent($uploadId);
273 if (! empty($searchUploadId)) {
274 $this->vars[
'pageNo'] =
"show_upload_table";
275 $this->vars[
'body'] = $searchUploadId;
280 if ($plugin ==
null) {
281 $message =
"Agent spasht not installed";
283 $results = $plugin->AgentHasResults($uploadId);
285 if ($results != 0 && $running == 0) {
286 $message =
"Scan completed successfully\n";
288 $jobUrl =
Traceback_uri() .
"?mod=showjobs&upload=$uploadId";
289 $message = _(
"Agent scheduled.") .
" <a href=$jobUrl>Show</a>\n";
292 $this->vars[
'body_menu'] = $message;
297 $table[
'uploadId'] = $uploadId;
298 $table[
'uploadTreeId'] = $uploadtree_pk;
299 $table[
'agentId'] = $agentId;
300 $table[
'type'] =
'statement';
301 $table[
'filter'] =
'Show all';
303 $this->vars[
'tables'] = [$table];
305 $advanceSearchFormStatus =
"hidden";
312 $coord = $this->spashtDao->getCoordinateFromCompId($uploadId);
313 if ($coord !=
null) {
314 $upload_name = $coord->getName();
315 $revisionName = $coord->getRevision();
316 $namespaceName = $coord->getNamespace();
317 $typeName = $coord->getType();
318 $providerName = $coord->getProvider();
319 $advanceSearchFormStatus =
"show";
322 $this->vars[
'uploadName'] = $upload_name;
323 $this->vars[
'revisionName'] = $revisionName;
324 $this->vars[
'namespaceName'] = $namespaceName;
325 $this->vars[
'typeName'] = $typeName;
326 $this->vars[
'providerName'] = $providerName;
327 if (! empty($revisionName) || ! empty($namespaceName) || ! empty($typeName)
328 || ! empty($providerName)) {
329 $advanceSearchFormStatus =
"show";
332 $this->vars[
'advanceSearchFormStatus'] = $advanceSearchFormStatus;
333 $this->vars[
'fileList'] = $this->
getFileListing($uploadtree_pk, $uri,
334 $uploadtree_tablename, $agentId, $uploadId);
336 $out = $this->
render(
'agent_spasht.html.twig', $this->vars);
350 $Agent_pk, $upload_pk)
354 $Children = GetNonArtifactChildren($Uploadtree_pk, $uploadtree_tablename);
357 $uploadInfo = $this->uploadDao->getUploadEntry($Uploadtree_pk,
358 $uploadtree_tablename);
359 if (! empty($uploadInfo[
'parent'])) {
360 $uploadtree_pk = $uploadInfo[
'parent'];
362 $row[
'url'] =
"$Uri&item=$uploadtree_pk";
363 $row[
'content'] =
"../";
364 $row[
'id'] = $uploadInfo[
'uploadtree_pk'];
368 foreach ($Children as $child) {
375 $cellContent =
Isdir($child[
'ufile_mode']) ? $child[
'ufile_name'].
'/' : $child[
'ufile_name'];
378 $uploadtree_pk =
DirGetNonArtifact($child[
'uploadtree_pk'], $uploadtree_tablename);
379 $LinkUri =
"$Uri&item=" . $uploadtree_pk;
382 $LinkUri .=
"?mod=".$this->viewName.
"&agent=$Agent_pk&upload=$upload_pk&item=$child[uploadtree_pk]";
386 $row[
'url'] = $LinkUri;
387 $row[
'content'] = $cellContent;
388 $row[
'id'] = $child[
'uploadtree_pk'];
402 return IsDir($row[
'ufile_mode']);
427 $typeName, $providerName)
429 if (! empty($revisionName) && $coord->getRevision() != $revisionName) {
433 if (! empty($namespaceName) && $coord->getNamespace() != $namespaceName) {
437 if (! empty($typeName) && $coord->getType() != $typeName) {
441 if (! empty($providerName) && $coord->getProvider() != $providerName) {
456 $selection = Coordinate::generateFromString($optionSelect);
458 $uploadAvailable = $this->spashtDao->getComponent($uploadId);
459 if (! empty($uploadAvailable)) {
460 $result = $this->spashtDao->alterComponentRevision($selection, $uploadId);
462 $result = $this->spashtDao->addComponentRevision($selection, $uploadId);
468 $userId = Auth::getUserId();
469 $groupId = Auth::getGroupId();
473 $jobId = JobAddJob($userId, $groupId, $this->agentName, $uploadId);
474 $rv = $plugin->AgentAdd($jobId, $uploadId, $errorMessage);
476 $text = _(
"Scheduling of agent failed: ");
477 $this->vars[
'message'] = $text . $errorMessage;
478 } elseif ($rv == 0) {
479 $text = _(
"Agent already scheduled");
480 $this->vars[
'message'] = $text;
482 $text = _(
"Agent scheduled successfully.");
483 $jobUrl =
Traceback_uri() .
"?mod=showjobs&upload=$uploadId";
484 $this->vars[
'message'] =
"$text <a href=$jobUrl>Show</a>";
487 $patternName = $selection->getName();
494 $NewPlugin->Initialize();
char * uploadtree_tablename
upload.uploadtree_tablename
This is the Plugin class. All plugins should:
Output()
This function is called when user output is requested. This function is responsible for content....
render($templateName, $vars=null)
Contains the constants and helpers for authentication of user.
RegisterMenus()
Customize submenus.
handleNewSelection($optionSelect, $uploadId)
Initialize()
This is called before the plugin is used. It should assume that Install() was already run one time (p...
__construct()
base constructor. Most plugins will just use this
returnSortOrder()
Get sorting orders.
checkAdvanceSearch($coord, $revisionName, $namespaceName, $typeName, $providerName)
Check for Advance Search.
getFileListing($Uploadtree_pk, $Uri, $uploadtree_tablename, $Agent_pk, $upload_pk)
isADirectory($Uploadtree_pk)
Check if passed element is a directory.
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk).
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
isAlreadyRunning($agentName, $upload_pk)
Check if an agent is already running in a job.
Traceback_uri()
Get the URI without query to this location.
Traceback()
Get the URI + query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
GetUploadName($upload_pk)
Get Upload Name through upload id.
char * trim(char *ptext)
Trimming whitespace.
FUNCTION char * GetUploadtreeTableName(PGconn *pgConn, int upload_pk)
Get the uploadtree table name for this upload_pk If upload_pk does not exist, return "uploadtree".
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
int IsDir(char *Fname)
Given a filename, is it a directory?