示例#1
0
 public function clients($client = null)
 {
     $start = Input::get('start', Date::now()->sub('1 day'));
     $end = Input::get('end', Date::now());
     $clientselected = Input::get('Client', $client);
     $client = Client::where('clientid', '=', $clientselected)->first();
     $user = Sentry::getUser();
     // Get Clients to fill the Client Select Box And Select Values From Permissions
     $permissions = Userspermissions::where('id', '=', $user->id)->remember(10)->first();
     if ($permissions !== null) {
         $permissions = unserialize($permissions->clients);
         $clients = Client::wherein('clientid', $permissions)->remember(10)->get();
         $clientSelectBox = Client::clientSelectBox($clients->toArray());
     } else {
         $clientSelectBox = Client::clientSelectBox();
     }
     ///// End Permissions
     if ($client == Null) {
         $platform = "";
         $fileretension = "";
         $jobretension = "";
         $autoprune = "";
         $terminatedJobs = "0";
         $cancelJobs = "0";
         $runningJobs = "0";
         $wattingJobs = "0";
         $errorJobs = "0";
         // Indicates Failed and Okay Jobs
         $nTransBytes = "0";
         $nTransFiles = "0";
         $graphOkJob = "0";
         $graphFailedJob = "0";
     } else {
         $platform = $client->Uname;
         $autoprune = $client->AutoPrune;
         /* Calculate the Retension Period */
         $to = Date::now();
         $text = " Days";
         /* 86400  -> equal to seconds in i day*/
         $fileretension = $client->fileretention / 86400 . $text;
         if ($fileretension >= 365) {
             $type = ' Year';
             $fileretension = intval($fileretension / 31536000) . $type;
         }
         /* 86400  -> equal to seconds in i day*/
         $jobretension = $client->jobretention / 86400 . $text;
         if ($jobretension >= 365) {
             $type = ' Year';
             $jobretension = intval($jobretension / 31536000) . $type;
         }
         /* Get Terminated Jobs */
         $tjobs = Job::where('jobstatus', '=', 'T')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('clientid', '=', $client->clientid)->remember(10)->get();
         // Number Terminate Jobs
         $terminatedJobs = count($tjobs);
         /* Get Canceled Jobs */
         $canceledJobs = Job::where('jobstatus', '=', 'A')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('clientid', '=', $client->ClientId)->remember(10)->get();
         // Number Terminate Jobs
         $cancelJobs = count($canceledJobs);
         /* Get Canceled Jobs */
         $canceledJobs = Job::where('jobstatus', '=', 'A')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('clientid', '=', $client->ClientId)->remember(10)->get();
         // Number Terminate Jobs
         $cancelJobs = count($canceledJobs);
         /* Get Running Jobs */
         $runJobs = Job::where('jobstatus', '=', 'R')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('clientid', '=', $client->ClientId)->remember(10)->get();
         // Number Running Jobs
         $runningJobs = count($runJobs);
         /* Get Watting Jobs */
         $wateJobs = Job::wherein('jobstatus', array('c', 'F', 'j', 'M', 'm', 'p', 's', 't'))->where('endtime', '<=', $end)->where('starttime', '>=', $start)->where('clientid', '=', $client->ClientId)->remember(10)->get();
         // Number Watting Jobs
         $wattingJobs = count($wateJobs);
         /* Get Error Jobs */
         $errJobs = Job::wherein('jobstatus', array('e', 'f', 'E'))->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('clientid', '=', $client->ClientId)->remember(10)->get();
         // Number Error Jobs
         $errorJobs = count($errJobs);
         $nTransBytes = 0;
         $nTransFiles = 0;
         $terminatedJobs = count($tjobs);
         /* Calculate Jobs and Bytes */
         $tjobs = $tjobs->toArray();
         $nTransFiles = array_sum(array_fetch($tjobs, 'jobfiles'));
         $nTransBytes = array_sum(array_fetch($tjobs, 'jobbytes'));
         // Value for The Graphs
         $graphOkJob = $terminatedJobs != 0 ? $terminatedJobs / ($terminatedJobs + $errorJobs) * 100 : 0;
         $graphFailedJob = $errorJobs != 0 ? $errorJobs / ($errorJobs + $terminatedJobs) * 100 : 0;
         $nTransFiles = preg_replace("/(?<=\\d)(?=(\\d{3})+(?!\\d))/", ",", $nTransFiles);
         $nTransBytes = $this->byte_format($nTransBytes);
     }
     /* Draws Files Graph */
     $graphFiles = DB::table($this->tables['job'])->where('clientid', '=', $clientselected)->where('starttime', '>=', $start)->where('endtime', '<=', $end)->orderby('starttime', 'asc')->remember(10)->get(array(DB::raw('date(' . $this->tables['job'] . '.starttime) as date'), DB::raw('jobfiles as files')));
     $graphFiles = json_encode((array) $graphFiles);
     /* Draws Bytes Graph */
     $graphBytes = DB::table($this->tables['job'])->where('clientid', '=', $clientselected)->where('starttime', '>=', $start)->where('endtime', '<=', $end)->orderby('starttime', 'asc')->remember(10)->get(array(DB::raw('date(' . $this->tables['job'] . '.starttime) as date'), DB::raw('jobbytes as bytes')));
     $graphBytes = json_encode((array) $graphBytes);
     Former::populate(array('date' => $start . ' - ' . $end), array('Client' => $clientselected));
     return View::make('clients', array('terminatedJobs' => $terminatedJobs, 'nTransFiles' => $nTransFiles, 'cancelJobs' => $cancelJobs, 'runningJobs' => $runningJobs, 'wattingJobs' => $wattingJobs, 'errorJobs' => $errorJobs, 'nTransBytes' => $nTransBytes, 'start' => $start, 'end' => $end, 'type' => 'terminated', 'clientSelected' => $clientselected, 'graphOkJob' => $graphOkJob, 'graphFailedJob' => $graphFailedJob, 'platform' => $platform, 'fileretension' => $fileretension, 'jobretension' => $jobretension, 'autoprune' => $autoprune, 'clientSelectBox' => $clientSelectBox, 'graphFiles' => $graphFiles, 'graphBytes' => $graphBytes));
 }
