exec_admin.xml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?xml version="1.0" encoding='ISO-8859-1'?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <!-- Module User's Guide -->
  9. <chapter>
  10. <title>&adminguide;</title>
  11. <section id="exec.overview">
  12. <title>Overview</title>
  13. <para>
  14. The exec module allows external commands to be executed from a &kamailio;
  15. script. The commands may be any valid shell commands--the command string is
  16. passed to the shell using <quote>popen</quote> command. &kamailio; passes
  17. additional information about the request in environment variables:
  18. </para>
  19. <itemizedlist>
  20. <listitem>
  21. <para>
  22. SIP_HF_&lt;hf_name&gt; contains value of each header field in
  23. request. If a header field occurred multiple times, values are
  24. concatenated and comma-separated. &lt;hf_name&gt; is in capital
  25. letters. Ff a header-field name occurred in compact form,
  26. &lt;hf_name&gt; is canonical.
  27. </para>
  28. </listitem>
  29. <listitem>
  30. <para>
  31. SIP_TID is transaction identifier. All request retransmissions or
  32. CANCELs/ACKs associated with a previous INVITE result in the same
  33. value.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. SIP_DID is dialog identifier, which is the same as to-tag.
  39. Initially, it is empty.
  40. </para>
  41. </listitem>
  42. <listitem>
  43. <para>
  44. SIP_SRCIP is source &ip; address from which request came.
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. SIP_ORURI is the original request &uri;.
  50. </para>
  51. </listitem>
  52. <listitem>
  53. <para>
  54. SIP_RURI is <emphasis>current</emphasis> request &uri; (if
  55. unchanged, equal to original).
  56. </para>
  57. </listitem>
  58. <listitem>
  59. <para>
  60. SIP_USER is userpart of <emphasis>current</emphasis> request &uri;.
  61. </para>
  62. </listitem>
  63. <listitem>
  64. <para>
  65. SIP_OUSER is userpart of original request &uri;.
  66. </para>
  67. </listitem>
  68. </itemizedlist>
  69. <para>
  70. NOTE: The environment variables must be specified with double $
  71. (e.g., $$SIP_OUSER) in the parameters given to exec functions.
  72. Otherwise they will be evaluated as &kamailio; pseudo-variables,
  73. throwing errors.
  74. </para>
  75. </section>
  76. <section>
  77. <title>Dependencies</title>
  78. <section>
  79. <title>&kamailio; Modules</title>
  80. <para>
  81. The following modules must be loaded before this module:
  82. <itemizedlist>
  83. <listitem>
  84. <para>
  85. <emphasis>No dependencies on other &kamailio; modules</emphasis>.
  86. </para>
  87. </listitem>
  88. </itemizedlist>
  89. </para>
  90. </section>
  91. <section>
  92. <title>External Libraries or Applications</title>
  93. <para>
  94. The following libraries or applications must be installed before running
  95. &kamailio; with this module loaded:
  96. <itemizedlist>
  97. <listitem>
  98. <para>
  99. <emphasis>None</emphasis>.
  100. </para>
  101. </listitem>
  102. </itemizedlist>
  103. </para>
  104. </section>
  105. </section>
  106. <section>
  107. <title>Parameters</title>
  108. <section id="exec.p.setvars">
  109. <title><varname>setvars</varname> (integer)</title>
  110. <para>
  111. Turn off to disable setting environment variables for executed commands.
  112. </para>
  113. <para>
  114. <emphasis>
  115. Default value is 1.
  116. </emphasis>
  117. </para>
  118. <example>
  119. <title>Set <quote>setvars</quote> parameter</title>
  120. <programlisting format="linespecific">
  121. ...
  122. modparam("exec", "setvars", 1)
  123. ...
  124. </programlisting>
  125. </example>
  126. </section>
  127. <section id="exec.p.time_to_kill">
  128. <title>
  129. <varname>time_to_kill</varname> (integer)
  130. </title>
  131. <para>
  132. Specifies the longest time a program is allowed to execute. If the
  133. time is exceeded, the program is killed.
  134. </para>
  135. <para>
  136. <emphasis>
  137. Default value is 0.
  138. </emphasis>
  139. </para>
  140. <example>
  141. <title>Set <quote>time_to_kill</quote> parameter</title>
  142. <programlisting format="linespecific">
  143. ...
  144. modparam("exec", "time_to_kill", 20)
  145. ...
  146. </programlisting>
  147. </example>
  148. </section>
  149. </section>
  150. <section>
  151. <title>Functions</title>
  152. <section id="exec.f.exec_dset">
  153. <title>
  154. <function moreinfo="none">exec_dset(command)</function>
  155. </title>
  156. <para>
  157. Executes an external command. Current &uri; is passed to the command
  158. as parameter. Output of the command is considered &uri; set
  159. (separated by lines).
  160. </para>
  161. <para>Meaning of the parameters is as follows:</para>
  162. <itemizedlist>
  163. <listitem>
  164. <para><emphasis>command</emphasis> - Command to be executed. It can
  165. include pseudo- variabes;
  166. </para>
  167. </listitem>
  168. </itemizedlist>
  169. <para>
  170. WARNING: if the var you are passing out has a bash special
  171. character in it, the var needs to be placed inside quotes, for example:
  172. exec_dset("print-contact.sh '$ct'");
  173. </para>
  174. <para>
  175. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  176. </para>
  177. <example>
  178. <title><function moreinfo="none">exec_dset</function> usage</title>
  179. <programlisting format="linespecific">
  180. ...
  181. exec_dset("echo TEST > /tmp/test.txt");
  182. exec_dset("echo TEST > /tmp/$rU.txt");
  183. ...
  184. </programlisting>
  185. </example>
  186. </section>
  187. <section id="exec.f.exec_msg">
  188. <title>
  189. <function moreinfo="none">exec_msg(command)</function>
  190. </title>
  191. <para>
  192. Executes an external command. The whole message is passed to it in
  193. input, no command-line parameters are added, output of the command is
  194. not processed.
  195. </para>
  196. <para>
  197. The <quote>examples</quote> directory in the source tarball contains several examples
  198. that shows how to use this function.
  199. </para>
  200. <para>Meaning of the parameters is as follows:</para>
  201. <itemizedlist>
  202. <listitem>
  203. <para><emphasis>command</emphasis> - Command to be executed. It
  204. can include pseudo-variables.
  205. </para>
  206. </listitem>
  207. </itemizedlist>
  208. <para>
  209. WARNING: if the var you are passing out has a bash special
  210. character in it, the var needs to be placed inside quotes, for example:
  211. exec_msg("print-contact.sh '$ct'");
  212. </para>
  213. <para>
  214. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  215. </para>
  216. <example>
  217. <title><function moreinfo="none">exec_msg</function> usage</title>
  218. <programlisting format="linespecific">
  219. ...
  220. exec_msg("echo TEST > /tmp/test.txt");
  221. exec_msg("echo TEST > /tmp/$rU.txt");
  222. ...
  223. </programlisting>
  224. </example>
  225. </section>
  226. <section id="exec.f.exec_avp">
  227. <title>
  228. <function moreinfo="none">exec_avp(command [, avplist])</function>
  229. </title>
  230. <para>
  231. Executes an external command. Each line from output of the command
  232. is saved in an AVP from 'avplist'. If 'avplist' is missing, the
  233. AVPs are named 1, 2, 3, ...
  234. </para>
  235. <para>Meaning of the parameters is as follows:</para>
  236. <itemizedlist>
  237. <listitem>
  238. <para><emphasis>command</emphasis> - Command to be executed. It can
  239. include pseudo- variabes;
  240. </para>
  241. </listitem>
  242. <listitem>
  243. <para><emphasis>avplist</emphasis> - comma separated list with AVP
  244. names to store the result in;
  245. </para>
  246. </listitem>
  247. </itemizedlist>
  248. <para>
  249. WARNING: if the var you are passing out has a bash special
  250. character in it, the var needs to be placed inside quotes, for example:
  251. exec_avp("print-contact.sh '$ct'");
  252. </para>
  253. <para>
  254. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE.
  255. </para>
  256. <example>
  257. <title><function moreinfo="none">exec_avp</function> usage</title>
  258. <programlisting format="linespecific">
  259. ...
  260. exec_avp("echo TEST");
  261. exec_avp("echo TEST", "$avp(s:test)");
  262. ...
  263. </programlisting>
  264. </example>
  265. </section>
  266. </section>
  267. <section id="exec.known_issues">
  268. <title>Known Issues</title>
  269. <para>
  270. There is currently no guarantee that scripts ever return and stop
  271. blocking the &sip; server. (There is kill.c but it is not used along with
  272. the current mechanisms based on popen. Besides that kill.c is ugly).
  273. </para>
  274. </section>
  275. </chapter>