summaryrefslogtreecommitdiffstats
path: root/tools/infra-dashboard/utils
diff options
context:
space:
mode:
Diffstat (limited to 'tools/infra-dashboard/utils')
-rw-r--r--tools/infra-dashboard/utils/book.php82
-rw-r--r--tools/infra-dashboard/utils/database.php20
-rw-r--r--tools/infra-dashboard/utils/jenkinsAdapter.php204
-rw-r--r--tools/infra-dashboard/utils/login.php56
4 files changed, 0 insertions, 362 deletions
diff --git a/tools/infra-dashboard/utils/book.php b/tools/infra-dashboard/utils/book.php
deleted file mode 100644
index 6d4c5b20..00000000
--- a/tools/infra-dashboard/utils/book.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-
- include 'database.php';
-
- function book() {
- $resource_id = $_POST['resource_id'];
- $resource_name = $_POST['resource_name'];
- $user_id = $_POST['user_id'];
- $start = $_POST['start'];
- $end = $_POST['end'];
- $purpose = $_POST['purpose'];
-
- $query = "select role.name as rolename from user, role, user_role where user.user_id = ".$user_id." and role.role_id=user_role.role_id and user_role.user_id=user.user_id;";
- $result = mysql_query($query);
-
- if(mysql_num_rows($result) == 0) {
- echo "1"; //return a code instead of a meesage. Display the message later in javascript according to the returned code.
- //echo "Booking not possible (your account is not associated with a role). Please contact the administrator.";
- exit;
- }
- $is_only_lab_owner = true;
- while ($row = mysql_fetch_array($result)) {
- $rolename = $row['rolename'];
- if ($rolename != "lab_owner") $is_only_lab_owner = false;
- }
- if ($is_only_lab_owner) {
- $query = "select * from user u inner join user_resource r on r.user_id=u.user_id and u.user_id=".$user_id." and r.resource_id=".$resource_id.";";
- $result = mysql_query($query);
- if(mysql_num_rows($result) == 0) {
- echo "2";
- //echo "You are not allowed to book this resource. ";
- exit;
- }
- }
- $query = "INSERT INTO booking (resource_id, user_id, starttime, endtime, purpose) VALUES (".$resource_id.",".$user_id.",'".$start."','".$end."', '".$purpose."');";
- $result = mysql_query($query);
- if(mysql_insert_id()>0){
- echo "Booking successful. The resource '".$resource_name."' is booked from ".$start." to ".$end.".";
- }
- else{
- echo "Mysql Error : ".mysql_error().". Query = ".$query;
- }
-
- }
-
- function getBookedDates() {
- $resource_id = $_POST['resource_id'];
- $query = "SELECT b.booking_id, b.resource_id,u.name as username,u.email,b.starttime,b.endtime,b.creation,b.purpose FROM booking as b,user as u WHERE b.resource_id=".$resource_id." AND b.user_id=u.user_id;";
- $result = mysql_query($query);
-
- $events = array();
- while ($row = mysql_fetch_array($result)) {
- $e = array();
- $e['id'] = $row['booking_id'];
- $e['booker_name'] = $row['username'];
- $e['booker_email'] = $row['email'];
- $e['title'] = $row['purpose'];
- $e['start'] = $row['starttime'];
- $e['end'] = $row['endtime'];
- $e['bookdate'] = $row['creation'];
-
- // Merge the event array into the return array
- array_push($events, $e);
- }
-
- echo json_encode($events);
- }
-
-
-
- $action = $_POST['action'];
-
- connectDB();
- if ($action == "book") {
- book();
- } elseif ($action == "getBookedDates" ) {
- getBookedDates();
- } else {
- echo "Invalid POST action.";
- }
- closeDB();
-?>
diff --git a/tools/infra-dashboard/utils/database.php b/tools/infra-dashboard/utils/database.php
deleted file mode 100644
index b72c3d12..00000000
--- a/tools/infra-dashboard/utils/database.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
- include '../../../../auth-db.php';
- date_default_timezone_set('UTC');
- function connectDB() {
- global $username;
- global $password;
- global $hostname;
- global $dbname;
-
- $dbhandle = mysql_connect($hostname, $username, $password)
- or die("Unable to connect to MySQL.".mysql_error());
- $selected = mysql_select_db($dbname,$dbhandle)
- or die("Could not select opnfv_pharos DB.");
- }
-
- function closeDB(){
- mysql_connect($dbhandle);
- }
-
-?>
diff --git a/tools/infra-dashboard/utils/jenkinsAdapter.php b/tools/infra-dashboard/utils/jenkinsAdapter.php
deleted file mode 100644
index c238feb7..00000000
--- a/tools/infra-dashboard/utils/jenkinsAdapter.php
+++ /dev/null
@@ -1,204 +0,0 @@
-<?php
-
- function getSlaves() {
- $query="https://build.opnfv.org/ci/computer/api/xml?tree=computer[displayName,offline,idle]";
- $output = file_get_contents($query);
- $xml = simplexml_load_string($output);
- if ($xml) return $xml;
- else return "";
- }
-
- function getCiSlaves(){
- $query="https://build.opnfv.org/ci/label/ci-pod/api/xml?xpath=labelAtom/node[nodeName]&wrapper=nodes";
- $output = file_get_contents($query);
- $xml = simplexml_load_string($output);
- if ($xml) return $xml;
- else return "";
- }
-
- function getAllBuilds(){
- $query="https://build.opnfv.org/ci/api/xml?tree=jobs[displayName,url,lastBuild[fullDisplayName,building,builtOn,timestamp,result]]";
- $output = file_get_contents($query);
- $xml = simplexml_load_string($output);
- if ($xml) return $xml;
- else return "";
- }
-
- $SLAVES = getSlaves();
- $CI_PODS = getCiSlaves();
- $ALL_BUILDS = getAllBuilds();
-
- function getActiveBuilds() {
- global $ALL_BUILDS;
- //$query="https://build.opnfv.org/ci/api/xml?tree=jobs[displayName,url,lastBuild[fullDisplayName,building,builtOn,timestamp]]&xpath=hudson/job[lastBuild/building=%27true%27]&wrapper=hudson";
- $xml = $ALL_BUILDS->xpath('job[lastBuild/building="true"]');
- if ($xml) return $xml;
- else return "";
- }
-
- $ACTIVE_BUILDS = getActiveBuilds();
-
- function slaveExists($slave) {
- global $SLAVES;
- $slave = $SLAVES->xpath('computer[displayName="'.$slave.'"]');
- if ($slave) return true;
- else return false;
- }
-
- function getSlaveStatus($slave) {
- global $SLAVES;
- $status = "unknown";
- if (!slaveExists($slave)) return $status;
- $slave = $SLAVES->xpath('computer[displayName="'.$slave.'"]');
- $offline = $slave[0]->offline;
-
- if ($offline == "true") $status = "offline";
- else $status = "online";
- return $status;
- }
-
- function getSlaveUrl($slave) {
- if (slaveExists($slave)) return "https://build.opnfv.org/ci/computer/".$slave;
- else return "";
- }
-
-
- function isCiPod($slave) {
- global $CI_PODS;
- $result = $CI_PODS->xpath('node[nodeName="'.$slave.'"]');
- if ($result) return true;
- else return false;
- }
-
- function isDevPod($slave) {
- global $CI_PODS;
- if (isCiPod($slave)) return false;
- else if (strpos($slave, 'pod') !== false) return true;
- else return false;
- }
-
- function parseJobString($str) {
- $scenario = '';
- $installer = '';
- $branch = '';
- $installers = array("fuel", "joid", "apex", "compass");
- $branches = array("master","arno", "brahmaputra", "colorado");
- $arr = split ('[ -]', $str);
- for($x = 0; $x < count($arr); $x++) {
- if (strcmp($arr[$x],"os") == 0) //all the scenarios start with 'os'
- $scenario = $arr[$x].'-'.$arr[$x+1].'-'.$arr[$x+2].'-'.$arr[$x+3];
- else if (in_array($arr[$x], $installers))
- $installer = $arr[$x];
- else if (in_array($arr[$x], $branches))
- $branch = $arr[$x];
- }
- $arr2 = explode(' ', $str);
- $jobname = $arr2[0]; //take first word as job name
-
- return array(
- "jobname"=>$jobname,
- "installer"=>$installer,
- "branch"=>$branch,
- "scenario"=>$scenario
- );
- }
-
-
- function getJJob($slave) {
- global $ALL_BUILDS;
- if (!slaveExists($slave)) return "";
-
- //$builds = $ALL_BUILDS;
- //$xml = $ALL_BUILDS->xpath('job[lastBuild/building="true"][lastBuild/builtOn="'.$slave.'"]');
- $builds = $ALL_BUILDS->xpath('job[lastBuild/builtOn="'.$slave.'"]');
- if (! $builds) { //the slave does not have jobs in building state
- //echo "NO JOBS FOUND";
- return "";
- }
- else {
- //is there any active build?
- $builds = $ALL_BUILDS->xpath('job[lastBuild/building="true"][lastBuild/builtOn="'.$slave.'"]');
- if ($builds) { // there are active builds for this slave
- //print_r($builds);
-
- $child_job = simplexml_import_dom($builds[0]);
- foreach ($builds as &$build) {
- $int1 = intval($build->lastBuild->timestamp);
- $int2 = intval($child_job->lastBuild->timestamp);
- if ($int1 > $int2) {
- $child_job = simplexml_import_dom($build);
- }
- }
- $url = strval($child_job->url);
- $fullDisplayName = $child_job->lastBuild->fullDisplayName;
- //echo $fullDisplayName."<br>";
-
- $params = parseJobString($fullDisplayName);
-
- $type = 0; // type=0 means the job is running
- $job_params = array(
- "name"=>$params['jobname'],
- "url"=>$url,
- "scenario"=>$params['scenario'],
- "installer"=>$params['installer'],
- "branch"=>$params['branch'],
- "type"=>$type
- );
- //print_r($job_params);
- return $job_params;
-
- }
- else { // there are NO active builds for this slave, we take the latest build
- //echo "NO Active builds";
- $builds = $ALL_BUILDS->xpath('job[lastBuild/building="false"][lastBuild/builtOn="'.$slave.'"]');
- $last_job = simplexml_import_dom($builds[0]);
- //print_r($last_job);
- foreach ($builds as &$build) {
- $int1 = intval($build->lastBuild->timestamp);
- $int2 = intval($last_job->lastBuild->timestamp);
- if ($int1 > $int2) {
- $last_job = simplexml_import_dom($build);
- }
- }
- $url = strval($last_job->url);
- $result = strval($last_job->lastBuild->result);
- $fullDisplayName = $last_job->lastBuild->fullDisplayName;
-
- $params = parseJobString($fullDisplayName);
-
- $type = 3;
- if ($result == "SUCCESS") $type = 1; // type=1 means it's the last job and it succeded
- if ($result == "FAILURE") $type = 2; // type=2 means it's the last job and it failed
- if ($result == "UNSTABLE") $type = 3; // type=3 means it's the last job is unstable
-
- $job_params = array(
- "name"=>$params['jobname'],
- "url"=>$url,
- "scenario"=>$params['scenario'],
- "installer"=>$params['installer'],
- "branch"=>$params['branch'],
- "type"=>$type
- );
-
- return $job_params;
- //print_r($job_params);
- }
-
- }
- }
-
- /*
- $slave = "lf-pod2";
- $job_params = getJJob($slave);
-
- $status = getSlaveStatus($slave);
- echo "Status slave ".$slave.": ".$status."<br>";
- echo "Job: ".$job_params['name']."<br>";
- echo "URL: ".$job_params['url']."<br>";
- echo "Scenario: ".$job_params['scenario']."<br>";
- echo "Installer: ".$job_params['installer']."<br>";
- echo "Branch: ".$job_params['branch']."<br>";
- echo "Type: ".$job_params['type']."<br>";
- */
-
-?>
diff --git a/tools/infra-dashboard/utils/login.php b/tools/infra-dashboard/utils/login.php
deleted file mode 100644
index 2ac7101d..00000000
--- a/tools/infra-dashboard/utils/login.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
- include 'database.php';
-
-
- function login(){
- $email = $_POST['email'];
- $password = $_POST['password'];
-
- $query = "SELECT * FROM user where EMAIL='".$email."';";
- $result = mysql_query($query);
-
- $user = array();
- if(mysql_num_rows($result) > 0) {
- $query = "SELECT * FROM user where email='".$email."' and password='".$password."';";
- $result = mysql_query($query);
- if(mysql_num_rows($result) > 0) {
- while($row = mysql_fetch_assoc($result)) {
- $user = $row;
- $user["result"] = 0;
-
- $_SESSION['user_id'] = $user['user_id'];
- $_SESSION['user_name'] = $user['name'];
- $_SESSION['user_email'] = $user['email'];
- }
- } else {
- $user["result"] = 1; //wrong password
- }
- } else {
- $user["result"] = 2; //user not registered
- }
- echo json_encode($user);
-
- }
-
-
- $action = $_POST['action'];
-
- connectDB();
- session_start();
-
- if ($action == "login") {
- login();
- } else if ($action == "logout") {
- unset($_SESSION['user_id']);
- unset($_SESSION['user_name']);
- unset($_SESSION['user_email']);
- session_destroy();
- } else {
- echo "Invalid POST action.";
- }
- closeDB();
-
-?>
-
-