====== Services ======

Synchronet Services((a feature suggested by Angus McLeod of ANJO BBS)) are loadable modules or external executables designed to be loaded by the Synchronet //Services Server// to service a particular TCP or UDP protocol for remote client connections. Synchronet Services are similar in concept to UNIX's [x]inetd services.

===== Configure =====

The //Services Server// can be configured via [[util:SCFG]]:Servers->Services Server:

  ╔═════════════════════════════════════════════╗
  ║           Services Server Settings          ║
  ╠═════════════════════════════════════════════╣
  ║ │Enabled                       Yes          ║
  ║ │Log Level                     Info         ║
  ║ │Network Interfaces            0.0.0.0, ::  ║
  ║ │Lookup Client Hostname        No           ║
  ║ │Configuration File            services.ini ║
  ║ │Login Requirements                         ║
  ║ │Login Info Save                            ║
  ║ │Limit Rate of Connections     <disabled>   ║
  ║ │JavaScript Settings...                     ║
  ║ │Failed Login Attempts...                   ║
  ╚═════════════════════════════════════════════╝

... or (on Windows) via [[monitor:SBBSCTRL]]:Services->Configure:

{{:service:sbbsctrl.3.20.srvcs.config.png}}

... or by editing the ''[Services]'' section of the ''[[dir:ctrl]]/[[config:sbbs.ini]]'' file.

Changes take effect after the Services Server is **recycled**.

==== Settings ====

^ Key                   ^ SCFG label                  ^ Default        ^ Description ^
| ''Enabled''            | //Enabled//                 | ''true''       | Start the Services Server when Synchronet launches. |
| ''LogLevel''           | //Log Level//               | ''Info''       | Minimum severity of events written to the log. Raise to ''Debug'' for troubleshooting; lower (e.g. ''Notice'') to reduce volume. |
| ''Interface''          | //Network Interfaces//      | ''0.0.0.0,::''  | Comma-separated IPv4/IPv6 addresses the server binds to. Restrict to specific addresses to limit exposure on multi-homed hosts. Individual services may further override their bindings in [[:config:services.ini]]. |
| ''Options''//(NO_HOST_LOOKUP bit)// | //Lookup Client Hostname// | hostname lookup on | Perform a reverse DNS lookup on every connecting client. //Yes// adds the hostname to logs and makes it available to scripts; //No// is faster and avoids DNS stalls. |
| ''iniFileName''        | //Configuration File//      | ''services.ini'' | Path (relative to [[dir:ctrl]]) of the INI file defining the individual services to load. See [[:config:services.ini]]. |
| ''LoginRequirements''  | //Login Requirements//      | (none)         | Access Requirements String (ARS) a user must satisfy before any authenticated service will accept their login. Blank = no extra restriction beyond per-service checks. |
| ''LoginInfoSave''      | //Login Info Save//         | (none)         | ARS controlling which successful logins are recorded in the user record's last-on history. Blank = save all. |
| ''MaxConnectsPerPeriod'' / ''ConnectRateLimitPeriod'' | //Limit Rate of Connections// | disabled | Cap connections-per-period per client IP; optionally auto-filter abusers via ''RateLimitFilter''. |

The Services Server also accepts the standard per-server [[:config:javascript|JavaScript runtime tuning]] keys and failed-login thresholds; both inherit from the global defaults unless overridden in the ''[Services]'' section.

==== Services ====

Services are normally configured via the ''[[dir:ctrl]]/[[:config:services.ini]]'' file with some global settings controlled via the ''[Services]'' section of the ''[[:config:sbbs.ini]]'' file.

... or (on Windows) via the "Services" tab of the [[monitor:SBBSCTRL]]:Services->Configure dialog:

{{:service:sbbsctrl.3.20.services.config.png}}

Some static services (e.g. the [[:service:ircd|IRC Daemon]]) may alternatively be executed independently of the //Services Server// using [[:util:JSexec]].

===== Service Types =====

There are four types of services currently supported:

  - Dynamic JavaScript (the most common service type)
  - Static JavaScript (e.g. the [[:service:ircd|IRC Daemon]])
  - Dynamic Native
  - Static Native

===== JavaScript Services =====
Additional methods and properties available to Synchronet Services written in JavaScript:

==== Properties ====

^Property  ^Type     ^Description^
|''logged_in'' |boolean|Indication if user has successfully authenticated or not|
|''datagram''  |string |Contents of received UDP datagram (when applicable)|

==== Methods ====

Along with the [[http://synchro.net/docs/jsobjs.html#global_methods|common global methods]], JavaScript services include support for the following methods:

^Method   ^Returns ^Usage ^Description^
|''login''|boolean|''login(user, password [,increment_logins=//false//])''|Attempt to authenticate as specified user (name or number)|
|''logout''|boolean|''logout()''                                          |Logout currently authenticated user|
|''server.client_add''|void|''server.client_add(//Socket//, [user], [host])''    |Register client based on specified socket connection, with optional username and hostname|
|''server.client_update''|void|''server.client_update(//Socket//, [user], [host])''|Update client based on specified socket connection, with optional username and hostname|
|''server.client_remove''|void|''server.client_remove(//Socket//)''    |Unregister client based on specified socket connection|

===== Included Services =====

{{indexmenu>.}}

===== See Also =====
  * [[:config:services.ini]]
  * [[:server:|Servers]]
  * [[server:web|Web Server]]

{{tag>tcpip servers services javascript}}
