vlocity-vinstall-gambas / Vlocity / .svn / text-base / Conf3.class.svn-base

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
' 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 sListToReset AS String
PRIVATE bImported AS Boolean
PRIVATE sUsrName AS String

PRIVATE ReservedUUIDsandnames AS NEW String[]


PRIVATE FUNCTION check_uuid(uuid_in AS String) AS Integer
  
  DIM uuid, sline AS String
  DIM entry AS String[]
    FOR EACH sLine IN ReservedUUIDsandnames
      entry = Split(sLine, " ")
      IF Trim(entry[0]) = uuid_in THEN RETURN 1
    NEXT 
    RETURN 0
  
END


PUBLIC FUNCTION check_for_impartable_accounts() AS Boolean

DIM sName, sDump AS String
DIM sAccounts, sList AS NEW String[]


  FOR EACH sName IN Dir(Main.Install.TargetMount &/ "home", "*", gb.Directory)
    IF sName <> "ftp" THEN 
      IF Exist(Main.Install.TargetMount &/ "home" &/ Trim(sname) &/ ".bashrc") THEN sList.Push(Trim(sName))
    END IF
  NEXT 
  
  IF sList.Count <= 0 THEN RETURN
  
  FOR EACH sname IN sList
    SHELL "grep ^" & Trim(sName) & Space(1) & Main.Install.TargetMount &/ "etc/group | cut -f1 -d:" TO sDump
      IF Len(Trim(sDump)) > 0 THEN CONTINUE ' user account exists
        DEBUG "Found home dir for " & sname
      'ExistinAccounts.Add(Trim(sname))
      Main.ImportUsers.Push(Trim(sname))
      
  NEXT 
  
   IF Main.ImportUsers.Count > 0 THEN 
    SHELL "ls -n " & Main.Install.TargetMount &/ "home | grep -v ftp | grep -v lost+found | tr -s \' \',\"\" | cut -f3,8 -d \' \'" TO sDump
    sList = Split(Trim(sDump), gb.NewLine)
    FOR EACH sname IN sList
      ReservedUUIDsandnames.Push(sname)
      MdlMain.uuidList.Push(sname)
    NEXT 
   END IF
    
  
END


PUBLIC SUB Form_Open()
  
  ME.Button1.Width = MdlObjSizer.get_object_width(Button1.Text) + 64
  ME.btAddUsr.Width = MdlObjSizer.get_object_width(Button1.Text) + 64
  ME.Button2.Width = MdlObjSizer.get_object_width(Button1.Text) + 64
  MdlMain.Resize_Object(ME.btSel)
  MdlMain.Resize_Object(ME.TextLabel4)
  ME.TextLabel1.Width = ME.TextLabel4.Width
  ME.TextLabel2.Width = ME.TextLabel4.Width
  ME.TextLabel3.Width = ME.TextLabel4.Width
  MdlMain.doublecheck_home_mount()
  ME.check_for_impartable_accounts()
  WITH ME
  cbkeeplocales.Text = ("Keep regional settings used during installation") & gb.NewLine & ("for this account") 
    '.btPicSel.Text = ("Select") & gb.NewLine & ("Picture")
    .tlbanner.Text = "<h2>" & tlbanner.Text & "</h2>"
    .tlTxt.Text = ("Create as many user accounts as you want / need here.") & "<br>" &
     ("Choose a unique login name for each user account.") & "<br><br>"
      ' --- only if running embedded --- '
      IF ClsGlobal.fRunningMainForm THEN 
        .tlTxt.Text = tlTxt.Text &
          ("When finished, Click") & Space(1) & "\"" & ClsGlobal.fRunningMainForm.btnext.text & "\"" & Space(1) & ("to continue")
      END IF
        IF Exist(Main.Install.TargetMount &/ "usr/share/apps/kdm/pics/users/default2.png") THEN 
          .btPicSel.Picture = Picture.Load(Main.Install.TargetMount &/ "usr/share/apps/kdm/pics/users/default2.png")
          .btPicSel.Text = ""
          
        ELSE 
          .btPicSel.Text = ("Select") & gb.NewLine & ("Picture")
        END IF
      .btPicSel.ToolTip = ("Click this here to select the user face icon")
  END WITH 
  WAIT 
  'Button1.Enabled = Main.ImportUsers.Count > 0 'ME.check_for_impartable_accounts()
  MdlMain.Display_User_Group_Choices(ME.lbUsrGrps)
    IF Main.ImportUsers.Count > 0 THEN 
    'ME.btsel.Enabled = Main.ImportUsers.Count > 0
    ME.btSel.Enabled = TRUE
      Message.Info(Main.Install.Name & Space(1) & ("has found existing user directories in your selected /home partition.") & gb.NewLine &
      ("You may import these user accounts by clicking on") & Space(1) & btsel.Text)
    END IF
  

