public function actionSaveGraphPositions() { Yii::trace($_POST); if ($_POST['nodes']) { switch ($_POST['mode']) { case 'dom': foreach ($_POST['nodes'] as $node) { $dom = Domain::findOne(str_replace("dom", "", $node['id'])); $dom->graph_x = $node['x']; $dom->graph_y = $node['y']; $dom->save(); } break; case 'dev': foreach ($_POST['nodes'] as $node) { $dev = Device::findOne(str_replace("dev", "", $node['id'])); $dev->graph_x = $node['x']; $dev->graph_y = $node['y']; $dev->save(); } break; case 'net': break; default: break; } } return ""; }
/** * * @param int $id * @return boolean */ public static function disable($id) { $workflow = BpmWorkflow::findOne(['id' => $id]); $workflow->active = 0; $domain = Domain::findOne(['name' => $workflow->domain]); if (!$domain) { return false; } if (!$workflow->save()) { return false; } // Procura por execuções em aberto envolvendo o workflow. $flows = BpmFlow::find()->where(['workflow_id' => $id])->all(); foreach ($flows as $flow) { $conId = $flow->connection_id; //Deleta o fluxo $flow->delete(); //Deleta autorizações ConnectionAuth::deleteAll(['connection_id' => $conId, 'domain' => $domain->name]); //Cria novo fluxo, com workflow desativado BpmFlow::startFlow($conId, $domain->name); //Dispara continuidade dos workflows Connection::continueWorkflows($conId, true); } return true; }
public function actionCreate($id) { $port = new Port(); $domain = Domain::findOne($id); if ($port->load($_POST)) { $port->type = 'NSI'; $port->directionality = 'BI'; if (!$port->validate()) { return $this->renderPartial('_add-port', array('networks' => $domain->getNetworks(), 'devices' => $domain->getDevices(), 'port' => $port)); } $port->save(); return; } return $this->renderPartial('_add-port', array('networks' => $domain->getNetworks(), 'devices' => $domain->getDevices(), 'port' => $port)); }
public function searchByDomains($params, $domains) { $validDomains = []; $this->load($params); if ($this->domain_name) { $domain = Domain::findOne(['name' => $this->domain_name]); $networks = Network::find()->where(['domain_id' => $domain->id]); } else { foreach ($domains as $domain) { $validDomains[] = $domain->id; } $networks = Network::find()->where(['in', 'domain_id', $validDomains]); } $dataProvider = new ActiveDataProvider(['query' => $networks, 'sort' => false, 'pagination' => ['pageSize' => 15]]); return $dataProvider; }
static function createToGroup($group_id, $domain, $reservation_id, $auth_id, $date = null) { $group = Group::findOne($group_id); $domain = Domain::findOne(['name' => $domain]); if (!$group || !$domain) { return false; } //Confere todos papeis associados ao grupo $roles = UserDomainRole::findByGroup($group); foreach ($roles->all() as $role) { if ($role->domain == null || $role->domain == $domain->name) { //Se papel for para todos dominios ou para dominio espeficido //Confere se já foi feita uma notificação de algum circuito desta reserva, se sim, reutiliza a mesma notificação $not = null; $notifications = Notification::find()->where(['user_id' => $role->user_id, 'type' => Notification::TYPE_AUTHORIZATION])->all(); foreach ($notifications as $notification) { $cauth = ConnectionAuth::findOne($notification->info); if ($cauth) { if ($cauth->domain == $domain->name) { $conn = Connection::findOne($cauth->connection_id); if ($conn) { if ($conn->reservation_id == $reservation_id) { $not = $notification; break; } } } } } if ($not) { //Se já existe, atualiza e coloca nova data //Pode receber uma data por parametro, neste caso, utiliza essa data como a data da criação da notificação if ($date) { $not->date = $date; } else { //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário $date = new \DateTime('now', new \DateTimeZone("UTC")); $dateAux = $date->format("Y-m-d H:i:s"); while (Notification::find()->where(['user_id' => $role->user_id, 'date' => $dateAux])->one()) { $date->modify('-1 second'); $dateAux = $date->format("Y-m-d H:i:s"); } $not->date = $dateAux; } $not->viewed = 0; $not->save(); } else { //Se for nova, cria notificação $not = new Notification(); $not->user_id = $role->user_id; if (isset($date)) { $not->date = $date; } else { //Pequena maquipulação do horário para que nunca existam duas notificações com o mesmo horário $date = new \DateTime('now', new \DateTimeZone("UTC")); $dateAux = $date->format("Y-m-d H:i:s"); while (Notification::find()->where(['user_id' => $role->user_id, 'date' => $dateAux])->one()) { $date->modify('-1 second'); $dateAux = $date->format("Y-m-d H:i:s"); } $not->date = $dateAux; } $not->date = $dateAux; $not->type = Notification::TYPE_AUTHORIZATION; $not->viewed = 0; $not->info = (string) $auth_id; $not->save(); } } } }
public function actionAnswer($id = null, $domain = null) { if ($id == null || $domain == null) { $this->actionAuthorization(); } else { if (!Domain::findOne(['name' => $domain])) { $this->actionAuthorization(); } else { Yii::trace("Respondendo a reserva id: " . $id); $userId = Yii::$app->user->getId(); //Confere se usuário pode autorizar $conn = Connection::find()->where(['reservation_id' => $id])->one(); $auth = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'type' => ConnectionAuth::TYPE_GROUP])->one(); if ($auth) { $onGroup = false; $roles = User::findOne($userId)->getRoles()->all(); foreach ($roles as $role) { if (($role->domain == $auth->domain || $role->domain == null) && $role->getGroup()->id == $auth->manager_group_id) { $onGroup = true; } } if (!$onGroup) { return $this->goHome(); } } $auth = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'type' => ConnectionAuth::TYPE_USER])->one(); if ($auth && $auth->manager_user_id != $userId) { return $this->goHome(); } $reservation = Reservation::findOne(['id' => $id]); //Confere se alguma ja expirou $connectionsExpired = $conn = Connection::find()->where(['reservation_id' => $reservation->id])->andWhere(['<=', 'start', DateUtils::now()])->all(); foreach ($connectionsExpired as $connection) { $requests = ConnectionAuth::find()->where(['connection_id' => $connection->id, 'status' => Connection::AUTH_STATUS_PENDING])->all(); foreach ($requests as $request) { $request->changeStatusToExpired(); $connection->auth_status = Connection::AUTH_STATUS_EXPIRED; $connection->save(); ReservationNotification::create($connection->id); } } $allRequest = null; $connections = Connection::find()->where(['reservation_id' => $id])->all(); foreach ($connections as $conn) { if ($allRequest == null) { $allRequest = ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domain]); } else { $allRequest->union(ConnectionAuth::find()->where(['connection_id' => $conn->id, 'domain' => $domain])); } } $allRequest = $allRequest->all(); $domainRoles = User::findOne(['id' => $userId])->getRoles()->all(); $requests = []; foreach ($allRequest as $request) { if ($request->manager_user_id == $userId) { $requests[$request->id] = $request; } else { foreach ($domainRoles as $domainRule) { $groupId = $domainRule->getGroup()->id; if ($request->manager_group_id == $groupId) { $requests[$request->id] = $request; } } } } $events = []; foreach ($requests as $request) { $events[] = ['id' => $request->id, 'title' => "\n" . $request->getConnection()->one()->getReservation()->one()->bandwidth . " Mbps", 'start' => Yii::$app->formatter->asDatetime($request->getConnection()->one()->start, "php:Y-m-d H:i:s"), 'end' => Yii::$app->formatter->asDatetime($request->getConnection()->one()->finish, "php:Y-m-d H:i:s")]; } $info = new AuthorizationDetailed($reservation, Connection::find()->where(['reservation_id' => $id])->one()->id, $domain); if (sizeof($requests) <= 0) { return $this->redirect('index'); } else { return $this->render('detailed', array('domain' => $domain, 'info' => $info, 'requests' => $requests, 'events' => $events, 'language' => Yii::$app->language)); } } } }
public function actionDelete() { if (self::can("domain/delete")) { if (isset($_POST['delete'])) { foreach ($_POST['delete'] as $domainId) { $dom = Domain::findOne($domainId); if ($dom->delete()) { Yii::$app->getSession()->addFlash('success', Yii::t('topology', 'Domain {name} deleted', ['name' => $dom->name])); } else { Yii::$app->getSession()->setFlash('error', Yii::t('topology', 'Error deleting domain {name}', ['name' => $dom->name])); } } } } else { Yii::$app->getSession()->addFlash('warning', Yii::t('topology', 'You are not allowed to delete domains')); } return $this->redirect(array('index')); }
public function searchByDomains($params) { $this->load($params); $userId = Yii::$app->user->getId(); $now = DateUtils::now(); $authorizations = []; //Armazena os pedidos $reservationsVisited = []; //Armazena as reservas ja incluidas nos pedidos e o dominio ao qual o pedido foi feito. //Pega todas requisições feitas para o usuário if ($this->domain) { $userRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } else { $userRequests = ConnectionAuth::find()->where(['manager_user_id' => $userId, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } foreach ($userRequests as $request) { //Limpa mantendo apenas 1 por reserva $uniq = true; $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one(); if (isset($conn)) { $request->changeStatusToExpired(); $conn->auth_status = Connection::AUTH_STATUS_EXPIRED; $conn->save(); ReservationNotification::create($conn->id); } else { $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one(); foreach ($reservationsVisited as $res) { if ($conn->reservation_id == $res[0] && $request->domain == $res[1]) { $uniq = false; } } if ($uniq) { $aux = []; $aux[0] = $conn->reservation_id; $aux[1] = $request->domain; $reservationsVisited[] = $aux; $source = $conn->getFirstPath()->one(); $destination = $conn->getLastPath()->one(); if (!$this->src_domain || $this->src_domain == $source->domain) { if (!$this->dst_domain || $this->dst_domain == $destination->domain) { $form = new AuthorizationForm(); $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain); $authorizations[] = $form; } } } } } //Pega todos os papeis do usuário $domainRoles = User::findOne(['id' => $userId])->getRoles()->all(); foreach ($domainRoles as $role) { //Passa por todos papeis if ($this->domain) { $groupRequests = ConnectionAuth::find()->where(['domain' => $this->domain, 'manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } else { $groupRequests = ConnectionAuth::find()->where(['manager_group_id' => $role->getGroup()->id, 'status' => Connection::AUTH_STATUS_PENDING])->all(); } foreach ($groupRequests as $request) { //Passa por todas requisições para testar se o dominio corresponde $domain = Domain::findOne(['name' => $request->domain]); if ($domain) { if ($role->domain == NULL || $role->domain == $domain->name) { $uniq = true; $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['<=', 'start', DateUtils::now()])->one(); if (isset($conn)) { $request->changeStatusToExpired(); $conn->auth_status = Connection::AUTH_STATUS_EXPIRED; $conn->save(); ReservationNotification::create($conn->id); } else { $conn = Connection::find()->where(['id' => $request->connection_id])->andWhere(['>', 'start', DateUtils::now()])->one(); foreach ($reservationsVisited as $res) { if ($conn->reservation_id == $res[0] && $domain->name == $res[1]) { $uniq = false; } } if ($uniq) { $aux = []; $aux[0] = $conn->reservation_id; $aux[1] = $request->domain; $reservationsVisited[] = $aux; $source = $conn->getFirstPath()->one(); $destination = $conn->getLastPath()->one(); if (!$this->src_domain || $this->src_domain == $source->domain) { if (!$this->dst_domain || $this->dst_domain == $destination->domain) { $form = new AuthorizationForm(); $form->setValues(Reservation::findOne(['id' => $conn->reservation_id]), $request->domain, $source->domain, $destination->domain); $authorizations[] = $form; } } } } } } } } $dataProvider = new ArrayDataProvider(['allModels' => $authorizations, 'sort' => false, 'pagination' => ['pageSize' => 15]]); return $dataProvider; }
public function getDomainName() { return Domain::findOne($this->domain_id)->name; }
/** * * @param unknown $connection_id * @param unknown $domainTop */ public static function startFlow($connection_id, $domainTop) { $domain = Domain::findOne(['name' => $domainTop]); $workflow = BpmWorkflow::findOne(['domain' => $domainTop, 'active' => 1]); Yii::trace("!!!! INICIA WORKFLOW !!!! "); Yii::trace("Connection ID: " . $connection_id); Yii::trace("Domain: " . $domainTop); if (isset($workflow) && isset($domain)) { Yii::trace("Workflow ID: " . $workflow->id); $initNode = BpmNode::findOne(['workflow_id' => $workflow->id, 'type' => 'New_Request']); $node = BpmNode::findOne(['id' => $initNode->output_yes]); $flowLine = new BpmFlow(); $flowLine->node_id = $node->id; $flowLine->type = $node->type; $flowLine->value = $node->value; $flowLine->workflow_id = $workflow->id; $flowLine->connection_id = $connection_id; $flowLine->domain = $domainTop; if ($flowLine->type == 'Request_Group_Authorization' || $flowLine->type == 'Request_User_Authorization') { $flowLine->status = self::STATUS_WAITING; } else { $flowLine->status = self::STATUS_READY; } if ($node->operator != null) { $flowLine->operator = $node->operator; } if (!$flowLine->save()) { Yii::$app->getSession()->setFlash('error', 'Unsuccessful save'); } return; } else { Yii::trace("Sem Workflow ATIVO."); } if (!$domain) { Yii::trace("Dominio não existe mais na base. ACEITO."); } else { if ($domain->default_policy == Domain::ACCEPT_ALL) { Yii::trace("ACEITO pela POLITICA PADRÃO."); $auth = new ConnectionAuth(); $auth->domain = $domainTop; $auth->status = Connection::AUTH_STATUS_APPROVED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->connection_id = $connection_id; $auth->save(); } else { Yii::trace("NEGADO pela POLITICA PADRÃO."); BpmFlow::deleteAll(['connection_id' => $connection_id]); $conn = Connection::findOne(['id' => $connection_id]); $conn->auth_status = Connection::AUTH_STATUS_REJECTED; if (!$conn->save()) { } $auth = new ConnectionAuth(); $auth->domain = $domainTop; $auth->status = Connection::AUTH_STATUS_REJECTED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->connection_id = $connection_id; $auth->save(); } } }
public function actionIsActive($id = null) { if ($id) { if (BpmWorkflow::findOne(['id' => $id])->active == 1) { $domain = Domain::findOne(['name' => BpmWorkflow::findOne(['id' => $id])->domain]); if ($domain) { echo json_encode(Yii::t("bpm", 'This Workflow is enabled for domain {domain}. This domain will not have an enabled workflow. Do you confirm?', ['domain' => $domain->name])); } else { echo 0; } } else { echo 0; } } }
static function deleteRole($udr, $group = null, $domain = null) { if (!isset($group)) { $group = $udr->getGroup(); } if (!isset($group)) { $domain = Domain::findOne(['name' => $udr->domain]); } //Remove notificações relativas ao antigo papel if ($domain) { AaaNotification::deleteNotificationsGroup($udr->user_id, $group, $domain->name); } else { AaaNotification::deleteNotificationsGroup($udr->user_id, $group, null); } //Notificação removido papel if ($domain) { AaaNotification::create($udr->user_id, Notification::NOTICE_TYPE_DEL_GROUP, $group->id, $domain->name); } else { AaaNotification::create($udr->user_id, Notification::NOTICE_TYPE_DEL_GROUP, $group->id, null); } }
/** * @copyright Copyright (c) 2012-2016 RNP * @license http://github.com/ufrgs-hyman/meican#license */ use meican\base\grid\Grid; use yii\helpers\Html; use yii\i18n\Formatter; use yii\widgets\ActiveForm; use yii\data\ArrayDataProvider; use yii\bootstrap\Modal; use meican\topology\models\Domain; use meican\circuits\models\Reservation; use meican\circuits\models\Connection; use meican\base\widgets\DetailView; \meican\circuits\assets\authorization\Detailed::register($this); $this->params['header'] = [Yii::t('circuits', "Reply request as <b>") . Domain::findOne(['name' => $domain])->name . '</b>', ['Home', 'Circuits']]; ?> <script> var jsonEvents = <?php echo json_encode($events); ?> ; var domain = <?php echo json_encode($domain); ?> ; var reservationId = <?php echo $info->reservation_id; ?> ;
public static function continueWorkflows($id, $asking = true) { Yii::trace("CONTINUA WORKFLOWS"); $paths = ConnectionPath::find()->select('DISTINCT `domain`')->where(['conn_id' => $id])->all(); Yii::trace("Dominios envolvidos:"); foreach ($paths as $path) { Yii::trace($path->domain); } //Analisa se existem pedidos em espera. Neste momento, realiza as perguntas aos admins. foreach ($paths as $path) { if (Connection::findOne(['id' => $id])->auth_status == self::AUTH_STATUS_REJECTED) { break; } else { $domain = Domain::findOne(['name' => $path->domain]); if (isset($domain)) { BpmFlow::doRequest($id, $domain->name, $asking); } } if (ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { break; } //Se tem uma pergunta ativa. } if (!$asking || ConnectionAuth::find()->where(['connection_id' => $id, 'status' => self::AUTH_STATUS_PENDING])->count() > 0) { return; } $conn = Connection::findOne(['id' => $id]); if ($conn->auth_status == self::AUTH_STATUS_PENDING) { $conn->auth_status = self::AUTH_STATUS_APPROVED; if (!$conn->save()) { } if (!$conn->isCancelStatus()) { $conn->requestProvision(); } } //Remove fluxos não finalizados BpmFlow::removeFlows($id); }