FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
common-Ui.php
1 <?php
2 /*
3  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
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  */
18 
41 function getHost($URL)
42 {
43  if (empty ($URL))
44  {
45  return (NULL);
46  }
47  $host = parse_url($URL, PHP_URL_HOST);
48  //print "DB: getHost: url is:$URL\nafter parse, found is:$found\n";
49  /*
50  * if the host is localhost, this won't work, so we go get the real
51  * host name. This is due to the fact that on a server where
52  * the db and and scheduler are on the same system, the Db.conf
53  * file can have localhost for the hostname.
54  */
55  if ($host == 'localhost')
56  {
57  $realHost = exec("hostname -f", $out, $rtn);
58  if($rtn == 0)
59  {
60  $host = $realHost;
61  }
62  }
63  return ($host);
64 } // getHost
65 
77 function getMailSubjects() {
78  /*
79  * use preg_match, but the test must be run by the user who owns the email file
80  * in /var/mail.
81  */
82  $MailFile = "/var/mail/";
83  $Sujects = array();
84 
85  //$user = get_current_user();
86  $user = exec('id -un', $out, $rtn);
87  $UserMail = $MailFile . $user;
88  if(file_exists($UserMail) === FALSE) {
89  return(array("ERROR! $UserMail does not exist"));
90  }
91  $FH = fopen($UserMail,'r');
92  if($FH === FALSE) {
93  return(array("ERROR! Cannot open $UserMail"));
94  }
95  while (! feof($FH)){
96  $line = fgets($FH);
97  $matched = preg_match('/Subject:\sFOSSology Results.*?$/',$line, $matches);
98  if($matched) {
99  $Subjects[] = $line;
100  }
101  }
102  return($Subjects);
103 } //getMailSubjects
104 
115 function makeUrl($host, $query) {
116 
117  if (empty ($host)) {
118  return (NULL);
119  }
120  if (empty ($query)) {
121  return (NULL);
122  }
123  return ("http://$host$query");
124 }
125 
126 
127 ?>