END
PUBLIC FUNCTION GetNext() AS String
  
  RETURN "Conf4"
  
END

PUBLIC SUB OnExit()
  
  'quick check to see if we can create an account in a snap
    IF ME.txtLogin.Text THEN 
      IF ME.txtPass1.Text THEN 
        IF ME.txtPass2.Text THEN 
          IF ME.txtPass1.Text = ME.txtPass2.Text THEN 
            'everythign is ready... create the account.
              ME.btAddUsr_Click() ' trigger the account creation process.
          ELSE 
            DEBUG "Passwords entered for" & Space(1) & txtLogin.Text & Space(1) & "do not match... cannot create account"
          END IF
        END IF
      END IF
    END IF
    
  
END
PUBLIC SUB StartUp()
  

  
END




PUBLIC SUB Form_Resize()

  'ME.scrlConts.Height = ME.ClientH - (ME.scrlConts.Top + 8)
  
  ME.lbUsrGrps.Width = ME.lbUsrGrps.Parent.Width - (ME.lbUsrGrps.Left * 2)
  ME.lbUsrGrps.Height = ME.lbUsrGrps.Parent.Height - (ME.lbUsrGrps.Top * 1.25)
  
  ME.scrlConts.Height = ME.ClientH - ME.scrlConts.top - 24
  ME.Panel1.Height = ME.Panel1.Parent.Height - ME.Panel1.Top
  ME.HPanel2.Height = ME.HPanel2.Parent.Height - ME.HPanel2.Top - 8
  ME.frmRights.Height = HPanel2.Height '- cbkeeplocales.Height - 4
  ME.lbUsrGrps.Height = frmRights.Height - lbUsrGrps.Top - 4

END

PUBLIC SUB TextBox4_KeyPress()

  

END


PUBLIC SUB btPicSel_Click()
  Dialog.Path = Main.Install.TargetMount &/ "/usr/share/apps/kdm/pics/users"
  IF NOT (txtLogin.Text) THEN 
    Dialog.Title = ("Select picture ID")
  ELSE 
    Dialog.Title = ("Select picture ID for") & Space(1) & ME.txtLogin.Text
  END IF
  Dialog.Filter = ["*.png;*.jpg;*.jpeg", "Picture Files"]
  IF Dialog.OpenFile() THEN RETURN 
      LAST.Picture = Picture.Load(Dialog.Path)
      LAST.text = ""
      LAST.tooltip = ("Click here to select user picture")

END

PUBLIC SUB Button2_Click()
  DIM obj AS Object
  
  ' clear this form
    ME.txtLogin.Clear
    ME.txtRealName.Clear
    ME.txtPass1.Clear
    ME.txtPass2.Clear
    ME.btAddUsr.Enabled = FALSE
    
    FOR EACH obj IN ME.lbUsrGrps.Children
      obj.delete
    NEXT 
    MdlMain.$objUsrGroups.Clear
    MdlMain.Display_User_Group_Choices(ME.lbUsrGrps)
    ' default the picture
    'ME.btPicSel.Picture = Picture.Load("/usr/share/apps/kdm/pics/users/default2.png")
      IF Exist(Main.Install.TargetMount &/ "usr" &/ "share" &/ "apps" &/ "kdm" &/ "pics" &/ "users" &/ "default2.png") THEN 
        ME.btPicSel.Picture = Picture.Load(Main.Install.TargetMount &/ "usr" &/ "share" &/ "apps" &/ "kdm" &/ "pics" &/ "users" &/ "default2.png")
        ME.btPicSel.Text = ""
      ELSE 
        ME.btPicSel.Text = ("Select") & gb.NewLine & ("Picture")
      END IF
    Dialog.Path = ""
    sListToReset = ""
    ME.btAddUsr.Text = ("Add User")
    ClsGlobal.fRunningMainForm.btnext.enabled = TRUE

