35 exec($DB_COMMAND, $dbout, $rc);
36 preg_match(
"/(\d+)/", $dbout[0], $matches);
37 $test_name = $matches[1];
38 $DB_NAME =
"fosstest".$test_name;
39 $REPO_NAME =
"testDbRepo".$test_name;
40 $SYSCONF_DIR = $dbout[0];
41 $PG_CONN = pg_connect(
"host=localhost port=5432 dbname=$DB_NAME user=fossy password=fossy")
42 or die("Could not connect");
55 exec(
"$DB_COMMAND -d $DB_NAME");
65 function get_upload_id($upload_info)
68 preg_match(
"/UploadPk is: '(\d+)'/", $upload_info, $matches);
69 $upload_id = $matches[1];
85 function connect_to_DB($fossology_testconfig)
87 $test_pg_conn = FALSE;
89 $db_conf_file = $fossology_testconfig .
"/Db.conf";
91 $test_pg_conn = pg_connect(
92 str_replace(
";",
" ", file_get_contents($db_conf_file)));
94 if (empty($test_pg_conn)) {
95 print
"Error - could not connect to test db via $db_conf_file\n";
97 print
"Successfully connected to test db\n";
99 return ($test_pg_conn);
110 function check_agent_status($test_dbh, $agent_name, $upload_id)
113 $ars_table_name = $agent_name.
"_ars";
115 $sql =
"SELECT upload_fk FROM $ars_table_name where upload_fk = $upload_id and ars_success=true;";
117 #$result = pg_query($PG_CONN, $sql); 118 $result = pg_query($test_dbh, $sql);
119 $count = pg_num_rows($result);
120 pg_free_result($result);
136 function check_file_uploadtree($test_dbh, $file_name, $upload_id)
139 $sql =
"SELECT uploadtree_pk FROM uploadtree where upload_fk = $upload_id and ufile_name = '$file_name';";
141 $result = pg_query($test_dbh, $sql);
142 $count = pg_num_rows($result);
143 pg_free_result($result);
154 function add_user($user=
'fossy', $password=
'fossy')
158 $Seed = rand() . rand();
159 $Hash = sha1($Seed . $password);
160 $sql =
"SELECT * FROM users WHERE user_name = '$user';";
161 $result = pg_query($PG_CONN, $sql);
162 $row0 = pg_fetch_assoc($result);
163 pg_free_result($result);
164 if (empty($row0[
'user_name'])) {
166 $SQL =
"INSERT INTO users (user_name,user_desc,user_seed,user_pass," .
167 "user_perm,user_email,email_notify,root_folder_fk) 168 VALUES ('$user','Default Administrator','$Seed','$Hash',10,'$password','y',1);";
170 $result = pg_query($PG_CONN, $SQL);
171 pg_free_result($result);
178 function preparations()
183 if (is_dir(
"/srv/fossology/$REPO_NAME")) {
184 exec(
"sudo chmod 2770 /srv/fossology/$REPO_NAME");
185 exec(
"sudo chown fossy /srv/fossology/$REPO_NAME -R");
186 exec(
"sudo chgrp fossy /srv/fossology/$REPO_NAME -R");
188 if (is_dir($SYSCONF_DIR)) {
189 exec(
"sudo chown fossy $SYSCONF_DIR -R");
190 exec(
"sudo chgrp fossy $SYSCONF_DIR -R");
197 function stop_scheduler()
201 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
202 exec(
"sudo $scheduler_path -k");
208 function scheduler_operation()
211 $scheduler_path =
"/usr/local/share/fossology/scheduler/agent/fo_scheduler";
212 exec(
"sudo $scheduler_path -k");
213 $scheduler_path =
"$SYSCONF_DIR/mods-enabled/scheduler/agent/fo_scheduler";
214 exec(
"sudo $scheduler_path -k");
215 exec(
"sudo $scheduler_path --daemon --reset --verbose=952 -c $SYSCONF_DIR");
221 function add_proxy($proxy_type=
'http_proxy', $porxy=
'web-proxy.cce.hp.com:8088')
225 $foss_conf = $SYSCONF_DIR.
"/fossology.conf";
226 exec(
"sudo sed 's/.$proxy_type.*=.*/$proxy_type=$porxy/' $foss_conf >/tmp/fossology.conf");
227 exec(
"sudo mv /tmp/fossology.conf $foss_conf");
238 function get_uploadtree_id($test_dbh, $upload_id)
240 $sql =
"SELECT uploadtree_pk from uploadtree where upload_fk =$upload_id order by uploadtree_pk limit 1;";
241 $result = pg_query($test_dbh, $sql);
242 $row = pg_fetch_assoc($result);
243 $uploadtree_id = $row[
'uploadtree_pk'];
244 pg_free_result($result);
245 return $uploadtree_id;
add_user($User, $Desc, $Seed, $Hash, $Perm, $Email, $Email_notify, $agentList, $Folder, $default_bucketpool_fk='')
Add a user.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN