FOSSology  4.4.0
Open Source License Compliance by Open Source Software
common-Ui.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
30 function getHost($URL)
31 {
32  if (empty ($URL))
33  {
34  return (NULL);
35  }
36  $host = parse_url($URL, PHP_URL_HOST);
37  //print "DB: getHost: url is:$URL\nafter parse, found is:$found\n";
38  /*
39  * if the host is localhost, this won't work, so we go get the real
40  * host name. This is due to the fact that on a server where
41  * the db and and scheduler are on the same system, the Db.conf
42  * file can have localhost for the hostname.
43  */
44  if ($host == 'localhost')
45  {
46  $realHost = exec("hostname -f", $out, $rtn);
47  if($rtn == 0)
48  {
49  $host = $realHost;
50  }
51  }
52  return ($host);
53 } // getHost
54 
66 function getMailSubjects() {
67  /*
68  * use preg_match, but the test must be run by the user who owns the email file
69  * in /var/mail.
70  */
71  $MailFile = "/var/mail/";
72  $Sujects = array();
73 
74  //$user = get_current_user();
75  $user = exec('id -un', $out, $rtn);
76  $UserMail = $MailFile . $user;
77  if(file_exists($UserMail) === FALSE) {
78  return(array("ERROR! $UserMail does not exist"));
79  }
80  $FH = fopen($UserMail,'r');
81  if($FH === FALSE) {
82  return(array("ERROR! Cannot open $UserMail"));
83  }
84  while (! feof($FH)){
85  $line = fgets($FH);
86  $matched = preg_match('/Subject:\sFOSSology Results.*?$/',$line, $matches);
87  if($matched) {
88  $Subjects[] = $line;
89  }
90  }
91  return($Subjects);
92 } //getMailSubjects
93 
104 function makeUrl($host, $query) {
105 
106  if (empty ($host)) {
107  return (NULL);
108  }
109  if (empty ($query)) {
110  return (NULL);
111  }
112  return ("http://$host$query");
113 }