END

PRIVATE FUNCTION Check_Text_Entry() AS Boolean
  
  ' will return true for faulty entry, false for clear
  ' tHIS FUNCTION WILL MAKE SURE EVERYTHING IS CLEAR FOR USER ACCOUNT TO BE CREATED.
  IF NOT (txtLogin.Text) THEN 
    Balloon.Error(("You must enter a login name first."), txtLogin)
    RETURN TRUE
  ELSE IF NOT (txtPass1.Text) THEN 
    Balloon.Error(("Please select a password for") & Space(1) & txtLogin.Text & Space(1) & ("before continuing"), txtPass1)
    RETURN TRUE
  ELSE IF NOT (txtPass2.Text) THEN 
    Balloon.Error(("You must enter the password twice for added security"), txtPass2)
    RETURN TRUE
  END IF
  RETURN FALSE
END

PUBLIC SUB btAddUsr_Click()
  DIM bashrc AS String
  DIM sPicpath AS String
  
  '1) Check to make sure all entries are filled in
  '2) Check to see if the user does not already exist
  '3) If conditions 1 & 2 are passed, then create the account.
  '4) Check for errors during account creation ^^^^^^^^^^^^^ (done in step3)
  
  MdlMain.Set_App_Status(("Working ... Please wait"), 10)
  
  '-== Get the right picture path ==-
    IF NOT (Dialog.Path) THEN 
      'sPicpath = '"/usr/share/apps/kdm/pics/users/default2.png" '"/usr/share/apps/kdm/pics/users/default2.png"
      IF Exist(Main.Install.TargetMount &/ "usr/share/apps/kdm/pics/users/default2.png") THEN sPicpath = Main.Install.TargetMount &/ "usr/share/apps/kdm/pics/users/default2.png"
    ELSE 
      sPicpath = Dialog.Path
    END IF
  
    

  '-== Make sure we have valid entries before trying to create a user account ==-  
  IF Check_Text_Entry() = FALSE THEN 
    IF MdlMain.CHECK_EXISTING_USER(Trim(ME.txtLogin.Text)) = FALSE THEN 'RETURN 
      'IF MdlMain.CREATE_NEW_USER_ACCOUNT(Trim(txtLogin.Text), Trim(txtRealName.Text), sPicpath, Trim(txtPass2.Text)) > 0 THEN ' create new account while checking for errors
      ''' This checks to make sure the UID is not reserved
      ' ' ' ' REPEAT 
      ' ' ' '   INC MdlMain.iUID
      ' ' ' ' UNTIL check_uuid(MdlMain.iUID) = 0
      
          
          IF bImported = TRUE THEN 
            ' Tap in here to import an account
            IF MdlMain.Import_Account(Main.ImportUserName, txtRealName.Text, Trim(txtPass2.Text), sPicpath) > 0 THEN 
              Message.Error(("Unable to import user account") & Space(1) & Main.ImportUserName & gb.NewLine &
                ("Please run VasmCC after installation is done."))
                RETURN 
            ELSE 
              ME.btsel.Enabled = Main.ImportUsers.Count > 0
              ME.Button1.Enabled = Main.ImportUsers.Count > 0
              'ME.btAddUsr.Text = ("Add User")
              Message.Info(("Account for") & Space(1) & Main.ImportUserName & Space(1) & ("has been imported into your new installation.") & gb.NewLine &
              Space(1) & ("Using this account under another distribution will result in corrupt") & gb.NewLine & ("application cofigurations, so use it for") & Space(1)&
              Main.Install.Name & ("only."))
            END IF             
              
            
          
          ELSE 
      IF MdlMain.CREATE_NEW_USER_ACCOUNT(Trim(txtLogin.Text), Trim(txtRealName.Text), Trim(txtPass2.Text), sPicpath) > 0 THEN 
        Message.Error(("Unable to successfully create user account. Please run VasmCC after installation is done."))
      END IF
        'INC MdlMain.iUID
      END IF
    ELSE ' user exists
      Message.Error(("User") & Space(1) & "\"" & Trim(ME.txtLogin.Text) & "\"" & Space(1) & ("already exists in the system.") & "<br>" &
      ("Please select another user login name"))
      RETURN 
      STOP EVENT 
    END IF
  ELSE 
    RETURN 
    STOP EVENT 
  END IF
  ' clear the form now
    IF sListToReset THEN 
      ' user account is being imported
      Reset_Accounts_Settings(Trim(ME.txtLogin.Text))
    END IF
  
  ' Save the language settings.
  IF cbkeeplocales.Value = TRUE THEN 
    'bashrc = Trim(File.Load(Main.Install.TargetMount &/ "home" &/ txtLogin.Text &/ ".bashrc"))
      bashrc = bashrc & gb.NewLine &
      "# 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 &/ "home" &/ txtLogin.Text &/ ".bash_profile /mnt/target/home" &/ txtLogin.Text &/ ".bash_profile.bak" WAIT 
      File.Save(Main.Install.TargetMount &/ "home" &/ txtLogin.Text &/ ".bash_profile", bashrc)
      SHELL "chmod 644 /mnt/target/home" &/ txtLogin.Text &/ ".bash_profile" WAIT 
      SHELL "chroot /mnt/target chown " & txtLogin.Text & Space(1) & "/home/" & txtLogin.Text &/ ".bash_profile" WAIT 
  END IF
   'MdlMain.WRITE_USER_AUTOSTART(Trim(txtLogin.Text), "vlstartup.sh")
  
  Button2_Click() ' clears the form
  ClsGlobal.fRunningMainForm.btnext.enabled = TRUE
  
END

PUBLIC SUB Reset_Accounts_Settings(sUsrLogin AS String)
  
  DIM sSkelPath AS String = Main.Install.TargetMount &/ "etc/skel"
  DIM sTargetPath AS String = Main.Install.TargetMount &/ "home" &/ sUsrLogin
  DIM sSettings AS String[] = Split(Replace(Trim(sListToReset), " ", ","), ",")
  DIM sFile AS String
  DIM i AS Integer
  
    FOR i = 0 TO sSettings.Max
      sFile = Trim(sSettings[i])
      TRY KILL sTargetPath &/ sFile
      SHELL "cp -r " & sSkelPath &/ sFile & Space(1) & sTargetPath WAIT 
      SHELL "chroot " & Main.Install.TargetMount & " /bin/chown " & sUsrLogin & ":users " & sTargetPath &/ sFile WAIT 
    NEXT 

  
  
END


PUBLIC SUB txtLogin_KeyPress()
  
  bImported = FALSE
  ME.btAddUsr.Text = ("Add User")
  ME.Button1.Enabled = FALSE
  IF Key.Code <> Key.Tab THEN 
    IF Key.Text = Space(1) THEN LAST.text = Replace(LAST.text, " ", "")
    IF Key.Code = Key.Left THEN RETURN 
    IF Key.Code = Key.Right THEN RETURN 
    IF Key.Code = Key.Up THEN RETURN 
    IF Key.Code = Key.Down THEN RETURN 
    IF Key.Code = Key.BackSpace THEN RETURN 
    'IF Key.Shift THEN RETURN 
  IF Key.Text LIKE "*[a-z]*" OR Key.Text LIKE "*[0-9]*" THEN 
    ' legal characters
  ELSE 
  ' illegal characters
    'Balloon.Info(("Use only lowercase letters and numbers for this field"), LAST)
    Message.Warning(("Use only lowercase letters and numbers for this field."))
    RETURN 
    STOP EVENT 
  END IF
  END IF
  
END


PUBLIC SUB Button1_Click()
  
  'Button2_Click()
  Conf3a.Import_User()
  'Message(ME.sListToReset)
  
END



PUBLIC SUB btSel_Click()
  
  'FrmUsrList.Show()
IF FrmUsrList.Run() THEN 
sUsrName = ME.txtLogin.Text
bImported = FALSE
ME.btAddUsr.Text = ("Add User")
RETURN 
END IF
'ME.txtLogin.Text = "Test"
sUsrName = Main.ImportUserName
ME.txtLogin.Text = Main.ImportUserName
ME.btAddUsr.Text = ("Import User")
bImported = TRUE
  Button1.Enabled = TRUE

END

PUBLIC SUB txtPass2_Change()

  ME.btAddUsr.Enabled = txtPass1.Text = txtPass2.Text

END
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.