public ActionResult DeleteConfirmed(int id) { LinuxInfo linuxInfo = db.LinuxInfoes.Find(id); db.LinuxInfoes.Remove(linuxInfo); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Id,Technician,Client,Site,OS,MachineName,ScannedDate,FileName,HtmlFile")] LinuxInfo linuxInfo) { if (ModelState.IsValid) { db.Entry(linuxInfo).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(linuxInfo)); }
// GET: LinuxInfoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LinuxInfo linuxInfo = db.LinuxInfoes.Find(id); if (linuxInfo == null) { return(HttpNotFound()); } return(View(linuxInfo)); }
public ActionResult Create([Bind(Include = "Id,Technician,Client,Site,OS,MachineName,ScannedDate,FileName,HtmlFile")] LinuxInfo linuxInfo, HttpPostedFileBase xmlUploader) { if (ModelState.IsValid) { if (xmlUploader != null && xmlUploader.ContentLength > 0) { string filename = xmlUploader.FileName; string contentType = xmlUploader.ContentType; byte[] data = new byte[xmlUploader.ContentLength]; xmlUploader.InputStream.Read(data, 0, xmlUploader.ContentLength); string TextFile = System.Text.Encoding.UTF8.GetString(data); linuxInfo.HtmlFile = TextFile; linuxInfo.FileName = filename; db.LinuxInfoes.Add(linuxInfo); db.SaveChanges(); return(RedirectToAction("Index")); } } return(View(linuxInfo)); }
private static LinuxInfo GetLinuxInfo() { LinuxInfo result = null; // Sample os-release file: // NAME="Ubuntu" // VERSION = "14.04.3 LTS, Trusty Tahr" // ID = ubuntu // ID_LIKE = debian // PRETTY_NAME = "Ubuntu 14.04.3 LTS" // VERSION_ID = "14.04" // HOME_URL = "http://www.ubuntu.com/" // SUPPORT_URL = "http://help.ubuntu.com/" // BUG_REPORT_URL = "http://bugs.launchpad.net/ubuntu/" // We use ID and VERSION_ID if (File.Exists("/etc/os-release")) { string[] lines = File.ReadAllLines("/etc/os-release"); result = new LinuxInfo(); foreach (string line in lines) { if (line.StartsWith("ID=", StringComparison.Ordinal)) { result.ID = line.Substring(3).Trim('"', '\''); } else if (line.StartsWith("VERSION_ID=", StringComparison.Ordinal)) { result.Version = line.Substring(11).Trim('"', '\''); } } } else if (File.Exists("/etc/redhat-release")) { string[] lines = File.ReadAllLines("/etc/redhat-release"); if (lines.Length >= 1) { string line = lines[0]; if (line.StartsWith("Red Hat Enterprise Linux Server release 6.") || line.StartsWith("CentOS release 6.")) { result = new LinuxInfo("rhel", "6"); } } } if (result != null) { // For some distros, we don't want to use the full version from VERSION_ID. One example is // Red Hat Enterprise Linux, which includes a minor version in their VERSION_ID but minor // versions are backwards compatible. // // In this case, we'll normalized RIDs like 'rhel.7.2' and 'rhel.7.3' to a generic // 'rhel.7'. This brings RHEL in line with other distros like CentOS or Debian which // don't put minor version numbers in their VERSION_ID fields because all minor versions // are backwards compatible. // Handle if VersionId is null by just setting the index to -1. int lastVersionNumberSeparatorIndex = result.Version?.IndexOf('.') ?? -1; // For Alpine, the version reported has three components, so we need to find the second version separator if (lastVersionNumberSeparatorIndex != -1 && result.ID == "alpine") { lastVersionNumberSeparatorIndex = result.Version.IndexOf('.', lastVersionNumberSeparatorIndex + 1); } if (lastVersionNumberSeparatorIndex != -1 && (result.ID == "rhel" || result.ID == "alpine")) { result.Version = result.Version.Substring(0, lastVersionNumberSeparatorIndex); } } return(result); }