示例#1
0
 public function getConverted_name()
 {
     switch ($this->ctype) {
         case 'host':
             $host = Host::model()->findByPk($this->name);
             return $host !== null && $host->short ? $host->short : $host->fqdn;
         default:
             return $this->name;
     }
 }
示例#2
0
 /**
  * Logs in the user using the given username and password in the model.
  * @return boolean whether login is successful
  */
 public function searchResult()
 {
     $result = array();
     $hosts = Host::model()->findAllByAttributes(array('id' => $this->hosts));
     switch ($this->type) {
         case "camtable_mac":
             $search_table = 'camtable';
             $search_field = 'mac';
             break;
         case "camtable_vlan":
             $search_table = 'camtable';
             $search_field = 'vlan_tag';
             break;
     }
     if (count($hosts) && $search_table == 'camtable') {
         foreach ($hosts as $host) {
             $host->loadCamTable();
             foreach ($host->cam_table as $row) {
                 if ($this->exact_match) {
                     $found = $row[$search_field] == $this->query;
                 } else {
                     $found = strpos($row[$search_field], $this->query) !== FALSE;
                 }
                 if ($found) {
                     $hostDst = $host->getHostOnPort($row['port']);
                     if ($this->exclude_link_ports && !empty($hostDst)) {
                         continue;
                     }
                     $row['host'] = $host;
                     $row['hostDst'] = $hostDst;
                     $row['vlan'] = Vlan::model()->findByAttributes(array('tag' => $row['vlan_tag']));
                     $result[] = $row;
                 }
             }
         }
     }
     return $result;
 }
 protected function setHostFaceOnHosts($model, $host_ids)
 {
     /* unset old hosts */
     foreach ($model->hosts as $host) {
         if ($host instanceof Host) {
             $host->host_face_id = null;
             $host->save();
         }
     }
     /* set new hosts */
     $hosts = Host::model()->findAllByPk($host_ids);
     foreach ($hosts as $host) {
         if ($host instanceof Host) {
             $host->host_face_id = $model->id;
             $host->save();
         }
     }
 }
示例#4
0
echo $form->labelEx($model, 'svg');
?>
		<?php 
echo $form->textArea($model, 'svg', array('rows' => 6, 'cols' => 50));
?>
		<?php 
echo $form->error($model, 'svg');
?>
	</div>
        
	<div class="row">
		<?php 
echo $form->labelEx($model, 'hosts');
?>
                <?php 
echo $form->dropDownList($model, 'hosts', CHtml::listData(Host::model()->findAll(), 'id', 'name', 'type'), array('empty' => '', 'multiple' => 'multiple', 'size' => 15));
?>
		<?php 
echo $form->error($model, 'hosts');
?>
	</div>

	<div class="row buttons">
		<?php 
echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');
?>
	</div>

<?php 
$this->endWidget();
?>
示例#5
0
 public function actionPassword()
 {
     $model = new HostChangePassword();
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') {
         echo CActiveForm::validate($model);
         Yii::app()->end();
     }
     if (isset($_POST['HostChangePassword'])) {
         $model->attributes = $_POST['HostChangePassword'];
         if ($model->validate()) {
             $new_password = Host::model()->findbyPk($this->_user['hostId']);
             $new_password->password = $model->password;
             $new_password->verifyPassword = $model->password;
             $new_password->save();
             Yii::app()->user->setFlash('msg', '保存成功');
         }
     }
     $this->render('password', array('model' => $model));
 }
示例#6
0
 /**
  * Displays connections of Host.
  */
 public function actionArpTable()
 {
     try {
         if (isset($_GET['id'])) {
             $model = $this->loadModel((int) $_GET['id']);
         } else {
             if (isset($_GET['name'])) {
                 $model = $this->loadModelByName((string) $_GET['name']);
             }
         }
         $model->loadArpTable();
         foreach ($model->arp_table as $mac => $ip) {
             $atItem['mac'] = $mac;
             $atItem['ip'] = $ip;
             $atItem['host'] = $mac ? Host::model()->findByAttributes(array('mac' => $mac)) : null;
             $arp_table[] = $atItem;
         }
         $this->render('arpTable', array('model' => $model, 'arp_table' => $arp_table));
     } catch (CHttpException $e) {
         if (isset($_GET['name'])) {
             $name = (string) trim($_GET['name']);
             $this->render('addHostNotFound', array('name' => $name));
         } else {
             throw new CHttpException(404, 'The requested page does not exist.');
         }
     }
 }
