19 require_once
"/usr/local/share/fossology/lib/php/bootstrap.php";
36 $Options = getopt(
"pt:u:");
37 if ( array_key_exists(
't', $Options)
38 && array_key_exists(
'u', $Options)
40 $Missing = array_key_exists(
'm', $Options) ? true :
false;
41 $tag_pk = $Options[
't'];
42 $upload_pk = $Options[
'u'];
44 echo
"Fatal: Missing parameter\n";
49 if ( array_key_exists(
'p', $Options)) {
55 $sql =
"select distinct(pfile_fk), pfile_sha1, ufile_name from uploadtree,pfile where upload_fk='$upload_pk' and pfile_pk=pfile_fk";
58 if (pg_num_rows($result) == 0) {
59 echo
"Empty upload_pk $upload_pk\n";
64 $ToAntelink = array();
67 while ($row = pg_fetch_assoc($result)) {
70 if (count($ToAntelink) >= $MaxSend) {
71 $TaggedFileCount += QueryTag($ToAntelink, $tag_pk, $PrintOnly);
72 $ToAntelink = array();
76 if (count($ToAntelink)) {
77 $TaggedFileCount += QueryTag($ToAntelink, $tag_pk, $PrintOnly);
80 echo
"$TaggedFileCount files tagged out of $TotalFileCount files.\n";
85 function Usage($argc, $argv)
87 echo
"$argv[0] -p -u {upload_pk} -t {tag_pk}\n";
88 echo
" -p means to only print out filenames to be tagged, but do not update the db.\n";
99 function QueryTag($ToAntelink, $tag_pk, $PrintOnly)
103 $AntepediaServer =
"https://api.antepedia.com/acme/v3/bquery/";
106 $http_proxy = $SysConf[
'FOSSOLOGY'][
'http_proxy'];
107 $ProxyServer = substr($http_proxy, 0, strrpos($http_proxy,
":"));
108 $ProxyPort = substr(strrchr($http_proxy,
":"), 1);
111 $sha1array = array();
112 foreach ($ToAntelink as $row) {
113 $sha1array[] = $row[
'pfile_sha1'];
115 $PostData = json_encode($sha1array);
117 $curlch = curl_init($AntepediaServer);
119 curl_setopt($curlch, CURLOPT_SSL_VERIFYPEER, FALSE);
120 curl_setopt($curlch, CURLOPT_SSL_VERIFYHOST, 2);
122 curl_setopt($curlch, CURLOPT_POST, TRUE);
123 curl_setopt($curlch,CURLOPT_POSTFIELDS, $PostData);
124 curl_setopt($curlch, CURLOPT_RETURNTRANSFER, TRUE);
125 curl_setopt($curlch,CURLOPT_USERAGENT,
'Curl-php');
127 if (! empty($ProxyServer)) {
128 curl_setopt($curlch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
129 curl_setopt($curlch, CURLOPT_PROXY, $ProxyServer);
130 if (! empty($ProxyPort)) {
131 curl_setopt($curlch, CURLOPT_PROXYPORT, $ProxyPort);
133 curl_setopt($curlch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
136 curl_setopt($curlch, CURLOPT_HTTPHEADER, array(
137 'Content-Type: application/json',
139 'Accept:application/json, text/javascript, */*; q=0.01'
143 $response = curl_exec($curlch);
145 if (curl_errno($curlch)) {
147 echo
"Error " . curl_errno($curlch) .
": " . curl_error($curlch);
154 $response = json_decode($response);
157 if ($response->error) {
158 echo $response->error .
"\n";
164 foreach ($response->results as $result) {
165 $row = GetRawRow($result->sha1, $ToAntelink);
168 echo $row[
'ufile_name'] .
"\n";
174 $sql =
"SELECT * from tag_file where pfile_fk='$row[pfile_fk]' and tag_fk='$tag_pk'";
175 $sqlresult = pg_query(
$PG_CONN, $sql);
177 if (pg_num_rows($sqlresult) == 0) {
178 $sql =
"insert into tag_file (tag_fk, pfile_fk, tag_file_date, tag_file_text) values ($tag_pk, '$row[pfile_fk]', now(), NULL)";
179 $InsResult = pg_query(
$PG_CONN, $sql);
182 pg_free_result($sqlresult);
193 function GetRawRow($sha1, $ToAntelink)
196 foreach ($ToAntelink as $row) {
197 if (strcasecmp($row[
'pfile_sha1'], $sha1) == 0) {
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
ConfigInit($sysconfdir, &$SysConf, $exitOnDbFail=true)
Initialize the fossology system after bootstrap().
Usage()
Print Usage statement.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
bootstrap($sysconfdir="")
Bootstrap the fossology php library.