public function actionIndex()
 {
     if (!self::can("domainTopology/read") && !self::can("domain/read")) {
         return $this->goHome();
     }
     return $this->render('index', ['domains' => Domain::find()->select(['id', 'name'])->asArray()->all()]);
 }
Esempio n. 2
0
 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 "";
 }
Esempio n. 3
0
 /**
  * 
  * @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;
 }
Esempio n. 4
0
 static function findOneByDomainAndNode($domainName, $node)
 {
     $dom = Domain::findByName($domainName)->one();
     if ($dom) {
         return self::find()->where(['node' => $node, 'domain_id' => $dom->id])->one();
     }
     return null;
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 public function actionIndex()
 {
     if (self::can("user/read")) {
         $allowedDomains = Domain::find()->orderBy(['name' => SORT_ASC])->all();
         $searchModel = new UserSearch();
         $data = $searchModel->searchByDomains(Yii::$app->request->get(), $allowedDomains, true);
     } else {
         if (self::can("role/read")) {
             $allowedDomains = self::whichDomainsCan('role/read');
             $searchModel = new UserSearch();
             $data = $searchModel->searchByDomains(Yii::$app->request->get(), $allowedDomains, false);
         } else {
             return $this->goHome();
         }
     }
     return $this->render('index', array('searchModel' => $searchModel, 'users' => $data, 'domains' => $allowedDomains));
 }
Esempio n. 7
0
 static function findOneByName($name)
 {
     return Domain::find()->where(['name' => $name])->one();
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
<div class="box box-default">
    <div class="box-header with-border">
        <h3 class="box-title"><?php 
echo Yii::t("aaa", "Federation sign-in");
?>
</h3></h3>
    </div>
    <div class="box-body">
        <?php 
echo $form->field($model, 'status')->dropDownList(ArrayHelper::map([['id' => 'true', 'name' => Yii::t("aaa", "Enabled")], ['id' => 'false', 'name' => Yii::t("aaa", "Disabled")]], 'id', 'name'));
?>
        <?php 
echo $form->field($model, 'group')->dropDownList(ArrayHelper::map(UserDomainRole::getDomainGroups(), 'role_name', 'name'));
?>
		<?php 
echo $form->field($model, 'domain')->dropDownList(array_merge([null => Yii::t("aaa", "any")], ArrayHelper::map(Domain::find()->orderBy(['name' => SORT_ASC])->asArray()->all(), 'name', 'name')));
?>
    </div>
    <div class="box-footer">
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-6">
                <button type="submit" class="btn btn-primary"><?php 
echo Yii::t("aaa", 'Save');
?>
</button>
            </div>
        </div>
    </div>
</div>

<?php 
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDomain()
 {
     return $this->hasOne(Domain::className(), ['id' => 'domain_id']);
 }
Esempio n. 12
0
 public function actionCreate()
 {
     return $this->render('create/create2', ['domains' => Domain::find()->asArray()->all(), 'reserveForm' => new ReservationForm()]);
 }
Esempio n. 13
0
/**
 * @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;
?>
;
Esempio n. 14
0
 public function actionGetUserDomains()
 {
     $domains = Domain::find()->orderBy(['name' => SORT_ASC])->all();
     $domainsClean = [];
     foreach ($domains as $domain) {
         if (self::can('workflow/create', $domain->name)) {
             $domainsClean[$domain->name] = $domain->name;
         }
     }
     echo json_encode($domainsClean);
 }
Esempio n. 15
0
echo $form->field($model, 'name')->textInput(['size' => 50]);
?>
        <?php 
echo $form->field($model, 'nsa')->textInput(['size' => 50]);
?>
       <?php 
echo $form->field($model, 'type')->dropDownList(ArrayHelper::map(Provider::getTypes(), 'id', 'name'));
?>
        <?php 
echo $form->field($model, 'latitude')->textInput(['size' => 20]);
?>
        <?php 
echo $form->field($model, 'longitude')->textInput(['size' => 20]);
?>
       <?php 
echo $form->field($model, 'domain_id')->dropDownList(ArrayHelper::map(Domain::find()->select(['id', 'name'])->asArray()->all(), 'id', 'name'));
?>
    </div>
    <div class="box-footer">
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-6">
                <button type="submit" class="btn btn-primary"><?php 
echo Yii::t("topology", 'Save');
?>
</button>
            </div>
        </div>
    </div>
</div>

<?php 
Esempio n. 16
0
 public function actionIndex($mode = "read")
 {
     $data = new ActiveDataProvider(['query' => Test::find()->where(['type' => Reservation::TYPE_TEST]), 'pagination' => ['pageSize' => 15], 'sort' => false]);
     return $this->render('status', array('data' => $data, 'mode' => $mode, 'domains' => json_encode(Domain::find()->orderBy(['name' => "SORT ASC"])->asArray()->select(['id', 'name'])->all())));
 }
Esempio n. 17
0
 static function getDomains($allowed_domains)
 {
     $domains_name = [];
     foreach ($allowed_domains as $domain) {
         $domains_name[] = $domain->name;
     }
     return Domain::find()->where(['in', 'name', $domains_name])->orderBy(['name' => "SORT ASC"])->asArray()->all();
 }
Esempio n. 18
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);
     }
 }
Esempio n. 19
0
 public function actionGetAllColor($cols = null)
 {
     $query = Device::find()->orderBy(['name' => 'SORT ASC'])->asArray();
     $cols ? $data = $query->select(array_merge(json_decode($cols), ['domain_id']))->all() : ($data = $query->all());
     foreach ($data as &$dev) {
         $dev['color'] = Domain::find()->where(['id' => $dev['domain_id']])->select(['color'])->asArray()->one()['color'];
     }
     $temp = Json::encode($data);
     Yii::trace($temp);
     return $temp;
 }
 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();
             }
         }
     }
 }
Esempio n. 21
0
 static function whichDomainsCan($permissions = null, $asArray = false)
 {
     $domains = Domain::find()->orderBy(['name' => SORT_ASC]);
     if ($asArray) {
         $domains = $domains->asArray()->all();
         $canDomains = [];
         foreach ($domains as $domain) {
             if (self::can($permissions, $domain['name'])) {
                 $canDomains[] = $domain;
             }
         }
         return $canDomains;
     } else {
         $domains = $domains->all();
         $canDomains = [];
         foreach ($domains as $domain) {
             if (self::can($permissions, $domain->name)) {
                 $canDomains[] = $domain;
             }
         }
         return $canDomains;
     }
 }
Esempio n. 22
0
 public function actionUpdateRoleDomain($id)
 {
     $udr = UserDomainRole::findOne($id);
     if (!$udr) {
         if (!self::can("user/read") && !self::can("role/read", $udr->domain)) {
             return $this->goHome();
         } else {
             Yii::$app->getSession()->addFlash('warning', Yii::t('topology', 'Role not found'));
             return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
         }
     }
     if (!self::can("role/update", $udr->domain) && !self::can("user/update")) {
         if (!self::can("user/read") && !self::can("role/read")) {
             return $this->goHome();
         } else {
             Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to update roles'));
             return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
         }
     }
     $udr->getGroup();
     $group = $udr->getGroup();
     $domain = $udr->getDomain();
     if (isset($_POST["UserDomainRole"])) {
         $form = $_POST["UserDomainRole"];
         $udr->_groupRoleName = $form["_groupRoleName"];
         $roleDomain = $form['domain'];
         if ($roleDomain == "") {
             $udr->domain = null;
         } else {
             $udr->domain = $roleDomain;
         }
         $alreadyHas = false;
         $roles = UserDomainRole::find()->where(['domain' => $udr->domain, 'user_id' => $udr->user_id])->all();
         foreach ($roles as $role) {
             if ($role->getGroup()->role_name == $udr->_groupRoleName) {
                 $alreadyHas = true;
                 break;
             }
         }
         if ($alreadyHas) {
             Yii::$app->getSession()->setFlash("warning", Yii::t("aaa", 'The user already has this profile'));
             return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
         } else {
             if ($udr->save()) {
                 AaaNotification::createRole($udr);
                 AaaNotification::deleteRole($udr, $group, $domain);
                 Yii::$app->getSession()->setFlash("success", Yii::t("aaa", 'Role updated successfully'));
                 return $this->redirect(array('/aaa/user/view', 'id' => $udr->user_id));
             } else {
                 foreach ($udr->getErrors() as $attribute => $error) {
                     Yii::$app->getSession()->setFlash("error", $error[0]);
                 }
             }
         }
     }
     if (self::can("user/create")) {
         $anyDomain = [null => Yii::t("aaa", "any")];
         $domains = Domain::find()->orderBy(['name' => SORT_ASC])->asArray()->all();
     } else {
         $domains = self::whichDomainsCan("role/create");
         $anyDomain = [];
     }
     $groups = [];
     if ($udr->domain != null) {
         foreach (UserDomainRole::getDomainGroupsByDomainNoArray($udr->domain) as $group) {
             $groups[$group->role_name] = $group->name . " (" . $udr->domain . ")";
         }
     }
     foreach (UserDomainRole::getGlobalDomainGroupsNoArray() as $group) {
         $groups[$group->role_name] = $group->name;
     }
     return $this->renderPartial('_edit-role-domain', array('udr' => $udr, 'groups' => $groups, 'domains' => $domains, 'anyDomain' => $anyDomain));
 }
Esempio n. 23
0
 public function actionGetByName($name, $cols = null)
 {
     $query = Domain::find()->where(['name' => $name])->asArray();
     $cols ? $data = $query->select(json_decode($cols))->one() : ($data = $query->one());
     $temp = Json::encode($data);
     Yii::trace($temp);
     return $temp;
 }
Esempio n. 24
0
 /**
  * 
  * @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 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));
             }
         }
     }
 }
Esempio n. 26
0
 public function getDomainName()
 {
     return Domain::findOne($this->domain_id)->name;
 }
Esempio n. 27
0
 private function search()
 {
     foreach ($this->parser->getData()['domains'] as $domainName => $domainData) {
         $domain = Domain::findByName($domainName)->one();
         if ($domain == null) {
             $change = $this->buildChange();
             $change->domain = $domainName;
             $change->item_type = Change::ITEM_TYPE_DOMAIN;
             $change->data = json_encode(['' => '']);
             $change->type = Change::TYPE_CREATE;
             $change->save();
             $invalidDevices = false;
         } else {
             //VERIFICA DEVICES
             if ($this->parser instanceof NSIParser) {
                 $invalidDevices = Device::find()->where(['domain_id' => $domain->id]);
             } else {
                 $invalidDevices = false;
             }
             ///////////
         }
         if ($this->parser instanceof NSIParser && isset($domainData['nsa'])) {
             foreach ($domainData['nsa'] as $nsaId => $nsaData) {
                 $provider = Provider::find()->where(['nsa' => $nsaId])->one();
                 if (!$provider) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_CREATE;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 } elseif ($nsaData['lat'] && $nsaData['lng'] && intval($provider->latitude) != intval($nsaData['lat']) || intval($provider->longitude) != intval($nsaData['lng'])) {
                     $change = $this->buildChange();
                     $change->type = Change::TYPE_UPDATE;
                     $change->item_id = $provider->id;
                     $change->domain = $domainName;
                     $change->item_type = Change::ITEM_TYPE_PROVIDER;
                     $change->data = json_encode(['name' => $nsaData['name'], 'type' => $nsaData['type'], 'lat' => $nsaData["lat"], 'lng' => $nsaData["lng"], 'nsa' => $nsaId]);
                     $change->save();
                 }
                 if ($provider) {
                     $oldPeerings = $provider->getPeerings();
                     $oldServices = $provider->getServices();
                 }
                 $newPeerings = [];
                 $newServices = [];
                 if (isset($nsaData['peerings'])) {
                     foreach ($nsaData['peerings'] as $dstNsaId) {
                         if ($provider) {
                             $dstProv = Provider::findOneByNsa($dstNsaId);
                             if ($dstProv) {
                                 $peering = Peering::findOne(['src_id' => $provider->id, 'dst_id' => $dstProv->id]);
                                 if ($peering) {
                                     //$newPeerings[] = $peering->id;
                                     continue;
                                 }
                             }
                         }
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_PEERING;
                         $change->data = json_encode(['srcNsaId' => $nsaId, 'dstNsaId' => $dstNsaId]);
                         $change->save();
                     }
                 }
                 foreach ($nsaData['services'] as $serviceUrl => $serviceType) {
                     $service = Service::findOneByUrl($serviceUrl);
                     if (!$service) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_CREATE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['provName' => $nsaData['name'], 'provNsa' => $nsaId, 'type' => $serviceType, 'url' => $serviceUrl]);
                         $change->save();
                     } else {
                         $newServices[] = $service->id;
                     }
                 }
                 if ($provider) {
                     $oldServices = $oldServices->andWhere(['not in', 'id', $newServices])->select(['id'])->asArray()->all();
                     foreach ($oldServices as $invalidService) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_id = $invalidService['id'];
                         $change->item_type = Change::ITEM_TYPE_SERVICE;
                         $change->data = json_encode(['' => '']);
                         $change->save();
                     }
                 }
             }
         }
         //PERFSONAR
         if ($this->parser instanceof NMWGParser) {
             if (isset($domainData['devices'])) {
                 $this->importDevices($domainData["devices"], $domainName, $invalidDevices);
             }
             //NSI
         } else {
             if (isset($domainData['nets'])) {
                 $this->importNetworks($domainData["nets"], $domainName, $invalidDevices);
                 if ($invalidDevices) {
                     $invalidDevices = $invalidDevices->select(['id', 'node'])->asArray()->all();
                     foreach ($invalidDevices as $device) {
                         $change = $this->buildChange();
                         $change->type = Change::TYPE_DELETE;
                         $change->domain = $domainName;
                         $change->item_type = Change::ITEM_TYPE_DEVICE;
                         $change->item_id = $device['id'];
                         $change->data = json_encode(["node" => $device['node']]);
                         $change->save();
                     }
                 }
             }
         }
     }
 }
Esempio n. 28
0
 public function apply()
 {
     $data = json_decode($this->data);
     switch ($this->item_type) {
         case self::ITEM_TYPE_DOMAIN:
             $dom = new Domain();
             $dom->name = $this->domain;
             $dom->color = ColorUtils::generate();
             $dom->default_policy = Domain::ACCEPT_ALL;
             if ($dom->save()) {
                 $this->setApplied();
                 return $this->save();
             } else {
                 $this->error = "Unknown";
             }
             break;
         case self::ITEM_TYPE_PROVIDER:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $dom = Domain::findOneByName($this->domain);
                     if ($dom) {
                         $prov = new Provider();
                         $prov->nsa = $data->nsa;
                         $prov->name = $data->name;
                         $prov->type = $data->type;
                         $prov->latitude = $data->lat;
                         $prov->longitude = $data->lng;
                         $prov->domain_id = $dom->id;
                         if ($prov->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Domain does not exist";
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $dom = Domain::findOneByName($this->domain);
                     if ($dom) {
                         $prov = Provider::findOne($this->item_id);
                         if ($prov) {
                             $prov->name = $data->name;
                             $prov->type = $data->type;
                             $prov->latitude = $data->lat;
                             $prov->longitude = $data->lng;
                             $prov->domain_id = $dom->id;
                             if ($prov->save()) {
                                 $this->setApplied();
                                 return $this->save();
                             } else {
                                 $this->error = "Unknown";
                             }
                         } else {
                             $this->error = "Provider does not exist";
                         }
                     } else {
                         $this->error = "Domain does not exist";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $this->error = 'Invalid action';
                     break;
             }
             break;
         case self::ITEM_TYPE_PEERING:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $prov = Provider::findOneByNsa($data->srcNsaId);
                     if ($prov) {
                         $dstProv = Provider::findOneByNsa($data->dstNsaId);
                         if ($dstProv) {
                             $peering = new Peering();
                             $peering->src_id = $prov->id;
                             $peering->dst_id = $dstProv->id;
                             if ($peering->save()) {
                                 $this->setApplied();
                                 return $this->save();
                             } else {
                                 $this->error = "Unknown";
                             }
                         } else {
                             $this->error = "Destination not found";
                         }
                     } else {
                         $this->error = "Source not found";
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $port = Port::findOneByUrn($data->urn);
                     if ($port) {
                         $dstPort = Port::findOneByUrn($data->dst_urn);
                         if ($dstPort) {
                             $port->setAlias($dstPort);
                             if ($port->save()) {
                                 $this->setApplied();
                                 return $this->save();
                             } else {
                                 $this->error = "Unknown";
                             }
                         } else {
                             $this->error = "Destination not found";
                         }
                     } else {
                         $this->error = "Source not found";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         $port->alias_id = null;
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Source not found";
                     }
             }
             break;
         case self::ITEM_TYPE_SERVICE:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $prov = Provider::findOneByNsa($data->provNsa);
                     if ($prov) {
                         $service = new Service();
                         $service->provider_id = $prov->id;
                         $service->type = $data->type;
                         $service->url = $data->url;
                         if ($service->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Provider not found";
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $this->error = "Invalid action";
                     break;
                 case self::TYPE_DELETE:
                     $service = Service::findOne($this->item_id);
                     if ($service) {
                         if ($service->delete()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Error deleting";
                         }
                     } else {
                         $this->error = "Service not found";
                     }
                     break;
             }
             break;
         case self::ITEM_TYPE_NETWORK:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $dom = Domain::findOneByName($this->domain);
                     if ($dom) {
                         $net = new Network();
                         $net->latitude = $data->lat;
                         $net->longitude = $data->lng;
                         $net->name = $data->name;
                         $net->urn = $data->urn;
                         $net->domain_id = $dom->id;
                         if ($net->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Domain not found";
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $net = Network::findOne($this->item_id);
                     if ($net) {
                         $net->latitude = $data->lat;
                         $net->longitude = $data->lng;
                         $net->name = $data->name;
                         if ($net->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Network not found";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $this->error = "In development";
                     break;
             }
             break;
         case self::ITEM_TYPE_DEVICE:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     //NECESSARIO pq o parser nao analisa esse caso VERIFICAR
                     /* $dev = Device::findOneByDomainAndNode($this->domain, $data->node);
                        if ($dev) {
                            $dev->latitude = $data->lat;
                            $dev->longitude = $data->lng;
                            $dev->address = $data->address;
                        } else {*/
                     //}
                     $dom = Domain::findOneByName($this->domain);
                     if ($dom) {
                         $dev = new Device();
                         $dev->domain_id = $dom->id;
                         $dev->latitude = $data->lat;
                         $dev->longitude = $data->lng;
                         $dev->node = $data->node;
                         $dev->name = $dev->node;
                         $dev->address = $data->address;
                         if ($dev->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             Yii::trace($dev->getErrors());
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = 'Domain not found';
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $dev = Device::findOne($this->item_id);
                     if ($dev) {
                         $dev->latitude = $data->lat;
                         $dev->longitude = $data->lng;
                         $dev->address = $data->address;
                         if ($dev->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             Yii::trace($dev->getErrors());
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = 'Device not found';
                     }
                     break;
                 case self::TYPE_DELETE:
                     $dev = Device::findOne($this->item_id);
                     if ($dev) {
                         if ($dev->delete()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = 'Fatal error. Contact the administrator.';
                         }
                     } else {
                         $this->error = 'Device not found';
                     }
             }
             break;
         case self::ITEM_TYPE_BIPORT:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $dev = Device::findOneByDomainAndNode($this->domain, $data->node);
                     if ($dev) {
                         $port = new Port();
                         $port->type = $data->type;
                         $port->directionality = Port::DIR_BI;
                         $port->urn = $data->urn;
                         $port->name = $data->name;
                         $port->max_capacity = $data->cap_max;
                         $port->min_capacity = $data->cap_min;
                         $port->granularity = $data->granu;
                         $port->vlan_range = $data->vlan;
                         $port->device_id = $dev->id;
                         if ($data->netUrn) {
                             $net = Network::findByUrn($data->netUrn)->one();
                             if ($net) {
                                 $port->network_id = $net->id;
                             }
                         }
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             Yii::trace($port->getErrors());
                             $this->error = "Unknown";
                         }
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         $port->name = $data->name;
                         $port->max_capacity = $data->cap_max;
                         $port->min_capacity = $data->cap_min;
                         $port->granularity = $data->granu;
                         $port->vlan_range = $data->vlan;
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             Yii::trace($port->getErrors());
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Port not found";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         if ($port->delete()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = 'Error deleting';
                         }
                     } else {
                         $this->error = 'Port not found';
                     }
             }
             break;
         case self::ITEM_TYPE_UNIPORT:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $dev = Device::findOneByDomainAndNode($this->domain, $data->node);
                     $biPortUrn = Port::findOne(['urn' => $data->biPortUrn]);
                     if ($dev && $biPortUrn) {
                         $port = new Port();
                         $port->type = Port::TYPE_NSI;
                         if ($data->dir == "IN") {
                             $port->directionality = Port::DIR_UNI_IN;
                         } else {
                             $port->directionality = Port::DIR_UNI_OUT;
                         }
                         $port->urn = $data->urn;
                         $port->name = $data->name;
                         $port->max_capacity = $data->cap_max;
                         $port->min_capacity = $data->cap_min;
                         $port->granularity = $data->granu;
                         $port->biport_id = $biPortUrn->id;
                         $port->vlan_range = $data->vlan;
                         $port->device_id = $dev->id;
                         if ($data->netUrn) {
                             $net = Network::findByUrn($data->netUrn)->one();
                             if ($net) {
                                 $port->network_id = $net->id;
                             }
                         }
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         $port->name = isset($data->name) ? $data->name : $port->name;
                         $port->max_capacity = isset($data->cap_max) ? $data->cap_max : null;
                         $port->min_capacity = isset($data->cap_min) ? $data->cap_min : null;
                         $port->granularity = isset($data->granu) ? $data->granu : null;
                         $port->vlan_range = isset($data->vlan) ? $data->vlan : null;
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Port not found";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         if ($port->delete()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = 'Error deleting port';
                         }
                     } else {
                         $this->error = 'Port not found';
                     }
             }
             break;
         case self::ITEM_TYPE_LINK:
             switch ($this->type) {
                 case self::TYPE_CREATE:
                     $port = Port::findOneByUrn($data->urn);
                     if ($port) {
                         $dstPort = Port::findOneByUrn($data->dst_urn);
                         if ($dstPort) {
                             $port->setAlias($dstPort);
                             if ($port->save()) {
                                 $this->setApplied();
                                 return $this->save();
                             } else {
                                 $this->error = "Unknown";
                             }
                         } else {
                             $this->error = 'Destination port not found';
                         }
                     } else {
                         $this->error = "Source port not found";
                     }
                     break;
                 case self::TYPE_UPDATE:
                     $port = Port::findOneByUrn($data->urn);
                     if ($port) {
                         $dstPort = Port::findOneByUrn($data->dst_urn);
                         if ($dstPort) {
                             $port->setAlias($dstPort);
                             if ($port->save()) {
                                 $this->setApplied();
                                 return $this->save();
                             } else {
                                 $this->error = "Unknown";
                             }
                         } else {
                             $this->error = 'Destination port not found';
                         }
                     } else {
                         $this->error = "Source port not found";
                     }
                     break;
                 case self::TYPE_DELETE:
                     $port = Port::findOne($this->item_id);
                     if ($port) {
                         $port->alias_id = null;
                         if ($port->save()) {
                             $this->setApplied();
                             return $this->save();
                         } else {
                             $this->error = "Unknown";
                         }
                     } else {
                         $this->error = "Source port not found";
                     }
             }
             break;
         default:
             break;
     }
     $this->status = self::STATUS_FAILED;
     $this->save();
     return false;
 }