示例#7
0
 public function actionListHosts()
 {
     $this->layout = '//layouts/json';
     try {
         if (isset($_GET['hostId'])) {
             $hostId = (int) $_GET['hostId'];
             // get root host
             //
             $rootHost = $hosts[] = Host::model()->findbyPk($hostId);
             // get connections
             $hostConnections = $rootHost->getConnections();
             // get host from connections
             foreach ($hostConnections as $hosts_conn) {
                 array_push($hosts, $hosts_conn->hostDst);
             }
             // in switches, get hosts by CAM table
             if ($rootHost->type == Host::TYPE_SWITCH) {
                 $rootHost->loadCamTable();
                 // TODO: associar roteadores aos switches para pegar a
                 // tabela ARP dos gateways da rede
                 //
                 $gateway = Host::model()->findByPk(Yii::app()->params['hostGatewayId']);
                 //                    $arpTable = array();
                 foreach ($rootHost->cam_table as $k => $camHost) {
                     // se existir conexao cadastrada para a porta, ignore o host
                     // TODO: usar tipo do link==backbone
                     $hostOnPort = $rootHost->getHostOnPort($camHost['port']);
                     if ($hostOnPort instanceof Host && $hostOnPort->type != Host::TYPE_UNKNOWN) {
                         continue;
                     }
                     // havendo 2 ou + hosts numa porta sem conexao cadastrada, criar 'hub virtual'
                     $port = $camHost['port'];
                     $portLabelPrefix = 'port_';
                     if ($port == $rootHost->cam_table[$k + 1]['port'] || $sourcePort == $portLabelPrefix . $port) {
                         $sourcePort = $portLabelPrefix . $port;
                         if (!isset($virtualHost[$sourcePort])) {
                             $virtualHost[$sourcePort] = new Host();
                             $virtualHost[$sourcePort]->name = $sourcePort;
                             $virtualHost[$sourcePort]->type = Host::TYPE_SUPPOSED_HUB;
                             array_push($hosts, $virtualHost[$sourcePort]);
                             $virtualConn[$sourcePort] = new Connection();
                             $virtualConn[$sourcePort]->hostSrc = $rootHost;
                             $virtualConn[$sourcePort]->hostDst = $virtualHost[$sourcePort];
                             $virtualConn[$sourcePort]->host_src_port = $camHost['port'];
                             $virtualConn[$sourcePort]->type = Connection::TYPE_SUPPOSED_LINK;
                             // TODO: especificar tipo do link
                             array_push($hostConnections, $virtualConn[$sourcePort]);
                         }
                     } else {
                         unset($sourcePort);
                     }
                     // host
                     $host = Host::model()->findByAttributes(array('mac' => $camHost['mac']));
                     if ($host instanceof Host) {
                         $h = $host;
                     } else {
                         $h = new Host();
                         $h->mac = $camHost['mac'];
                         $h->ip = $gateway instanceof Host ? $gateway->getIpInArpTable($camHost['mac']) : null;
                         $h->name = $h->ip ? $h->ip : $h->mac;
                         $h->setTypeByMAC();
                     }
                     array_push($hosts, $h);
                     // connection
                     $c = new Connection();
                     $c->hostSrc = $virtualHost[$sourcePort] ? $virtualHost[$sourcePort] : $rootHost;
                     $c->hostDst = $h;
                     $c->host_src_port = $camHost['port'];
                     $c->type = Connection::TYPE_UNKNOWN;
                     // vlan
                     $c->vlan = Vlan::model()->findByAttributes(array('tag' => $camHost['vlan_tag']));
                     if (!$c->vlan instanceof Vlan) {
                         $c->vlan = new Vlan();
                         $c->vlan->tag = $camHost['vlan_tag'];
                     }
                     array_push($hostConnections, $c);
                 }
             }
         } else {
             $hosts = Host::model()->findAll(array('order' => 'id'));
             $hostConnections = Connection::model()->findAll();
         }
         $this->render('listHosts', array('hosts' => $hosts, 'hostConnections' => $hostConnections));
     } catch (Exception $exc) {
         $this->render('error', array('error' => "listHosts error:" . $exc->getMessage()));
     }
 }