示例#2
0
 public function saveuser()
 {
     /* Get Post */
     $userpost = Input::all();
     /* Rules Edit Form */
     $rules = array('email' => 'required|email', 'password' => 'required|max:50');
     /* Validation settings */
     $validation = Validator::make($userpost, $rules);
     if ($validation->fails()) {
         //failed to validate
         //let's go back to that form with errors, input
         $messages = $validation->messages();
         $html = '<div class="alert alert-error">';
         foreach ($messages->all() as $message) {
             $html .= ' ' . $message . '<br>';
         }
         $html .= '</div>';
         Former::withErrors($validation);
         echo json_encode(array('html' => $html));
     } else {
         try {
             /* If Has Id is Update Else is Insert */
             if (Input::has('id')) {
                 $id = Input::get('id');
                 // Find the user using the user id
                 $user = Sentry::getUserProvider()->findById(Input::get('id'));
                 $user->email = Input::get('email');
                 $user->password = Input::get('password');
                 $user->first_name = Input::get('first_name', '');
                 $user->last_name = Input::get('last_name', '');
                 // Get the user groups
                 $groupsOriginal = $user->getGroups();
                 // Remove All Ther Original From The User
                 foreach ($groupsOriginal as $group) {
                     $adminGroupRemove = Sentry::getGroupProvider()->findById($group->id);
                     $user->removeGroup($adminGroupRemove);
                 }
                 // Add the new Groups to the user
                 foreach (Input::get('usergroups') as $group) {
                     // Find the group using the group id
                     $adminGroupAdd = Sentry::getGroupProvider()->findById($group);
                     // Assign the group to the user
                     $user->addGroup($adminGroupAdd);
                 }
                 // Update the user
                 if ($user->save()) {
                     echo json_encode(array('html' => '<div class="alert alert-success"> User Sucessufull Updated </div> '));
                 } else {
                     echo json_encode(array('html' => '<div class="alert alert-error"> Error </div> '));
                 }
             } else {
                 /* Insert User on Database */
                 $user = Sentry::getUserProvider()->create(array('email' => Input::get('email'), 'password' => Input::get('password'), 'first_name' => Input::get('first_name', ''), 'last_name' => Input::get('last_name', ''), 'activated' => '1'));
                 $id = $user->getId();
                 if (Input::has('usergroups')) {
                     foreach (Input::get('usergroups') as $group) {
                         // Find the group using the group id
                         $adminGroup = Sentry::getGroupProvider()->findById($group);
                         // Assign the group to the user
                         $user->addGroup($adminGroup);
                     }
                 } else {
                     // Find the group using the group id
                     $adminGroup = Sentry::getGroupProvider()->findById(1);
                     // Assign the group to the user
                     $user->addGroup($adminGroup);
                 }
                 echo json_encode(array('html' => '<div class="alert alert-success"> User Sucessufull Created </div> '));
             }
             /* Permissions */
             $permissions = Userspermissions::find($id);
             if ($permissions != null) {
                 $permissions->delete();
             }
             $permissions = new Userspermissions();
             $permissions->id = $id;
             //$vd= new VD;
             //$vd->dump(Input::get('userClients'));
             // var_dump(serialize(Input::get('userClients')));
             $permissions->clients = serialize(Input::get('userClients'));
             $permissions->jobs = serialize(Input::get('userJobs'));
             $permissions->save();
         } catch (\Exception $e) {
             // Log::info( $e->getMessage() );
             echo json_encode(array('html' => '<div class="alert alert-error">' . $e->getMessage() . ' </div> '));
         }
     }
 }
