From 1387f1d5d0f68a3957347ffa86132bb67757bea2 Mon Sep 17 00:00:00 2001 From: katmastt Date: Thu, 21 Mar 2024 09:26:40 +0000 Subject: [PATCH 1/3] Token implementation for on-demand batch computation projects --- controllers/AdministrationController.php | 1 + controllers/ProjectController.php | 297 +++++++++++++++++++ models/NewTokenRequestForm.php | 46 +++ models/Project.php | 13 + models/Schema.php | 19 ++ models/Token.php | 313 ++++++++++++++++++++ views/project/delete_token.php | 0 views/project/edit_ondemand.php | 8 +- views/project/index.php | 11 +- views/project/new_ondemand_request.php | 8 +- views/project/new_token.php | 187 ++++++++++++ views/project/new_token_request.php | 130 ++++++++ views/project/new_token_request_confirm.php | 9 + views/project/on_demand_access.php | 83 ++++++ views/project/token_management.php | 111 +++++++ web/css/project/new-token.css | 60 ++++ web/css/project/tokens.css | 140 +++++++++ web/js/project/new-token.js | 62 ++++ widgets/Alert.php | 1 + 19 files changed, 1486 insertions(+), 13 deletions(-) create mode 100644 models/NewTokenRequestForm.php create mode 100644 models/Schema.php create mode 100644 models/Token.php create mode 100644 views/project/delete_token.php create mode 100644 views/project/new_token.php create mode 100644 views/project/new_token_request.php create mode 100644 views/project/new_token_request_confirm.php create mode 100644 views/project/on_demand_access.php create mode 100644 views/project/token_management.php create mode 100644 web/css/project/new-token.css create mode 100644 web/css/project/tokens.css create mode 100644 web/js/project/new-token.js diff --git a/controllers/AdministrationController.php b/controllers/AdministrationController.php index ab5f7a5..28efa41 100644 --- a/controllers/AdministrationController.php +++ b/controllers/AdministrationController.php @@ -33,6 +33,7 @@ use app\models\Analytics; use app\models\ColdStorageRequest; use webvimark\modules\UserManagement\models\User as Userw; +use app\models\Schema; class AdministrationController extends Controller { diff --git a/controllers/ProjectController.php b/controllers/ProjectController.php index 678a6be..03778ed 100644 --- a/controllers/ProjectController.php +++ b/controllers/ProjectController.php @@ -2,6 +2,8 @@ namespace app\controllers; +use app\models\Token; +use app\models\NewTokenRequestForm; use app\components\EmailVerifiedFilter; use app\models\ColdStorageAutoaccept; use app\models\ColdStorageLimits; @@ -2653,6 +2655,40 @@ public function actionEditProject($id) + } + + if ($prType==0){ + + //if the owner removed users, delete them from the schema api project + $removed_users = array(); + $schema_api_url=Yii::$app->params['schema_api_url']; + $schema_api_token=Yii::$app->params['schema_api_token']; + $headers = [ + 'Authorization: '.$schema_api_token, + 'Content-Type: application/json' + ]; + + foreach ($pold['user_list'] as $prev_user){ + $found=0; + foreach($prequest['user_list'] as $cur_user){ + if ($prev_user==$cur_user){ + $found=1; + } + } + if ($found==0){ + $removed_users[] = $prev_user; + } + } + foreach ($removed_users as $removed_user) { + $user=User::returnUsernameById($removed_user); + $username=explode('@',$user)[0]; + // echo $user; + // ob_flush(); + $URL = $schema_api_url."/api_auth/contexts/{$prequest->name}/users/{$username}"; + Token::DeleteUserFromProject($URL, $headers); + + } + } if ($prType==2) @@ -3799,6 +3835,267 @@ public function actionDeleteProject($pid, $pname){ } + public function actionTokenManagement($id) { + + // $schema_api=SchemaAPI::find()->one(); + $schema_api_url=Yii::$app->params['schema_api_url']; + $schema_api_token=Yii::$app->params['schema_api_token']; + $existing=Vm::find()->where(['project_id'=>$id])->andWhere(['active'=>true])->one(); + $project=Project::find()->where(['id'=>$id])->one(); + $project_id=$project->id; + + //make an API call to schema API to validate if the user is registered + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + $headers = [ + 'Authorization: '.$schema_api_token, + 'Content-Type: application/json' + ]; + + //$URL1 = "http://62.217.122.242:8080/api_auth/users/"; + //$URL = $URL1."{$username}"; + $URL = $schema_api_url."/api_auth/users/{$username}"; + $user_exists = Token::UserRegistered($URL, $headers); + //user is not registed => register user + if ($user_exists == 0) { + $temp1 = '{"username":'; + $temp2 = '"'; + //$temp3 = '",'; + $temp4 = $temp2.$username.$temp2.'}'; + //$URL = "http://62.217.122.242:8080/api_auth/users"; + $URL = $schema_api_url."/api_auth/users"; + $user_post = $temp1.$temp4; + $return=Token::Register($URL, $headers, $user_post); + $issued_tokens = 0; + } + + //make an API call to schema API to validate if the project is registered + $pname = $project->name; + $URL = $schema_api_url."/api_auth/contexts/{$pname}"; + $project_exists = Token::ProjectRegistered($URL, $headers); + $strArray=array(); + + // project is not registered => register project + if($project_exists == 0){ + $quotas = Project::getOndemandQuotasApi($project->id); + $temp1 = '{"name":'; + $temp2 = '"'; + $quo = []; + $i = 0; + foreach ($quotas[0] as $q) { + $quo[$i] = $q; + $i=$i+1; + } + //$temp3 = '",'; + $project_post = '{"name":"'.$pname.'","max_tasks":'.$quo[0].',"max_cpu":'.$quo[1].',"max_ram_gb":'.$quo[2]. '}'; + //$temp4 = $temp2.$pname.$temp2.'}'; + // $URL = "http://62.217.122.242:8080/api_auth/contexts"; + $URL = $schema_api_url."/api_auth/contexts"; + //$project_post = $temp1.$temp4; + $return=Token::Register($URL, $headers, $project_post); + $issued_tokens = 0; + } + elseif ($project_exists == 1) { + $quotas = Project::getOndemandQuotasApi($project->id); + //$project=Project::find()->where(['name'=>$pname])->one(); + $temp1 = '{"name":'; + $temp2 = '"'; + $quo = []; + $i = 0; + foreach ($quotas[0] as $q) { + $quo[$i] = $q; + $i=$i+1; + } + //$temp3 = '",'; + $project_post = '{"name":"'.$pname.'","max_tasks":'.$quo[0].',"max_cpu":'.$quo[1].',"max_ram_gb":'.$quo[2]. '}'; + //$temp4 = $temp2.$pname.$temp2.'}'; + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}"; + //$project_post = $temp1.$temp4; + $return=Token::EditToken($URL, $headers, $project_post); + // $URL2 = "/tokens"; + // $URL = $URL1.$pname.$URL2; + // $issued_tokens = Token::GetTokens($URL, $headers); + + } + else { + //placeholder for bad request + } + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users"; + //check if the user is registered to the project + $user_registered = Token::IsUserRegisteredProject($URL, $headers, $username); + //user is not registered to the project + if ($user_registered == 0) { + $temp1 = '{"username":'; + $temp2 = '"'; + $temp4 = $temp2.$username.$temp2.'}'; + $post_body = $temp1.$temp4; + $return = Token::Register($URL, $headers, $post_body); + return $this->render('token_management',['model'=>$existing, 'requestId'=>$id, 'project'=>$project, 'issued_tokens'=>0, + 'strArray'=>'', 'URL'=>$URL, 'headers'=>$headers, 'project_exists'=>$project_exists]); + } else { + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users/{$username}/tokens?status=active"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens?status=active"; + //$URL = "http://62.217.122.242:8080/api_auth/contexts/context0/users/user0/tokens"; + $issued_tokens = Token::GetTokens($URL, $headers); + return $this->render('token_management',['model'=>$existing, 'requestId'=>$id, 'project'=>$project, 'issued_tokens'=>$issued_tokens[0], + 'strArray'=>$issued_tokens[1], 'URL'=>$URL, 'headers'=>$headers, 'project_exists'=>$project_exists]); + } + } + + public function actionNewTokenRequest($id, $mode, $uuid){ + //retrieve schema API base url and authentication token + // $schema_api=SchemaAPI::find()->one(); + $schema_api_url=Yii::$app->params['schema_api_url']; + $schema_api_token=Yii::$app->params['schema_api_token']; + // $schema_api_url=$schema_api->schema_api_url; + // $schema_api_token=$schema_api->schema_api_auth_token; + + $existing=Vm::find()->where(['project_id'=>$id])->andWhere(['active'=>true])->one(); + + $project=Project::find()->where(['id'=>$id])->one(); + $project_id=$project->id; + $pname = $project->name; + $model = new NewTokenRequestForm(); + + $headers = [ + 'Authorization: '.$schema_api_token, + 'Content-Type: application/json' + ]; + + if ($model->load(Yii::$app->request->post())) { + $prequest=ProjectRequest::find()->where(['project_id'=>$id])->one(); + $exp_date = new \DateTime($prequest->end_date); + $s_exp_date = new \DateTime($model->expiration_date); + $message=$model->validateDates($exp_date, $s_exp_date, $mode); + + if( $message=='ok'|| $message =='empty') { + // valid data received in $model + if ($message!='ok' && $message!='empty' && !empty($prequest)){ + Yii::$app->session->setFlash('danger', "$message"); + return $this->redirect(['project/token-management', 'id'=>$id]); + //return $this->actionTokenManagement($project_id,$model->expiration_date); + + } elseif($message=='empty'&& !empty($prequest) && $mode==0 ) { + $s_exp_date = $exp_date; + } + + $time = date('h:i:s'); + if ($mode == 1){ + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + $pname = $project->name; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + $temp1 = '{"title":'; + $temp2 = '"'; + $temp3 = '"}'; + if ($message != 'empty') { + $temp4 = $temp2.$model->name.$temp2; + $patch = $temp1.$temp4.',"expiry":"'.$s_exp_date->format("Y-m-d")."T".$time.'.000000"}'; + } else { + $temp4 = $temp2.$model->name.$temp3; + $patch = $temp1.$temp4; + } + Token::EditToken($URL, $headers, $patch); + $success = 'Your token information was updated succesfully.'; + Yii::$app->session->setFlash('success', "$success"); + return $this->redirect(['project/token-management','id'=>$id]); + //return $this->actionTokenManagement($project_id, $patch ); + + } elseif ($mode == 0){ + $pname = $project->name; + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users/{$username}/tokens"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens"; + $token = Token::CreateNewToken($URL, $headers, $model->name, $s_exp_date, $pname, $username); + if (!empty($token[0])){ + $success = 'Your new token is the following, please store it: '. $token[0]; + Yii::$app->session->setFlash('success-new-token', "$success"); + } else { + $error = 'Error during token creation:
'.$token[1]; + Yii::$app->session->setFlash('error', "$error"); + } + return $this->redirect(['project/token-management','id'=>$id]); + //return $this->actionTokenManagement($project_id,$model->expiration_date); + } + } else { + + Yii::$app->session->setFlash('danger', "$message"); + //return $this->actionOnDemandLp($project_id,$model->expiration_date); + } + + } else { + + if ($mode == 1) { + $pname = $project->name; + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + $token_details = Token::GetTokenDetails($URL, $headers); + $exp_date = $token_details[1]->format('y-m-d'); + return $this->render('new_token_request', ['model' => $model, 'requestId'=>$id, 'project'=>$project, 'mode'=>$mode, 'uuid'=>$uuid, 'title'=>$token_details[0], 'exp_date'=>$exp_date]); + + } elseif ($mode==0) { + return $this->render('new_token_request', ['model' => $model, 'requestId'=>$id, 'project'=>$project, 'mode'=>$mode, 'uuid'=>$uuid]); + + } else { + + $pname = $project->name; + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + // $URL = $URL1.$pname."/tokens"."/".$uuid; + $out=Token::DeleteToken($URL, $headers); + $success = 'Your token was deleted.'; + Yii::$app->session->setFlash('success', "$success"); + //return $this->actionTokenManagement($project_id); + return $this->redirect(['project/token-management', 'id'=>$id]); + + } + // either the page is initially displayed or there is some validation error + + } + if ($mode == 0){ + return $this->render('new_token_request', ['model' => $model, 'requestId'=>$id, 'project'=>$project, 'mode'=>$mode, 'uuid'=>$uuid]); + } elseif($mode == 1){ + $pname = $project->name; + $user=Userw::getCurrentUser(); + $username=explode('@',$user['username'])[0]; + // $URL = "http://62.217.122.242:8080/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + $URL = $schema_api_url."/api_auth/contexts/{$pname}/users/{$username}/tokens/{$uuid}"; + //$URL = "http://62.217.122.242:8080/api_auth/contexts/context0/users/user0/tokens/{$uuid}"; + $token_details = Token::GetTokenDetails($URL, $headers); + $exp_date = $token_details[1]->format('y-m-d'); + return $this->render('new_token_request', ['model' => $model, 'requestId'=>$id, 'project'=>$project, 'mode'=>$mode, 'uuid'=>$uuid, 'title'=>$token_details[0], 'exp_date'=>$exp_date]); + } + + + } + + public function actionOnDemandAccess($id) { + + $configuration=Configuration::find()->one(); + $schema_url=$configuration->schema_url; + $existing=Vm::find()->where(['project_id'=>$id])->andWhere(['active'=>true])->one(); + $project=Project::find()->where(['id'=>$id])->one(); + $request_id = $project['latest_project_request_id']; + $project_id=$project->id; + + $details=OndemandRequest::findOne(['request_id'=>$request_id]); + $usage=ProjectRequest::getProjectSchemaUsage($project->name); + $num_of_jobs=$details->num_of_jobs; + $used_jobs=$usage['count']; + $remaining_jobs=$num_of_jobs-$used_jobs; + + return $this->render('on_demand_access', ['project'=>$project, 'details'=>$details,'initial_jobs'=>$num_of_jobs, 'remaining_jobs'=>$remaining_jobs, 'usage'=>$usage, 'request_id'=>$request_id, 'id'=>$id, 'compute'=>$schema_url ]); + + } + + } diff --git a/models/NewTokenRequestForm.php b/models/NewTokenRequestForm.php new file mode 100644 index 0000000..e5355c3 --- /dev/null +++ b/models/NewTokenRequestForm.php @@ -0,0 +1,46 @@ +expiration_date)){ + + if (strtotime($this->expiration_date) < strtotime(date("Y-m-d"))) { + if ($mode==0){ + return 'Token creation was unsuccessful: please provide a valid date.'; + } else { + return 'Token edit was unsuccessful: please provide a valid date.'; + } + } elseif ($given_date->format("Y-m-d") > $date_e->format("Y-m-d")) { + if ($mode==0){ + return 'Token creation was unsuccessful: please provide a date that does not exceed the expiration date of the project.'; + } else { + return 'Token edit was unsuccessful: please provide a date that does not exceed the expiration date of the project.'; + } + } else { + return "ok"; + } + } else { + return 'empty'; + } + + } + +} \ No newline at end of file diff --git a/models/Project.php b/models/Project.php index 09f7fb9..4dea420 100644 --- a/models/Project.php +++ b/models/Project.php @@ -1574,4 +1574,17 @@ public static function DeleteProject($pid){ } } + + public static function getOndemandQuotasApi($project_id){ + $query=new Query; + + $query->select(['odr.num_of_jobs','odr.ram','odr.cores']) + ->from('project as p') + ->innerJoin('project_request as pr','p.latest_project_request_id=pr.id') + ->innerJoin('ondemand_request as odr','pr.id=odr.request_id') + ->where(['p.id'=>$project_id]) + ->one(); + $results=$query->all(); + return $results; + } } \ No newline at end of file diff --git a/models/Schema.php b/models/Schema.php new file mode 100644 index 0000000..1934884 --- /dev/null +++ b/models/Schema.php @@ -0,0 +1,19 @@ +"; + $strArray_title = explode(':',$detail_t); + $title = $strArray_title[1]; + $title = str_replace('"', '', $title); + //echo "$title". "
"; + } elseif (strpos($detail_t, 'expiry') == true){ + $strArray_expiry = explode('T',$detail_t); + $expiry_t = $strArray_expiry[0]; + $strArray_expiry = explode(':',$expiry_t); + $expiry = $strArray_expiry[1]; + $expiry = str_replace('"', '', $expiry); + //echo "$expiry". "
"; + $today = date("Y-m-d"); + $today_date = new \DateTime(date("Y-m-d")); + $expiry_date = new \DateTime($expiry); + if ($expiry > $today) { + $interval = $expiry_date->diff($today_date); + //echo "difference " . $interval->days . " days "."
"; + $exp_days = $interval->days; + $active = "Yes"; + } else { + $exp_days = 0; + $active = "No"; + + } + } elseif (strpos($detail_t, 'uuid') == true){ + $strArray_uuid = explode(':',$detail_t); + $uuid = $strArray_uuid[1]; + $uuid = str_replace('"', '', $uuid); + //echo "$uuid"."
"; + } + } + return [$title, $expiry_date, $exp_days, $active, $uuid]; + + } + + public static function GetTokenDetails($URL, $headers){ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $token_details = curl_exec($ch); + curl_close($ch); + $strArray_td = explode(',',$token_details); + foreach ($strArray_td as $detail) { + $detail_t = $detail; + if (strpos($detail_t, 'title') == true){ + //echo "$piece". "
"; + $strArray_title = explode(':',$detail_t); + $title = $strArray_title[1]; + $title = str_replace('"', '', $title); + //echo "$title". "
"; + } elseif (strpos($detail_t, 'expiry') == true){ + $strArray_expiry = explode('T',$detail_t); + $expiry_t = $strArray_expiry[0]; + $strArray_expiry = explode(':',$expiry_t); + $expiry = $strArray_expiry[1]; + $expiry = str_replace('"', '', $expiry); + //echo "$expiry". "
"; + $today = date("Y-m-d"); + $today_date = new \DateTime(date("Y-m-d")); + $expiry_date = new \DateTime($expiry); + if ($expiry > $today) { + $interval = $expiry_date->diff($today_date); + //echo "difference " . $interval->days . " days "."
"; + $exp_days = $interval->days; + $active = "Yes"; + } else { + $exp_days = 0; + $active = "No"; + + } + } elseif (strpos($detail_t, 'uuid') == true){ + $strArray_uuid = explode(':',$detail_t); + $uuid = $strArray_uuid[1]; + $uuid = str_replace('"', '', $uuid); + //echo "$uuid"."
"; + } + } + return [$title, $expiry_date, $exp_days, $active, $uuid]; + + } + + public static function EditToken($URL, $headers, $patch){ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $patch); + $out = curl_exec($ch); + curl_close($ch); + return $out; + + } + + public static function CreateNewToken($URL, $headers, $pname, $exp_date, $project_name, $username){ + + $schema_api_url=Yii::$app->params['schema_api_url']; + $schema_api_token=Yii::$app->params['schema_api_token']; + $time = date('h:i:s'); + $status = 0; + $token=[]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + if (empty($pname)){ + $post = '{"expiry":"'.$exp_date->format("Y-m-d")."T".$time.'.000000"}'; + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + $token[0] = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + } + else{ + //if the user provided a name then make the api call with that name + $temp1 = '{"title":'; + $temp2 = '"'; + $temp4 = $temp2.$pname.$temp2; + $post = $temp1.$temp4.',"expiry":"'.$exp_date->format("Y-m-d")."T".$time.'.000000"}'; + + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post); + $token[0] = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + + } + curl_close($ch); + if ($status==201){ + $strArray = explode(':',$token[0]); + $token[0] = $strArray[11]; + $token[0] = str_replace('"', '', $token[0]); + $token[0] = str_replace('}', '', $token[0]); + if (empty($pname)) { + $uuid = $strArray[1]; + $uuid = str_replace('"', '', $uuid); + $uuid = str_replace(',title', '', $uuid); + $URL = $schema_api_url."/api_auth/contexts/{$project_name}/users/{$username}/tokens/{$uuid}"; + $hint = $strArray[3]; + $hint = str_replace('"', '', $hint); + $temp1 = '{"title":'; + $temp2 = '"'; + $temp3 = '"}'; + $patch = $temp1.$temp2.$hint.$temp3; + $out = Token::EditToken($URL, $headers, $patch); + } + } else { + $token[1]= $token[0]; + $token[0]= ''; + } + return $token; + + } + + public static function DeleteToken($URL, $headers){ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $out = curl_exec($ch); + curl_close($ch); + return $out; + + } + + public static function DeleteUserFromProject($URL, $headers){ + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + $out = curl_exec($ch); + curl_close($ch); + return $out; + + } +} +?> \ No newline at end of file diff --git a/views/project/delete_token.php b/views/project/delete_token.php new file mode 100644 index 0000000..e69de29 diff --git a/views/project/edit_ondemand.php b/views/project/edit_ondemand.php index 2fca39b..2e03c00 100644 --- a/views/project/edit_ondemand.php +++ b/views/project/edit_ondemand.php @@ -19,11 +19,11 @@ if($autoacceptlimits->ram==$upperlimits->ram) { - $ram_label= "Maximum allowed memory per job (in GBs) * [upper limits: $upperlimits->ram] "; + $ram_label= "Maximum allowed memory (in GBs) * [upper limits: $upperlimits->ram] "; } else { - $ram_label= "Maximum allowed memory per job (in GBs) * [upper limits: $autoacceptlimits->ram (automatically accepted), $upperlimits->ram (with review)] "; + $ram_label= "Maximum allowed memory (in GBs) * [upper limits: $autoacceptlimits->ram (automatically accepted), $upperlimits->ram (with review)] "; } if($autoacceptlimits->num_of_jobs==$upperlimits->num_of_jobs) @@ -37,11 +37,11 @@ if($autoacceptlimits->cores==$upperlimits->cores) { - $cores_label= "Available cores per job * [upper limits: $autoacceptlimits->cores] " ; + $cores_label= "Available cores * [upper limits: $autoacceptlimits->cores] " ; } else { - $cores_label= "Available cores per job * [upper limits: $autoacceptlimits->cores (automatically accepted), $upperlimits->cores (with review)] " ; + $cores_label= "Available cores * [upper limits: $autoacceptlimits->cores (automatically accepted), $upperlimits->cores (with review)] " ; } diff --git a/views/project/index.php b/views/project/index.php index 86c2747..28c4b65 100644 --- a/views/project/index.php +++ b/views/project/index.php @@ -138,12 +138,13 @@ if ($res['project_type']==0) { - $projectLink=$schema_url; + // $projectLink=$schema_url; + $projectLink=Url::to(['/project/on-demand-access','id'=>$res['project_id']]); - if(empty($schema_url)) - { - $ondemand_access_class='disabled'; - } + // if(empty($schema_url)) + // { + // $ondemand_access_class='disabled'; + // } $projectTarget='_self'; $project_icon=''; diff --git a/views/project/new_ondemand_request.php b/views/project/new_ondemand_request.php index 03f9743..12b7912 100644 --- a/views/project/new_ondemand_request.php +++ b/views/project/new_ondemand_request.php @@ -19,11 +19,11 @@ if($autoacceptlimits->ram==$upperlimits->ram) { - $ram_label= "Maximum allowed memory per job (in GBs) * [upper limits: $upperlimits->ram] "; + $ram_label= "Maximum allowed memory (in GBs) * [upper limits: $upperlimits->ram] "; } else { - $ram_label= "Maximum allowed memory per job (in GBs) * [upper limits: $autoacceptlimits->ram (automatically accepted), $upperlimits->ram (with review)] "; + $ram_label= "Maximum allowed memory (in GBs) * [upper limits: $autoacceptlimits->ram (automatically accepted), $upperlimits->ram (with review)] "; } if($autoacceptlimits->num_of_jobs==$upperlimits->num_of_jobs) @@ -37,11 +37,11 @@ if($autoacceptlimits->cores==$upperlimits->cores) { - $cores_label= "Available cores per job * [upper limits: $autoacceptlimits->cores] " ; + $cores_label= "Available cores * [upper limits: $autoacceptlimits->cores] " ; } else { - $cores_label= "Available cores per job * [upper limits: $autoacceptlimits->cores (automatically accepted), $upperlimits->cores (with review)] " ; + $cores_label= "Available cores * [upper limits: $autoacceptlimits->cores (automatically accepted), $upperlimits->cores (with review)] " ; } if (!empty($errors)) diff --git a/views/project/new_token.php b/views/project/new_token.php new file mode 100644 index 0000000..2e56f46 --- /dev/null +++ b/views/project/new_token.php @@ -0,0 +1,187 @@ +registerJsFile('@web/js/project/view-request-user.js', ['depends' => [\yii\web\JqueryAsset::className()]]); +$this->registerJsFile('@web/js/project/new-token.js'); + +$back_icon=''; +// $back_link='/project/index'; +$access_icon=''; + + +Headers::begin() ?> +$project->name, + 'buttons'=> + [ + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=>['/project/on-demand-lp','id'=>$requestId], 'type'=>'a', + 'options'=>['class'=>'btn btn-default']] + ], + ]); +?> + + + +

