api_utils.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. package httpd
  2. import (
  3. "bytes"
  4. "context"
  5. "errors"
  6. "fmt"
  7. "io"
  8. "mime"
  9. "net/http"
  10. "net/url"
  11. "os"
  12. "path"
  13. "strconv"
  14. "strings"
  15. "time"
  16. "github.com/go-chi/chi/v5"
  17. "github.com/go-chi/chi/v5/middleware"
  18. "github.com/go-chi/render"
  19. "github.com/klauspost/compress/zip"
  20. "github.com/drakkan/sftpgo/v2/common"
  21. "github.com/drakkan/sftpgo/v2/dataprovider"
  22. "github.com/drakkan/sftpgo/v2/logger"
  23. "github.com/drakkan/sftpgo/v2/metric"
  24. "github.com/drakkan/sftpgo/v2/plugin"
  25. "github.com/drakkan/sftpgo/v2/smtp"
  26. "github.com/drakkan/sftpgo/v2/util"
  27. )
  28. type pwdChange struct {
  29. CurrentPassword string `json:"current_password"`
  30. NewPassword string `json:"new_password"`
  31. }
  32. type pwdReset struct {
  33. Code string `json:"code"`
  34. Password string `json:"password"`
  35. }
  36. type baseProfile struct {
  37. Email string `json:"email,omitempty"`
  38. Description string `json:"description,omitempty"`
  39. AllowAPIKeyAuth bool `json:"allow_api_key_auth"`
  40. }
  41. type adminProfile struct {
  42. baseProfile
  43. }
  44. type userProfile struct {
  45. baseProfile
  46. PublicKeys []string `json:"public_keys,omitempty"`
  47. }
  48. func sendAPIResponse(w http.ResponseWriter, r *http.Request, err error, message string, code int) {
  49. var errorString string
  50. if _, ok := err.(*util.RecordNotFoundError); ok {
  51. errorString = http.StatusText(http.StatusNotFound)
  52. } else if err != nil {
  53. errorString = err.Error()
  54. }
  55. resp := apiResponse{
  56. Error: errorString,
  57. Message: message,
  58. }
  59. ctx := context.WithValue(r.Context(), render.StatusCtxKey, code)
  60. render.JSON(w, r.WithContext(ctx), resp)
  61. }
  62. func getRespStatus(err error) int {
  63. if _, ok := err.(*util.ValidationError); ok {
  64. return http.StatusBadRequest
  65. }
  66. if _, ok := err.(*util.MethodDisabledError); ok {
  67. return http.StatusForbidden
  68. }
  69. if _, ok := err.(*util.RecordNotFoundError); ok {
  70. return http.StatusNotFound
  71. }
  72. if os.IsNotExist(err) {
  73. return http.StatusBadRequest
  74. }
  75. if os.IsPermission(err) {
  76. return http.StatusForbidden
  77. }
  78. if errors.Is(err, plugin.ErrNoSearcher) || errors.Is(err, dataprovider.ErrNotImplemented) {
  79. return http.StatusNotImplemented
  80. }
  81. return http.StatusInternalServerError
  82. }
  83. // mappig between fs errors for HTTP protocol and HTTP response status codes
  84. func getMappedStatusCode(err error) int {
  85. var statusCode int
  86. switch {
  87. case errors.Is(err, os.ErrPermission):
  88. statusCode = http.StatusForbidden
  89. case errors.Is(err, common.ErrReadQuotaExceeded):
  90. statusCode = http.StatusForbidden
  91. case errors.Is(err, os.ErrNotExist):
  92. statusCode = http.StatusNotFound
  93. case errors.Is(err, common.ErrQuotaExceeded):
  94. statusCode = http.StatusRequestEntityTooLarge
  95. case errors.Is(err, common.ErrOpUnsupported):
  96. statusCode = http.StatusBadRequest
  97. default:
  98. statusCode = http.StatusInternalServerError
  99. }
  100. return statusCode
  101. }
  102. func getURLParam(r *http.Request, key string) string {
  103. v := chi.URLParam(r, key)
  104. unescaped, err := url.PathUnescape(v)
  105. if err != nil {
  106. return v
  107. }
  108. return unescaped
  109. }
  110. func getCommaSeparatedQueryParam(r *http.Request, key string) []string {
  111. var result []string
  112. for _, val := range strings.Split(r.URL.Query().Get(key), ",") {
  113. val = strings.TrimSpace(val)
  114. if val != "" {
  115. result = append(result, val)
  116. }
  117. }
  118. return util.RemoveDuplicates(result)
  119. }
  120. func getBoolQueryParam(r *http.Request, param string) bool {
  121. return r.URL.Query().Get(param) == "true"
  122. }
  123. func handleCloseConnection(w http.ResponseWriter, r *http.Request) {
  124. r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
  125. connectionID := getURLParam(r, "connectionID")
  126. if connectionID == "" {
  127. sendAPIResponse(w, r, nil, "connectionID is mandatory", http.StatusBadRequest)
  128. return
  129. }
  130. if common.Connections.Close(connectionID) {
  131. sendAPIResponse(w, r, nil, "Connection closed", http.StatusOK)
  132. } else {
  133. sendAPIResponse(w, r, nil, "Not Found", http.StatusNotFound)
  134. }
  135. }
  136. func getSearchFilters(w http.ResponseWriter, r *http.Request) (int, int, string, error) {
  137. var err error
  138. limit := 100
  139. offset := 0
  140. order := dataprovider.OrderASC
  141. if _, ok := r.URL.Query()["limit"]; ok {
  142. limit, err = strconv.Atoi(r.URL.Query().Get("limit"))
  143. if err != nil {
  144. err = errors.New("invalid limit")
  145. sendAPIResponse(w, r, err, "", http.StatusBadRequest)
  146. return limit, offset, order, err
  147. }
  148. if limit > 500 {
  149. limit = 500
  150. }
  151. }
  152. if _, ok := r.URL.Query()["offset"]; ok {
  153. offset, err = strconv.Atoi(r.URL.Query().Get("offset"))
  154. if err != nil {
  155. err = errors.New("invalid offset")
  156. sendAPIResponse(w, r, err, "", http.StatusBadRequest)
  157. return limit, offset, order, err
  158. }
  159. }
  160. if _, ok := r.URL.Query()["order"]; ok {
  161. order = r.URL.Query().Get("order")
  162. if order != dataprovider.OrderASC && order != dataprovider.OrderDESC {
  163. err = errors.New("invalid order")
  164. sendAPIResponse(w, r, err, "", http.StatusBadRequest)
  165. return limit, offset, order, err
  166. }
  167. }
  168. return limit, offset, order, err
  169. }
  170. func renderCompressedFiles(w http.ResponseWriter, conn *Connection, baseDir string, files []string,
  171. share *dataprovider.Share,
  172. ) {
  173. w.Header().Set("Content-Type", "application/zip")
  174. w.Header().Set("Accept-Ranges", "none")
  175. w.Header().Set("Content-Transfer-Encoding", "binary")
  176. w.WriteHeader(http.StatusOK)
  177. wr := zip.NewWriter(w)
  178. for _, file := range files {
  179. fullPath := path.Join(baseDir, file)
  180. if err := addZipEntry(wr, conn, fullPath, baseDir); err != nil {
  181. if share != nil {
  182. dataprovider.UpdateShareLastUse(share, -1) //nolint:errcheck
  183. }
  184. panic(http.ErrAbortHandler)
  185. }
  186. }
  187. if err := wr.Close(); err != nil {
  188. conn.Log(logger.LevelError, "unable to close zip file: %v", err)
  189. if share != nil {
  190. dataprovider.UpdateShareLastUse(share, -1) //nolint:errcheck
  191. }
  192. panic(http.ErrAbortHandler)
  193. }
  194. }
  195. func addZipEntry(wr *zip.Writer, conn *Connection, entryPath, baseDir string) error {
  196. info, err := conn.Stat(entryPath, 1)
  197. if err != nil {
  198. conn.Log(logger.LevelDebug, "unable to add zip entry %#v, stat error: %v", entryPath, err)
  199. return err
  200. }
  201. if info.IsDir() {
  202. _, err := wr.Create(getZipEntryName(entryPath, baseDir) + "/")
  203. if err != nil {
  204. conn.Log(logger.LevelDebug, "unable to create zip entry %#v: %v", entryPath, err)
  205. return err
  206. }
  207. contents, err := conn.ReadDir(entryPath)
  208. if err != nil {
  209. conn.Log(logger.LevelDebug, "unable to add zip entry %#v, read dir error: %v", entryPath, err)
  210. return err
  211. }
  212. for _, info := range contents {
  213. fullPath := path.Join(entryPath, info.Name())
  214. if err := addZipEntry(wr, conn, fullPath, baseDir); err != nil {
  215. return err
  216. }
  217. }
  218. return nil
  219. }
  220. if !info.Mode().IsRegular() {
  221. // we only allow regular files
  222. conn.Log(logger.LevelDebug, "skipping zip entry for non regular file %#v", entryPath)
  223. return nil
  224. }
  225. reader, err := conn.getFileReader(entryPath, 0, http.MethodGet)
  226. if err != nil {
  227. conn.Log(logger.LevelDebug, "unable to add zip entry %#v, cannot open file: %v", entryPath, err)
  228. return err
  229. }
  230. defer reader.Close()
  231. f, err := wr.Create(getZipEntryName(entryPath, baseDir))
  232. if err != nil {
  233. conn.Log(logger.LevelDebug, "unable to create zip entry %#v: %v", entryPath, err)
  234. return err
  235. }
  236. _, err = io.Copy(f, reader)
  237. return err
  238. }
  239. func getZipEntryName(entryPath, baseDir string) string {
  240. entryPath = strings.TrimPrefix(entryPath, baseDir)
  241. return strings.TrimPrefix(entryPath, "/")
  242. }
  243. func downloadFile(w http.ResponseWriter, r *http.Request, connection *Connection, name string,
  244. info os.FileInfo, inline bool,
  245. ) (int, error) {
  246. var err error
  247. rangeHeader := r.Header.Get("Range")
  248. if rangeHeader != "" && checkIfRange(r, info.ModTime()) == condFalse {
  249. rangeHeader = ""
  250. }
  251. offset := int64(0)
  252. size := info.Size()
  253. responseStatus := http.StatusOK
  254. if strings.HasPrefix(rangeHeader, "bytes=") {
  255. if strings.Contains(rangeHeader, ",") {
  256. return http.StatusRequestedRangeNotSatisfiable, fmt.Errorf("unsupported range %#v", rangeHeader)
  257. }
  258. offset, size, err = parseRangeRequest(rangeHeader[6:], size)
  259. if err != nil {
  260. return http.StatusRequestedRangeNotSatisfiable, err
  261. }
  262. responseStatus = http.StatusPartialContent
  263. }
  264. reader, err := connection.getFileReader(name, offset, r.Method)
  265. if err != nil {
  266. return getMappedStatusCode(err), fmt.Errorf("unable to read file %#v: %v", name, err)
  267. }
  268. defer reader.Close()
  269. w.Header().Set("Last-Modified", info.ModTime().UTC().Format(http.TimeFormat))
  270. if checkPreconditions(w, r, info.ModTime()) {
  271. return 0, fmt.Errorf("%v", http.StatusText(http.StatusPreconditionFailed))
  272. }
  273. ctype := mime.TypeByExtension(path.Ext(name))
  274. if ctype == "" {
  275. ctype = "application/octet-stream"
  276. }
  277. if responseStatus == http.StatusPartialContent {
  278. w.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", offset, offset+size-1, info.Size()))
  279. }
  280. w.Header().Set("Content-Length", strconv.FormatInt(size, 10))
  281. w.Header().Set("Content-Type", ctype)
  282. if !inline {
  283. w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%#v", path.Base(name)))
  284. }
  285. w.Header().Set("Accept-Ranges", "bytes")
  286. w.WriteHeader(responseStatus)
  287. if r.Method != http.MethodHead {
  288. _, err = io.CopyN(w, reader, size)
  289. if err != nil {
  290. connection.Log(logger.LevelDebug, "error reading file to download: %v", err)
  291. panic(http.ErrAbortHandler)
  292. }
  293. }
  294. return http.StatusOK, nil
  295. }
  296. func checkPreconditions(w http.ResponseWriter, r *http.Request, modtime time.Time) bool {
  297. if checkIfUnmodifiedSince(r, modtime) == condFalse {
  298. w.WriteHeader(http.StatusPreconditionFailed)
  299. return true
  300. }
  301. if checkIfModifiedSince(r, modtime) == condFalse {
  302. w.WriteHeader(http.StatusNotModified)
  303. return true
  304. }
  305. return false
  306. }
  307. func checkIfUnmodifiedSince(r *http.Request, modtime time.Time) condResult {
  308. ius := r.Header.Get("If-Unmodified-Since")
  309. if ius == "" || isZeroTime(modtime) {
  310. return condNone
  311. }
  312. t, err := http.ParseTime(ius)
  313. if err != nil {
  314. return condNone
  315. }
  316. // The Last-Modified header truncates sub-second precision so
  317. // the modtime needs to be truncated too.
  318. modtime = modtime.Truncate(time.Second)
  319. if modtime.Before(t) || modtime.Equal(t) {
  320. return condTrue
  321. }
  322. return condFalse
  323. }
  324. func checkIfModifiedSince(r *http.Request, modtime time.Time) condResult {
  325. if r.Method != http.MethodGet && r.Method != http.MethodHead {
  326. return condNone
  327. }
  328. ims := r.Header.Get("If-Modified-Since")
  329. if ims == "" || isZeroTime(modtime) {
  330. return condNone
  331. }
  332. t, err := http.ParseTime(ims)
  333. if err != nil {
  334. return condNone
  335. }
  336. // The Last-Modified header truncates sub-second precision so
  337. // the modtime needs to be truncated too.
  338. modtime = modtime.Truncate(time.Second)
  339. if modtime.Before(t) || modtime.Equal(t) {
  340. return condFalse
  341. }
  342. return condTrue
  343. }
  344. func checkIfRange(r *http.Request, modtime time.Time) condResult {
  345. if r.Method != http.MethodGet && r.Method != http.MethodHead {
  346. return condNone
  347. }
  348. ir := r.Header.Get("If-Range")
  349. if ir == "" {
  350. return condNone
  351. }
  352. if modtime.IsZero() {
  353. return condFalse
  354. }
  355. t, err := http.ParseTime(ir)
  356. if err != nil {
  357. return condFalse
  358. }
  359. if modtime.Add(60 * time.Second).Before(t) {
  360. return condTrue
  361. }
  362. return condFalse
  363. }
  364. func parseRangeRequest(bytesRange string, size int64) (int64, int64, error) {
  365. var start, end int64
  366. var err error
  367. values := strings.Split(bytesRange, "-")
  368. if values[0] == "" {
  369. start = -1
  370. } else {
  371. start, err = strconv.ParseInt(values[0], 10, 64)
  372. if err != nil {
  373. return start, size, err
  374. }
  375. }
  376. if len(values) >= 2 {
  377. if values[1] != "" {
  378. end, err = strconv.ParseInt(values[1], 10, 64)
  379. if err != nil {
  380. return start, size, err
  381. }
  382. if end >= size {
  383. end = size - 1
  384. }
  385. }
  386. }
  387. if start == -1 && end == 0 {
  388. return 0, 0, fmt.Errorf("unsupported range %#v", bytesRange)
  389. }
  390. if end > 0 {
  391. if start == -1 {
  392. // we have something like -500
  393. start = size - end
  394. size = end
  395. // start cannit be < 0 here, we did end = size -1 above
  396. } else {
  397. // we have something like 500-600
  398. size = end - start + 1
  399. if size < 0 {
  400. return 0, 0, fmt.Errorf("unacceptable range %#v", bytesRange)
  401. }
  402. }
  403. return start, size, nil
  404. }
  405. // we have something like 500-
  406. size -= start
  407. if size < 0 {
  408. return 0, 0, fmt.Errorf("unacceptable range %#v", bytesRange)
  409. }
  410. return start, size, err
  411. }
  412. func updateLoginMetrics(user *dataprovider.User, ip string, err error) {
  413. metric.AddLoginAttempt(dataprovider.LoginMethodPassword)
  414. if err != nil && err != common.ErrInternalFailure && err != common.ErrNoCredentials {
  415. logger.ConnectionFailedLog(user.Username, ip, dataprovider.LoginMethodPassword, common.ProtocolHTTP, err.Error())
  416. event := common.HostEventLoginFailed
  417. if _, ok := err.(*util.RecordNotFoundError); ok {
  418. event = common.HostEventUserNotFound
  419. }
  420. common.AddDefenderEvent(ip, event)
  421. }
  422. metric.AddLoginResult(dataprovider.LoginMethodPassword, err)
  423. dataprovider.ExecutePostLoginHook(user, dataprovider.LoginMethodPassword, ip, common.ProtocolHTTP, err)
  424. }
  425. func checkHTTPClientUser(user *dataprovider.User, r *http.Request, connectionID string) error {
  426. if util.IsStringInSlice(common.ProtocolHTTP, user.Filters.DeniedProtocols) {
  427. logger.Info(logSender, connectionID, "cannot login user %#v, protocol HTTP is not allowed", user.Username)
  428. return fmt.Errorf("protocol HTTP is not allowed for user %#v", user.Username)
  429. }
  430. if !user.IsLoginMethodAllowed(dataprovider.LoginMethodPassword, nil) {
  431. logger.Info(logSender, connectionID, "cannot login user %#v, password login method is not allowed", user.Username)
  432. return fmt.Errorf("login method password is not allowed for user %#v", user.Username)
  433. }
  434. if user.MaxSessions > 0 {
  435. activeSessions := common.Connections.GetActiveSessions(user.Username)
  436. if activeSessions >= user.MaxSessions {
  437. logger.Info(logSender, connectionID, "authentication refused for user: %#v, too many open sessions: %v/%v", user.Username,
  438. activeSessions, user.MaxSessions)
  439. return fmt.Errorf("too many open sessions: %v", activeSessions)
  440. }
  441. }
  442. if !user.IsLoginFromAddrAllowed(r.RemoteAddr) {
  443. logger.Info(logSender, connectionID, "cannot login user %#v, remote address is not allowed: %v", user.Username, r.RemoteAddr)
  444. return fmt.Errorf("login for user %#v is not allowed from this address: %v", user.Username, r.RemoteAddr)
  445. }
  446. return nil
  447. }
  448. func handleForgotPassword(r *http.Request, username string, isAdmin bool) error {
  449. var email, subject string
  450. var err error
  451. var admin dataprovider.Admin
  452. var user dataprovider.User
  453. if username == "" {
  454. return util.NewValidationError("Username is mandatory")
  455. }
  456. if isAdmin {
  457. admin, err = dataprovider.AdminExists(username)
  458. email = admin.Email
  459. subject = fmt.Sprintf("Email Verification Code for admin %#v", username)
  460. } else {
  461. user, err = dataprovider.UserExists(username)
  462. email = user.Email
  463. subject = fmt.Sprintf("Email Verification Code for user %#v", username)
  464. if err == nil {
  465. if !isUserAllowedToResetPassword(r, &user) {
  466. return util.NewValidationError("You are not allowed to reset your password")
  467. }
  468. }
  469. }
  470. if err != nil {
  471. if _, ok := err.(*util.RecordNotFoundError); ok {
  472. logger.Debug(logSender, middleware.GetReqID(r.Context()), "username %#v does not exists, reset password request silently ignored, is admin? %v",
  473. username, isAdmin)
  474. return nil
  475. }
  476. return util.NewGenericError("Error retrieving your account, please try again later")
  477. }
  478. if email == "" {
  479. return util.NewValidationError("Your account does not have an email address, it is not possible to reset your password by sending an email verification code")
  480. }
  481. c := newResetCode(username, isAdmin)
  482. body := new(bytes.Buffer)
  483. data := make(map[string]string)
  484. data["Code"] = c.Code
  485. if err := smtp.RenderPasswordResetTemplate(body, data); err != nil {
  486. logger.Warn(logSender, middleware.GetReqID(r.Context()), "unable to render password reset template: %v", err)
  487. return util.NewGenericError("Unable to render password reset template")
  488. }
  489. startTime := time.Now()
  490. if err := smtp.SendEmail(email, subject, body.String(), smtp.EmailContentTypeTextHTML); err != nil {
  491. logger.Warn(logSender, middleware.GetReqID(r.Context()), "unable to send password reset code via email: %v, elapsed: %v",
  492. err, time.Since(startTime))
  493. return util.NewGenericError(fmt.Sprintf("Unable to send confirmation code via email: %v", err))
  494. }
  495. logger.Debug(logSender, middleware.GetReqID(r.Context()), "reset code sent via email to %#v, email: %#v, is admin? %v, elapsed: %v",
  496. username, email, isAdmin, time.Since(startTime))
  497. resetCodes.Store(c.Code, c)
  498. return nil
  499. }
  500. func handleResetPassword(r *http.Request, code, newPassword string, isAdmin bool) (
  501. *dataprovider.Admin, *dataprovider.User, error,
  502. ) {
  503. var admin dataprovider.Admin
  504. var user dataprovider.User
  505. var err error
  506. if newPassword == "" {
  507. return &admin, &user, util.NewValidationError("Please set a password")
  508. }
  509. if code == "" {
  510. return &admin, &user, util.NewValidationError("Please set a confirmation code")
  511. }
  512. c, ok := resetCodes.Load(code)
  513. if !ok {
  514. return &admin, &user, util.NewValidationError("Confirmation code not found")
  515. }
  516. resetCode := c.(*resetCode)
  517. if resetCode.IsAdmin != isAdmin {
  518. return &admin, &user, util.NewValidationError("Invalid confirmation code")
  519. }
  520. if isAdmin {
  521. admin, err = dataprovider.AdminExists(resetCode.Username)
  522. if err != nil {
  523. return &admin, &user, util.NewValidationError("Unable to associate the confirmation code with an existing admin")
  524. }
  525. admin.Password = newPassword
  526. err = dataprovider.UpdateAdmin(&admin, admin.Username, util.GetIPFromRemoteAddress(r.RemoteAddr))
  527. if err != nil {
  528. return &admin, &user, util.NewGenericError(fmt.Sprintf("Unable to set the new password: %v", err))
  529. }
  530. } else {
  531. user, err = dataprovider.UserExists(resetCode.Username)
  532. if err != nil {
  533. return &admin, &user, util.NewValidationError("Unable to associate the confirmation code with an existing user")
  534. }
  535. if err == nil {
  536. if !isUserAllowedToResetPassword(r, &user) {
  537. return &admin, &user, util.NewValidationError("You are not allowed to reset your password")
  538. }
  539. }
  540. user.Password = newPassword
  541. err = dataprovider.UpdateUser(&user, user.Username, util.GetIPFromRemoteAddress(r.RemoteAddr))
  542. if err != nil {
  543. return &admin, &user, util.NewGenericError(fmt.Sprintf("Unable to set the new password: %v", err))
  544. }
  545. }
  546. resetCodes.Delete(code)
  547. return &admin, &user, nil
  548. }
  549. func isUserAllowedToResetPassword(r *http.Request, user *dataprovider.User) bool {
  550. if !user.CanResetPassword() {
  551. return false
  552. }
  553. if util.IsStringInSlice(common.ProtocolHTTP, user.Filters.DeniedProtocols) {
  554. return false
  555. }
  556. if !user.IsLoginMethodAllowed(dataprovider.LoginMethodPassword, nil) {
  557. return false
  558. }
  559. if !user.IsLoginFromAddrAllowed(r.RemoteAddr) {
  560. return false
  561. }
  562. return true
  563. }