 
 
 module.exports = new Kite 'sharedHosting'
-  
-  
+
+
   timeout:({timeout}, callback)->
     setTimeout (-> callback null, timeout), timeout
- 
+
   interval:({interval}, callback)->
     setInterval (-> callback null, interval), interval
 
   executeCommand: require './executecommand'
-  
+
   fetchSafeFileName:(options,callback)->
     {filePath}    = options
     original      = filePath+""

    # This method will create operation system user with default group in LDAP
    # Note: you should not define default group for user. dafault group name has the same name with username
    #
    
    #
    # options =
    #   username : String #username of the unix user
    #   fullName : String #fullName - real name for unux user
    #   password : String #password of the unix
    
    #
    # return =
    #   backend : String # backend FQDN where user has created
    
    {username,fullName,password} = options
    
    # define user and group ldap schema
    
    user =
      objectClass: ['top','person','organizationalPerson','inetorgperson','posixAccount']
      cn : username

                            callback null,"[OK] user and group #{username} has been added to LDAP"

  createVhost : (options,callback)->

    {username,uid,domainName} = options

    domainName ?= "#{username}.#{config.defaultDomain}"
    targetPath = "/Users/#{username}/Sites/#{domainName}"
    cmd        = "mkdir -p #{targetPath} && cp -r #{config.defaultVhostFiles}/website #{targetPath} && chown #{uid}:#{uid} -R #{targetPath}/*"
    log.debug "executing CreateVhost:",cmd

    exec cmd,(err,stdout,stderr)->
      unless err
        callback null, "vhost created with default files:",domainName