New token request

+name; + $temp3 = '"}'; + $temp4 = $temp2.$pname.$temp3; + $project_post = $temp1.$temp4; + $headers = [ + "Authorization: Token e2b5e57c47d8bd073ce2b02e49ab2ddeb869837559138e134d3ed13a714c6ac9a236381e83b22e22e7849b04bef7d25ba3be9db33c67a7cbf239e9bd199bd04ca602f1baf1db7018eb231f574a48d9e90e19ac4c9fb1acfead568fe749fe4c94", + 'Content-Type: application/json' + ]; + + $ch = curl_init(); + $URL1 = "http://62.217.122.242/api_auth/contexts/"; + $URL = $URL1.$pname; + + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + echo $URL; + $project_exists = curl_exec($ch); + curl_close($ch); + + //first check if the project has already been registered + + if(strpos($project_exists, "No context with name ") == true){ + + //if the project is not registered then register it to the api + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, "http://62.217.122.242:80/api_auth/contexts"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $project_post); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_exec($ch); + curl_close($ch); + } + + //get new token + + $ch = curl_init(); + $URL2 = "/tokens"; + $URL = $URL1.$pname.$URL2; + + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + if (empty($model->name)){ + + $token = curl_exec($ch); + curl_close($ch); + + } + else { + //if the user provided a name then make the api call with that name + + $temp1 = '{"title":'; + $temp2 = '"'; + $pname = $model->name; + $temp3 = '"}'; + $temp4 = $temp2.$pname.$temp3; + $tname_post = $temp1.$temp4; + + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $tname_post); + $token = curl_exec($ch); + curl_close($ch); + + } + + $strArray = explode(':',$token); + $token = $strArray[1]; + $token = str_replace('"', '', $token); + $token = str_replace('}', '', $token); +?> + +
 
