Beispiel #1
0
 public function actionManage()
 {
     // TODO add check owner
     $id = Yii::app()->user->getId();
     if (isset($_POST['CamsForm']) && !empty($_POST['CamsForm']) && array_sum($_POST['CamsForm']) != 0) {
         if (isset($_POST['doubleShare'])) {
             Yii::app()->user->setFlash('share', $_POST['CamsForm']);
             $this->redirect($this->createUrl('cams/share', array('type' => 'dshare')));
             Yii::app()->end();
         }
         if (isset($_POST['doubleAssign'])) {
             Yii::app()->user->setFlash('share', $_POST['CamsForm']);
             $this->redirect($this->createUrl('cams/share', array('type' => 'dassign')));
             Yii::app()->end();
         }
         if (isset($_POST['share'])) {
             Yii::app()->user->setFlash('share', $_POST['CamsForm']);
             $this->redirect(array('share'));
             Yii::app()->end();
         }
         if (isset($_POST['assign'])) {
             Yii::app()->user->setFlash('share', $_POST['CamsForm']);
             $this->redirect($this->createUrl('cams/share', array('type' => 'assign')));
             Yii::app()->end();
         }
         foreach ($_POST['CamsForm'] as $key => $cam) {
             if ($cam) {
                 $key = explode('_', $key);
                 $key[2] = Cams::model()->getRealId($key[1]);
                 if ($key[0] == 'shcam') {
                     $cam = Shared::model()->findByPK((int) $key[1]);
                 } elseif ($key[0] == 'pcam') {
                     $cam = Shared::model()->findByAttributes(array('cam_id' => $key[2], 'user_id' => $id, 'is_public' => '1'));
                     if (!$cam) {
                         $cam = new Shared();
                         $cam->owner_id = Cams::model()->findByPK($key[2])->user_id;
                         $cam->user_id = $id;
                         $cam->cam_id = $key[2];
                         $cam->show = 1;
                         $cam->is_public = 1;
                     }
                 } else {
                     $cam = Cams::model()->findByPK($key[2]);
                 }
                 if (!$cam) {
                     continue;
                 }
                 if (isset($_POST['show'])) {
                     $cam->show = $cam->show ? 0 : 1;
                     if ($cam->save()) {
                         Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('cams', 'Cams settings changed')));
                     }
                 } elseif (isset($_POST['del'])) {
                     if ($key[0] == 'shcam') {
                         if ($cam->delete()) {
                             Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('cams', 'Cams successfully deleted')));
                         }
                     } else {
                         $momentManager = new momentManager($cam->server_id);
                         if ($cam->delete()) {
                             $momentManager->delete($cam);
                             Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('cams', 'Cams successfully deleted')));
                         }
                     }
                 } elseif (isset($_POST['record'])) {
                     $cam->record = $cam->record ? 0 : 1;
                     $momentManager = new momentManager($cam->server_id);
                     $momentManager->rec($cam->record == 1 ? 'on' : 'off', $cam->id);
                     if ($cam->save()) {
                         Yii::app()->user->setFlash('notify', array('type' => 'success', 'message' => Yii::t('cams', 'Cams settings changed')));
                     }
                 }
             }
         }
         $this->refresh();
         Yii::app()->end();
     } elseif (isset($_POST['show']) || isset($_POST['del']) || isset($_POST['share']) || isset($_POST['assign'])) {
         Yii::app()->user->setFlash('notify', array('type' => 'warning', 'message' => Yii::t('cams', 'You must choose cams to modify')));
     }
     $public = array();
     $publicAll = Cams::model()->findAllByAttributes(array('is_public' => 1));
     $shared = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 0, 'is_approved' => 1));
     foreach ($shared as $key => $value) {
         if (!isset($value->cam->id)) {
             $value->delete();
             unset($shared[$key]);
         }
     }
     $publicEdited = Shared::model()->findAllByAttributes(array('user_id' => $id, 'is_public' => 1), array('index' => 'cam_id'));
     foreach ($publicAll as $cam) {
         if (isset($publicEdited[$cam->id])) {
             $public[] = $publicEdited[$cam->id];
         } else {
             $public[] = $cam;
         }
     }
     $this->render('list', array('form' => new CamsForm(), 'myCams' => Cams::model()->findAllByAttributes(array('user_id' => $id)), 'mySharedCams' => $shared, 'myPublicCams' => $public));
 }
Beispiel #2
0
 public function actionStat($type, $id)
 {
     Yii::import('ext.moment.index', 1);
     $momentManager = new momentManager($id);
     $stat = $momentManager->stat($type);
     //print_r($stat);
     if (empty($stat)) {
         $this->render('stat/index', array('title' => Yii::t('admin', 'Statistics not avaiable'), 'stat' => array(), 'type' => $type, 'id' => $id));
         Yii::app()->end();
     }
     switch ($type) {
         case 'disk':
             $stat = json_decode($stat, 1);
             foreach ($stat as $k => $s) {
                 foreach ($s['disk info'] as $key => $value) {
                     $s['disk info'][$key] = $this->convertSize($value);
                 }
                 $stat[$k] = $s;
             }
             $all = $stat;
             break;
         case 'rtmp':
             $all = str_replace(array('<html><body>', '</html></body>'), '', $stat);
             break;
         case 'load':
             $stat = json_decode($stat, 1);
             $all = array();
             $stat = array_reverse($stat['statistics']);
             $stat = array_slice($stat, 0, 100);
             $stat = array_reverse($stat);
             foreach ($stat as $key => $value) {
                 $all['time'][] = $value['time'];
                 foreach ($value as $k => $v) {
                     if ($k == 'time') {
                         continue;
                     }
                     if ($k == 'rtmp_sessions') {
                         $all['rtmp_sessions']['sessions'][] = (double) $v;
                         continue;
                     }
                     if ($k == 'HDD utilization') {
                         foreach ($v as $t) {
                             $all['hdd'][$t['device']][] = (double) $t['util'];
                         }
                         continue;
                     }
                     $all[$k]['min'][] = (double) $v['min'];
                     $all[$k]['max'][] = (double) $v['max'];
                     $all[$k]['avg'][] = (double) $v['avg'];
                 }
             }
             break;
         case 'source_info':
             print_r($stat);
             return true;
             break;
         default:
             $all = array();
             break;
     }
     $this->render('stat/index', array('title' => Yii::t('admin', 'Statistics(100 recent changes)'), 'stat' => $all, 'type' => $type, 'id' => $id));
 }