예제 #1
0
파일: hosts.php 프로젝트: bjcpgd/palserve
function hosts_new()
{
    if ($_POST) {
        $h = new Host();
        $h->save($_POST);
        update_scan_script();
        render('show', $h->id);
    }
    render();
}
예제 #2
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $host = new Host($id);
         $host->from_array($_POST);
         $host->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('hosts');
 }
예제 #3
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Host();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Host'])) {
         $model->attributes = $_POST['Host'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
예제 #4
0
 /**
  * 录入
  *
  */
 public function actionCreate()
 {
     parent::_acl();
     $model = new Host();
     if (isset($_POST['Host'])) {
         $acl = $this->_gets->getPost('acl');
         $model->attributes = $_POST['Host'];
         if ($model->save()) {
             AdminLogger::_create(array('catalog' => 'create', 'intro' => '录入内容,ID:' . $model->id));
             $this->redirect(array('index'));
         }
     }
     $this->render('host_create', array('model' => $model));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Session::token() != Input::get('_token') || !Request::ajax()) {
         App::abort(401, 'You are not authorized or using wrong request type or csrf token not provided.');
     }
     // store
     $host = new Host();
     $host->name = Input::get('name');
     $host->host = Input::get('host');
     $host->parent = Input::get('parent');
     $host->type = Input::get('type');
     $host->storage = Input::get('path');
     $host->source = Input::get('source');
     $host->ssh_login = Input::get('ssh_login');
     $host->ssh_pwd = Input::get('ssh_pwd');
     $host->db_name = Input::get('db_name');
     $host->db_user = Input::get('db_user');
     $host->db_pwd = Input::get('db_pwd');
     $host->cron = Input::get('cron');
     $host->save();
     return "Host saved!";
 }
예제 #6
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($name = null, $ip = null, $mac = null)
 {
     $model = new Host();
     /* Set attributes by _GET */
     if (!is_null($name) && !isset($_POST['Host'])) {
         $model->name = (string) trim($name);
     }
     if (!is_null($ip) && !isset($_POST['Host'])) {
         $model->ip = (string) trim($ip);
     }
     if (!is_null($mac) && !isset($_POST['Host'])) {
         $model->mac = (string) trim($mac);
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Host'])) {
         $model->attributes = $_POST['Host'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /** import_post()
 		Actually imports the post.
 	*/
 public function import_post()
 {
     try {
         // Error checking
         if ($_FILES["file"]["error"] > 0) {
             throw new Exception(sprintf('Error: ' . (is_array($_FILES["file"]["error"]) ? implode(', ', $_FILES["file"]["error"]) : $_FILES["file"]["error"])));
         }
         if (!file_exists($_FILES["file"]["tmp_name"])) {
             throw new Exception('Could not find tmp filename');
         }
         $numSuccess = $numFailed = $numAlreadyExist = 0;
         $handle = fopen($_FILES["file"]["tmp_name"], "r");
         // Get all the service id's so they can be enabled.
         $ModuleIDs = $this->getClass('ModuleManager')->find('', '', '', '', '', '', '', 'id');
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             // Ignore header data if left in CSV
             if (preg_match('#ie#', $data[0])) {
                 continue;
             }
             $totalRows++;
             if (count($data) < 7 && count($data) >= 2) {
                 try {
                     // Error checking
                     $MACs = $this->parseMacList($data[0]);
                     $Host = $this->getClass('HostManager')->getHostByMacAddresses($MACs);
                     if ($Host && $Host->isValid()) {
                         throw new Exception('A Host with any or one of these MACs already exists');
                     }
                     if ($this->getClass('HostManager')->exists($data[1])) {
                         throw new Exception('A host with this name already exists');
                     }
                     $Host = new Host(array('name' => $data[1], 'description' => $data[3] . ' Uploaded by batch import on', 'ip' => $data[2], 'imageID' => $data[4], 'createdTime' => $this->nice_date()->format('Y-m-d H:i:s'), 'createdBy' => $this->FOGUser->get('name')));
                     $Host->addModule($ModuleIDs);
                     $Host->addPriMAC($MACs[0]);
                     array_shift($MACs);
                     $Host->addAddMAC($MACs);
                     if ($Host->save()) {
                         $this->HookManager->processEvent('HOST_IMPORT', array('data' => &$data, 'Host' => &$Host));
                         $numSuccess++;
                     } else {
                         $numFailed++;
                     }
                 } catch (Exception $e) {
                     $numFailed++;
                     $uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, $e->getMessage());
                 }
             } else {
                 $numFailed++;
                 $uploadErrors .= sprintf('%s #%s: %s<br />', _('Row'), $totalRows, _('Invalid number of cells'));
             }
         }
         fclose($handle);
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     // Title
     $this->title = _('Import Host Results');
     unset($this->headerData);
     $this->attributes = array(array(), array());
     $this->templates = array('${field}', '${input}');
     $fields = array(_('Total Rows') => $totalRows, _('Successful Hosts') => $numSuccess, _('Failed Hosts') => $numFailed, _('Errors') => $uploadErrors);
     foreach ((array) $fields as $field => $input) {
         $this->data[] = array('field' => $field, 'input' => $input);
     }
     // Hook
     $this->HookManager->processEvent('HOST_IMPORT_FIELDS', array('headerData' => &$this->headerData, 'data' => &$this->data, 'templates' => &$this->templates, 'attributes' => &$this->attributes));
     // Output
     $this->render();
 }
예제 #8
0
                        if ($Host->createImagePackage(1, 'AutoRegTask')) {
                            print _('Done, with imaging!');
                        } else {
                            print _('Done, but unable to create task!');
                        }
                    } else {
                        print _('Done!');
                    }
                } else {
                    $realhost = $macsimple;
                    if (!$Host || !$Host->isValid()) {
                        $Host = new Host(array('name' => $realhost, 'description' => sprintf('%s %s', _('Created by FOG Reg on'), date('F j, Y, g:i a')), 'createdTime' => $FOGCore->formatTime('now', 'Y-m-d H:i:s'), 'createdBy' => 'FOGREG'));
                        $Host->addPriMAC($PriMAC);
                        $Host->addAddMAC($MACs);
                        $Host->addModule($ids);
                        if (!$Host->save()) {
                            throw new Exception(_('Failed to save new Host!'));
                        }
                        print _('Done');
                    } else {
                        print _('Already registered as') . ': ' . $Host->get('name');
                    }
                }
            } else {
                print _('Already registered as') . ': ' . $Host->get('name');
            }
        }
    } catch (Exception $e) {
        print $e->getMessage();
    }
}
예제 #9
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'];
             if ($teacherModel->validate() && $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);
                 if ($studentModel->validate() && $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'];
                     //echo CActiveForm::validate($hostModel);
                     if ($hostModel->validate() && $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));
 }
예제 #10
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));
 }