+
Your new token is the following:
+ + + +
+ +
+ + +
+
 
+
+
+ +
+
+ +

Token update

+name) and empty($model->expiration_date)){ +?> +

Token update was unsuccessful:

+

you didn't provide any of the requested information.

+name)) { + $headers = [ + "Authorization: Token e2b5e57c47d8bd073ce2b02e49ab2ddeb869837559138e134d3ed13a714c6ac9a236381e83b22e22e7849b04bef7d25ba3be9db33c67a7cbf239e9bd199bd04ca602f1baf1db7018eb231f574a48d9e90e19ac4c9fb1acfead568fe749fe4c94", + 'Content-Type: application/json' + ]; + $URL1 = "http://62.217.122.242/api_auth/contexts/"; + $pname = $project->name; + $URL = $URL1.$pname."/tokens"."/".$uuid; + //echo "$URL"."
"; + $temp1 = '{"title":'; + $temp2 = '"'; + $temp3 = '"}'; + $temp4 = $temp2.$model->name.$temp3; + $patch = $temp1.$temp4; + //echo "$patch"."
"; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL,$URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_POSTFIELDS, $patch); + $out = curl_exec($ch); + curl_close($ch); + //echo "$out"."
"; +?> +
Your token information was updated succesfully.
+ \ No newline at end of file diff --git a/views/project/new_token_request.php b/views/project/new_token_request.php new file mode 100644 index 0000000..cdc7705 --- /dev/null +++ b/views/project/new_token_request.php @@ -0,0 +1,130 @@ +registerJsFile('@web/js/project/project-request.js', ['depends' => [\yii\web\JqueryAsset::className()]]); +echo Html::CssFile('@web/css/project/project-request.css'); +$this->registerJsFile('@web/js/project/project-request.js', ['depends' => [\yii\web\JqueryAsset::className()]]); +$sub=$project->name; +if ($mode==0){ + $this->title='API token creation'.'
'; +}else { + $this->title='API token modification'.'
'; + +} + +$exclamation_icon=''; + +?> + + + +$this->title, + 'subtitle'=>$sub]) + +?> + +
+ +
Please provide the specifications for a new API token to be created:
+
 
+ + + + + field($model, 'name')->label('Name (select one that would be easy to remember, otherwise 8 first characters of the token will be selected)')->textarea([ 'style'=>'width: 600px; height: 40px; resize:none', 'rows'=>1]) ?> + + +
+ Expiration date (if not selected, project expiration date will apply) '; + echo DatePicker::widget([ + 'model' => $model, + 'attribute' => 'expiration_date', + 'options' => ['placeholder' => 'Enter Date', 'style'=>'width: 523px; height: 40px; resize:none'], + 'pluginOptions' => [ + 'autoclose'=>true, + 'format'=>'yyyy-mm-dd' + ] + ]);?> +
+ +
+
'btn btn-success', 'style'=>'width:90px']) ?>
+
$requestId], ['class'=>'btn btn-default', 'style'=>'width:90px; color:grey;']) ?>
+
+ + +
+
+
+
+
+
+ +
+
+ + +
 
