Source

vlocity-vinstall-gambas / Vlocity / Conf2.class

Full commit
' Gambas class file
'    This file is part of vinstall-ng

'    vinstall-ng is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    vinstall-ng  is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with vinstall-ng.  If not, see <http://www.gnu.org/licenses/>.

PUBLIC SUB Form_Open()

  WITH ME
    .tlbanner.Text = "<h2>" & .tlbanner.Text & "</h2>"
    .TextLabel1.Text = ("The linux root account is pre-defined to be used as the system administrator's account. ")&
    ("This account is used to perform system-wide changes such as adding / removing software, system-wide updates, managing user accounts, etc.") & "<br><br>" &
    ("Most other every-day tasks do not require administrative priviledges.") & "<br>" & "<br>" &
    ("For added security, use a password that is easy for you to remember, but hard for others to guess.") & "<br><br>" & ("DO NOT LEAVE THIS BLANK")
  END WITH 
  ClsGlobal.fRunningMainForm.btnext.enabled = FALSE

'   update status tree
  MdlMain.ADVANCE_STATUS_TREE("Step7", "Step8")
  ClsGlobal.fRunningMainForm.btnext.enabled = FALSE
END

PUBLIC SUB Form_Resize()

  hbox2.Width = hbox2.Parent.Width - (hbox2.Left * 2)

END
PUBLIC FUNCTION GetNext() AS String
  
  ' IF ME.cbImportAccts.Value = TRUE THEN 
  '   RETURN "Conf3a"
  ' ELSE 
   RETURN "Conf3"
'   END IF
  
  
END
PUBLIC SUB StartUp()
  DIM i AS Integer
  DIM sres AS String
  
  
  REPEAT 
    SHELL "mount | grep bind" TO sres
      IF Len(Trim(sres)) <= 0 THEN 
      DEBUG "About to set passwords, and bind mounting is not in place... Trying to bind mounts now... Attempt " & i; " of 5"
        MdlBootMngr.DO_BIND_MOUNTING()
      END IF
      WAIT 1
      INC i
  UNTIL Len(Trim(sres)) > 0 OR i = 5
  ClsGlobal.fRunningMainForm.btnext.enabled = FALSE
END

PRIVATE SUB Append_sysconfigvec()
  DIM Locales AS String
  
  Locales = "# LOCALES ADDITIONS MADE BY THE VL GUI INSTALLER" & gb.NewLine &
      "export LANG=" & ClsGlobal.sysLang & gb.NewLine &
      "`setxkbmap -model " & ClsGlobal.sysKbModel & Space(1) & "-layout" & Space(1) & ClsGlobal.sysKbLayout & "`" & gb.NewLine &
      "# END OF MODIFICATIONS BY THE VL GUI INSTALLER" & gb.NewLine
      SHELL "mv " & Main.Install.TargetMount &/ "root/.bash_profile /mnt/target/root/.bash_profile.bak" WAIT 
      
      File.Save(Main.Install.TargetMount &/ "root/.bash_profile", Locales)
      SHELL "chmod 640 /mnt/target/root/.bash_profile" WAIT 
      SHELL "chroot /mnt/target chown root /root/.bash_profile" WAIT 
      'SHELL "chroot /mnt/target chown " & txtLogin.Text & Space(1) & "/home/" & txtLogin.Text &/ ".bash_profile" WAIT 
  
  SHELL "echo \"XKB=1\" >> " & Main.Install.TargetMount &/ "etc/sysconfig/vector" WAIT 
  
END

PUBLIC SUB OnExit()
  
  MdlMain.Set_App_Status(("Saving Administrator password."), 10)
  ' -== Commented for testing purposers ==-
  SET_ROOT_PASSWORD(Trim(textbox2.Text))
  IF cbKeepLoc.Value = TRUE THEN Append_sysconfigvec()
  
  textbox1.Text = ""
  textbox2.Text = ""
  MdlMain.Set_App_Status(("Root password saved successfully"))
END

PRIVATE SUB SET_ROOT_PASSWORD(SPASS AS String)
  
  DIM hproc AS Process
  DIM sdump AS String
  SHELL "chroot " & Main.Install.TargetMount & " groupadd netdev " WAIT
  hproc = SHELL "chroot " & Main.Install.TargetMount & " /sbin/passwdx root " & Trim(SPASS) WAIT 
    IF hproc.Value > 0 THEN 
      SHELL "chroot " & Main.Install.TargetMount & " /sbin/passwdx root " & Trim(SPASS) TO sdump
      PRINT " ------ ERROR SAVING ROOT PASSWORD (Error details below) -------"
      PRINT sdump
      PRINT "------- END OF ROOT PASSWORD ERROR -------"
      RETURN 
    END IF
  PRINT "Root password changed"
  MdlMain.Set_App_Status(("Root password has been saved"))
  
END



PUBLIC FUNCTION compare_passwords() AS Boolean
  'DIM hproc AS Process
  'DIM sRes AS String
  IF NOT (textbox1.Text) OR NOT (textbox2.Text) THEN RETURN FALSE
  IF textbox1.Text <> textbox2.Text THEN 
    'Message.Error(("Passwords do not match. Please enter the same password twice"))
    'STOP EVENT 
    RETURN FALSE
  ELSE 
    'SHELL "chroot " & Main.Install.TargetMount & " /sbin/passwdx root " & Trim(textbox1.Text) & " || echo ERROR" TO sRes 
  '   'hproc = SHELL "/usr/bin/chroot" & Space(1) & Main.Install.TargetMount & Space(1) & "; sleep 2; /sbin/passwx root" & Space(1) & Trim(textbox1.Text) WAIT 
  '   SHELL "chroot" & Space(1) & Main.Install.TargetMount & " /sbin/passwdx root " & Trim(ME.TextBox1.Text) & " || echo ERROR" TO sRes
  '         ' 
  '     IF InStr(sRes, "ERROR") THEN 
  '       Message.Error(("Password was not set. See error log below") & "<br>" & Trim(sRes))
  '       RETURN FALSE
  '       'STOP EVENT 
  '     ELSE 
  '       DEBUG "root password has been changed"   
  '       RETURN TRUE     
  '     END IF
  ' END IF
  RETURN TRUE
  END IF

END




PUBLIC SUB TextBox2_KeyRelease()

  'ClsGlobal.fRunningMainForm.btnext.enabled = textbox2.Text = textbox1.Text
  ClsGlobal.fRunningMainForm.btnext.enabled = ME.compare_passwords()

END

PUBLIC SUB TextBox1_KeyRelease()

  ClsGlobal.fRunningMainForm.btnext.enabled = ME.compare_passwords()

END