示例#8
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  *
  * @param
  *          integer the ID of the model to be loaded
  *          
  */
 public function loadModel($id)
 {
     $model = Host::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#9
0
 /**
  * Verify Old Password
  */
 public function verifyOldPassword($attribute, $params)
 {
     if (Host::model()->findByPk(Yii::app()->controller->_user['hostId'])->password != $this->hashPassword($this->{$attribute})) {
         $this->addError($attribute, "原密码不正确.");
     }
 }
示例#10
0
<?php

return array('elements' => array('adminEmail' => array('type' => 'text'), 'translateCamTable' => array('type' => 'checkbox'), 'hostGatewayId' => array('type' => 'dropdownlist', 'items' => CHtml::listData(Host::model()->findAll(), 'id', 'name', 'type')), 'cache' => array('type' => 'checkbox'), 'cacheTtlCam' => array('type' => 'text'), 'cacheTtlArp' => array('type' => 'text'), 'cacheTtlGetSnmp' => array('type' => 'text'), 'cacheTtlDefault' => array('type' => 'text')), 'buttons' => array('submit' => array('type' => 'submit', 'value' => Yii::t('default', 'Save'))));
示例#11
0
<?php

return array('elements' => array('type' => array('type' => 'dropdownlist', 'items' => SearchForm::getSearchTypes()), 'hosts' => array('type' => 'dropdownlist', 'items' => CHtml::listData(Host::model()->findAll(), 'id', 'name', 'type'), 'multiple' => 'multiple', 'size' => '20'), 'query' => array('type' => 'text'), 'exact_match' => array('type' => 'checkbox'), 'exclude_link_ports' => array('type' => 'checkbox')), 'buttons' => array('submit' => array('type' => 'submit', 'value' => Yii::t('default', 'Search'))));
示例#12
0
 public function actionReview()
 {
     $message = false;
     $place = Place::model()->findByPk($_GET['id']);
     $host = Host::model()->findByPk($place['host_id']);
     $model = PlaceReview::model()->findByAttributes(array('place_id' => $_GET['id'], 'teacher_id' => $this->_user['masterId']));
     if (!count($model)) {
         $model = new PlaceReview();
     }
     if (isset($_POST['PlaceReview'])) {
         $model->attributes = $_POST['PlaceReview'];
         $model->place_id = $_GET['id'];
         $model->teacher_id = $this->_user['masterId'];
         if ($model->save()) {
             $message = true;
         }
     }
     $this->render('review', array('place' => $place, 'host' => $host, 'message' => $message, 'model' => $model));
 }
示例#13
0
?>

                <select id="Connection_host_src_id_port_list">
                    <option> -- selecione <?php 
echo $form->labelEx($model, 'host_src_id');
?>
 -- </option>
                </select>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'host_dst_id');
?>
                <?php 
echo $form->dropDownList($model, 'host_dst_id', CHtml::listData(Host::model()->findAll(), 'id', 'name', 'type'), array('empty' => ''));
?>
		<?php 
echo $form->error($model, 'host_dst_id');
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'host_dst_port');
?>
		<?php 
echo $form->textField($model, 'host_dst_port', array('size' => 4, 'maxlength' => 100));
?>
		<?php 