+ + + +errorSummary($model) ?> + + field($model, 'name')->textInput(['value' => $title, 'style'=>'width: 600px; height: 40px; resize:none', 'rows'=>1]) ?> + +
+ Token expiration date '; + echo DatePicker::widget([ + 'model' => $model, + 'attribute' => 'expiration_date', + 'options' => ['placeholder' => $exp_date, 'style'=>'width: 523px; height: 40px; resize:none'], + 'pluginOptions' => [ + 'autoclose'=>true, + 'format'=>'yyyy-mm-dd' + ] + ]);?> +
+ +
+
'btn btn-success', 'style'=>'width:90px']) ?>
+
$requestId], ['class'=>'btn btn-default', 'style'=>'width:90px; color:grey;']) ?>
+
+
false]) ?>
+ + + +
+
+
+
+ +
+
+ + diff --git a/views/project/new_token_request_confirm.php b/views/project/new_token_request_confirm.php new file mode 100644 index 0000000..079b400 --- /dev/null +++ b/views/project/new_token_request_confirm.php @@ -0,0 +1,9 @@ + +

You have entered the following information:

+ + \ No newline at end of file diff --git a/views/project/on_demand_access.php b/views/project/on_demand_access.php new file mode 100644 index 0000000..be896f4 --- /dev/null +++ b/views/project/on_demand_access.php @@ -0,0 +1,83 @@ +registerJsFile('@web/js/project/index.js', ['depends' => [\yii\web\JqueryAsset::className()]]); + +$back_icon=''; +$access_icon=''; +$update_icon=''; +$back_link='/project/index'; +$delete_icon=''; +$new_icon=''; +$exclamation_icon=''; +$mode = 0; +$edit_button_class=''; +$access_button_class =''; +$ondemand_access_class = ''; + + +Headers::begin() ?> +'Project management '."
", + 'subtitle'=>$project->name, + 'buttons'=> + [ + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=>[$back_link], 'type'=>'a', + 'options'=>['class'=>'btn btn-default', 'style'=>'width: 100px; color:grey ']] + ], + ]); +?> + +
+

