/** * 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 model if no phone uses the model. */ public function delete($id) { $astPhonesWithModel = astPhoneModel::where('PHONE_MODEL_ID', '=', $id)->get(); if (count($astPhonesWithModel) == 0) { $astPhoneModel = astPhoneModelModel::findOrFail($id); $astPhoneModel->delete(); Session::flash('astMessage', 'Model has been deleted!'); return Redirect::route('models'); } else { Session::flash('astDeleteMessage', 'In order to delete this model, all phones with this model must be deleted first.'); return redirect()->route('showModel', [$id]); } }
/** * Delete an existing template if no phone uses the template. */ public function delete($id) { $astPhonesWithTemplate = astPhoneModel::where('PHONE_TEMPLATE_ID', '=', $id)->get(); if (count($astPhonesWithTemplate) == 0) { $astPhoneTemplate = astPhoneTemplateModel::findOrFail($id); $astPhoneTemplate->delete(); Session::flash('astMessage', 'Template has been deleted!'); return Redirect::route('templates'); } else { Session::flash('astDeleteMessage', 'In order to delete this template, all phones with this template must be deleted first.'); return redirect()->route('showTemplate', [$id]); } }
/** * Delete an existing location if no phone uses the model. */ public function delete($id) { $astPhonesWithLocation = astPhoneModel::where('PHONE_LOCATION_ID', '=', $id)->get(); if (count($astPhonesWithLocation) == 0) { $astPhoneLocation = astPhoneLocationModel::findOrFail($id); $astPhoneLocation->delete(); Session::flash('astMessage', 'Location has been deleted!'); return Redirect::route('locations'); } else { Session::flash('astDeleteMessage', 'In order to delete this location, all phones with this location must be deleted first.'); return redirect()->route('showLocation', [$id]); } }