You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nickserv.go 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. // Copyright (c) 2017 Daniel Oaks <daniel@danieloaks.net>
  2. // released under the MIT license
  3. package irc
  4. import (
  5. "fmt"
  6. "regexp"
  7. "strconv"
  8. "strings"
  9. "time"
  10. "github.com/goshuirc/irc-go/ircfmt"
  11. "github.com/oragono/oragono/irc/modes"
  12. "github.com/oragono/oragono/irc/passwd"
  13. "github.com/oragono/oragono/irc/sno"
  14. "github.com/oragono/oragono/irc/utils"
  15. )
  16. // "enabled" callbacks for specific nickserv commands
  17. func servCmdRequiresAccreg(config *Config) bool {
  18. return config.Accounts.Registration.Enabled
  19. }
  20. func servCmdRequiresAuthEnabled(config *Config) bool {
  21. return config.Accounts.AuthenticationEnabled
  22. }
  23. func servCmdRequiresNickRes(config *Config) bool {
  24. return config.Accounts.AuthenticationEnabled && config.Accounts.NickReservation.Enabled
  25. }
  26. func servCmdRequiresBouncerEnabled(config *Config) bool {
  27. return config.Accounts.Multiclient.Enabled
  28. }
  29. const (
  30. nsPrefix = "NickServ!NickServ@localhost"
  31. )
  32. const nickservHelp = `NickServ lets you register, log in to, and manage an account.`
  33. var (
  34. nickservCommands = map[string]*serviceCommand{
  35. "drop": {
  36. handler: nsDropHandler,
  37. help: `Syntax: $bDROP [nickname]$b
  38. DROP de-links the given (or your current) nickname from your user account.`,
  39. helpShort: `$bDROP$b de-links your current (or the given) nickname from your user account.`,
  40. enabled: servCmdRequiresNickRes,
  41. authRequired: true,
  42. },
  43. "enforce": {
  44. hidden: true,
  45. handler: nsEnforceHandler,
  46. help: `Syntax: $bENFORCE [method]$b
  47. ENFORCE is an alias for $bGET enforce$b and $bSET enforce$b. See the help
  48. entry for $bSET$b for more information.`,
  49. authRequired: true,
  50. enabled: servCmdRequiresNickRes,
  51. },
  52. "ghost": {
  53. handler: nsGhostHandler,
  54. help: `Syntax: $bGHOST <nickname>$b
  55. GHOST disconnects the given user from the network if they're logged in with the
  56. same user account, letting you reclaim your nickname.`,
  57. helpShort: `$bGHOST$b reclaims your nickname.`,
  58. enabled: servCmdRequiresNickRes,
  59. authRequired: true,
  60. minParams: 1,
  61. },
  62. "group": {
  63. handler: nsGroupHandler,
  64. help: `Syntax: $bGROUP$b
  65. GROUP links your current nickname with your logged-in account, so other people
  66. will not be able to use it.`,
  67. helpShort: `$bGROUP$b links your current nickname to your user account.`,
  68. enabled: servCmdRequiresNickRes,
  69. authRequired: true,
  70. },
  71. "identify": {
  72. handler: nsIdentifyHandler,
  73. help: `Syntax: $bIDENTIFY <username> [password]$b
  74. IDENTIFY lets you login to the given username using either password auth, or
  75. certfp (your client certificate) if a password is not given.`,
  76. helpShort: `$bIDENTIFY$b lets you login to your account.`,
  77. enabled: servCmdRequiresAuthEnabled,
  78. minParams: 1,
  79. },
  80. "list": {
  81. handler: nsListHandler,
  82. help: `Syntax: $bLIST [regex]$b
  83. LIST returns the list of registered nicknames, which match the given regex.
  84. If no regex is provided, all registered nicknames are returned.`,
  85. helpShort: `$bLIST$b searches the list of registered nicknames.`,
  86. enabled: servCmdRequiresAuthEnabled,
  87. capabs: []string{"accreg"},
  88. minParams: 0,
  89. },
  90. "info": {
  91. handler: nsInfoHandler,
  92. help: `Syntax: $bINFO [username]$b
  93. INFO gives you information about the given (or your own) user account.`,
  94. helpShort: `$bINFO$b gives you information on a user account.`,
  95. },
  96. "register": {
  97. handler: nsRegisterHandler,
  98. // TODO: "email" is an oversimplification here; it's actually any callback, e.g.,
  99. // person@example.com, mailto:person@example.com, tel:16505551234.
  100. help: `Syntax: $bREGISTER <password> [email]$b
  101. REGISTER lets you register your current nickname as a user account. If the
  102. server allows anonymous registration, you can omit the e-mail address.
  103. If you are currently logged in with a TLS client certificate and wish to use
  104. it instead of a password to log in, send * as the password.`,
  105. helpShort: `$bREGISTER$b lets you register a user account.`,
  106. enabled: servCmdRequiresAccreg,
  107. minParams: 1,
  108. maxParams: 2,
  109. },
  110. "sadrop": {
  111. handler: nsDropHandler,
  112. help: `Syntax: $bSADROP <nickname>$b
  113. SADROP forcibly de-links the given nickname from the attached user account.`,
  114. helpShort: `$bSADROP$b forcibly de-links the given nickname from its user account.`,
  115. capabs: []string{"accreg"},
  116. enabled: servCmdRequiresNickRes,
  117. minParams: 1,
  118. },
  119. "saregister": {
  120. handler: nsSaregisterHandler,
  121. help: `Syntax: $bSAREGISTER <username> [password]$b
  122. SAREGISTER registers an account on someone else's behalf.
  123. This is for use in configurations that require SASL for all connections;
  124. an administrator can set use this command to set up user accounts.`,
  125. helpShort: `$bSAREGISTER$b registers an account on someone else's behalf.`,
  126. enabled: servCmdRequiresAuthEnabled,
  127. capabs: []string{"accreg"},
  128. minParams: 1,
  129. },
  130. "sessions": {
  131. handler: nsSessionsHandler,
  132. help: `Syntax: $bSESSIONS [nickname]$b
  133. SESSIONS lists information about the sessions currently attached, via
  134. the server's multiclient functionality, to your nickname. An administrator
  135. can use this command to list another user's sessions.`,
  136. helpShort: `$bSESSIONS$b lists the sessions attached to a nickname.`,
  137. enabled: servCmdRequiresBouncerEnabled,
  138. },
  139. "unregister": {
  140. handler: nsUnregisterHandler,
  141. help: `Syntax: $bUNREGISTER <username> [code]$b
  142. UNREGISTER lets you delete your user account (or someone else's, if you're an
  143. IRC operator with the correct permissions). To prevent accidental
  144. unregistrations, a verification code is required; invoking the command without
  145. a code will display the necessary code.`,
  146. helpShort: `$bUNREGISTER$b lets you delete your user account.`,
  147. enabled: servCmdRequiresAuthEnabled,
  148. minParams: 1,
  149. },
  150. "erase": {
  151. handler: nsUnregisterHandler,
  152. help: `Syntax: $bERASE <username> [code]$b
  153. ERASE deletes all records of an account, allowing it to be re-registered.
  154. This should be used with caution, because it violates an expectation that
  155. account names are permanent identifiers. Typically, UNREGISTER should be
  156. used instead. A confirmation code is required; invoking the command
  157. without a code will display the necessary code.`,
  158. helpShort: `$bERASE$b erases all records of an account, allowing reuse.`,
  159. enabled: servCmdRequiresAuthEnabled,
  160. capabs: []string{"accreg"},
  161. minParams: 1,
  162. },
  163. "verify": {
  164. handler: nsVerifyHandler,
  165. help: `Syntax: $bVERIFY <username> <code>$b
  166. VERIFY lets you complete an account registration, if the server requires email
  167. or other verification.`,
  168. helpShort: `$bVERIFY$b lets you complete account registration.`,
  169. enabled: servCmdRequiresAccreg,
  170. minParams: 2,
  171. },
  172. "passwd": {
  173. handler: nsPasswdHandler,
  174. help: `Syntax: $bPASSWD <current> <new> <new_again>$b
  175. Or: $bPASSWD <username> <new>$b
  176. PASSWD lets you change your account password. You must supply your current
  177. password and confirm the new one by typing it twice. If you're an IRC operator
  178. with the correct permissions, you can use PASSWD to reset someone else's
  179. password by supplying their username and then the desired password. To
  180. indicate an empty password, use * instead.`,
  181. helpShort: `$bPASSWD$b lets you change your password.`,
  182. enabled: servCmdRequiresAuthEnabled,
  183. minParams: 2,
  184. },
  185. "get": {
  186. handler: nsGetHandler,
  187. help: `Syntax: $bGET <setting>$b
  188. GET queries the current values of your account settings. For more information
  189. on the settings and their possible values, see HELP SET.`,
  190. helpShort: `$bGET$b queries the current values of your account settings`,
  191. authRequired: true,
  192. enabled: servCmdRequiresAuthEnabled,
  193. minParams: 1,
  194. },
  195. "saget": {
  196. handler: nsGetHandler,
  197. help: `Syntax: $bSAGET <account> <setting>$b
  198. SAGET queries the values of someone else's account settings. For more
  199. information on the settings and their possible values, see HELP SET.`,
  200. helpShort: `$bSAGET$b queries the current values of another user's account settings`,
  201. enabled: servCmdRequiresAuthEnabled,
  202. minParams: 2,
  203. capabs: []string{"accreg"},
  204. },
  205. "set": {
  206. handler: nsSetHandler,
  207. helpShort: `$bSET$b modifies your account settings`,
  208. // these are broken out as separate strings so they can be translated separately
  209. helpStrings: []string{
  210. `Syntax $bSET <setting> <value>$b
  211. SET modifies your account settings. The following settings are available:`,
  212. `$bENFORCE$b
  213. 'enforce' lets you specify a custom enforcement mechanism for your registered
  214. nicknames. Your options are:
  215. 1. 'none' [no enforcement, overriding the server default]
  216. or else they will be renamed]
  217. 2. 'strict' [you must already be authenticated to use the nick]
  218. 3. 'default' [use the server default]`,
  219. `$bMULTICLIENT$b
  220. If 'multiclient' is enabled and you are already logged in and using a nick, a
  221. second client of yours that authenticates with SASL and requests the same nick
  222. is allowed to attach to the nick as well (this is comparable to the behavior
  223. of IRC "bouncers" like ZNC). Your options are 'on' (allow this behavior),
  224. 'off' (disallow it), and 'default' (use the server default value).`,
  225. `$bAUTOREPLAY-LINES$b
  226. 'autoreplay-lines' controls the number of lines of channel history that will
  227. be replayed to you automatically when joining a channel. Your options are any
  228. positive number, 0 to disable the feature, and 'default' to use the server
  229. default.`,
  230. `$bREPLAY-JOINS$b
  231. 'replay-joins' controls whether replayed channel history will include
  232. lines for join and part. This provides more information about the context of
  233. messages, but may be spammy. Your options are 'always', 'never', and the default
  234. of 'commands-only' (the messages will be replayed in /HISTORY output, but not
  235. during autoreplay).`,
  236. `$bALWAYS-ON$b
  237. 'always-on' controls whether your nickname/identity will remain active
  238. even while you are disconnected from the server. Your options are 'true',
  239. 'false', and 'default' (use the server default value).`,
  240. `$bAUTOREPLAY-MISSED$b
  241. 'autoreplay-missed' is only effective for always-on clients. If enabled,
  242. if you have at most one active session, the server will remember the time
  243. you disconnect and then replay missed messages to you when you reconnect.
  244. Your options are 'on' and 'off'.`,
  245. `$bDM-HISTORY$b
  246. 'dm-history' is only effective for always-on clients. It lets you control
  247. how the history of your direct messages is stored. Your options are:
  248. 1. 'off' [no history]
  249. 2. 'ephemeral' [a limited amount of temporary history, not stored on disk]
  250. 3. 'on' [history stored in a permanent database, if available]
  251. 4. 'default' [use the server default]`,
  252. `$bAUTO-AWAY$b
  253. 'auto-away' is only effective for always-on clients. If enabled, you will
  254. automatically be marked away when all your sessions are disconnected, and
  255. automatically return from away when you connect again.`,
  256. },
  257. authRequired: true,
  258. enabled: servCmdRequiresAuthEnabled,
  259. minParams: 2,
  260. },
  261. "saset": {
  262. handler: nsSetHandler,
  263. help: `Syntax: $bSASET <account> <setting> <value>$b
  264. SASET modifies the values of someone else's account settings. For more
  265. information on the settings and their possible values, see HELP SET.`,
  266. helpShort: `$bSASET$b modifies another user's account settings`,
  267. enabled: servCmdRequiresAuthEnabled,
  268. minParams: 3,
  269. capabs: []string{"accreg"},
  270. },
  271. "cert": {
  272. handler: nsCertHandler,
  273. help: `Syntax: $bCERT <LIST | ADD | DEL> [account] [certfp]$b
  274. CERT examines or modifies the TLS certificate fingerprints that can be used to
  275. log into an account. Specifically, $bCERT LIST$b lists the authorized
  276. fingerprints, $bCERT ADD <fingerprint>$b adds a new fingerprint, and
  277. $bCERT DEL <fingerprint>$b removes a fingerprint. If you're an IRC operator
  278. with the correct permissions, you can act on another user's account, for
  279. example with $bCERT ADD <account> <fingerprint>$b.`,
  280. helpShort: `$bCERT$b controls a user account's certificate fingerprints`,
  281. enabled: servCmdRequiresAuthEnabled,
  282. minParams: 1,
  283. },
  284. }
  285. )
  286. // nsNotice sends the client a notice from NickServ
  287. func nsNotice(rb *ResponseBuffer, text string) {
  288. // XXX i can't figure out how to use OragonoServices[servicename].prefix here
  289. // without creating a compile-time initialization loop
  290. rb.Add(nil, nsPrefix, "NOTICE", rb.target.Nick(), text)
  291. }
  292. func nsGetHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  293. var account string
  294. if command == "saget" {
  295. account = params[0]
  296. params = params[1:]
  297. } else {
  298. account = client.Account()
  299. }
  300. accountData, err := server.accounts.LoadAccount(account)
  301. if err == errAccountDoesNotExist {
  302. nsNotice(rb, client.t("No such account"))
  303. return
  304. } else if err != nil {
  305. nsNotice(rb, client.t("Error loading account data"))
  306. return
  307. }
  308. displaySetting(params[0], accountData.Settings, client, rb)
  309. }
  310. func displaySetting(settingName string, settings AccountSettings, client *Client, rb *ResponseBuffer) {
  311. config := client.server.Config()
  312. switch strings.ToLower(settingName) {
  313. case "enforce":
  314. storedValue := settings.NickEnforcement
  315. serializedStoredValue := nickReservationToString(storedValue)
  316. nsNotice(rb, fmt.Sprintf(client.t("Your stored nickname enforcement setting is: %s"), serializedStoredValue))
  317. serializedActualValue := nickReservationToString(configuredEnforcementMethod(config, storedValue))
  318. nsNotice(rb, fmt.Sprintf(client.t("Given current server settings, your nickname is enforced with: %s"), serializedActualValue))
  319. case "autoreplay-lines":
  320. if settings.AutoreplayLines == nil {
  321. nsNotice(rb, fmt.Sprintf(client.t("You will receive the server default of %d lines of autoreplayed history"), config.History.AutoreplayOnJoin))
  322. } else {
  323. nsNotice(rb, fmt.Sprintf(client.t("You will receive %d lines of autoreplayed history"), *settings.AutoreplayLines))
  324. }
  325. case "replay-joins":
  326. switch settings.ReplayJoins {
  327. case ReplayJoinsCommandsOnly:
  328. nsNotice(rb, client.t("You will see JOINs and PARTs in /HISTORY output, but not in autoreplay"))
  329. case ReplayJoinsAlways:
  330. nsNotice(rb, client.t("You will see JOINs and PARTs in /HISTORY output and in autoreplay"))
  331. case ReplayJoinsNever:
  332. nsNotice(rb, client.t("You will not see JOINs and PARTs in /HISTORY output or in autoreplay"))
  333. }
  334. case "multiclient":
  335. if !config.Accounts.Multiclient.Enabled {
  336. nsNotice(rb, client.t("This feature has been disabled by the server administrators"))
  337. } else {
  338. switch settings.AllowBouncer {
  339. case MulticlientAllowedServerDefault:
  340. if config.Accounts.Multiclient.AllowedByDefault {
  341. nsNotice(rb, client.t("Multiclient functionality is currently enabled for your account, but you can opt out"))
  342. } else {
  343. nsNotice(rb, client.t("Multiclient functionality is currently disabled for your account, but you can opt in"))
  344. }
  345. case MulticlientDisallowedByUser:
  346. nsNotice(rb, client.t("Multiclient functionality is currently disabled for your account"))
  347. case MulticlientAllowedByUser:
  348. nsNotice(rb, client.t("Multiclient functionality is currently enabled for your account"))
  349. }
  350. }
  351. case "always-on":
  352. stored := settings.AlwaysOn
  353. actual := persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, stored)
  354. nsNotice(rb, fmt.Sprintf(client.t("Your stored always-on setting is: %s"), persistentStatusToString(stored)))
  355. if actual {
  356. nsNotice(rb, client.t("Given current server settings, your client is always-on"))
  357. } else {
  358. nsNotice(rb, client.t("Given current server settings, your client is not always-on"))
  359. }
  360. case "autoreplay-missed":
  361. stored := settings.AutoreplayMissed
  362. if stored {
  363. alwaysOn := persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, settings.AlwaysOn)
  364. if alwaysOn {
  365. nsNotice(rb, client.t("Autoreplay of missed messages is enabled"))
  366. } else {
  367. nsNotice(rb, client.t("You have enabled autoreplay of missed messages, but you can't receive them because your client isn't set to always-on"))
  368. }
  369. } else {
  370. nsNotice(rb, client.t("Your account is not configured to receive autoreplayed missed messages"))
  371. }
  372. case "auto-away":
  373. stored := settings.AutoAway
  374. alwaysOn := persistenceEnabled(config.Accounts.Multiclient.AlwaysOn, settings.AlwaysOn)
  375. actual := persistenceEnabled(config.Accounts.Multiclient.AutoAway, settings.AutoAway)
  376. nsNotice(rb, fmt.Sprintf(client.t("Your stored auto-away setting is: %s"), persistentStatusToString(stored)))
  377. if actual && alwaysOn {
  378. nsNotice(rb, client.t("Given current server settings, auto-away is enabled for your client"))
  379. } else if actual && !alwaysOn {
  380. nsNotice(rb, client.t("Because your client is not always-on, auto-away is disabled"))
  381. } else if !actual {
  382. nsNotice(rb, client.t("Given current server settings, auto-away is disabled for your client"))
  383. }
  384. case "dm-history":
  385. effectiveValue := historyEnabled(config.History.Persistent.DirectMessages, settings.DMHistory)
  386. csNotice(rb, fmt.Sprintf(client.t("Your stored direct message history setting is: %s"), historyStatusToString(settings.DMHistory)))
  387. csNotice(rb, fmt.Sprintf(client.t("Given current server settings, your direct message history setting is: %s"), historyStatusToString(effectiveValue)))
  388. default:
  389. nsNotice(rb, client.t("No such setting"))
  390. }
  391. }
  392. func nsSetHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  393. var account string
  394. if command == "saset" {
  395. account = params[0]
  396. params = params[1:]
  397. } else {
  398. account = client.Account()
  399. }
  400. var munger settingsMunger
  401. var finalSettings AccountSettings
  402. var err error
  403. switch strings.ToLower(params[0]) {
  404. case "pass":
  405. nsNotice(rb, client.t("To change a password, use the PASSWD command. For details, /msg NickServ HELP PASSWD"))
  406. return
  407. case "enforce":
  408. var method NickEnforcementMethod
  409. method, err = nickReservationFromString(params[1])
  410. if err != nil {
  411. err = errInvalidParams
  412. break
  413. }
  414. // updating enforcement settings is special-cased, because it requires
  415. // an update to server.accounts.accountToMethod
  416. finalSettings, err = server.accounts.SetEnforcementStatus(account, method)
  417. if err == nil {
  418. finalSettings.NickEnforcement = method // success
  419. }
  420. case "autoreplay-lines":
  421. var newValue *int
  422. if strings.ToLower(params[1]) != "default" {
  423. val, err_ := strconv.Atoi(params[1])
  424. if err_ != nil || val < 0 {
  425. err = errInvalidParams
  426. break
  427. }
  428. newValue = new(int)
  429. *newValue = val
  430. }
  431. munger = func(in AccountSettings) (out AccountSettings, err error) {
  432. out = in
  433. out.AutoreplayLines = newValue
  434. return
  435. }
  436. case "multiclient":
  437. var newValue MulticlientAllowedSetting
  438. if strings.ToLower(params[1]) == "default" {
  439. newValue = MulticlientAllowedServerDefault
  440. } else {
  441. var enabled bool
  442. enabled, err = utils.StringToBool(params[1])
  443. if enabled {
  444. newValue = MulticlientAllowedByUser
  445. } else {
  446. newValue = MulticlientDisallowedByUser
  447. }
  448. }
  449. if err == nil {
  450. munger = func(in AccountSettings) (out AccountSettings, err error) {
  451. out = in
  452. out.AllowBouncer = newValue
  453. return
  454. }
  455. }
  456. case "replay-joins":
  457. var newValue ReplayJoinsSetting
  458. newValue, err = replayJoinsSettingFromString(params[1])
  459. if err == nil {
  460. munger = func(in AccountSettings) (out AccountSettings, err error) {
  461. out = in
  462. out.ReplayJoins = newValue
  463. return
  464. }
  465. }
  466. case "always-on":
  467. // #821: it's problematic to alter the value of always-on if you're not
  468. // the (actual or potential) always-on client yourself. make an exception
  469. // for `saset` to give operators an escape hatch (any consistency problems
  470. // can probably be fixed by restarting the server):
  471. if command != "saset" {
  472. details := client.Details()
  473. if details.nick != details.accountName {
  474. err = errNickAccountMismatch
  475. }
  476. }
  477. if err == nil {
  478. var newValue PersistentStatus
  479. newValue, err = persistentStatusFromString(params[1])
  480. // "opt-in" and "opt-out" don't make sense as user preferences
  481. if err == nil && newValue != PersistentOptIn && newValue != PersistentOptOut {
  482. munger = func(in AccountSettings) (out AccountSettings, err error) {
  483. out = in
  484. out.AlwaysOn = newValue
  485. return
  486. }
  487. }
  488. }
  489. case "autoreplay-missed":
  490. var newValue bool
  491. newValue, err = utils.StringToBool(params[1])
  492. if err == nil {
  493. munger = func(in AccountSettings) (out AccountSettings, err error) {
  494. out = in
  495. out.AutoreplayMissed = newValue
  496. return
  497. }
  498. }
  499. case "auto-away":
  500. var newValue PersistentStatus
  501. newValue, err = persistentStatusFromString(params[1])
  502. // "opt-in" and "opt-out" don't make sense as user preferences
  503. if err == nil && newValue != PersistentOptIn && newValue != PersistentOptOut {
  504. munger = func(in AccountSettings) (out AccountSettings, err error) {
  505. out = in
  506. out.AutoAway = newValue
  507. return
  508. }
  509. }
  510. case "dm-history":
  511. var newValue HistoryStatus
  512. newValue, err = historyStatusFromString(params[1])
  513. if err == nil {
  514. munger = func(in AccountSettings) (out AccountSettings, err error) {
  515. out = in
  516. out.DMHistory = newValue
  517. return
  518. }
  519. }
  520. default:
  521. err = errInvalidParams
  522. }
  523. if munger != nil {
  524. finalSettings, err = server.accounts.ModifyAccountSettings(account, munger)
  525. }
  526. switch err {
  527. case nil:
  528. nsNotice(rb, client.t("Successfully changed your account settings"))
  529. displaySetting(params[0], finalSettings, client, rb)
  530. case errInvalidParams, errAccountDoesNotExist, errFeatureDisabled, errAccountUnverified, errAccountUpdateFailed:
  531. nsNotice(rb, client.t(err.Error()))
  532. case errNickAccountMismatch:
  533. nsNotice(rb, fmt.Sprintf(client.t("Your nickname must match your account name %s exactly to modify this setting. Try changing it with /NICK, or logging out and back in with the correct nickname."), client.AccountName()))
  534. default:
  535. // unknown error
  536. nsNotice(rb, client.t("An error occurred"))
  537. }
  538. }
  539. func nsDropHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  540. sadrop := command == "sadrop"
  541. var nick string
  542. if len(params) > 0 {
  543. nick = params[0]
  544. } else {
  545. nick = client.NickCasefolded()
  546. }
  547. err := server.accounts.SetNickReserved(client, nick, sadrop, false)
  548. if err == nil {
  549. nsNotice(rb, fmt.Sprintf(client.t("Successfully ungrouped nick %s with your account"), nick))
  550. } else if err == errAccountNotLoggedIn {
  551. nsNotice(rb, client.t("You're not logged into an account"))
  552. } else if err == errAccountCantDropPrimaryNick {
  553. nsNotice(rb, client.t("You can't ungroup your primary nickname (try unregistering your account instead)"))
  554. } else {
  555. nsNotice(rb, client.t("Could not ungroup nick"))
  556. }
  557. }
  558. func nsGhostHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  559. nick := params[0]
  560. ghost := server.clients.Get(nick)
  561. if ghost == nil {
  562. nsNotice(rb, client.t("No such nick"))
  563. return
  564. } else if ghost == client {
  565. nsNotice(rb, client.t("You can't GHOST yourself (try /QUIT instead)"))
  566. return
  567. } else if ghost.AlwaysOn() {
  568. nsNotice(rb, client.t("You can't GHOST an always-on client"))
  569. return
  570. }
  571. authorized := false
  572. account := client.Account()
  573. if account != "" {
  574. // the user must either own the nick, or the target client
  575. authorized = (server.accounts.NickToAccount(nick) == account) || (ghost.Account() == account)
  576. }
  577. if !authorized {
  578. nsNotice(rb, client.t("You don't own that nick"))
  579. return
  580. }
  581. ghost.Quit(fmt.Sprintf(ghost.t("GHOSTed by %s"), client.Nick()), nil)
  582. ghost.destroy(nil)
  583. }
  584. func nsGroupHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  585. nick := client.Nick()
  586. err := server.accounts.SetNickReserved(client, nick, false, true)
  587. if err == nil {
  588. nsNotice(rb, fmt.Sprintf(client.t("Successfully grouped nick %s with your account"), nick))
  589. } else if err == errAccountTooManyNicks {
  590. nsNotice(rb, client.t("You have too many nicks reserved already (you can remove some with /NS DROP)"))
  591. } else if err == errNicknameReserved {
  592. nsNotice(rb, client.t("That nickname is already reserved by someone else"))
  593. } else {
  594. nsNotice(rb, client.t("Error reserving nickname"))
  595. }
  596. }
  597. func nsLoginThrottleCheck(client *Client, rb *ResponseBuffer) (success bool) {
  598. client.stateMutex.Lock()
  599. throttled, remainingTime := client.loginThrottle.Touch()
  600. client.stateMutex.Unlock()
  601. if throttled {
  602. nsNotice(rb, fmt.Sprintf(client.t("Please wait at least %v and try again"), remainingTime))
  603. return false
  604. }
  605. return true
  606. }
  607. func nsIdentifyHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  608. if client.LoggedIntoAccount() {
  609. nsNotice(rb, client.t("You're already logged into an account"))
  610. return
  611. }
  612. var err error
  613. loginSuccessful := false
  614. var username, passphrase string
  615. if len(params) == 1 {
  616. if rb.session.certfp != "" {
  617. username = params[0]
  618. } else {
  619. // XXX undocumented compatibility mode with other nickservs, allowing
  620. // /msg NickServ identify passphrase
  621. username = client.NickCasefolded()
  622. passphrase = params[0]
  623. }
  624. } else {
  625. username = params[0]
  626. passphrase = params[1]
  627. }
  628. // try passphrase
  629. if passphrase != "" {
  630. if !nsLoginThrottleCheck(client, rb) {
  631. return
  632. }
  633. err = server.accounts.AuthenticateByPassphrase(client, username, passphrase)
  634. loginSuccessful = (err == nil)
  635. }
  636. // try certfp
  637. if !loginSuccessful && rb.session.certfp != "" {
  638. err = server.accounts.AuthenticateByCertFP(client, rb.session.certfp, "")
  639. loginSuccessful = (err == nil)
  640. }
  641. nickFixupFailed := false
  642. if loginSuccessful {
  643. if !fixupNickEqualsAccount(client, rb, server.Config()) {
  644. loginSuccessful = false
  645. // fixupNickEqualsAccount sends its own error message, don't send another
  646. nickFixupFailed = true
  647. }
  648. }
  649. if loginSuccessful {
  650. sendSuccessfulAccountAuth(client, rb, true, true)
  651. } else if !nickFixupFailed {
  652. nsNotice(rb, fmt.Sprintf(client.t("Authentication failed: %s"), authErrorToMessage(server, err)))
  653. }
  654. }
  655. func nsListHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  656. if !client.HasRoleCapabs("accreg") {
  657. nsNotice(rb, client.t("Insufficient privileges"))
  658. return
  659. }
  660. var searchRegex *regexp.Regexp
  661. if len(params) > 0 {
  662. var err error
  663. searchRegex, err = regexp.Compile(params[0])
  664. if err != nil {
  665. nsNotice(rb, client.t("Invalid regex"))
  666. return
  667. }
  668. }
  669. nsNotice(rb, ircfmt.Unescape(client.t("*** $bNickServ LIST$b ***")))
  670. nicks := server.accounts.AllNicks()
  671. for _, nick := range nicks {
  672. if searchRegex == nil || searchRegex.MatchString(nick) {
  673. nsNotice(rb, fmt.Sprintf(" %s", nick))
  674. }
  675. }
  676. nsNotice(rb, ircfmt.Unescape(client.t("*** $bEnd of NickServ LIST$b ***")))
  677. }
  678. func nsInfoHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  679. if !server.Config().Accounts.AuthenticationEnabled && !client.HasRoleCapabs("accreg") {
  680. nsNotice(rb, client.t("This command has been disabled by the server administrators"))
  681. return
  682. }
  683. var accountName string
  684. if len(params) > 0 {
  685. nick := params[0]
  686. if server.Config().Accounts.NickReservation.Enabled {
  687. accountName = server.accounts.NickToAccount(nick)
  688. if accountName == "" {
  689. nsNotice(rb, client.t("That nickname is not registered"))
  690. return
  691. }
  692. } else {
  693. accountName = nick
  694. }
  695. } else {
  696. accountName = client.Account()
  697. if accountName == "" {
  698. nsNotice(rb, client.t("You're not logged into an account"))
  699. return
  700. }
  701. }
  702. account, err := server.accounts.LoadAccount(accountName)
  703. if err != nil || !account.Verified {
  704. nsNotice(rb, client.t("Account does not exist"))
  705. return
  706. }
  707. nsNotice(rb, fmt.Sprintf(client.t("Account: %s"), account.Name))
  708. registeredAt := account.RegisteredAt.Format(time.RFC1123)
  709. nsNotice(rb, fmt.Sprintf(client.t("Registered at: %s"), registeredAt))
  710. // TODO nicer formatting for this
  711. for _, nick := range account.AdditionalNicks {
  712. nsNotice(rb, fmt.Sprintf(client.t("Additional grouped nick: %s"), nick))
  713. }
  714. for _, channel := range server.accounts.ChannelsForAccount(accountName) {
  715. nsNotice(rb, fmt.Sprintf(client.t("Registered channel: %s"), channel))
  716. }
  717. }
  718. func nsRegisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  719. details := client.Details()
  720. passphrase := params[0]
  721. var email string
  722. if 1 < len(params) {
  723. email = params[1]
  724. }
  725. certfp := rb.session.certfp
  726. if passphrase == "*" {
  727. if certfp == "" {
  728. nsNotice(rb, client.t("You must be connected with TLS and a client certificate to do this"))
  729. return
  730. } else {
  731. passphrase = ""
  732. }
  733. }
  734. if !nsLoginThrottleCheck(client, rb) {
  735. return
  736. }
  737. config := server.Config()
  738. account := details.nick
  739. if config.Accounts.NickReservation.ForceGuestFormat {
  740. matches := config.Accounts.NickReservation.guestRegexp.FindStringSubmatch(account)
  741. if matches == nil || len(matches) < 2 {
  742. nsNotice(rb, client.t("Erroneous nickname"))
  743. return
  744. }
  745. account = matches[1]
  746. }
  747. var callbackNamespace, callbackValue string
  748. noneCallbackAllowed := false
  749. for _, callback := range config.Accounts.Registration.EnabledCallbacks {
  750. if callback == "*" {
  751. noneCallbackAllowed = true
  752. }
  753. }
  754. // XXX if ACC REGISTER allows registration with the `none` callback, then ignore
  755. // any callback that was passed here (to avoid confusion in the case where the ircd
  756. // has no mail server configured). otherwise, register using the provided callback:
  757. if noneCallbackAllowed {
  758. callbackNamespace = "*"
  759. } else {
  760. callbackNamespace, callbackValue = parseCallback(email, config.Accounts)
  761. if callbackNamespace == "" || callbackValue == "" {
  762. nsNotice(rb, client.t("Registration requires a valid e-mail address"))
  763. return
  764. }
  765. }
  766. err := server.accounts.Register(client, account, callbackNamespace, callbackValue, passphrase, rb.session.certfp)
  767. if err == nil {
  768. if callbackNamespace == "*" {
  769. err = server.accounts.Verify(client, account, "")
  770. if err == nil && fixupNickEqualsAccount(client, rb, config) {
  771. sendSuccessfulRegResponse(client, rb, true)
  772. }
  773. } else {
  774. messageTemplate := client.t("Account created, pending verification; verification code has been sent to %s")
  775. message := fmt.Sprintf(messageTemplate, callbackValue)
  776. nsNotice(rb, message)
  777. }
  778. } else {
  779. // details could not be stored and relevant numerics have been dispatched, abort
  780. message, _ := registrationErrorToMessageAndCode(err)
  781. nsNotice(rb, client.t(message))
  782. }
  783. }
  784. func nsSaregisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  785. var account, passphrase string
  786. account = params[0]
  787. if 1 < len(params) && params[1] != "*" {
  788. passphrase = params[1]
  789. }
  790. err := server.accounts.SARegister(account, passphrase)
  791. if err != nil {
  792. var errMsg string
  793. if err == errAccountAlreadyRegistered || err == errAccountAlreadyVerified {
  794. errMsg = client.t("Account already exists")
  795. } else if err == errAccountBadPassphrase {
  796. errMsg = client.t("Passphrase contains forbidden characters or is otherwise invalid")
  797. } else {
  798. server.logger.Error("services", "unknown error from saregister", err.Error())
  799. errMsg = client.t("Could not register")
  800. }
  801. nsNotice(rb, errMsg)
  802. } else {
  803. nsNotice(rb, fmt.Sprintf(client.t("Successfully registered account %s"), account))
  804. server.snomasks.Send(sno.LocalAccounts, fmt.Sprintf(ircfmt.Unescape("Operator $c[grey][$r%s$c[grey]] registered account $c[grey][$r%s$c[grey]] with SAREGISTER"), client.Oper().Name, account))
  805. }
  806. }
  807. func nsUnregisterHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  808. erase := command == "erase"
  809. username := params[0]
  810. var verificationCode string
  811. if len(params) > 1 {
  812. verificationCode = params[1]
  813. }
  814. if username == "" {
  815. nsNotice(rb, client.t("You must specify an account"))
  816. return
  817. }
  818. var accountName string
  819. var registeredAt time.Time
  820. if erase {
  821. // account may not be in a loadable state, e.g., if it was unregistered
  822. accountName = username
  823. // make the confirmation code nondeterministic for ERASE
  824. registeredAt = server.ctime
  825. } else {
  826. account, err := server.accounts.LoadAccount(username)
  827. if err == errAccountDoesNotExist {
  828. nsNotice(rb, client.t("Invalid account name"))
  829. return
  830. } else if err != nil {
  831. nsNotice(rb, client.t("Internal error"))
  832. return
  833. }
  834. accountName = account.Name
  835. registeredAt = account.RegisteredAt
  836. }
  837. if !(accountName == client.AccountName() || client.HasRoleCapabs("accreg")) {
  838. nsNotice(rb, client.t("Insufficient oper privs"))
  839. return
  840. }
  841. expectedCode := utils.ConfirmationCode(accountName, registeredAt)
  842. if expectedCode != verificationCode {
  843. if erase {
  844. nsNotice(rb, ircfmt.Unescape(client.t("$bWarning: erasing this account will allow it to be re-registered; consider UNREGISTER instead.$b")))
  845. } else {
  846. nsNotice(rb, ircfmt.Unescape(client.t("$bWarning: unregistering this account will remove its stored privileges.$b")))
  847. }
  848. nsNotice(rb, fmt.Sprintf(client.t("To confirm, run this command: %s"), fmt.Sprintf("/NS %s %s %s", strings.ToUpper(command), accountName, expectedCode)))
  849. return
  850. }
  851. err := server.accounts.Unregister(accountName, erase)
  852. if err == errAccountDoesNotExist {
  853. nsNotice(rb, client.t(err.Error()))
  854. } else if err != nil {
  855. nsNotice(rb, client.t("Error while unregistering account"))
  856. } else {
  857. nsNotice(rb, fmt.Sprintf(client.t("Successfully unregistered account %s"), accountName))
  858. server.logger.Info("accounts", "client", client.Nick(), "unregistered account", accountName)
  859. client.server.snomasks.Send(sno.LocalAccounts, fmt.Sprintf(ircfmt.Unescape("Client $c[grey][$r%s$c[grey]] unregistered account $c[grey][$r%s$c[grey]]"), client.NickMaskString(), accountName))
  860. }
  861. }
  862. func nsVerifyHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  863. username, code := params[0], params[1]
  864. err := server.accounts.Verify(client, username, code)
  865. var errorMessage string
  866. if err != nil {
  867. switch err {
  868. case errAccountAlreadyLoggedIn, errAccountVerificationInvalidCode, errAccountAlreadyVerified:
  869. errorMessage = err.Error()
  870. default:
  871. errorMessage = errAccountVerificationFailed.Error()
  872. }
  873. }
  874. if errorMessage != "" {
  875. nsNotice(rb, client.t(errorMessage))
  876. return
  877. }
  878. if fixupNickEqualsAccount(client, rb, server.Config()) {
  879. sendSuccessfulRegResponse(client, rb, true)
  880. }
  881. }
  882. func nsPasswdHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  883. var target string
  884. var newPassword string
  885. var errorMessage string
  886. hasPrivs := client.HasRoleCapabs("accreg")
  887. switch len(params) {
  888. case 2:
  889. if !hasPrivs {
  890. errorMessage = `Insufficient privileges`
  891. } else {
  892. target, newPassword = params[0], params[1]
  893. if newPassword == "*" {
  894. newPassword = ""
  895. }
  896. }
  897. case 3:
  898. target = client.Account()
  899. if target == "" {
  900. errorMessage = `You're not logged into an account`
  901. } else if params[1] != params[2] {
  902. errorMessage = `Passwords do not match`
  903. } else {
  904. if !nsLoginThrottleCheck(client, rb) {
  905. return
  906. }
  907. accountData, err := server.accounts.LoadAccount(target)
  908. if err != nil {
  909. errorMessage = `You're not logged into an account`
  910. } else {
  911. hash := accountData.Credentials.PassphraseHash
  912. if hash != nil && passwd.CompareHashAndPassword(hash, []byte(params[0])) != nil {
  913. errorMessage = `Password incorrect`
  914. } else {
  915. newPassword = params[1]
  916. if newPassword == "*" {
  917. newPassword = ""
  918. }
  919. }
  920. }
  921. }
  922. default:
  923. errorMessage = `Invalid parameters`
  924. }
  925. if errorMessage != "" {
  926. nsNotice(rb, client.t(errorMessage))
  927. return
  928. }
  929. err := server.accounts.setPassword(target, newPassword, hasPrivs)
  930. switch err {
  931. case nil:
  932. nsNotice(rb, client.t("Password changed"))
  933. case errEmptyCredentials:
  934. nsNotice(rb, client.t("You can't delete your password unless you add a certificate fingerprint"))
  935. case errCredsExternallyManaged:
  936. nsNotice(rb, client.t("Your account credentials are managed externally and cannot be changed here"))
  937. case errCASFailed:
  938. nsNotice(rb, client.t("Try again later"))
  939. default:
  940. server.logger.Error("internal", "could not upgrade user password:", err.Error())
  941. nsNotice(rb, client.t("Password could not be changed due to server error"))
  942. }
  943. }
  944. func nsEnforceHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  945. newParams := []string{"enforce"}
  946. if len(params) == 0 {
  947. nsGetHandler(server, client, "get", newParams, rb)
  948. } else {
  949. newParams = append(newParams, params[0])
  950. nsSetHandler(server, client, "set", newParams, rb)
  951. }
  952. }
  953. func nsSessionsHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  954. target := client
  955. if 0 < len(params) {
  956. target = server.clients.Get(params[0])
  957. if target == nil {
  958. nsNotice(rb, client.t("No such nick"))
  959. return
  960. }
  961. // same permissions check as RPL_WHOISACTUALLY for now:
  962. if target != client && !client.HasMode(modes.Operator) {
  963. nsNotice(rb, client.t("Command restricted"))
  964. return
  965. }
  966. }
  967. sessionData, currentIndex := target.AllSessionData(rb.session)
  968. nsNotice(rb, fmt.Sprintf(client.t("Nickname %[1]s has %[2]d attached session(s)"), target.Nick(), len(sessionData)))
  969. for i, session := range sessionData {
  970. if currentIndex == i {
  971. nsNotice(rb, fmt.Sprintf(client.t("Session %d (currently attached session):"), i+1))
  972. } else {
  973. nsNotice(rb, fmt.Sprintf(client.t("Session %d:"), i+1))
  974. }
  975. nsNotice(rb, fmt.Sprintf(client.t("IP address: %s"), session.ip.String()))
  976. nsNotice(rb, fmt.Sprintf(client.t("Hostname: %s"), session.hostname))
  977. nsNotice(rb, fmt.Sprintf(client.t("Created at: %s"), session.ctime.Format(time.RFC1123)))
  978. nsNotice(rb, fmt.Sprintf(client.t("Last active: %s"), session.atime.Format(time.RFC1123)))
  979. if session.certfp != "" {
  980. nsNotice(rb, fmt.Sprintf(client.t("Certfp: %s"), session.certfp))
  981. }
  982. }
  983. }
  984. func nsCertHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
  985. verb := strings.ToLower(params[0])
  986. params = params[1:]
  987. var target, certfp string
  988. switch verb {
  989. case "list":
  990. if 1 <= len(params) {
  991. target = params[0]
  992. }
  993. case "add", "del":
  994. if 2 <= len(params) {
  995. target, certfp = params[0], params[1]
  996. } else if len(params) == 1 {
  997. certfp = params[0]
  998. } else {
  999. nsNotice(rb, client.t("Invalid parameters"))
  1000. return
  1001. }
  1002. default:
  1003. nsNotice(rb, client.t("Invalid parameters"))
  1004. return
  1005. }
  1006. hasPrivs := client.HasRoleCapabs("accreg")
  1007. if target != "" && !hasPrivs {
  1008. nsNotice(rb, client.t("Insufficient privileges"))
  1009. return
  1010. } else if target == "" {
  1011. target = client.Account()
  1012. if target == "" {
  1013. nsNotice(rb, client.t("You're not logged into an account"))
  1014. return
  1015. }
  1016. }
  1017. var err error
  1018. switch verb {
  1019. case "list":
  1020. accountData, err := server.accounts.LoadAccount(target)
  1021. if err == errAccountDoesNotExist {
  1022. nsNotice(rb, client.t("Account does not exist"))
  1023. return
  1024. } else if err != nil {
  1025. nsNotice(rb, client.t("An error occurred"))
  1026. return
  1027. }
  1028. certfps := accountData.Credentials.Certfps
  1029. nsNotice(rb, fmt.Sprintf(client.t("There are %[1]d certificate fingerprint(s) authorized for account %[2]s."), len(certfps), accountData.Name))
  1030. for i, certfp := range certfps {
  1031. nsNotice(rb, fmt.Sprintf("%d: %s", i+1, certfp))
  1032. }
  1033. return
  1034. case "add":
  1035. err = server.accounts.addRemoveCertfp(target, certfp, true, hasPrivs)
  1036. case "del":
  1037. err = server.accounts.addRemoveCertfp(target, certfp, false, hasPrivs)
  1038. }
  1039. switch err {
  1040. case nil:
  1041. if verb == "add" {
  1042. nsNotice(rb, client.t("Certificate fingerprint successfully added"))
  1043. } else {
  1044. nsNotice(rb, client.t("Certificate fingerprint successfully removed"))
  1045. }
  1046. case errNoop:
  1047. if verb == "add" {
  1048. nsNotice(rb, client.t("That certificate fingerprint was already authorized"))
  1049. } else {
  1050. nsNotice(rb, client.t("Certificate fingerprint not found"))
  1051. }
  1052. case errAccountDoesNotExist:
  1053. nsNotice(rb, client.t("Account does not exist"))
  1054. case errLimitExceeded:
  1055. nsNotice(rb, client.t("You already have too many certificate fingerprints"))
  1056. case utils.ErrInvalidCertfp:
  1057. nsNotice(rb, client.t("Invalid certificate fingerprint"))
  1058. case errCertfpAlreadyExists:
  1059. nsNotice(rb, client.t("That certificate fingerprint is already associated with another account"))
  1060. case errEmptyCredentials:
  1061. nsNotice(rb, client.t("You can't remove all your certificate fingerprints unless you add a password"))
  1062. case errCredsExternallyManaged:
  1063. nsNotice(rb, client.t("Your account credentials are managed externally and cannot be changed here"))
  1064. case errCASFailed:
  1065. nsNotice(rb, client.t("Try again later"))
  1066. default:
  1067. server.logger.Error("internal", "could not modify certificates:", err.Error())
  1068. nsNotice(rb, client.t("An error occurred"))
  1069. }
  1070. }