Approved resources

+
+

  Jobs:  

 (remaining:  )


+

  Cores:  

cores?> (average use:  )


+

  Ram:  

ram?>GB (average use:  GB)



+ +

 *These computational resources are available for the execution of containerized software packages and workflows.

+
+ +
+

Using the resources

+
+

  There are two ways to use the approved computational resources of this project:


+

        ‐ Use our Job execution User Interface (UI) to manually run computational analysis tasks leveraging Web-based wizards.


+

        ‐ Use our Job execution API to programmatically run computational analysis tasks (API tokens need to be issued).



+ +

  You can select the way that better fits your needs (but it's possible to consume your approved resources using both ways):


+
+
+
+"btn btn-success btn-md $access_button_class $ondemand_access_class", 'style'=>'width:270px; height:60px; text-align: center; line-height: 45px; font-size:20px; ','target'=>'_blank'])?> +
+
+$id],['class'=>"btn btn-success btn-md $edit_button_class", 'style'=>'width:270px; height:60px; text-align: center; line-height: 45px; font-size:20px;'])?> +
+ +
+"btn btn btn-secondary btn-md $access_button_class $ondemand_access_class", 'style'=>'width:270px; height:60px; text-align: center; line-height: 45px; font-size:20px;'])?> +
+
+"btn btn btn-secondary btn-md $access_button_class $ondemand_access_class", 'style'=>'width:270px; height:60px; text-align: center; line-height: 45px; font-size:20px;','target'=>'_blank'])?> +
+ +
+
+
+
+

