/**
  * Returns an array of parameter values of a phone
  */
 public static function astPhoneParameterValuesToArray($astPhone)
 {
     $valuesArray = array();
     $values = astPhoneParameterValueModel::where('PHONE_ID', '=', $astPhone->PHONE_ID)->get();
     foreach ($values as $value) {
         $valuesArray[$value->parameter->NAME] = $value->VALUE;
     }
     return $valuesArray;
 }
Ejemplo n.º 2
0
 /**
  * Transfer the XML file with overwrite.
  */
 public function transferXMLOverwrite($id)
 {
     // create file
     $astPhone = astPhoneModel::findOrFail($id);
     $template = $astPhone->phoneTemplate->TEMPLATE;
     $values = astPhoneParameterValueModel::where('PHONE_ID', '=', $id)->get();
     // place the parameter values into the template
     foreach ($values as $value) {
         $template = str_replace('_' . $value->parameter->NAME . '_', $value->VALUE, $template);
     }
     $filename = $astPhone->phoneModel->PSN . '-' . $astPhone->MAC . '.cnf.xml';
     $filepath = 'documents/ast_xml/' . $filename;
     $outfile = fopen($filepath, "w");
     fwrite($outfile, $template);
     fclose($outfile);
     $serverIP = $astPhone->phoneLocation->SERVER_IP;
     // file transfer
     // Remote File Name and Path
     $remote_file = '/tftpboot/' . $filename;
     // FTP Account (Remote Server)
     $ftp_host = $serverIP;
     // host
     $ftp_user_name = session()->get('astServerUsername');
     // username
     $ftp_user_pass = session()->get('astServerPassword');
     // password
     session()->forget('astServerUsername');
     session()->forget('astServerPassword');
     // Connect using basic FTP
     $connect_it = ftp_connect($ftp_host);
     if ($connect_it == false) {
         Session::flash('unsuccessfulMessage', 'Could not connect.');
         return redirect()->back();
     }
     // Login to FTP
     $login_result = ftp_login($connect_it, $ftp_user_name, $ftp_user_pass);
     // If can not connect.
     if ($login_result == false) {
         Session::flash('unsuccessfulMessage', 'Could not connect.');
         return redirect()->back();
     }
     // check if file already exists
     $check_file_exist = $remote_file;
     $contents_on_server = ftp_nlist($connect_it, '/tftpboot/');
     if (in_array($check_file_exist, $contents_on_server)) {
         ftp_delete($connect_it, $remote_file);
     }
     // Send $local_file to FTP
     if (ftp_put($connect_it, $remote_file, $filepath, FTP_BINARY)) {
         // Close the connection
         ftp_close($connect_it);
         Session::flash('astMessage', 'XML file has been transferred!');
         return Redirect::route('phones');
     } else {
         Session::flash('unsuccessfulMessage', 'XML file could not be transferred!');
         return Redirect::route('showPhone', [$id]);
     }
 }
 /**
  * Delete an existing parameter.
  */
 public function delete($id)
 {
     // delete parameter values
     $astParameterValues = astPhoneParameterValueModel::where('PARAMETER_ID', '=', $id)->get();
     foreach ($astParameterValues as $astParameterValue) {
         $astParameterValue->delete();
     }
     $astParameter = astParameterModel::findOrFail($id);
     $astParameter->delete();
     Session::flash('astMessage', 'Parameter has been deleted!');
     return Redirect::route('parameters');
 }