echo $form->error($model, 'host_dst_port');
示例#14
0
 /**
  * 首页
  */
 public function actionIndex()
 {
     $teacherModel = new Teacher();
     $studentModel = new Student();
     $hostModel = new Host();
     if (XUtils::method() == 'POST') {
         /*switch($_POST){
         				case isset($_POST['Teacher']): $nowModel = new Teacher; $nowAttributes = $_POST['Teacher']; $nowRedirect = '/master';  break;
         				case isset($_POST['Student']): $nowModel = new Student; $nowAttributes = $_POST['Student']; $nowRedirect = '/student/info/sinfo'; break;
         				case isset($_POST['Host']): $nowModel = new Host; $nowAttributes = $_POST['Host']; $nowRedirect = '/host/default/Info'; break;
         				default: $nowModel = 0;
         			}
         			if($nowModel){
         				$nowModel->attributes = $nowAttributes;
         
         
                         if ($nowModel->validate() && $nowModel->save()) {
         
                             parent::_stateWrite(
                                     array(
                                 'masterId' => $nowModel->id,
         						
                                 'name' => $nowModel->name,
                                     ), array('prefix' => '_master')
                             );
         
                             $cookie = new CHttpCookie('userName', $nowModel->name);
                             Yii::app()->request->cookies['userName'] = $cookie;
                             $this->redirect(array($nowRedirect));
                         }
         			}*/
         if (isset($_POST['Teacher'])) {
             $teacherModel->attributes = $_POST['Teacher'];
             $studentUser = Student::model()->countByAttributes(array('user' => $teacherModel->user));
             $hostUser = Host::model()->countByAttributes(array('user' => $teacherModel->user));
             //echo CActiveForm::validate($hostModel);
             //判断账号与其他角色账号是否相同
             if ($studentUser != 0 || $hostUser != 0) {
                 Yii::app()->user->setFlash('TeacherUserError', '您的手机号已在其他角色注册');
             }
             $tAgree = Yii::app()->request->getPost('teacherAgree');
             if ($tAgree === NULL) {
                 Yii::app()->user->setFlash('teacherAgreeMessage', '同意条款未勾选');
             }
             if ($teacherModel->validate() && $studentUser == 0 && $hostUser == 0 && $tAgree === 'on' && $teacherModel->save()) {
                 parent::_stateWrite(array('masterId' => $teacherModel->id, 'name' => $teacherModel->name), array('prefix' => '_master'));
                 if ($teacherModel->name == '') {
                     $teacherModel->name = '导师';
                 }
                 $cookie = new CHttpCookie('userName', $teacherModel->name);
                 Yii::app()->request->cookies['userName'] = $cookie;
                 $this->_cookiesSet('userId', $teacherModel->id);
                 $this->_cookiesSet('userType', 'student');
                 Yii::app()->user->setFlash('TSSuccess', '注册成功!请完善个人信息并提交身份认证即可发布课程');
                 $this->redirect(array('/master'));
             }
         } else {
             if (isset($_POST['Student'])) {
                 $studentModel->attributes = $_POST['Student'];
                 //echo CActiveForm::validate($studentModel);
                 $teacherUser = Teacher::model()->countByAttributes(array('user' => $studentModel->user));
                 $hostUser = Host::model()->countByAttributes(array('user' => $studentModel->user));
                 //echo CActiveForm::validate($hostModel);
                 //判断账号与其他角色账号是否相同
                 if ($teacherUser != 0 || $hostUser != 0) {
                     Yii::app()->user->setFlash('StudentUserError', '您的手机号已在其他角色注册');
                 }
                 $sAgree = Yii::app()->request->getPost('studentAgree');
                 if ($sAgree === NULL) {
                     Yii::app()->user->setFlash('studentAgreeMessage', '同意条款未勾选');
                 }
                 $studentModel->register_time = date('Y-m-d H:m:s', time());
                 if ($studentModel->validate() && $teacherUser == 0 && $hostUser == 0 && $sAgree === 'on' && $studentModel->save()) {
                     parent::_stateWrite(array('studentId' => $studentModel->id, 'name' => $studentModel->name), array('prefix' => '_student'));
                     if ($studentModel->name == '') {
                         $studentModel->name = '学员';
                     }
                     $cookie = new CHttpCookie('userName', $studentModel->name);
                     Yii::app()->request->cookies['userName'] = $cookie;
                     $this->_cookiesSet('userId', $studentModel->id);
                     $this->_cookiesSet('userType', 'student');
                     $this->redirect(array('/student/info/sinfo'));
                 }
             } else {
                 if (isset($_POST['Host'])) {
                     $hostModel->attributes = $_POST['Host'];
                     $teacherUser = Teacher::model()->countByAttributes(array('user' => $hostModel->user));
                     $studentUser = Student::model()->countByAttributes(array('user' => $hostModel->user));
                     //echo CActiveForm::validate($hostModel);
                     //判断账号与其他角色账号是否相同
                     if ($studentUser != 0 || $teacherUser != 0) {
                         Yii::app()->user->setFlash('HostUserError', '您的手机号已在其他角色注册');
                     }
                     $hAgree = Yii::app()->request->getPost('hostAgree');
                     if ($hAgree === NULL) {
                         Yii::app()->user->setFlash('hostAgreeMessage', '同意条款未勾选');
                     }
                     if ($hostModel->validate() && $studentUser == 0 && $teacherUser == 0 && $hAgree === 'on' && $hostModel->save()) {
                         parent::_stateWrite(array('hostId' => $hostModel->id, 'name' => $hostModel->name), array('prefix' => '_host'));
                         if ($hostModel->name == '') {
                             $hostModel->name = '场地主';
                         }
                         $cookie = new CHttpCookie('userName', $hostModel->name);
                         Yii::app()->request->cookies['userName'] = $cookie;
                         $this->_cookiesSet('userId', $hostModel->id);
                         $this->_cookiesSet('userType', 'host');
                         $this->redirect(array('/host'));
                     }
                 }
             }
         }
     }
     $this->render('index', array('teacherModel' => $teacherModel, 'studentModel' => $studentModel, 'hostModel' => $hostModel));
 }