Monitoring job execution

+
+

  API calls can used to retrieve the status of the computational jobs related to this project (for details, see API documentation). +
  You can also examine the status of any job from the respective page of the Job execution UI:


+
+
+
+"btn btn-success btn-md $access_button_class $ondemand_access_class", 'style'=>'width:270px; height:60px; text-align: center; line-height: 45px; font-size:20px;','target'=>'_blank'])?> +
\ No newline at end of file diff --git a/views/project/token_management.php b/views/project/token_management.php new file mode 100644 index 0000000..9b00e4a --- /dev/null +++ b/views/project/token_management.php @@ -0,0 +1,111 @@ +registerJsFile('@web/js/project/index.js', ['depends' => [\yii\web\JqueryAsset::className()]]); + +$back_icon=''; +$access_icon=''; +$update_icon=''; +$back_link='/project/on-demand-access'; +$delete_icon=''; +$new_icon=''; +$exclamation_icon=''; +$mode = 0; + + +Headers::begin() ?> +'API tokens management'."
", + 'subtitle'=>$project->name, + 'buttons'=> + [ + // //added the access button that redirects you to schema + // ['fontawesome_class'=>$access_icon,'name'=> 'Access', 'action'=> ['/site/index'], 'type'=>'a', 'options'=>['class'=>'btn btn-success btn-md', 'style'=>'width: 100px'] ], + // //added the token button + + //['fontawesome_class'=>$new_icon,'name'=> 'New Token', 'action'=> ['/project/new-token-request','id'=>$requestId, 'mode'=>$mode, 'uuid'=>$mode], 'type'=>'a', 'options'=>['class'=>'btn btn-secondary btn-md'] ], + //['fontawesome_class'=>$update_icon,'name'=> 'Update', 'action'=> ['/project/edit-project','id'=>$request_id], 'type'=>'a', 'options'=>['class'=>'btn btn-secondary btn-md'] ], + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=>['project/on-demand-access', 'id'=>$project->id], 'type'=>'a', + 'options'=>['class'=>'btn btn-default', 'style'=>'width: 100px; color:grey ']] + ], + ]); +?> + +
+
This page allows for the creation and management of API authentication & authorization tokens that are used for running computational jobs in the context + of an approved project. Keep in mind that the creation of multiple tokens for the same project is supported. +
+ + +
+ +
+ $requestId, 'mode'=>$mode, 'uuid'=>$mode],['class'=>'btn btn-success create-vm-btn', 'style'=>'width:110px'])?> + +
+ +

Issued tokens() +

