29 require_once
"/usr/local/share/fossology/lib/php/bootstrap.php";
46 $Options = getopt(
"pt:u:");
47 if ( array_key_exists(
't', $Options)
48 && array_key_exists(
'u', $Options)
50 $Missing = array_key_exists(
'm', $Options) ?
true :
false;
51 $tag_pk = $Options[
't'];
52 $upload_pk = $Options[
'u'];
54 echo
"Fatal: Missing parameter\n";
59 if ( array_key_exists(
'p', $Options)) {
65 $sql =
"select distinct(pfile_fk), pfile_sha1, ufile_name from uploadtree,pfile where upload_fk='$upload_pk' and pfile_pk=pfile_fk";
68 if (pg_num_rows($result) == 0) {
69 echo
"Empty upload_pk $upload_pk\n";
74 $ToAntelink = array();
77 while ($row = pg_fetch_assoc($result)) {
80 if (count($ToAntelink) >= $MaxSend) {
81 $TaggedFileCount += QueryTag($ToAntelink, $tag_pk, $PrintOnly);
82 $ToAntelink = array();
86 if (count($ToAntelink)) {
87 $TaggedFileCount += QueryTag($ToAntelink, $tag_pk, $PrintOnly);
90 echo
"$TaggedFileCount files tagged out of $TotalFileCount files.\n";
95 function Usage($argc, $argv)
97 echo
"$argv[0] -p -u {upload_pk} -t {tag_pk}\n";
98 echo
" -p means to only print out filenames to be tagged, but do not update the db.\n";
109 function QueryTag($ToAntelink, $tag_pk, $PrintOnly)
113 $AntepediaServer =
"https://api.antepedia.com/acme/v3/bquery/";
116 $http_proxy = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
117 $ProxyServer = substr($http_proxy, 0, strrpos($http_proxy,
":"));
118 $ProxyPort = substr(strrchr($http_proxy,
":"), 1);
121 $sha1array = array();
122 foreach ($ToAntelink as $row) {
123 $sha1array[] = $row[
'pfile_sha1'];
125 $PostData = json_encode($sha1array);
127 $curlch = curl_init($AntepediaServer);
129 curl_setopt($curlch, CURLOPT_SSL_VERIFYPEER, FALSE);
130 curl_setopt($curlch, CURLOPT_SSL_VERIFYHOST, 2);
132 curl_setopt($curlch, CURLOPT_POST, TRUE);
133 curl_setopt($curlch,CURLOPT_POSTFIELDS, $PostData);
134 curl_setopt($curlch, CURLOPT_RETURNTRANSFER, TRUE);
135 curl_setopt($curlch,CURLOPT_USERAGENT,
'Curl-php');
137 if (! empty($ProxyServer)) {
138 curl_setopt($curlch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
139 curl_setopt($curlch, CURLOPT_PROXY, $ProxyServer);
140 if (! empty($ProxyPort)) {
141 curl_setopt($curlch, CURLOPT_PROXYPORT, $ProxyPort);
143 curl_setopt($curlch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
146 curl_setopt($curlch, CURLOPT_HTTPHEADER, array(
147 'Content-Type: application/json',
149 'Accept:application/json, text/javascript, */*; q=0.01' 153 $response = curl_exec($curlch);
155 if (curl_errno($curlch)) {
157 echo
"Error " . curl_errno($curlch) .
": " . curl_error($curlch);
164 $response = json_decode($response);
167 if ($response->error) {
168 echo $response->error .
"\n";
174 foreach ($response->results as $result) {
175 $row = GetRawRow($result->sha1, $ToAntelink);
178 echo $row[
'ufile_name'] .
"\n";
184 $sql =
"SELECT * from tag_file where pfile_fk='$row[pfile_fk]' and tag_fk='$tag_pk'";
185 $sqlresult = pg_query($PG_CONN, $sql);
187 if (pg_num_rows($sqlresult) == 0) {
188 $sql =
"insert into tag_file (tag_fk, pfile_fk, tag_file_date, tag_file_text) values ($tag_pk, '$row[pfile_fk]', now(), NULL)";
189 $InsResult = pg_query($PG_CONN, $sql);
192 pg_free_result($sqlresult);
203 function GetRawRow($sha1, $ToAntelink)
206 foreach ($ToAntelink as $row) {
207 if (strcasecmp($row[
'pfile_sha1'], $sha1) == 0) {
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
bootstrap($sysconfdir="")
Bootstrap the fossology php library.
ConfigInit($sysconfdir, &$SysConf)
Initialize the fossology system after bootstrap().