/trafficserver-3.2.0/mgmt/cli/ShowCmd.cc

# · C++ · 2476 lines · 1551 code · 358 blank · 567 comment · 227 complexity · ce6b8e44d705d54eec32f4653e703a4b MD5 · raw file

Large files are truncated click here to view the full file

  1. /** @file
  2. This file contains the "show" command implementation.
  3. @section license License
  4. Licensed to the Apache Software Foundation (ASF) under one
  5. or more contributor license agreements. See the NOTICE file
  6. distributed with this work for additional information
  7. regarding copyright ownership. The ASF licenses this file
  8. to you under the Apache License, Version 2.0 (the
  9. "License"); you may not use this file except in compliance
  10. with the License. You may obtain a copy of the License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unless required by applicable law or agreed to in writing, software
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. */
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <unistd.h>
  21. #include "ShowCmd.h"
  22. #include "ConfigCmd.h"
  23. #include "createArgument.h"
  24. #include "CliMgmtUtils.h"
  25. #include "CliDisplay.h"
  26. #include "ink_defs.h"
  27. #include "ink_string.h"
  28. #include <SysAPI.h>
  29. ////////////////////////////////////////////////////////////////
  30. // Cmd_Show
  31. //
  32. // This is the callback function for the "show" command.
  33. //
  34. // Parameters:
  35. // clientData -- information about parsed arguments
  36. // interp -- the Tcl interpreter
  37. // argc -- number of command arguments
  38. // argv -- the command arguments
  39. //
  40. int
  41. Cmd_Show(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  42. {
  43. NOWARN_UNUSED(clientData);
  44. /* call to processArgForCommand must appear at the beginning
  45. * of each command's callback function
  46. */
  47. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  48. return CMD_ERROR;
  49. }
  50. if (processHelpCommand(argc, argv) == CLI_OK)
  51. return CMD_OK;
  52. char *cmdinfo, *temp;
  53. int i = 0;
  54. Cli_Debug("Cmd_Show\n");
  55. Tcl_Eval(interp, "info commands show* ");
  56. int cmdinfo_size = sizeof(char) * (strlen(Tcl_GetStringResult(interp)) + 2);
  57. cmdinfo = (char *)alloca(cmdinfo_size);
  58. ink_strlcpy(cmdinfo, Tcl_GetStringResult(interp), cmdinfo_size);
  59. int temp_size = sizeof(char) * (strlen(cmdinfo) + 20);
  60. temp = (char *)alloca(temp_size);
  61. ink_strlcpy(temp, "lsort \"", temp_size);
  62. ink_strlcat(temp, cmdinfo, temp_size);
  63. ink_strlcat(temp, "\"", temp_size);
  64. Tcl_Eval(interp, temp);
  65. ink_strlcpy(cmdinfo, Tcl_GetStringResult(interp), cmdinfo_size);
  66. i = i + strlen("show ");
  67. while (cmdinfo[i] != 0) {
  68. if (cmdinfo[i] == ' ') {
  69. cmdinfo[i] = '\n';
  70. }
  71. i++;
  72. }
  73. cmdinfo[i] = '\n';
  74. i++;
  75. cmdinfo[i] = 0;
  76. Cli_Printf("Following are the available show commands\n");
  77. Cli_Printf(cmdinfo + strlen("show "));
  78. return 0;
  79. }
  80. ////////////////////////////////////////////////////////////////
  81. // Cmd_ShowStatus
  82. //
  83. // This is the callback function for the "show:status" command.
  84. //
  85. // Parameters:
  86. // clientData -- information about parsed arguments
  87. // interp -- the Tcl interpreter
  88. // argc -- number of command arguments
  89. // argv -- the command arguments
  90. //
  91. int
  92. Cmd_ShowStatus(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  93. {
  94. NOWARN_UNUSED(clientData);
  95. /* call to processArgForCommand must appear at the beginning
  96. * of each command's callback function
  97. */
  98. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  99. return CMD_ERROR;
  100. }
  101. if (processHelpCommand(argc, argv) == CLI_OK)
  102. return CMD_OK;
  103. Cli_Debug("Cmd_ShowStatus\n");
  104. return (ShowStatus());
  105. }
  106. ////////////////////////////////////////////////////////////////
  107. // Cmd_ShowVersion
  108. //
  109. // This is the callback function for the "show:version" command.
  110. //
  111. // Parameters:
  112. // clientData -- information about parsed arguments
  113. // interp -- the Tcl interpreter
  114. // argc -- number of command arguments
  115. // argv -- the command arguments
  116. //
  117. int
  118. Cmd_ShowVersion(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  119. {
  120. NOWARN_UNUSED(clientData);
  121. /* call to processArgForCommand must appear at the beginning
  122. * of each command's callback function
  123. */
  124. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  125. return CMD_ERROR;
  126. }
  127. if (processHelpCommand(argc, argv) == CLI_OK)
  128. return CMD_OK;
  129. Cli_Debug("Cmd_ShowVersion\n");
  130. return (ShowVersion());
  131. }
  132. ////////////////////////////////////////////////////////////////
  133. // Cmd_ShowPorts
  134. //
  135. // This is the callback function for the "show:ports" command.
  136. //
  137. // Parameters:
  138. // clientData -- information about parsed arguments
  139. // interp -- the Tcl interpreter
  140. // argc -- number of command arguments
  141. // argv -- the command arguments
  142. //
  143. int
  144. Cmd_ShowPorts(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  145. {
  146. NOWARN_UNUSED(clientData);
  147. /* call to processArgForCommand must appear at the beginning
  148. * of each command's callback function
  149. */
  150. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  151. return CMD_ERROR;
  152. }
  153. if (processHelpCommand(argc, argv) == CLI_OK)
  154. return CMD_OK;
  155. Cli_Debug("Cmd_ShowPorts\n");
  156. return (ShowPorts());
  157. }
  158. ////////////////////////////////////////////////////////////////
  159. // Cmd_ShowCluster
  160. //
  161. // This is the callback function for the "show:security" command.
  162. //
  163. // Parameters:
  164. // clientData -- information about parsed arguments
  165. // interp -- the Tcl interpreter
  166. // argc -- number of command arguments
  167. // argv -- the command arguments
  168. //
  169. int
  170. Cmd_ShowCluster(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  171. {
  172. NOWARN_UNUSED(clientData);
  173. /* call to processArgForCommand must appear at the beginning
  174. * of each command's callback function
  175. */
  176. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  177. return CMD_ERROR;
  178. }
  179. if (processHelpCommand(argc, argv) == CLI_OK)
  180. return CMD_OK;
  181. Cli_Debug("Cmd_ShowCluster\n");
  182. return (ShowCluster());
  183. }
  184. ////////////////////////////////////////////////////////////////
  185. // Cmd_ShowSecurity
  186. //
  187. // This is the callback function for the "show:security" command.
  188. //
  189. // Parameters:
  190. // clientData -- information about parsed arguments
  191. // interp -- the Tcl interpreter
  192. // argc -- number of command arguments
  193. // argv -- the command arguments
  194. //
  195. int
  196. Cmd_ShowSecurity(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  197. {
  198. NOWARN_UNUSED(clientData);
  199. /* call to processArgForCommand must appear at the beginning
  200. * of each command's callback function
  201. */
  202. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  203. return CMD_ERROR;
  204. }
  205. if (processHelpCommand(argc, argv) == CLI_OK)
  206. return CMD_OK;
  207. Cli_Debug("Cmd_ShowSecurity\n");
  208. return (ShowSecurity());
  209. }
  210. ////////////////////////////////////////////////////////////////
  211. // Cmd_ShowHttp
  212. //
  213. // This is the callback function for the "show:http" command.
  214. //
  215. // Parameters:
  216. // clientData -- information about parsed arguments
  217. // interp -- the Tcl interpreter
  218. // argc -- number of command arguments
  219. // argv -- the command arguments
  220. //
  221. int
  222. Cmd_ShowHttp(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  223. {
  224. NOWARN_UNUSED(clientData);
  225. /* call to processArgForCommand must appear at the beginning
  226. * of each command's callback function
  227. */
  228. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  229. return CMD_ERROR;
  230. }
  231. if (processHelpCommand(argc, argv) == CLI_OK)
  232. return CMD_OK;
  233. Cli_Debug("Cmd_ShowHttp\n");
  234. return (ShowHttp());
  235. }
  236. ////////////////////////////////////////////////////////////////
  237. // Cmd_ShowIcp
  238. //
  239. // This is the callback function for the "show:icp" command.
  240. //
  241. // Parameters:
  242. // clientData -- information about parsed arguments
  243. // interp -- the Tcl interpreter
  244. // argc -- number of command arguments
  245. // argv -- the command arguments
  246. //
  247. int
  248. Cmd_ShowIcp(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  249. {
  250. /* call to processArgForCommand must appear at the beginning
  251. * of each command's callback function
  252. */
  253. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  254. return CMD_ERROR;
  255. }
  256. if (processHelpCommand(argc, argv) == CLI_OK)
  257. return CMD_OK;
  258. Cli_Debug("Cmd_ShowIcp argc %d\n", argc);
  259. cli_cmdCallbackInfo *cmdCallbackInfo;
  260. cli_parsedArgInfo *argtable;
  261. cmdCallbackInfo = (cli_cmdCallbackInfo *) clientData;
  262. argtable = cmdCallbackInfo->parsedArgTable;
  263. if (argtable[0].parsed_args != CLI_PARSED_ARGV_END) {
  264. if (argtable[0].parsed_args == CMD_SHOW_ICP_PEER) {
  265. return (ShowIcpPeer());
  266. }
  267. Cli_Error(ERR_INVALID_COMMAND);
  268. return CMD_ERROR;
  269. }
  270. return (ShowIcp());
  271. }
  272. ////////////////////////////////////////////////////////////////
  273. // CmdArgs_ShowIcp
  274. //
  275. // Register "show:icp" arguments with the Tcl interpreter.
  276. //
  277. int
  278. CmdArgs_ShowIcp()
  279. {
  280. createArgument("peers", 1, CLI_ARGV_CONSTANT,
  281. (char *) NULL, CMD_SHOW_ICP_PEER, "ICP Peer Configuration", (char *) NULL);
  282. return 0;
  283. }
  284. ////////////////////////////////////////////////////////////////
  285. // Cmd_ShowProxy
  286. //
  287. // This is the callback function for the "show:proxy" command.
  288. //
  289. // Parameters:
  290. // clientData -- information about parsed arguments
  291. // interp -- the Tcl interpreter
  292. // argc -- number of command arguments
  293. // argv -- the command arguments
  294. //
  295. int
  296. Cmd_ShowProxy(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  297. {
  298. NOWARN_UNUSED(clientData);
  299. /* call to processArgForCommand must appear at the beginning
  300. * of each command's callback function
  301. */
  302. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  303. return CMD_ERROR;
  304. }
  305. if (processHelpCommand(argc, argv) == CLI_OK)
  306. return CMD_OK;
  307. Cli_Debug("Cmd_ShowProxy\n");
  308. return (ShowProxy());
  309. }
  310. ////////////////////////////////////////////////////////////////
  311. // Cmd_ShowCache
  312. //
  313. // This is the callback function for the "show:cache" command.
  314. //
  315. // Parameters:
  316. // clientData -- information about parsed arguments
  317. // interp -- the Tcl interpreter
  318. // argc -- number of command arguments
  319. // argv -- the command arguments
  320. //
  321. int
  322. Cmd_ShowCache(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  323. {
  324. /* call to processArgForCommand must appear at the beginning
  325. * of each command's callback function
  326. */
  327. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  328. return CMD_ERROR;
  329. }
  330. if (processHelpCommand(argc, argv) == CLI_OK)
  331. return CMD_OK;
  332. Cli_Debug("Cmd_ShowCache\n");
  333. cli_cmdCallbackInfo *cmdCallbackInfo;
  334. cli_parsedArgInfo *argtable;
  335. cmdCallbackInfo = (cli_cmdCallbackInfo *) clientData;
  336. argtable = cmdCallbackInfo->parsedArgTable;
  337. if (argtable[0].parsed_args != CLI_PARSED_ARGV_END) {
  338. if (argtable[0].parsed_args == CMD_SHOW_CACHE_RULES) {
  339. return (ShowCacheRules());
  340. } else if (argtable[0].parsed_args == CMD_SHOW_CACHE_STORAGE) {
  341. return (ShowCacheStorage());
  342. }
  343. Cli_Error(ERR_INVALID_COMMAND);
  344. return CMD_ERROR;
  345. }
  346. return (ShowCache());
  347. }
  348. ////////////////////////////////////////////////////////////////
  349. // CmdArgs_ShowCache
  350. //
  351. // Register "show:cache" arguments with the Tcl interpreter.
  352. //
  353. int
  354. CmdArgs_ShowCache()
  355. {
  356. createArgument("rules", 1, CLI_ARGV_CONSTANT,
  357. (char *) NULL, CMD_SHOW_CACHE_RULES, "Rules from cache.config", (char *) NULL);
  358. createArgument("storage", 1, CLI_ARGV_CONSTANT,
  359. (char *) NULL, CMD_SHOW_CACHE_STORAGE, "Rules from storage.config", (char *) NULL);
  360. return 0;
  361. }
  362. ////////////////////////////////////////////////////////////////
  363. // Cmd_ShowVirtualIp
  364. //
  365. // This is the callback function for the "show:virtual-ip" command.
  366. //
  367. // Parameters:
  368. // clientData -- information about parsed arguments
  369. // interp -- the Tcl interpreter
  370. // argc -- number of command arguments
  371. // argv -- the command arguments
  372. //
  373. int
  374. Cmd_ShowVirtualIp(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  375. {
  376. NOWARN_UNUSED(clientData);
  377. /* call to processArgForCommand must appear at the beginning
  378. * of each command's callback function
  379. */
  380. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  381. return CMD_ERROR;
  382. }
  383. if (processHelpCommand(argc, argv) == CLI_OK)
  384. return CMD_OK;
  385. Cli_Debug("Cmd_ShowVirtualIp\n");
  386. return (ShowVirtualIp());
  387. }
  388. ////////////////////////////////////////////////////////////////
  389. // Cmd_ShowHostDb
  390. //
  391. // This is the callback function for the "show:hostdb" command.
  392. //
  393. // Parameters:
  394. // clientData -- information about parsed arguments
  395. // interp -- the Tcl interpreter
  396. // argc -- number of command arguments
  397. // argv -- the command arguments
  398. //
  399. int
  400. Cmd_ShowHostDb(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  401. {
  402. NOWARN_UNUSED(clientData);
  403. /* call to processArgForCommand must appear at the beginning
  404. * of each command's callback function
  405. */
  406. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  407. return CMD_ERROR;
  408. }
  409. if (processHelpCommand(argc, argv) == CLI_OK)
  410. return CMD_OK;
  411. Cli_Debug("Cmd_ShowHostDb\n");
  412. return (ShowHostDb());
  413. }
  414. ////////////////////////////////////////////////////////////////
  415. // Cmd_ShowDnsResolver
  416. //
  417. // This is the callback function for the "show:dns-resolver" command.
  418. //
  419. // Parameters:
  420. // clientData -- information about parsed arguments
  421. // interp -- the Tcl interpreter
  422. // argc -- number of command arguments
  423. // argv -- the command arguments
  424. //
  425. int
  426. Cmd_ShowDnsResolver(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  427. {
  428. NOWARN_UNUSED(clientData);
  429. /* call to processArgForCommand must appear at the beginning
  430. * of each command's callback function
  431. */
  432. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  433. return CMD_ERROR;
  434. }
  435. if (processHelpCommand(argc, argv) == CLI_OK)
  436. return CMD_OK;
  437. Cli_Debug("Cmd_ShowDnsResolver\n");
  438. return (ShowDnsResolver());
  439. }
  440. ////////////////////////////////////////////////////////////////
  441. // Cmd_ShowLogging
  442. //
  443. // This is the callback function for the "show:logging" command.
  444. //
  445. // Parameters:
  446. // clientData -- information about parsed arguments
  447. // interp -- the Tcl interpreter
  448. // argc -- number of command arguments
  449. // argv -- the command arguments
  450. //
  451. int
  452. Cmd_ShowLogging(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  453. {
  454. NOWARN_UNUSED(clientData);
  455. /* call to processArgForCommand must appear at the beginning
  456. * of each command's callback function
  457. */
  458. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  459. return CMD_ERROR;
  460. }
  461. if (processHelpCommand(argc, argv) == CLI_OK)
  462. return CMD_OK;
  463. Cli_Debug("Cmd_ShowLogging\n");
  464. return (ShowLogging());
  465. }
  466. ////////////////////////////////////////////////////////////////
  467. // Cmd_ShowSsl
  468. //
  469. // This is the callback function for the "show:ssl" command.
  470. //
  471. // Parameters:
  472. // clientData -- information about parsed arguments
  473. // interp -- the Tcl interpreter
  474. // argc -- number of command arguments
  475. // argv -- the command arguments
  476. //
  477. int
  478. Cmd_ShowSsl(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  479. {
  480. NOWARN_UNUSED(clientData);
  481. /* call to processArgForCommand must appear at the beginning
  482. * of each command's callback function
  483. */
  484. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  485. return CMD_ERROR;
  486. }
  487. if (processHelpCommand(argc, argv) == CLI_OK)
  488. return CMD_OK;
  489. Cli_Debug("Cmd_ShowSsl\n");
  490. return (ShowSsl());
  491. }
  492. ////////////////////////////////////////////////////////////////
  493. // Cmd_ShowParents
  494. //
  495. // This is the callback function for the "show:parents" command.
  496. //
  497. // Parameters:
  498. // clientData -- information about parsed arguments
  499. // interp -- the Tcl interpreter
  500. // argc -- number of command arguments
  501. // argv -- the command arguments
  502. //
  503. int
  504. Cmd_ShowParents(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  505. {
  506. /* call to processArgForCommand must appear at the beginning
  507. * of each command's callback function
  508. */
  509. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  510. return CMD_ERROR;
  511. }
  512. if (processHelpCommand(argc, argv) == CLI_OK)
  513. return CMD_OK;
  514. Cli_Debug("Cmd_ShowParents\n");
  515. cli_cmdCallbackInfo *cmdCallbackInfo;
  516. cli_parsedArgInfo *argtable;
  517. cmdCallbackInfo = (cli_cmdCallbackInfo *) clientData;
  518. argtable = cmdCallbackInfo->parsedArgTable;
  519. if (argtable[0].parsed_args != CLI_PARSED_ARGV_END) {
  520. if (argtable[0].parsed_args == CMD_SHOW_PARENT_RULES) {
  521. return (ShowParentRules());
  522. }
  523. Cli_Error(ERR_INVALID_COMMAND);
  524. return CMD_ERROR;
  525. }
  526. return (ShowParents());
  527. }
  528. ////////////////////////////////////////////////////////////////
  529. // CmdArgs_ShowParents
  530. //
  531. // Register "show:parents" arguments with the Tcl interpreter.
  532. //
  533. int
  534. CmdArgs_ShowParents()
  535. {
  536. createArgument("rules", 1, CLI_ARGV_CONSTANT,
  537. (char *) NULL, CMD_SHOW_PARENT_RULES, "Display parent.config rules file", (char *) NULL);
  538. return 0;
  539. }
  540. ////////////////////////////////////////////////////////////////
  541. // Cmd_ShowRemap
  542. //
  543. // This is the callback function for the "show:remap" command.
  544. //
  545. // Parameters:
  546. // clientData -- information about parsed arguments
  547. // interp -- the Tcl interpreter
  548. // argc -- number of command arguments
  549. // argv -- the command arguments
  550. //
  551. int
  552. Cmd_ShowRemap(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  553. {
  554. NOWARN_UNUSED(clientData);
  555. /* call to processArgForCommand must appear at the beginning
  556. * of each command's callback function
  557. */
  558. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  559. return CMD_ERROR;
  560. }
  561. if (processHelpCommand(argc, argv) == CLI_OK)
  562. return CMD_OK;
  563. Cli_Debug("Cmd_ShowRemap\n");
  564. return (ShowRemap());
  565. }
  566. ////////////////////////////////////////////////////////////////
  567. // Cmd_ShowSocks
  568. //
  569. // This is the callback function for the "show:socks" command.
  570. //
  571. // Parameters:
  572. // clientData -- information about parsed arguments
  573. // interp -- the Tcl interpreter
  574. // argc -- number of command arguments
  575. // argv -- the command arguments
  576. //
  577. int
  578. Cmd_ShowSocks(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  579. {
  580. /* call to processArgForCommand must appear at the beginning
  581. * of each command's callback function
  582. */
  583. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  584. return CMD_ERROR;
  585. }
  586. if (processHelpCommand(argc, argv) == CLI_OK)
  587. return CMD_OK;
  588. Cli_Debug("Cmd_ShowSocks\n");
  589. cli_cmdCallbackInfo *cmdCallbackInfo;
  590. cli_parsedArgInfo *argtable;
  591. cmdCallbackInfo = (cli_cmdCallbackInfo *) clientData;
  592. argtable = cmdCallbackInfo->parsedArgTable;
  593. if (argtable[0].parsed_args != CLI_PARSED_ARGV_END) {
  594. if (argtable[0].parsed_args == CMD_SHOW_SOCKS_RULES) {
  595. return (ShowSocksRules());
  596. }
  597. Cli_Error(ERR_INVALID_COMMAND);
  598. return CMD_ERROR;
  599. }
  600. return (ShowSocks());
  601. }
  602. ////////////////////////////////////////////////////////////////
  603. // CmdArgs_ShowSocks
  604. //
  605. // Register "show:socks" arguments with the Tcl interpreter.
  606. //
  607. int
  608. CmdArgs_ShowSocks()
  609. {
  610. createArgument("rules", 1, CLI_ARGV_CONSTANT,
  611. (char *) NULL, CMD_SHOW_SOCKS_RULES, "Display socks.config rules file", (char *) NULL);
  612. return 0;
  613. }
  614. ////////////////////////////////////////////////////////////////
  615. // Cmd_ShowPortTunnels
  616. //
  617. // This is the callback function for the "show:port-tunnels" command.
  618. //
  619. // Parameters:
  620. // clientData -- information about parsed arguments
  621. // interp -- the Tcl interpreter
  622. // argc -- number of command arguments
  623. // argv -- the command arguments
  624. //
  625. int
  626. Cmd_ShowPortTunnels(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  627. {
  628. NOWARN_UNUSED(clientData);
  629. /* call to processArgForCommand must appear at the beginning
  630. * of each command's callback function
  631. */
  632. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  633. return CMD_ERROR;
  634. }
  635. if (processHelpCommand(argc, argv) == CLI_OK)
  636. return CMD_OK;
  637. Cli_Debug("Cmd_ShowPortTunnels\n");
  638. return (ShowPortTunnels());
  639. }
  640. ////////////////////////////////////////////////////////////////
  641. // Cmd_ShowScheduledUpdate
  642. //
  643. // This is the callback function for the "show:scheduled-update" command.
  644. //
  645. // Parameters:
  646. // clientData -- information about parsed arguments
  647. // interp -- the Tcl interpreter
  648. // argc -- number of command arguments
  649. // argv -- the command arguments
  650. //
  651. int
  652. Cmd_ShowScheduledUpdate(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  653. {
  654. /* call to processArgForCommand must appear at the beginning
  655. * of each command's callback function
  656. */
  657. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  658. return CMD_ERROR;
  659. }
  660. if (processHelpCommand(argc, argv) == CLI_OK)
  661. return CMD_OK;
  662. Cli_Debug("Cmd_ShowScheduledUpdate\n");
  663. cli_cmdCallbackInfo *cmdCallbackInfo;
  664. cli_parsedArgInfo *argtable;
  665. cmdCallbackInfo = (cli_cmdCallbackInfo *) clientData;
  666. argtable = cmdCallbackInfo->parsedArgTable;
  667. if (argtable[0].parsed_args != CLI_PARSED_ARGV_END) {
  668. if (argtable[0].parsed_args == CMD_SHOW_UPDATE_RULES) {
  669. return (ShowScheduledUpdateRules());
  670. }
  671. Cli_Error(ERR_INVALID_COMMAND);
  672. return CMD_ERROR;
  673. }
  674. return (ShowScheduledUpdate());
  675. }
  676. ////////////////////////////////////////////////////////////////
  677. // CmdArgs_ShowScheduledUpdate
  678. //
  679. // Register "show:scheduled-update" arguments with the Tcl interpreter.
  680. //
  681. int
  682. CmdArgs_ShowScheduledUpdate()
  683. {
  684. createArgument("rules", 1, CLI_ARGV_CONSTANT,
  685. (char *) NULL, CMD_SHOW_UPDATE_RULES, "Display update.config rules file", (char *) NULL);
  686. return 0;
  687. }
  688. ////////////////////////////////////////////////////////////////
  689. // Cmd_ShowProxyStats
  690. //
  691. // This is the callback function for the "show:proxy-stats" command.
  692. //
  693. // Parameters:
  694. // clientData -- information about parsed arguments
  695. // interp -- the Tcl interpreter
  696. // argc -- number of command arguments
  697. // argv -- the command arguments
  698. //
  699. int
  700. Cmd_ShowProxyStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  701. {
  702. NOWARN_UNUSED(clientData);
  703. /* call to processArgForCommand must appear at the beginning
  704. * of each command's callback function
  705. */
  706. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  707. return CMD_ERROR;
  708. }
  709. if (processHelpCommand(argc, argv) == CLI_OK)
  710. return CMD_OK;
  711. Cli_Debug("Cmd_ShowProxyStats\n");
  712. return (ShowProxyStats());
  713. }
  714. ////////////////////////////////////////////////////////////////
  715. // Cmd_ShowHttpTransStats
  716. //
  717. // This is the callback function for the "show:http-trans-stats" command.
  718. //
  719. // Parameters:
  720. // clientData -- information about parsed arguments
  721. // interp -- the Tcl interpreter
  722. // argc -- number of command arguments
  723. // argv -- the command arguments
  724. //
  725. int
  726. Cmd_ShowHttpTransStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  727. {
  728. NOWARN_UNUSED(clientData);
  729. /* call to processArgForCommand must appear at the beginning
  730. * of each command's callback function
  731. */
  732. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  733. return CMD_ERROR;
  734. }
  735. if (processHelpCommand(argc, argv) == CLI_OK)
  736. return CMD_OK;
  737. Cli_Debug("Cmd_ShowHttpTransStats\n");
  738. return (ShowHttpTransStats());
  739. }
  740. ////////////////////////////////////////////////////////////////
  741. // Cmd_ShowHttpStats
  742. //
  743. // This is the callback function for the "show:http-stats" command.
  744. //
  745. // Parameters:
  746. // clientData -- information about parsed arguments
  747. // interp -- the Tcl interpreter
  748. // argc -- number of command arguments
  749. // argv -- the command arguments
  750. //
  751. int
  752. Cmd_ShowHttpStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  753. {
  754. NOWARN_UNUSED(clientData);
  755. /* call to processArgForCommand must appear at the beginning
  756. * of each command's callback function
  757. */
  758. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  759. return CMD_ERROR;
  760. }
  761. if (processHelpCommand(argc, argv) == CLI_OK)
  762. return CMD_OK;
  763. Cli_Debug("Cmd_ShowHttpStats\n");
  764. return (ShowHttpStats());
  765. }
  766. ////////////////////////////////////////////////////////////////
  767. // Cmd_ShowIcpStats
  768. //
  769. // This is the callback function for the "show:icp-stats" command.
  770. //
  771. // Parameters:
  772. // clientData -- information about parsed arguments
  773. // interp -- the Tcl interpreter
  774. // argc -- number of command arguments
  775. // argv -- the command arguments
  776. //
  777. int
  778. Cmd_ShowIcpStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  779. {
  780. NOWARN_UNUSED(clientData);
  781. /* call to processArgForCommand must appear at the beginning
  782. * of each command's callback function
  783. */
  784. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  785. return CMD_ERROR;
  786. }
  787. if (processHelpCommand(argc, argv) == CLI_OK)
  788. return CMD_OK;
  789. Cli_Debug("Cmd_ShowIcpStats\n");
  790. return (ShowIcpStats());
  791. }
  792. ////////////////////////////////////////////////////////////////
  793. // Cmd_ShowCacheStats
  794. //
  795. // This is the callback function for the "show:cache-stats" command.
  796. //
  797. // Parameters:
  798. // clientData -- information about parsed arguments
  799. // interp -- the Tcl interpreter
  800. // argc -- number of command arguments
  801. // argv -- the command arguments
  802. //
  803. int
  804. Cmd_ShowCacheStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  805. {
  806. NOWARN_UNUSED(clientData);
  807. /* call to processArgForCommand must appear at the beginning
  808. * of each command's callback function
  809. */
  810. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  811. return CMD_ERROR;
  812. }
  813. if (processHelpCommand(argc, argv) == CLI_OK)
  814. return CMD_OK;
  815. Cli_Debug("Cmd_ShowCacheStats\n");
  816. return (ShowCacheStats());
  817. }
  818. ////////////////////////////////////////////////////////////////
  819. // Cmd_ShowHostDbStats
  820. //
  821. // This is the callback function for the "show:hostdb-stats" command.
  822. //
  823. // Parameters:
  824. // clientData -- information about parsed arguments
  825. // interp -- the Tcl interpreter
  826. // argc -- number of command arguments
  827. // argv -- the command arguments
  828. //
  829. int
  830. Cmd_ShowHostDbStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  831. {
  832. NOWARN_UNUSED(clientData);
  833. /* call to processArgForCommand must appear at the beginning
  834. * of each command's callback function
  835. */
  836. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  837. return CMD_ERROR;
  838. }
  839. if (processHelpCommand(argc, argv) == CLI_OK)
  840. return CMD_OK;
  841. Cli_Debug("Cmd_ShowHostDbStats\n");
  842. return (ShowHostDbStats());
  843. }
  844. ////////////////////////////////////////////////////////////////
  845. // Cmd_ShowDnsStats
  846. //
  847. // This is the callback function for the "show:dns-stats" command.
  848. //
  849. // Parameters:
  850. // clientData -- information about parsed arguments
  851. // interp -- the Tcl interpreter
  852. // argc -- number of command arguments
  853. // argv -- the command arguments
  854. //
  855. int
  856. Cmd_ShowDnsStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  857. {
  858. NOWARN_UNUSED(clientData);
  859. /* call to processArgForCommand must appear at the beginning
  860. * of each command's callback function
  861. */
  862. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  863. return CMD_ERROR;
  864. }
  865. if (processHelpCommand(argc, argv) == CLI_OK)
  866. return CMD_OK;
  867. Cli_Debug("Cmd_ShowDnsStats\n");
  868. return (ShowDnsStats());
  869. }
  870. ////////////////////////////////////////////////////////////////
  871. // Cmd_ShowLoggingStats
  872. //
  873. // This is the callback function for the "show:logging-stats" command.
  874. //
  875. // Parameters:
  876. // clientData -- information about parsed arguments
  877. // interp -- the Tcl interpreter
  878. // argc -- number of command arguments
  879. // argv -- the command arguments
  880. //
  881. int
  882. Cmd_ShowLoggingStats(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  883. {
  884. NOWARN_UNUSED(clientData);
  885. /* call to processArgForCommand must appear at the beginning
  886. * of each command's callback function
  887. */
  888. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  889. return CMD_ERROR;
  890. }
  891. if (processHelpCommand(argc, argv) == CLI_OK)
  892. return CMD_OK;
  893. Cli_Debug("Cmd_ShowLoggingStats\n");
  894. return (ShowLoggingStats());
  895. }
  896. ////////////////////////////////////////////////////////////////
  897. // Cmd_ShowAlarms
  898. //
  899. // This is the callback function for the "show:alarms" command.
  900. //
  901. // Parameters:
  902. // clientData -- information about parsed arguments
  903. // interp -- the Tcl interpreter
  904. // argc -- number of command arguments
  905. // argv -- the command arguments
  906. //
  907. int
  908. Cmd_ShowAlarms(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  909. {
  910. NOWARN_UNUSED(clientData);
  911. /* call to processArgForCommand must appear at the beginning
  912. * of each command's callback function
  913. */
  914. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  915. return CMD_ERROR;
  916. }
  917. if (processHelpCommand(argc, argv) == CLI_OK)
  918. return CMD_OK;
  919. Cli_Debug("Cmd_ShowAlarms\n");
  920. return (ShowAlarms());
  921. }
  922. ////////////////////////////////////////////////////////////////
  923. // Cmd_ShowNetwork
  924. //
  925. // This is the callback function for the "show:network" command.
  926. //
  927. // Parameters:
  928. // clientData -- information about parsed arguments
  929. // interp -- the Tcl interpreter
  930. // argc -- number of command arguments
  931. // argv -- the command arguments
  932. //
  933. int
  934. Cmd_ShowNetwork(ClientData clientData, Tcl_Interp * interp, int argc, const char *argv[])
  935. {
  936. NOWARN_UNUSED(clientData);
  937. /* call to processArgForCommand must appear at the beginning
  938. * of each command's callback function
  939. */
  940. if (processArgForCommand(interp, argc, argv) != CLI_OK) {
  941. return CMD_ERROR;
  942. }
  943. if (processHelpCommand(argc, argv) == CLI_OK)
  944. return CMD_OK;
  945. char hostname[256], ipaddr[32], netmask[32], domainname[256], router[32], dns_ip[32];
  946. char value[80];
  947. Cli_Debug("Cmd_ShowNetwork\n");
  948. memset(hostname, 0, 256);
  949. memset(ipaddr, 0, 32);
  950. memset(netmask, 0, 32);
  951. memset(domainname, 0, 32);
  952. memset(router, 0, 32);
  953. memset(dns_ip, 0, 32);
  954. Net_GetHostname(hostname, sizeof(hostname));
  955. Cli_Printf("\nHostname ---------------- %s\n", strlen(hostname) ? hostname : "not set");
  956. Net_GetDefaultRouter(value, sizeof(value));
  957. Cli_Printf("Default Gateway --------- %s\n", value);
  958. Net_GetDomain(value, sizeof(value));
  959. Cli_Printf("Search Domain ----------- %s\n", strlen(value) ? value : "none");
  960. Net_GetDNS_Servers(value, sizeof(value));
  961. Cli_Printf("DNS IP Addresses--------- %s\n", strlen(value) ? value : "none");
  962. char interface[80];
  963. int num_interfaces = Net_GetNetworkIntCount();
  964. for (int i = 0; i < num_interfaces; i++) {
  965. if (Net_GetNetworkInt(i, interface, sizeof(interface))) {
  966. Cli_Printf("No information for NIC %d\n", i);
  967. continue;
  968. }
  969. Cli_Printf("\nNIC %s\n", interface);
  970. Net_GetNIC_Status(interface, value, sizeof(value));
  971. Cli_Printf(" Status ---------------- %s\n", value);
  972. Net_GetNIC_Start(interface, value, sizeof(value));
  973. Cli_Printf(" Start on Boot --------- %s\n", value);
  974. Net_GetNIC_Protocol(interface, value, sizeof(value));
  975. Cli_Printf(" Start Protocol -------- %s\n", value);
  976. Net_GetNIC_IP(interface, value, sizeof(value));
  977. Cli_Printf(" IP Address ------------ %s\n", value);
  978. Net_GetNIC_Netmask(interface, value, sizeof(value));
  979. Cli_Printf(" Netmask --------------- %s\n", value);
  980. Net_GetNIC_Gateway(interface, value, sizeof(value));
  981. Cli_Printf(" Gateway --------------- %s\n", value);
  982. }
  983. Cli_Printf("\n");
  984. return CLI_OK;
  985. }
  986. ////////////////////////////////////////////////////////////////
  987. // CmdArgs_None
  988. //
  989. // Register a command with no arguments with the Tcl interpreter.
  990. //
  991. int
  992. CmdArgs_None()
  993. {
  994. return 0;
  995. }
  996. ////////////////////////////////////////////////////////////////
  997. //
  998. // "show" sub-command implementations
  999. //
  1000. ////////////////////////////////////////////////////////////////
  1001. // show status sub-command
  1002. int
  1003. ShowStatus()
  1004. {
  1005. TSProxyStateT state = TSProxyStateGet();
  1006. Cli_Printf("\n");
  1007. switch (state) {
  1008. case TS_PROXY_ON:
  1009. Cli_Printf("Proxy -- on\n");
  1010. break;
  1011. case TS_PROXY_OFF:
  1012. Cli_Printf("Proxy -- off\n");
  1013. break;
  1014. case TS_PROXY_UNDEFINED:
  1015. Cli_Printf("Proxy status undefined\n");
  1016. break;
  1017. }
  1018. Cli_Printf("\n");
  1019. return CLI_OK;
  1020. }
  1021. // show version sub-command
  1022. int
  1023. ShowVersion()
  1024. {
  1025. TSError status = TS_ERR_OKAY;
  1026. TSString ts_version = NULL;
  1027. TSString tm_version = NULL;
  1028. status = Cli_RecordGetString("proxy.process.version.server.short", &ts_version);
  1029. status = Cli_RecordGetString("proxy.node.version.manager.short", &tm_version);
  1030. Cli_Printf("\n");
  1031. Cli_Printf("traffic_server version --- %s\n" "traffic_manager version -- %s\n", ts_version, tm_version);
  1032. Cli_Printf("\n");
  1033. return status;
  1034. }
  1035. // show ports sub-command
  1036. int
  1037. ShowPorts()
  1038. {
  1039. TSString http_ports = NULL;
  1040. TSInt cluster = -1;
  1041. TSInt cluster_rs = -1;
  1042. TSInt cluster_mc = -1;
  1043. TSInt socks_server = -1;
  1044. TSInt icp = -1;
  1045. TSString connect = NULL;
  1046. // retrieve values
  1047. Cli_RecordGetString("proxy.config.http.server_ports", &http_ports);
  1048. Cli_RecordGetInt("proxy.config.cluster.cluster_port", &cluster);
  1049. Cli_RecordGetInt("proxy.config.cluster.rsport", &cluster_rs);
  1050. Cli_RecordGetInt("proxy.config.cluster.mcport", &cluster_mc);
  1051. Cli_RecordGetString("proxy.config.http.connect_ports", &connect);
  1052. Cli_RecordGetInt("proxy.config.socks.socks_server_port", &socks_server);
  1053. Cli_RecordGetInt("proxy.config.icp.icp_port", &icp);
  1054. // display results
  1055. Cli_Printf("\n");
  1056. Cli_Printf("HTTP Ports ------------- %s\n", (http_ports != NULL) ? http_ports : "none");
  1057. Cli_Printf("Cluster Port ----------- %d\n", cluster);
  1058. Cli_Printf("Cluster RS Port -------- %d\n", cluster_rs);
  1059. Cli_Printf("Cluster MC Port -------- %d\n", cluster_mc);
  1060. Cli_Printf("Allowed CONNECT Ports -- %s\n", (connect != NULL) ? connect : "none");
  1061. Cli_Printf("SOCKS Server Port ------ %d\n", socks_server);
  1062. Cli_Printf("ICP Port --------------- %d\n", icp);
  1063. Cli_Printf("\n");
  1064. return CLI_OK;
  1065. }
  1066. // show cluster sub-command
  1067. int
  1068. ShowCluster()
  1069. {
  1070. TSInt cluster = -1;
  1071. TSInt cluster_rs = -1;
  1072. TSInt cluster_mc = -1;
  1073. Cli_RecordGetInt("proxy.config.cluster.cluster_port", &cluster);
  1074. Cli_RecordGetInt("proxy.config.cluster.rsport", &cluster_rs);
  1075. Cli_RecordGetInt("proxy.config.cluster.mcport", &cluster_mc);
  1076. Cli_Printf("\n");
  1077. Cli_Printf("Cluster Port ----------- %d\n", cluster);
  1078. Cli_Printf("Cluster RS Port -------- %d\n", cluster_rs);
  1079. Cli_Printf("Cluster MC Port -------- %d\n", cluster_mc);
  1080. Cli_Printf("\n");
  1081. return CLI_OK;
  1082. }
  1083. // show security sub-command
  1084. int
  1085. ShowSecurity()
  1086. {
  1087. Cli_Printf("\n");
  1088. Cli_Printf("Traffic Server Access\n" "-------------------\n");
  1089. TSError status = Cli_DisplayRules(TS_FNAME_IP_ALLOW);
  1090. return status;
  1091. }
  1092. // show http sub-command
  1093. int
  1094. ShowHttp()
  1095. {
  1096. // declare and initialize variables
  1097. TSInt http_enabled = -1;
  1098. TSInt keepalive_timeout_in = -1;
  1099. TSInt keepalive_timeout_out = -1;
  1100. TSInt inactivity_timeout_in = -1;
  1101. TSInt inactivity_timeout_out = -1;
  1102. TSInt activity_timeout_in = -1;
  1103. TSInt activity_timeout_out = -1;
  1104. TSInt max_alts = -1;
  1105. TSInt remove_from = -1;
  1106. TSInt remove_referer = -1;
  1107. TSInt remove_user_agent = -1;
  1108. TSInt remove_cookie = -1;
  1109. TSString other_header_list = NULL;
  1110. TSInt insert_client_ip = -1;
  1111. TSInt remove_client_ip = -1;
  1112. TSInt http_server = -1;
  1113. TSString http_other = NULL;
  1114. TSString global_user_agent = NULL;
  1115. // retrieve values
  1116. Cli_RecordGetInt("proxy.config.http.cache.http", &http_enabled);
  1117. Cli_RecordGetInt("proxy.config.http.keep_alive_no_activity_timeout_in", &keepalive_timeout_in);
  1118. Cli_RecordGetInt("proxy.config.http.keep_alive_no_activity_timeout_out", &keepalive_timeout_out);
  1119. Cli_RecordGetInt("proxy.config.http.transaction_no_activity_timeout_in", &inactivity_timeout_in);
  1120. Cli_RecordGetInt("proxy.config.http.transaction_no_activity_timeout_out", &inactivity_timeout_out);
  1121. Cli_RecordGetInt("proxy.config.http.transaction_active_timeout_in", &activity_timeout_in);
  1122. Cli_RecordGetInt("proxy.config.http.transaction_active_timeout_out", &activity_timeout_out);
  1123. Cli_RecordGetInt("proxy.config.cache.limits.http.max_alts", &max_alts);
  1124. Cli_RecordGetInt("proxy.config.http.anonymize_remove_from", &remove_from);
  1125. Cli_RecordGetInt("proxy.config.http.anonymize_remove_referer", &remove_referer);
  1126. Cli_RecordGetInt("proxy.config.http.anonymize_remove_user_agent", &remove_user_agent);
  1127. Cli_RecordGetInt("proxy.config.http.anonymize_remove_cookie", &remove_cookie);
  1128. Cli_RecordGetString("proxy.config.http.anonymize_other_header_list", &other_header_list);
  1129. Cli_RecordGetInt("proxy.config.http.anonymize_insert_client_ip", &insert_client_ip);
  1130. Cli_RecordGetInt("proxy.config.http.anonymize_remove_client_ip", &remove_client_ip);
  1131. Cli_RecordGetInt("proxy.config.http.server_port", &http_server);
  1132. Cli_RecordGetString("proxy.config.http.server_other_ports", &http_other);
  1133. Cli_RecordGetString("proxy.config.http.global_user_agent_header", &global_user_agent);
  1134. // display results
  1135. Cli_Printf("\n");
  1136. Cli_Printf("HTTP Caching ------------------ %s\n", (http_enabled == 1) ? "on" : "off");
  1137. Cli_Printf("HTTP Server Port -------------- %d\n", http_server);
  1138. Cli_Printf("HTTP Other Ports -------------- %s\n", (http_other != NULL) ? http_other : "none");
  1139. Cli_Printf("Keep-Alive Timeout Inbound ---- %d s\n", keepalive_timeout_in);
  1140. Cli_Printf("Keep-Alive Timeout Outbound --- %d s\n", keepalive_timeout_out);
  1141. Cli_Printf("Inactivity Timeout Inbound ---- %d s\n", inactivity_timeout_in);
  1142. Cli_Printf("Inactivity Timeout Outbound --- %d s\n", inactivity_timeout_out);
  1143. Cli_Printf("Activity Timeout Inbound ------ %d s\n", activity_timeout_in);
  1144. Cli_Printf("Activity Timeout Outbound ----- %d s\n", activity_timeout_out);
  1145. Cli_Printf("Maximum Number of Alternates -- %d\n", max_alts);
  1146. if (remove_from == 1 || remove_referer == 1 || remove_user_agent == 1 || remove_cookie == 1) {
  1147. Cli_Printf("Remove the following common headers -- \n");
  1148. if (remove_from == 1) {
  1149. Cli_Printf("From\n");
  1150. }
  1151. if (remove_referer == 1) {
  1152. Cli_Printf("Referer\n");
  1153. }
  1154. if (remove_user_agent == 1) {
  1155. Cli_Printf("User-Agent\n");
  1156. }
  1157. if (remove_cookie == 1) {
  1158. Cli_Printf("Cookie\n");
  1159. }
  1160. }
  1161. if (other_header_list != NULL && strlen(other_header_list)) {
  1162. Cli_Printf("Remove additional headers ----- " "%s\n", other_header_list);
  1163. }
  1164. if (insert_client_ip == 1) {
  1165. Cli_Printf("Insert Client IP Address into Header\n");
  1166. }
  1167. if (remove_client_ip == 1) {
  1168. Cli_Printf("Remove Client IP Address from Header\n");
  1169. }
  1170. if (global_user_agent) {
  1171. Cli_Printf("Set User-Agent header to %s\n", global_user_agent);
  1172. }
  1173. Cli_Printf("\n");
  1174. return CLI_OK;
  1175. }
  1176. // show icp sub-command
  1177. int
  1178. ShowIcp()
  1179. {
  1180. // declare and initialize variables
  1181. TSInt icp_enabled = 0;
  1182. TSInt icp_port = -1;
  1183. TSInt multicast_enabled = 0;
  1184. TSInt query_timeout = 2;
  1185. // retrieve value
  1186. Cli_RecordGetInt("proxy.config.icp.enabled", &icp_enabled);
  1187. Cli_RecordGetInt("proxy.config.icp.icp_port", &icp_port);
  1188. Cli_RecordGetInt("proxy.config.icp.multicast_enabled", &multicast_enabled);
  1189. Cli_RecordGetInt("proxy.config.icp.query_timeout", &query_timeout);
  1190. // display results
  1191. Cli_Printf("\n");
  1192. Cli_PrintEnable("ICP Mode Enabled ------- ", icp_enabled);
  1193. Cli_Printf("ICP Port --------------- %d\n", icp_port);
  1194. Cli_PrintEnable("ICP Multicast Enabled -- ", multicast_enabled);
  1195. Cli_Printf("ICP Query Timeout ------ %d s\n", query_timeout);
  1196. Cli_Printf("\n");
  1197. return CLI_OK;
  1198. }
  1199. // show icp peer sub-command
  1200. int
  1201. ShowIcpPeer()
  1202. {
  1203. // display rules from icp.config
  1204. Cli_Printf("\n");
  1205. Cli_Printf("icp.config Rules\n" "-------------------\n");
  1206. TSError status = Cli_DisplayRules(TS_FNAME_ICP_PEER);
  1207. Cli_Printf("\n");
  1208. return status;
  1209. }
  1210. // show proxy sub-command
  1211. int
  1212. ShowProxy()
  1213. {
  1214. TSString proxy_name = NULL;
  1215. Cli_RecordGetString("proxy.config.proxy_name", &proxy_name);
  1216. Cli_Printf("\n");
  1217. Cli_Printf("Name -- %s\n", proxy_name);
  1218. Cli_Printf("\n");
  1219. return CLI_OK;
  1220. }
  1221. // show cache sub-command
  1222. int
  1223. ShowCache()
  1224. {
  1225. // declare and initialize variables
  1226. TSInt cache_http = -1;
  1227. TSInt cache_bypass = -1;
  1228. TSInt max_doc_size = -1;
  1229. TSInt when_to_reval = -1;
  1230. TSInt reqd_headers = -1;
  1231. TSInt min_life = -1;
  1232. TSInt max_life = -1;
  1233. TSInt dynamic_urls = -1;
  1234. TSInt alternates = -1;
  1235. const char *vary_def_text = "NONE";
  1236. const char *vary_def_image = "NONE";
  1237. const char *vary_def_other = "NONE";
  1238. TSInt cookies = -1;
  1239. // retrieve values
  1240. Cli_RecordGetInt("proxy.config.http.cache.http", &cache_http);
  1241. Cli_RecordGetInt("proxy.config.cache.max_doc_size", &max_doc_size);
  1242. Cli_RecordGetInt("proxy.config.http.cache.when_to_revalidate", &when_to_reval);
  1243. Cli_RecordGetInt("proxy.config.http.cache.required_headers", &reqd_headers);
  1244. Cli_RecordGetInt("proxy.config.http.cache.heuristic_min_lifetime", &min_life);
  1245. Cli_RecordGetInt("proxy.config.http.cache.heuristic_max_lifetime", &max_life);
  1246. Cli_RecordGetInt("proxy.config.http.cache.cache_urls_that_look_dynamic", &dynamic_urls);
  1247. Cli_RecordGetInt("proxy.config.http.cache.enable_default_vary_headers", &alternates);
  1248. Cli_RecordGetString("proxy.config.http.cache.vary_default_text", (char**)&vary_def_text);
  1249. Cli_RecordGetString("proxy.config.http.cache.vary_default_images", (char**)&vary_def_image);
  1250. Cli_RecordGetString("proxy.config.http.cache.vary_default_other", (char**)&vary_def_other);
  1251. Cli_RecordGetInt("proxy.config.http.cache.cache_responses_to_cookies", &cookies);
  1252. // display results
  1253. Cli_Printf("\n");
  1254. Cli_PrintEnable("HTTP Caching --------------------------- ", cache_http);
  1255. Cli_PrintEnable("Ignore User Requests To Bypass Cache --- ", cache_bypass);
  1256. if (max_doc_size == 0)
  1257. Cli_Printf("Maximum HTTP Object Size ----------- NONE\n");
  1258. else
  1259. Cli_Printf("Maximum HTTP Object Size ----------- %d\n", max_doc_size);
  1260. Cli_Printf("Freshness\n");
  1261. Cli_Printf(" Verify Freshness By Checking --------- ");
  1262. switch (when_to_reval) {
  1263. case 0:
  1264. Cli_Printf("When The Object Has Expired\n");
  1265. break;
  1266. case 1:
  1267. Cli_Printf("When The Object Has No Expiry Date\n");
  1268. break;
  1269. case 2:
  1270. Cli_Printf("Always\n");
  1271. break;
  1272. case 3:
  1273. Cli_Printf("Never\n");
  1274. break;
  1275. default:
  1276. Cli_Printf("unknown\n");
  1277. break;
  1278. }
  1279. Cli_Printf(" Minimum Information to be Cacheable -- ");
  1280. switch (reqd_headers) {
  1281. case 0:
  1282. Cli_Printf("Nothing\n");
  1283. break;
  1284. case 1:
  1285. Cli_Printf("A Last Modified Time\n");
  1286. break;
  1287. case 2:
  1288. Cli_Printf("An Explicit Lifetime\n");
  1289. break;
  1290. default:
  1291. Cli_Printf("unknown\n");
  1292. break;
  1293. }
  1294. Cli_Printf(" If Object has no Expiration Date: \n" " Leave it in Cache for at least ----- %d s\n", min_life);
  1295. Cli_Printf(" but no more than ------------------- %d s\n", max_life);
  1296. Cli_Printf("Variable Content\n");
  1297. Cli_PrintEnable(" Cache Responses to URLs that contain\n \"?\",\";\",\"cgi\" or end in \".asp\" ----- ",
  1298. dynamic_urls);
  1299. Cli_PrintEnable(" Alternates Enabled ------------------- ", alternates);
  1300. Cli_Printf(" Vary on HTTP Header Fields: \n");
  1301. Cli_Printf(" Text ------------------------------- %s\n", vary_def_text);
  1302. Cli_Printf(" Images ----------------------------- %s\n", vary_def_image);
  1303. Cli_Printf(" Other ------------------------------ %s\n", vary_def_other);
  1304. Cli_Printf(" Cache responses to requests containing cookies for:\n");
  1305. switch (cookies) {
  1306. case 0:
  1307. Cli_Printf(" No Content-types\n");
  1308. break;
  1309. case 1:
  1310. Cli_Printf(" All Content-types\n");
  1311. break;
  1312. case 2:
  1313. Cli_Printf(" Only Image-content Types\n");
  1314. break;
  1315. case 3:
  1316. Cli_Printf(" Content Types which are not Text\n");
  1317. break;
  1318. case 4:
  1319. Cli_Printf(" Content Types which are not Text with some exceptions\n");
  1320. break;
  1321. }
  1322. Cli_Printf("\n");
  1323. return CLI_OK;
  1324. }
  1325. // show cache rules sub-command
  1326. int
  1327. ShowCacheRules()
  1328. {
  1329. // display rules from cache.config
  1330. Cli_Printf("\n");
  1331. Cli_Printf("cache.config rules\n" "-------------------\n");
  1332. TSError status = Cli_DisplayRules(TS_FNAME_CACHE_OBJ);
  1333. Cli_Printf("\n");
  1334. return status;
  1335. }
  1336. // show cache storage sub-command
  1337. int
  1338. ShowCacheStorage()
  1339. {
  1340. // display rules from storage.config
  1341. Cli_Printf("storage.config rules\n");
  1342. TSError status = Cli_DisplayRules(TS_FNAME_STORAGE);
  1343. return status;
  1344. }
  1345. // show virtual-ip sub-command
  1346. int
  1347. ShowVirtualIp()
  1348. {
  1349. TSCfgContext VipCtx;
  1350. int EleCount, i;
  1351. TSVirtIpAddrEle *VipElePtr;
  1352. VipCtx = TSCfgContextCreate(TS_FNAME_VADDRS);
  1353. if (TSCfgContextGet(VipCtx) != TS_ERR_OKAY)
  1354. Cli_Printf("ERROR READING FILE\n");
  1355. EleCount = TSCfgContextGetCount(VipCtx);
  1356. Cli_Printf("\n");
  1357. Cli_Printf("%d Elements in Record\n", EleCount);
  1358. Cli_Printf("\n");
  1359. for (i = 0; i < EleCount; i++) {
  1360. VipElePtr = (TSVirtIpAddrEle *) TSCfgContextGetEleAt(VipCtx, i);
  1361. Cli_Printf("%d %s %s %d\n", i, VipElePtr->ip_addr, VipElePtr->intr, VipElePtr->sub_intr);
  1362. }
  1363. Cli_Printf("\n");
  1364. return CLI_OK;
  1365. }
  1366. // show hostdb sub-command
  1367. int
  1368. ShowHostDb()
  1369. {
  1370. // declare and initialize variables
  1371. TSInt lookup_timeout = -1;
  1372. TSInt timeout = -1;
  1373. TSInt verify_after = -1;
  1374. TSInt fail_timeout = -1;
  1375. TSInt re_dns_on_reload = 0;
  1376. TSInt dns_lookup_timeout = -1;
  1377. TSInt dns_retries = -1;
  1378. // retrieve value
  1379. Cli_RecordGetInt("proxy.config.hostdb.lookup_timeout", &lookup_timeout);
  1380. Cli_RecordGetInt("proxy.config.hostdb.timeout", &timeout);
  1381. Cli_RecordGetInt("proxy.config.hostdb.verify_after", &verify_after);
  1382. Cli_RecordGetInt("proxy.config.hostdb.fail.timeout", &fail_timeout);
  1383. Cli_RecordGetInt("proxy.config.hostdb.re_dns_on_reload", &re_dns_on_reload);
  1384. Cli_RecordGetInt("proxy.config.dns.lookup_timeout", &dns_lookup_timeout);
  1385. Cli_RecordGetInt("proxy.config.dns.retries", &dns_retries);
  1386. // display results
  1387. Cli_Printf("\n");
  1388. Cli_Printf("Lookup Timeout ----------- %d s\n", lookup_timeout);
  1389. Cli_Printf("Foreground Timeout ------- %d s\n", timeout);
  1390. Cli_Printf("Background Timeout ------- %d s\n", verify_after);
  1391. Cli_Printf("Invalid Host Timeout ----- %d s\n", fail_timeout);
  1392. if (Cli_PrintEnable("Re-DNS on Reload --------- ", re_dns_on_reload) == CLI_ERROR) {
  1393. return CLI_ERROR;
  1394. }
  1395. Cli_Printf("Resolve Attempt Timeout -- %d s\n", dns_lookup_timeout);
  1396. Cli_Printf("Number of retries -------- %d \n", dns_retries);
  1397. Cli_Printf("\n");
  1398. return CLI_OK;
  1399. }
  1400. // show dns-resolver sub-command
  1401. int
  1402. ShowDnsResolver()
  1403. {
  1404. // declare and initialize variables
  1405. TSInt dns_search_default_domains = 0;
  1406. TSInt http_enable_url_expandomatic = 0;
  1407. // retrieve value
  1408. Cli_RecordGetInt("proxy.config.dns.search_default_domains", &dns_search_default_domains);
  1409. Cli_RecordGetInt("proxy.config.http.enable_url_expandomatic", &http_enable_url_expandomatic);
  1410. // display results
  1411. Cli_Printf("\n");
  1412. if (Cli_PrintEnable("Local Domain Expansion -- ", dns_search_default_domains) == CLI_ERROR) {
  1413. return CLI_ERROR;
  1414. }
  1415. if (Cli_PrintEnable(".com Domain Expansion --- ", http_enable_url_expandomatic) == CLI_ERROR) {
  1416. return CLI_ERROR;
  1417. }
  1418. Cli_Printf("\n");
  1419. return CLI_OK;
  1420. }
  1421. // show logging sub-command
  1422. int
  1423. ShowLogging()
  1424. {
  1425. // declare and initialize variables
  1426. TSInt logging_enabled = 0;
  1427. TSInt log_space = -1;
  1428. TSInt headroom_space = -1;
  1429. TSInt collation_mode = 0;
  1430. const char *collation_host = "None";
  1431. TSInt collation_port = -1;
  1432. TSString collation_secret = NULL;
  1433. TSInt host_tag = 0;
  1434. TSInt orphan_space = -1;
  1435. TSInt squid_log = 0;
  1436. TSInt is_ascii = 1;
  1437. TSString file_name = NULL;
  1438. TSString file_header = NULL;
  1439. TSInt common_log = 0;
  1440. TSInt common_is_ascii = 0;
  1441. TSString common_file_name = NULL;
  1442. TSString common_file_header = NULL;
  1443. TSInt extended_log = 0;
  1444. TSInt extended_is_ascii = 0;
  1445. TSString extended_file_name = NULL;
  1446. TSString extended_file_header = NULL;
  1447. TSInt extended2_log = 0;
  1448. TSInt extended2_is_ascii = 0;
  1449. TSString extended2_file_name = NULL;
  1450. TSString extended2_file_header = NULL;
  1451. TSInt icp_log = 0;
  1452. TSInt http_host_log = 0;
  1453. TSInt custom_log = 0;
  1454. TSInt xml_log = 0;
  1455. TSInt rolling = 0;
  1456. TSInt roll_offset_hr = -1;
  1457. TSInt roll_interval = -1;
  1458. TSInt auto_delete = 0;
  1459. // retrieve value
  1460. Cli_RecordGetInt("proxy.config.log.logging_enabled", &logging_enabled);
  1461. Cli_RecordGetInt("proxy.config.log.max_space_mb_for_logs", &log_space);
  1462. Cli_RecordGetInt("proxy.config.log.max_space_mb_headroom", &headroom_space);
  1463. Cli_RecordGetInt("proxy.local.log.collation_mode", &collation_mode);
  1464. Cli_RecordGetString("proxy.config.log.collation_host", (char**)&collation_host);
  1465. Cli_RecordGetInt("proxy.config.log.collation_port", &collation_port);
  1466. Cli_RecordGetString("proxy.config.log.collation_secret", &collation_secret);
  1467. Cli_RecordGetInt("proxy.config.log.collation_host_tagged", &host_tag);
  1468. Cli_RecordGetInt("proxy.config.log.max_space_mb_for_orphan_logs", &orphan_space);
  1469. Cli_RecordGetInt("proxy.config.log.squid_log_enabled", &squid_log);
  1470. Cli_RecordGetInt("proxy.config.log.squid_log_is_ascii", &is_ascii);
  1471. Cli_RecordGetString("proxy.config.log.squid_log_name", &file_name);
  1472. Cli_RecordGetString("proxy.config.log.squid_log_header", &file_header);
  1473. Cli_RecordGetInt("proxy.config.log.common_log_enabled", &common_log);
  1474. Cli_RecordGetInt("proxy.config.log.common_log_is_ascii", &common_is_ascii);
  1475. Cli_RecordGetString("proxy.config.log.common_log_name", &common_file_name);
  1476. Cli_RecordGetString("proxy.config.log.common_log_header", &common_file_header);
  1477. Cli_RecordGetInt("proxy.config.log.extended_log_enabled", &extended_log);
  1478. Cli_RecordGetInt("proxy.config.log.extended_log_is_ascii", &extended_is_ascii);
  1479. Cli_RecordGetString("proxy.config.log.extended_log_name", &extended_file_name);
  1480. Cli_RecordGetString("proxy.config.log.extended_log_header", &extended_file_header);
  1481. Cli_RecordGetInt("proxy.config.log.extended2_log_enabled", &extended2_log);
  1482. Cli_RecordGetInt("proxy.config.log.extended2_log_is_ascii", &extended2_is_ascii);
  1483. Cli_RecordGetString(