+
+ +
 
+ + + +
+ + + + + + + + + + +"; + $token_details = Token::SplitTokens($token); + $title = $token_details[0]; + $exp_days = $token_details[2]; + $active = $token_details[3]; + $uuid = $token_details[4]; + //echo "$token_details". "
"; + // $token_details[1] = $token_details[1]->format('d/m/Y'); + // echo $token_details[1]; + + +?> + + + + + + + +
Token nameExpires in 
+ $requestId, 'mode'=>1, 'uuid'=>$uuid],['class'=>'btn btn-secondary create-vm-btn', 'style'=>'width:90px'])?> + $requestId, 'mode'=>2, 'uuid'=>$uuid],['class'=>"btn btn-secondary btn-md delete-volume-btn", 'style'=>'width:90px','data' => [ + 'confirm' => 'Are you sure you want to delete the token with name '.$title. ' ?', + 'method' => 'post', + ],])?> + +
+
diff --git a/web/css/project/new-token.css b/web/css/project/new-token.css new file mode 100644 index 0000000..00ed7e8 --- /dev/null +++ b/web/css/project/new-token.css @@ -0,0 +1,60 @@ + +.limits-label { + color: grey; +} + +.autoaccept_not_allowed { + color: red; + font-weight: 400; +} + +.hidden { + display: none; +} + +.ow-anywhere { + overflow-wrap: anywhere; +} + +.ow-break-word { + overflow-wrap: break-word; +} + +.word-break { + word-break: break-all; +} + +.hyphens { + hyphens: auto; +} + +* { + --main-color: #333; + --contrast-color: white; +} + +.source-content { + font-size: 1.2em; + font-family: monospace; + word-wrap: break-word; + padding: 10px; + border: 1px solid var(--main-color); + border-radius: 5px; + position: relative +} + +.source-content .header { + position: absolute; + top: 0; + left:0; + transition: opacity 0.5s; + background-color: var(--main-color); + color: var(--contrast-color); + opacity: 0.5; + padding: 2px; + cursor: default; +} + +.source-content .header:hover { + opacity: 1; +} \ No newline at end of file diff --git a/web/css/project/tokens.css b/web/css/project/tokens.css new file mode 100644 index 0000000..68eea25 --- /dev/null +++ b/web/css/project/tokens.css @@ -0,0 +1,140 @@ +.header-button-area .btn-success +{ + margin-right:10px; +} + +.table-responsive +{ + margin-left:10px; + margin-right:10px; +} + + + +.bronze-user +{ + + color:#cd7f32; +} + +.silver-user +{ + color:#e0e0e0; +} + +.gold-user +{ + color:#f37d30; +} + +.fa-exclamation-triangle +{ + color:#E6833B!important; +} + +.favorite +{ + cursor: pointer; + color:red; +} + + + + .button { + background-color: #4CAF50; /* Green */ + border: none; + color: white; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + } + p.start { + font-family: 'Open Sans', sans-serif; + font-size: 17px; + line-height: 22px; + text-align: justify; + display: inline; + } + + dd { + font-family: 'Open Sans', sans-serif; + font-size: 20px; + line-height: 22px; + text-align: justify; + display: inline; + } + + p { + color: rgb(59, 59, 65); + } + + h4.start { + font-family: 'Open Sans', sans-serif; + font-size: 17px; + line-height: 22px; + margin: 0; + display: inline-block; + } + #containerIntro dd, + #containerIntro h4, + #containerIntro p { + display: inline; + vertical-align: top; + font-family: 'Open Sans', sans-serif; + font-size: 17px; + line-height: 22px; + } + .justified-adjustment { text-align: justify; } + + .justified-adjustment > * { + display: inline-block; + vertical-align: middle; + } + + .justified-adjustment::after { + content: ""; + width: 100%; + display: inline-block; + } + +.p1 { + font-family: 'Open Sans', sans-serif; + font-size: 17px; + line-height: 22px; + margin: 0; +} + + +.button-41 { + background-color: initial; + background-image: linear-gradient(-180deg, #00D775, #00BD68); + border-radius: 5px; + box-shadow: rgba(0, 0, 0, 0.1) 0 2px 4px; + color: #FFFFFF; + cursor: pointer; + display: inline-block; + font-family: Inter,-apple-system,system-ui,Roboto,"Helvetica Neue",Arial,sans-serif; + height: 44px; + line-height: 44px; + outline: 0; + overflow: hidden; + padding: 0 20px; + pointer-events: auto; + position: relative; + text-align: center; + touch-action: manipulation; + user-select: none; + -webkit-user-select: none; + vertical-align: top; + white-space: nowrap; + width: 100%; + z-index: 9; + border: 0; +} + +.button-41:hover { + background: #00bd68; +} + diff --git a/web/js/project/new-token.js b/web/js/project/new-token.js new file mode 100644 index 0000000..2716010 --- /dev/null +++ b/web/js/project/new-token.js @@ -0,0 +1,62 @@ +const SOURCE_COPY_EVENT_REGISTRY = {}; + + +const notifyCopied = (element) => { + const headerElements = element.getElementsByClassName("header"); + if (headerElements.length > 0) { + const headerElement = headerElements[0]; + if (SOURCE_COPY_EVENT_REGISTRY.hasOwnProperty(element.id)) { + clearTimeout(SOURCE_COPY_EVENT_REGISTRY[element.id]); + } + headerElement.innerText = "Copied!"; + SOURCE_COPY_EVENT_REGISTRY[element.id] = setTimeout(() => { + headerElement.innerText = "Copy"; + delete SOURCE_COPY_EVENT_REGISTRY[element.id]; + }, 2000); + } +} + +const assignCopyHandler = element => { + const copyButtons = element.getElementsByClassName("header"); + if (copyButtons.length > 0) { + const copyButton = copyButtons[0]; + const handleCopyEvent = event => { + const contentElements = element.getElementsByClassName("content"); + if (contentElements.length > 0) { + const contentElement = contentElements[0]; + const text = contentElement.innerText; + navigator.clipboard.writeText(text); + notifyCopied(element); + } + }; + copyButton.addEventListener("click", handleCopyEvent); + } + return element; +} + +const generateSourceContentContainer = (parent, content, id, useCopy = false) => { + const outerContainer = document.createElement("div"); + outerContainer.className = "source-content" + outerContainer.classList = outerContainer.className.split(); + + outerContainer.id = id; + + const contentContainer = document.createElement("div"); + contentContainer.className = "content"; + contentContainer.classList = contentContainer.className.split(); + + contentContainer.innerText = content; + + const headerContainer = (useCopy ? document.createElement("div") : null); + if (headerContainer) { + headerContainer.className = "header"; + headerContainer.classLise = headerContainer.className.split(); + + headerContainer.innerText = "Copy"; + + outerContainer.appendChild(headerContainer); + } + outerContainer.appendChild(contentContainer) + + return outerContainer; +} \ No newline at end of file diff --git a/widgets/Alert.php b/widgets/Alert.php index de04bbc..1ba16b5 100644 --- a/widgets/Alert.php +++ b/widgets/Alert.php @@ -36,6 +36,7 @@ class Alert extends \yii\bootstrap\Widget 'success' => 'alert-success', 'info' => 'alert-info', 'warning' => 'alert-warning', + 'success-new-token' => 'alert-success text-break' ]; /** * @var array the options for rendering the close button tag. From 06eee05eef8e5101bae913a15a7592171ccd3862 Mon Sep 17 00:00:00 2001 From: katmastt Date: Thu, 21 Mar 2024 09:38:47 +0000 Subject: [PATCH 2/3] unused view was deleted --- views/project/new_token.php | 187 ------------------------------------ 1 file changed, 187 deletions(-) delete mode 100644 views/project/new_token.php diff --git a/views/project/new_token.php b/views/project/new_token.php deleted file mode 100644 index 2e56f46..0000000 --- a/views/project/new_token.php +++ /dev/null @@ -1,187 +0,0 @@ -registerJsFile('@web/js/project/view-request-user.js', ['depends' => [\yii\web\JqueryAsset::className()]]); -$this->registerJsFile('@web/js/project/new-token.js'); - -$back_icon=''; -// $back_link='/project/index'; -$access_icon=''; - - -Headers::begin() ?> -$project->name, - 'buttons'=> - [ - ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=>['/project/on-demand-lp','id'=>$requestId], 'type'=>'a', - 'options'=>['class'=>'btn btn-default']] - ], - ]); -?> - - - -

New token request

-name; - $temp3 = '"}'; - $temp4 = $temp2.$pname.$temp3; - $project_post = $temp1.$temp4; - $headers = [ - "Authorization: Token e2b5e57c47d8bd073ce2b02e49ab2ddeb869837559138e134d3ed13a714c6ac9a236381e83b22e22e7849b04bef7d25ba3be9db33c67a7cbf239e9bd199bd04ca602f1baf1db7018eb231f574a48d9e90e19ac4c9fb1acfead568fe749fe4c94", - 'Content-Type: application/json' - ]; - - $ch = curl_init(); - $URL1 = "http://62.217.122.242/api_auth/contexts/"; - $URL = $URL1.$pname; - - curl_setopt($ch, CURLOPT_URL,$URL); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - echo $URL; - $project_exists = curl_exec($ch); - curl_close($ch); - - //first check if the project has already been registered - - if(strpos($project_exists, "No context with name ") == true){ - - //if the project is not registered then register it to the api - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, "http://62.217.122.242:80/api_auth/contexts"); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $project_post); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_exec($ch); - curl_close($ch); - } - - //get new token - - $ch = curl_init(); - $URL2 = "/tokens"; - $URL = $URL1.$pname.$URL2; - - curl_setopt($ch, CURLOPT_URL,$URL); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - if (empty($model->name)){ - - $token = curl_exec($ch); - curl_close($ch); - - } - else { - //if the user provided a name then make the api call with that name - - $temp1 = '{"title":'; - $temp2 = '"'; - $pname = $model->name; - $temp3 = '"}'; - $temp4 = $temp2.$pname.$temp3; - $tname_post = $temp1.$temp4; - - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $tname_post); - $token = curl_exec($ch); - curl_close($ch); - - } - - $strArray = explode(':',$token); - $token = $strArray[1]; - $token = str_replace('"', '', $token); - $token = str_replace('}', '', $token); -?> - -
 
-
Your new token is the following:
- - - -
- -
- - -
-
 
-
-
- -
-
- -

Token update

-name) and empty($model->expiration_date)){ -?> -

Token update was unsuccessful:

-

you didn't provide any of the requested information.

-name)) { - $headers = [ - "Authorization: Token e2b5e57c47d8bd073ce2b02e49ab2ddeb869837559138e134d3ed13a714c6ac9a236381e83b22e22e7849b04bef7d25ba3be9db33c67a7cbf239e9bd199bd04ca602f1baf1db7018eb231f574a48d9e90e19ac4c9fb1acfead568fe749fe4c94", - 'Content-Type: application/json' - ]; - $URL1 = "http://62.217.122.242/api_auth/contexts/"; - $pname = $project->name; - $URL = $URL1.$pname."/tokens"."/".$uuid; - //echo "$URL"."
"; - $temp1 = '{"title":'; - $temp2 = '"'; - $temp3 = '"}'; - $temp4 = $temp2.$model->name.$temp3; - $patch = $temp1.$temp4; - //echo "$patch"."
"; - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL,$URL); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_POSTFIELDS, $patch); - $out = curl_exec($ch); - curl_close($ch); - //echo "$out"."
"; -?> -
Your token information was updated succesfully.
- \ No newline at end of file From 48fd0b93dcd74168432b4a75ddfeb59e467970b4 Mon Sep 17 00:00:00 2001 From: katmastt Date: Thu, 21 Mar 2024 09:43:02 +0000 Subject: [PATCH 3/3] diable on-demand batch computations --- views/project/new_request.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/views/project/new_request.php b/views/project/new_request.php index 2e08b34..2515aaf 100644 --- a/views/project/new_request.php +++ b/views/project/new_request.php @@ -49,8 +49,7 @@
- -
+ "btn btn-default btn-lg btn-block tool-button disabled"]) ?>