示例#3
0
 public function jobs($job = null)
 {
     Asset::container('footer')->add('amcharts', 'assets/js/amcharts.js');
     Asset::container('footer')->add('jobs', 'assets/js/jobs.js');
     $start = Input::get('start', Date::now()->sub('1 day'));
     $end = Input::get('end', Date::now());
     $jobselected = Input::get('Job', $job);
     if (empty($jobselected)) {
         $jobselected = 0;
     } else {
         $jobselected = Job::select('name')->where('jobid', '=', $jobselected)->remember(10)->get();
         $jobselected = $jobselected->first()->name;
         /* Array Search for Get Id and set the select box when passing url id of job*/
         $job = array_search($jobselected, Job::jobSelectBox());
     }
     $user = Sentry::getUser();
     // Get Clients to fill the Client Select Box And Select Values From Permissions
     $permissions = Userspermissions::where('id', '=', $user->id)->first();
     if ($permissions !== null) {
         $permissions = unserialize($permissions->jobs);
         $jobs = Job::wherein('jobid', $permissions)->remember(10)->get();
         $jobsSelectBox = Job::jobSelectBox($jobs->toArray());
     } else {
         $jobsSelectBox = Job::jobSelectBox();
     }
     ///// End Permissions
     /* Get Included Files & Excluded Files Configuration */
     $cfgjob = "";
     //cfgJob::wherename($jobselected)->first();
     if ($cfgjob != "") {
         $cfgfileset = cfgFileset::wherename($cfgjob->fileset)->remember(10)->first();
         $fileinclude = cfgFileset::find($cfgfileset->id)->filesinclude()->remember(10)->get();
         $fileexclude = cfgFileset::find($cfgfileset->id)->filesexclude()->remember(10)->get();
     } else {
         $fileinclude = "";
         $fileexclude = "";
     }
     ///////////////////////////
     /* Get Terminated Jobs */
     $tjobs = Job::where('jobstatus', '=', 'T')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('name', '=', $jobselected)->remember(10)->get();
     //dd ($tjobs);
     // Number Terminate Jobs
     $terminatedJobs = count($tjobs);
     /* Get Canceled Jobs */
     $canceledJobs = Job::where('jobstatus', '=', 'A')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('name', '=', $jobselected)->remember(10)->get();
     // Number Terminate Jobs
     $cancelJobs = count($canceledJobs);
     /* Get Running Jobs */
     $runJobs = Job::where('jobstatus', '=', 'R')->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('name', '=', $jobselected)->remember(10)->get();
     // Number Running Jobs
     $runningJobs = count($runJobs);
     /* Get Watting Jobs */
     $wateJobs = Job::wherein('jobstatus', array('c', 'F', 'j', 'M', 'm', 'p', 's', 't'))->where('endtime', '<=', $end)->where('starttime', '>=', $start)->where('name', '=', $jobselected)->remember(10)->get();
     // Number Watting Jobs
     $wattingJobs = count($wateJobs);
     /* Get Error Jobs */
     $errJobs = Job::wherein('jobstatus', array('e', 'f', 'E'))->where('starttime', '>=', $start)->where('endtime', '<=', $end)->where('name', '=', $jobselected)->remember(10)->get();
     // Number Error Jobs
     $errorJobs = count($errJobs);
     // Indicates Failed and Okay Jobs
     $nTransBytes = 0;
     $nTransFiles = 0;
     $terminatedJobs = count($tjobs);
     /* Calculate Jobs and Bytes */
     $tjobs = $tjobs->toArray();
     if (Config::get('database.default') == 'pgsql') {
         $nTransFiles = array_sum(array_fetch($tjobs, 'jobfiles'));
         $nTransBytes = array_sum(array_fetch($tjobs, 'jobbytes'));
     } else {
         $nTransFiles = array_sum(array_fetch($tjobs, 'JobFiles'));
         $nTransBytes = array_sum(array_fetch($tjobs, 'JobBytes'));
     }
     /* Draw GRaphs */
     $graphBytes = DB::table($this->tables['job'])->where('name', '=', $jobselected)->where('starttime', '>=', $start)->where('endtime', '<=', $end)->orderby('starttime', 'asc')->remember(10)->get(array(DB::raw('date(' . $this->tables['job'] . '.starttime) as date'), DB::raw('jobbytes as bytes')));
     $graphBytes = json_encode((array) $graphBytes);
     $graphFiles = DB::table($this->tables['job'])->where('name', '=', $jobselected)->where('starttime', '>=', $start)->where('endtime', '<=', $end)->orderby('starttime', 'asc')->remember(10)->get(array(DB::raw('date(' . $this->tables['job'] . '.starttime) as date'), DB::raw('jobfiles as files')));
     $graphFiles = json_encode((array) $graphFiles);
     // var_dump($graphFiles);
     Former::populate(array('date' => $start . ' - ' . $end));
     //array('Job' => $jobselected) );
     return View::make('jobs', array('terminatedJobs' => $terminatedJobs, 'nTransFiles' => preg_replace("/(?<=\\d)(?=(\\d{3})+(?!\\d))/", ",", $nTransFiles), 'cancelJobs' => $cancelJobs, 'runningJobs' => $runningJobs, 'wattingJobs' => $wattingJobs, 'errorJobs' => $errorJobs, 'nTransBytes' => $this->byte_format($nTransBytes), 'start' => $start, 'end' => $end, 'job' => $job, 'type' => 'terminated', 'graphOkJob' => $terminatedJobs != 0 ? $terminatedJobs / ($terminatedJobs + $errorJobs) * 100 : 0, 'graphFailedJob' => $errorJobs != 0 ? $errorJobs / ($errorJobs + $terminatedJobs) * 100 : 0, 'filesinclude' => $fileinclude, 'filesexclude' => $fileexclude, 'jobSelectBox' => $jobsSelectBox, 'graphBytes' => $graphBytes, 'graphFiles' => $graphFiles));
 }