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

# · C++ · 2476 lines · 1551 code · 358 blank · 567 comment · 227 complexity · ce6b8e44d705d54eec32f4653e703a4b MD5 · raw 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("proxy.config.log.extended2_log_name", &extended2_file_name);
  1484. Cli_RecordGetString("proxy.config.log.extended2_log_header", &extended2_file_header);
  1485. Cli_RecordGetInt("proxy.config.log.separate_icp_logs", &icp_log);
  1486. Cli_RecordGetInt("proxy.config.log.separate_host_logs", &http_host_log);
  1487. Cli_RecordGetInt("proxy.config.log.separate_host_logs", &custom_log);
  1488. Cli_RecordGetInt("proxy.config.log.rolling_enabled", &rolling);
  1489. Cli_RecordGetInt("proxy.config.log.rolling_offset_hr", &roll_offset_hr);
  1490. Cli_RecordGetInt("proxy.config.log.rolling_interval_sec", &roll_interval);
  1491. Cli_RecordGetInt("proxy.config.log.auto_delete_rolled_files", &auto_delete);
  1492. // display results
  1493. Cli_Printf("\n");
  1494. Cli_Printf("Logging Mode ----------------------------- ");
  1495. switch (logging_enabled) {
  1496. case 0:
  1497. Cli_Printf("no logging\n");
  1498. break;
  1499. case 1:
  1500. Cli_Printf("errors only\n");
  1501. break;
  1502. case 2:
  1503. Cli_Printf("transactions only\n");
  1504. break;
  1505. case 3:
  1506. Cli_Printf("errors and transactions\n");
  1507. break;
  1508. default:
  1509. Cli_Printf("invalid mode\n");
  1510. break;
  1511. }
  1512. Cli_Printf("\nManagement\n");
  1513. Cli_Printf(" Log Space Limit ------------------------ %d MB\n", log_space);
  1514. Cli_Printf(" Log Space Headroom --------------------- %d MB\n", headroom_space);
  1515. Cli_PrintEnable("\nLog Collation ---------------------------- ", collation_mode);
  1516. Cli_Printf(" Host ----------------------------------- %s\n", collation_host);
  1517. Cli_Printf(" Port ----------------------------------- %d\n", collation_port);
  1518. Cli_Printf(" Secret --------------------------------- %s\n", collation_secret);
  1519. Cli_PrintEnable(" Host Tagged ---------------------------- ", host_tag);
  1520. Cli_Printf(" Space Limit for Orphan Files ----------- %d MB\n", orphan_space);
  1521. Cli_PrintEnable("\nSquid Format ----------------------------- ", squid_log);
  1522. if (is_ascii == 1)
  1523. Cli_Printf(" File Type ------------------------------ %s\n", "ASCII");
  1524. else if (is_ascii == 0)
  1525. Cli_Printf(" File Type ------------------------------ %s\n", "BINARY");
  1526. else
  1527. Cli_Debug(ERR_INVALID_PARAMETER);
  1528. Cli_Printf(" File Name ------------------------------ %s\n", file_name);
  1529. Cli_Printf(" File Header ---------------------------- %s\n", file_header);
  1530. Cli_PrintEnable("\nNetscape Common -------------------------- ", common_log);
  1531. if (common_is_ascii == 1)
  1532. Cli_Printf(" File Type ------------------------------ %s\n", "ASCII");
  1533. else if (common_is_ascii == 0)
  1534. Cli_Printf(" File Type ------------------------------ %s\n", "BINARY");
  1535. else
  1536. Cli_Debug(ERR_INVALID_PARAMETER);
  1537. Cli_Printf(" File Name ------------------------------ %s\n", common_file_name);
  1538. Cli_Printf(" File Header ---------------------------- %s\n", common_file_header);
  1539. Cli_PrintEnable("\nNetscape Extended ------------------------ ", extended_log);
  1540. if (extended_is_ascii == 1)
  1541. Cli_Printf(" File Type ------------------------------ %s\n", "ASCII");
  1542. else if (extended_is_ascii == 0)
  1543. Cli_Printf(" File Type ------------------------------ %s\n", "BINARY");
  1544. else
  1545. Cli_Debug(ERR_INVALID_PARAMETER);
  1546. Cli_Printf(" File Name ------------------------------ %s\n", extended_file_name);
  1547. Cli_Printf(" File Header ---------------------------- %s\n", extended_file_header);
  1548. Cli_PrintEnable("\nNetscape Extended2 ----------------------- ", extended2_log);
  1549. if (extended2_is_ascii == 1)
  1550. Cli_Printf(" File Type ------------------------------ %s\n", "ASCII");
  1551. else if (extended2_is_ascii == 0)
  1552. Cli_Printf(" File Type ------------------------------ %s\n", "BINARY");
  1553. else
  1554. Cli_Debug(ERR_INVALID_PARAMETER);
  1555. Cli_Printf(" File Name ---------------------------- %s\n", extended2_file_name);
  1556. Cli_Printf(" File Header ---------------------------- %s\n", extended2_file_header);
  1557. Cli_Printf("\nSplitting\n");
  1558. Cli_PrintEnable(" ICP Log Splitting ---------------------- ", icp_log);
  1559. Cli_PrintEnable(" HTTP Host Log Splitting ---------------- ", http_host_log);
  1560. Cli_PrintEnable("\nCustom Logs ------------------------------ ", custom_log);
  1561. if (xml_log == 0)
  1562. Cli_Printf("Custom Log Definition Format ------------- %s\n", "Traditional");
  1563. Cli_PrintEnable("\nRolling ---------------------------------- ", rolling);
  1564. Cli_Printf(" Roll Offset Hour ----------------------- %d\n", roll_offset_hr);
  1565. Cli_Printf(" Roll Interval -------------------------- %d s\n", roll_interval);
  1566. Cli_PrintEnable(" Auto-delete rolled files (low space) --- ", auto_delete);
  1567. Cli_Printf("\n");
  1568. return CLI_OK;
  1569. }
  1570. // show ssl sub-command
  1571. int
  1572. ShowSsl()
  1573. {
  1574. // declare and initialize variables
  1575. TSString connect_ports = NULL;
  1576. // retrieve value
  1577. Cli_RecordGetString("proxy.config.http.connect_ports", &connect_ports);
  1578. // display results
  1579. Cli_Printf("\n");
  1580. Cli_Printf("Restrict CONNECT connections to Ports -- %s\n", connect_ports);
  1581. Cli_Printf("\n");
  1582. return CLI_OK;
  1583. }
  1584. // show parents sub-command
  1585. int
  1586. ShowParents()
  1587. {
  1588. TSError status = TS_ERR_OKAY;
  1589. TSInt parent_enabled = -1;
  1590. TSString parent_cache = NULL;
  1591. Cli_RecordGetInt("proxy.config.http.parent_proxy_routing_enable", &parent_enabled);
  1592. Cli_RecordGetString("proxy.config.http.parent_proxies", &parent_cache);
  1593. Cli_Printf("\n");
  1594. Cli_Printf("Parent Caching -- %s\n", (parent_enabled == 1) ? "on" : "off");
  1595. Cli_Printf("Parent Cache ---- %s\n", parent_cache);
  1596. Cli_Printf("\n");
  1597. return status;
  1598. }
  1599. // show:parent rules sub-command
  1600. int
  1601. ShowParentRules()
  1602. {
  1603. // display rules from parent.config
  1604. Cli_Printf("\n");
  1605. Cli_Printf("parent.config rules\n" "-------------------\n");
  1606. TSError status = Cli_DisplayRules(TS_FNAME_PARENT_PROXY);
  1607. Cli_Printf("\n");
  1608. return status;
  1609. }
  1610. // show remap sub-command
  1611. int
  1612. ShowRemap()
  1613. {
  1614. // display rules from remap.config
  1615. Cli_Printf("\n");
  1616. Cli_Printf("remap.config rules\n" "-------------------\n");
  1617. TSError status = Cli_DisplayRules(TS_FNAME_REMAP);
  1618. Cli_Printf("\n");
  1619. return status;
  1620. }
  1621. // show socks sub-command
  1622. int
  1623. ShowSocks()
  1624. {
  1625. // declare and initialize variables
  1626. TSInt socks_enabled = 0;
  1627. TSInt version = -1;
  1628. TSString default_servers = NULL;
  1629. TSInt accept_enabled = -1;
  1630. TSInt accept_port = -1;
  1631. // retrieve values
  1632. Cli_RecordGetInt("proxy.config.socks.socks_needed", &socks_enabled);
  1633. Cli_RecordGetInt("proxy.config.socks.socks_version", &version);
  1634. Cli_RecordGetString("proxy.config.socks.default_servers", &default_servers);
  1635. Cli_RecordGetInt("proxy.config.socks.accept_enabled", &accept_enabled);
  1636. Cli_RecordGetInt("proxy.config.socks.accept_port", &accept_port);
  1637. // display results
  1638. Cli_Printf("\n");
  1639. Cli_PrintEnable("SOCKS -------------------- ", socks_enabled);
  1640. Cli_Printf("SOCKS Version ------------ %d\n", version);
  1641. Cli_Printf("SOCKS Default Servers ---- %s\n", default_servers);
  1642. Cli_PrintEnable("SOCKS Accept Enabled ----- ", accept_enabled);
  1643. Cli_Printf("SOCKS Accept Port -------- %d\n", accept_port);
  1644. Cli_Printf("\n");
  1645. return CLI_OK;
  1646. }
  1647. // show:socks rules sub-command
  1648. int
  1649. ShowSocksRules()
  1650. {
  1651. // display rules from socks.config
  1652. Cli_Printf("\n");
  1653. Cli_Printf("socks.config rules\n" "-------------------\n");
  1654. TSError status = Cli_DisplayRules(TS_FNAME_SOCKS);
  1655. Cli_Printf("\n");
  1656. return status;
  1657. }
  1658. // show port-tunnels sub-command
  1659. int
  1660. ShowPortTunnels()
  1661. {
  1662. TSString str_val = NULL;
  1663. TSError status = TS_ERR_OKAY;
  1664. status = Cli_RecordGetString("proxy.config.http.server_other_ports", &str_val);
  1665. if (status) {
  1666. return status;
  1667. }
  1668. Cli_Printf("\n");
  1669. Cli_Printf("server-other-ports -- %s\n", str_val);
  1670. Cli_Printf("\n");
  1671. Cli_Printf("To view the corresponding rule of the remap.config file in the following format\n");
  1672. Cli_Printf("map tunnel://<proxy_ip>:<port_num>/tunnel://<dest_server>:<dest_port>\n");
  1673. Cli_Printf("Use show:remap\n");
  1674. Cli_Printf("\n");
  1675. return CLI_OK;
  1676. }
  1677. // show scheduled-update sub-command
  1678. int
  1679. ShowScheduledUpdate()
  1680. {
  1681. // variable declaration
  1682. TSInt enabled = 0;
  1683. TSInt force = 0;
  1684. TSInt retry_count = -1;
  1685. TSInt retry_interval = -1;
  1686. TSInt concurrent_updates = 0;
  1687. // get value
  1688. Cli_RecordGetInt("proxy.config.update.enabled", &enabled);
  1689. Cli_RecordGetInt("proxy.config.update.retry_count", &retry_count);
  1690. Cli_RecordGetInt("proxy.config.update.retry_interval", &retry_interval);
  1691. Cli_RecordGetInt("proxy.config.update.concurrent_updates", &concurrent_updates);
  1692. Cli_RecordGetInt("proxy.config.update.force", &force);
  1693. //display values
  1694. // display rules from socks.config
  1695. Cli_Printf("\n");
  1696. if (Cli_PrintEnable("Scheduled Update ------------- ", enabled) == CLI_ERROR) {
  1697. return CLI_ERROR;
  1698. }
  1699. Cli_Printf("Update Error Retry Count ----- %d\n", retry_count);
  1700. Cli_Printf("Update Error Retry Interval -- %d s\n", retry_interval);
  1701. Cli_Printf("Maximum Concurrent Updates --- %d\n", concurrent_updates);
  1702. if (Cli_PrintEnable("Force Immediate Update ------- ", force) == CLI_ERROR) {
  1703. return CLI_ERROR;
  1704. }
  1705. Cli_Printf("\n");
  1706. return CLI_OK;
  1707. }
  1708. // show:scheduled-update rules sub-command
  1709. int
  1710. ShowScheduledUpdateRules()
  1711. {
  1712. Cli_Printf("\n");
  1713. Cli_Printf("update.config rules\n" "-------------------\n");
  1714. TSError status = Cli_DisplayRules(TS_FNAME_UPDATE_URL);
  1715. Cli_Printf("\n");
  1716. return status;
  1717. }
  1718. ////////////////////////////////////////////////////////////////
  1719. // statistics sub-commands
  1720. //
  1721. // show proxy-stats sub-command
  1722. int
  1723. ShowProxyStats()
  1724. {
  1725. TSFloat cache_hit_ratio = -1.0;
  1726. TSFloat cache_hit_mem_ratio = -1.0;
  1727. TSFloat bandwidth_hit_ratio = -1.0;
  1728. TSFloat percent_free = -1.0;
  1729. TSInt current_server_connection = -1;
  1730. TSInt current_client_connection = -1;
  1731. TSInt current_cache_connection = -1;
  1732. TSFloat client_throughput_out = -1.0;
  1733. TSFloat xacts_per_second = -1.0;
  1734. //get value
  1735. Cli_RecordGetFloat("proxy.node.cache_hit_ratio", &cache_hit_ratio);
  1736. Cli_RecordGetFloat("proxy.node.cache_hit_mem_ratio", &cache_hit_mem_ratio);
  1737. Cli_RecordGetFloat("proxy.node.bandwidth_hit_ratio", &bandwidth_hit_ratio);
  1738. Cli_RecordGetFloat("proxy.node.cache.percent_free", &percent_free);
  1739. Cli_RecordGetInt("proxy.node.current_server_connections", &current_server_connection);
  1740. Cli_RecordGetInt("proxy.node.current_client_connections", &current_client_connection);
  1741. Cli_RecordGetInt("proxy.node.current_cache_connections", &current_cache_connection);
  1742. Cli_RecordGetFloat("proxy.node.client_throughput_out", &client_throughput_out);
  1743. Cli_RecordGetFloat("proxy.node.user_agent_xacts_per_second", &xacts_per_second);
  1744. //display values
  1745. Cli_Printf("\n");
  1746. Cli_Printf("Document Hit Rate -------- %f %%\t *\n", 100 * cache_hit_ratio);
  1747. Cli_Printf("Ram cache Hit Rate ------- %f %%\t *\n", 100 * cache_hit_mem_ratio);
  1748. Cli_Printf("Bandwidth Saving --------- %f %%\t *\n", 100 * bandwidth_hit_ratio);
  1749. Cli_Printf("Cache Percent Free ------- %f %%\n", 100 * percent_free);
  1750. Cli_Printf("Open Server Connections -- %d\n", current_server_connection);
  1751. Cli_Printf("Open Client Connections -- %d\n", current_client_connection);
  1752. Cli_Printf("Open Cache Connections --- %d\n", current_cache_connection);
  1753. Cli_Printf("Client Throughput -------- %f MBit/Sec\n", client_throughput_out);
  1754. Cli_Printf("Transaction Per Second --- %f\n", xacts_per_second);
  1755. Cli_Printf("\n* Value represents 10 second average.\n");
  1756. Cli_Printf("\n");
  1757. return CLI_OK;
  1758. }
  1759. // show http-trans-stats sub-command
  1760. int
  1761. ShowHttpTransStats()
  1762. {
  1763. //varialbles
  1764. TSFloat frac_avg_10s_hit_fresh = -1.0;
  1765. TSInt msec_avg_10s_hit_fresh = -1;
  1766. TSFloat frac_avg_10s_hit_revalidated = -1.0;
  1767. TSInt msec_avg_10s_hit_revalidated = -1;
  1768. TSFloat frac_avg_10s_miss_cold = -1.0;
  1769. TSInt msec_avg_10s_miss_cold = -1;
  1770. TSFloat frac_avg_10s_miss_not_cachable = -1.0;
  1771. TSInt msec_avg_10s_miss_not_cachable = -1;
  1772. TSFloat frac_avg_10s_miss_changed = -1.0;
  1773. TSInt msec_avg_10s_miss_changed = -1;
  1774. TSFloat frac_avg_10s_miss_client_no_cache = -1.0;
  1775. TSInt msec_avg_10s_miss_client_no_cache = -1;
  1776. TSFloat frac_avg_10s_errors_connect_failed = -1.0;
  1777. TSInt msec_avg_10s_errors_connect_failed = -1;
  1778. TSFloat frac_avg_10s_errors_other = -1.0;
  1779. TSInt msec_avg_10s_errors_other = -1;
  1780. TSFloat frac_avg_10s_errors_aborts = -1.0;
  1781. TSInt msec_avg_10s_errors_aborts = -1;
  1782. TSFloat frac_avg_10s_errors_possible_aborts = -1.0;
  1783. TSInt msec_avg_10s_errors_possible_aborts = -1;
  1784. TSFloat frac_avg_10s_errors_early_hangups = -1.0;
  1785. TSInt msec_avg_10s_errors_early_hangups = -1;
  1786. TSFloat frac_avg_10s_errors_empty_hangups = -1.0;
  1787. TSInt msec_avg_10s_errors_empty_hangups = -1;
  1788. TSFloat frac_avg_10s_errors_pre_accept_hangups = -1.0;
  1789. TSInt msec_avg_10s_errors_pre_accept_hangups = -1;
  1790. TSFloat frac_avg_10s_other_unclassified = -1.0;
  1791. TSInt msec_avg_10s_other_unclassified = -1;
  1792. //get values
  1793. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.hit_fresh", &frac_avg_10s_hit_fresh);
  1794. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.hit_revalidated", &frac_avg_10s_hit_revalidated);
  1795. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.miss_cold", &frac_avg_10s_miss_cold);
  1796. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.miss_not_cacheable", &frac_avg_10s_miss_not_cachable);
  1797. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.miss_changed", &frac_avg_10s_miss_changed);
  1798. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.miss_client_no_cache",
  1799. &frac_avg_10s_miss_client_no_cache);
  1800. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.connect_failed",
  1801. &frac_avg_10s_errors_connect_failed);
  1802. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.other", &frac_avg_10s_errors_other);
  1803. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.aborts", &frac_avg_10s_errors_aborts);
  1804. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.possible_aborts",
  1805. &frac_avg_10s_errors_possible_aborts);
  1806. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.early_hangups",
  1807. &frac_avg_10s_errors_early_hangups);
  1808. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.empty_hangups",
  1809. &frac_avg_10s_errors_empty_hangups);
  1810. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.errors.pre_accept_hangups",
  1811. &frac_avg_10s_errors_pre_accept_hangups);
  1812. Cli_RecordGetFloat("proxy.node.http.transaction_frac_avg_10s.other.unclassified", &frac_avg_10s_other_unclassified);
  1813. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.hit_fresh", &msec_avg_10s_hit_fresh);
  1814. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.hit_revalidated", &msec_avg_10s_hit_revalidated);
  1815. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.miss_cold", &msec_avg_10s_miss_cold);
  1816. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.miss_not_cacheable", &msec_avg_10s_miss_not_cachable);
  1817. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.miss_changed", &msec_avg_10s_miss_changed);
  1818. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.miss_client_no_cache", &msec_avg_10s_miss_client_no_cache);
  1819. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.connect_failed",
  1820. &msec_avg_10s_errors_connect_failed);
  1821. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.other", &msec_avg_10s_errors_other);
  1822. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.aborts", &msec_avg_10s_errors_aborts);
  1823. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.possible_aborts",
  1824. &msec_avg_10s_errors_possible_aborts);
  1825. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.early_hangups", &msec_avg_10s_errors_early_hangups);
  1826. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.empty_hangups", &msec_avg_10s_errors_empty_hangups);
  1827. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.errors.pre_accept_hangups",
  1828. &msec_avg_10s_errors_pre_accept_hangups);
  1829. Cli_RecordGetInt("proxy.node.http.transaction_msec_avg_10s.other.unclassified", &msec_avg_10s_other_unclassified);
  1830. //display
  1831. Cli_Printf("\n");
  1832. Cli_Printf("HTTP Transaction Frequency and Speeds\n");
  1833. Cli_Printf("Transaction Type Frequency Speed(ms)\n");
  1834. Cli_Printf("--Hits--\n");
  1835. Cli_Printf("Fresh ----------------------- %f %% %d\n", 100 * frac_avg_10s_hit_fresh, msec_avg_10s_hit_fresh);
  1836. Cli_Printf("Stale Revalidated ----------- %f %% %d\n", 100 * frac_avg_10s_hit_revalidated,
  1837. msec_avg_10s_hit_revalidated);
  1838. Cli_Printf("--Misses--\n");
  1839. Cli_Printf("Now Cached ------------------ %f %% %d\n", 100 * frac_avg_10s_miss_cold, msec_avg_10s_miss_cold);
  1840. Cli_Printf("Server No Cache ------------- %f %% %d\n", 100 * frac_avg_10s_miss_not_cachable,
  1841. msec_avg_10s_miss_not_cachable);
  1842. Cli_Printf("Stale Reloaded -------------- %f %% %d\n", 100 * frac_avg_10s_miss_changed, msec_avg_10s_miss_changed);
  1843. Cli_Printf("Client No Cache ------------- %f %% %d\n", 100 * frac_avg_10s_miss_client_no_cache,
  1844. msec_avg_10s_miss_client_no_cache);
  1845. Cli_Printf("--Errors--\n");
  1846. Cli_Printf("Connection Failures --------- %f %% %d\n", 100 * frac_avg_10s_errors_connect_failed,
  1847. msec_avg_10s_errors_connect_failed);
  1848. Cli_Printf("Other Errors ---------------- %f %% %d\n", 100 * frac_avg_10s_errors_other, msec_avg_10s_errors_other);
  1849. Cli_Printf("--Aborted Transactions--\n");
  1850. Cli_Printf("Client Aborts --------------- %f %% %d\n", 100 * frac_avg_10s_errors_aborts, msec_avg_10s_errors_aborts);
  1851. Cli_Printf("Questionable Client Aborts -- %f %% %d\n", 100 * frac_avg_10s_errors_possible_aborts,
  1852. msec_avg_10s_errors_possible_aborts);
  1853. Cli_Printf("Partial Request Hangups ----- %f %% %d\n", 100 * frac_avg_10s_errors_early_hangups,
  1854. msec_avg_10s_errors_possible_aborts);
  1855. Cli_Printf("Pre-Request Hangups --------- %f %% %d\n", 100 * frac_avg_10s_errors_empty_hangups,
  1856. msec_avg_10s_errors_empty_hangups);
  1857. Cli_Printf("Pre-Connect Hangups --------- %f %% %d\n", 100 * frac_avg_10s_errors_pre_accept_hangups,
  1858. msec_avg_10s_errors_pre_accept_hangups);
  1859. Cli_Printf("--Other Transactions--\n");
  1860. Cli_Printf("Unclassified ---------------- %f %% %d\n", 100 * frac_avg_10s_other_unclassified,
  1861. msec_avg_10s_other_unclassified);
  1862. Cli_Printf("\n");
  1863. return CLI_OK;
  1864. }
  1865. // show http-stats sub-command
  1866. int
  1867. ShowHttpStats()
  1868. {
  1869. //variable declaration
  1870. TSInt user_agent_response_document_total_size = -1;
  1871. TSInt user_agent_response_header_total_size = -1;
  1872. TSInt current_client_connections = -1;
  1873. TSInt current_client_transactions = -1;
  1874. TSInt origin_server_response_document_total_size = -1;
  1875. TSInt origin_server_response_header_total_size = -1;
  1876. TSInt current_server_connections = -1;
  1877. TSInt current_server_transactions = -1;
  1878. //get value
  1879. Cli_RecordGetInt("proxy.process.http.user_agent_response_document_total_size",
  1880. &user_agent_response_document_total_size);
  1881. Cli_RecordGetInt("proxy.process.http.user_agent_response_header_total_size", &user_agent_response_header_total_size);
  1882. Cli_RecordGetInt("proxy.process.http.current_client_connections", &current_client_connections);
  1883. Cli_RecordGetInt("proxy.process.http.current_client_transactions", &current_client_transactions);
  1884. Cli_RecordGetInt("proxy.process.http.origin_server_response_document_total_size",
  1885. &origin_server_response_document_total_size);
  1886. Cli_RecordGetInt("proxy.process.http.origin_server_response_header_total_size",
  1887. &origin_server_response_header_total_size);
  1888. Cli_RecordGetInt("proxy.process.http.current_server_connections", &current_server_connections);
  1889. Cli_RecordGetInt("proxy.process.http.current_server_transactions", &current_server_transactions);
  1890. //display value
  1891. Cli_Printf("\n");
  1892. Cli_Printf("--Client--\n");
  1893. Cli_Printf("Total Document Bytes ----- %d MB\n", user_agent_response_document_total_size / (1024 * 1024));
  1894. Cli_Printf("Total Header Bytes ------- %d MB\n", user_agent_response_header_total_size / (1024 * 1024));
  1895. Cli_Printf("Total Connections -------- %d\n", current_client_connections);
  1896. Cli_Printf("Transactins In Progress -- %d\n", current_client_transactions);
  1897. Cli_Printf("--Server--\n");
  1898. Cli_Printf("Total Document Bytes ----- %d MB\n", origin_server_response_document_total_size / (1024 * 1024));
  1899. Cli_Printf("Total Header Bytes ------- %d MB\n", origin_server_response_header_total_size / (1024 * 1024));
  1900. Cli_Printf("Total Connections -------- %d\n", current_server_connections);
  1901. Cli_Printf("Transactins In Progress -- %d\n", current_server_transactions);
  1902. Cli_Printf("\n");
  1903. return CLI_OK;
  1904. }
  1905. // show proxy-stats sub-command
  1906. int
  1907. ShowIcpStats()
  1908. {
  1909. //variable declaration
  1910. TSInt icp_query_requests = -1;
  1911. TSInt total_udp_send_queries = -1;
  1912. TSInt icp_query_hits = -1;
  1913. TSInt icp_query_misses = -1;
  1914. TSInt icp_remote_responses = -1;
  1915. TSFloat total_icp_response_time = -1.0;
  1916. TSFloat total_icp_request_time = -1.0;
  1917. TSInt icp_remote_query_requests = -1;
  1918. TSInt cache_lookup_success = -1;
  1919. TSInt cache_lookup_fail = -1;
  1920. TSInt query_response_write = -1;
  1921. //get values
  1922. Cli_RecordGetInt("proxy.process.icp.icp_query_requests", &icp_query_requests);
  1923. Cli_RecordGetInt("proxy.process.icp.total_udp_send_queries", &total_udp_send_queries);
  1924. Cli_RecordGetInt("proxy.process.icp.icp_query_hits", &icp_query_hits);
  1925. Cli_RecordGetInt("proxy.process.icp.icp_query_misses", &icp_query_misses);
  1926. Cli_RecordGetInt("proxy.process.icp.icp_remote_responses", &icp_remote_responses);
  1927. Cli_RecordGetFloat("proxy.process.icp.total_icp_response_time", &total_icp_response_time);
  1928. Cli_RecordGetFloat("proxy.process.icp.total_icp_request_time", &total_icp_request_time);
  1929. Cli_RecordGetInt("proxy.process.icp.icp_remote_query_requests", &icp_remote_query_requests);
  1930. Cli_RecordGetInt("proxy.process.icp.cache_lookup_success", &cache_lookup_success);
  1931. Cli_RecordGetInt("proxy.process.icp.cache_lookup_fail", &cache_lookup_fail);
  1932. Cli_RecordGetInt("proxy.process.icp.query_response_write", &query_response_write);
  1933. //display values
  1934. Cli_Printf("\n");
  1935. Cli_Printf("--Queries Originating From This Node--\n");
  1936. Cli_Printf("Query Requests ----------------------------- %d\n", icp_query_requests);
  1937. Cli_Printf("Query Messages Sent ------------------------ %d\n", total_udp_send_queries);
  1938. Cli_Printf("Peer Hit Messages Received ----------------- %d\n", icp_query_hits);
  1939. Cli_Printf("Peer Miss Messages Received ---------------- %d\n", icp_query_misses);
  1940. Cli_Printf("Total Responses Received ------------------- %d\n", icp_remote_responses);
  1941. Cli_Printf("Average ICP Message Response Time ---------- %f ms\n", total_icp_response_time);
  1942. Cli_Printf("Average ICP Request Time ------------------- %f ms\n", total_icp_request_time);
  1943. Cli_Printf("\n");
  1944. Cli_Printf("--Queries Originating from ICP Peers--\n");
  1945. Cli_Printf("Query Messages Received -------------------- %d\n", icp_remote_query_requests);
  1946. Cli_Printf("Remote Query Hits -------------------------- %d\n", cache_lookup_success);
  1947. Cli_Printf("Remote Query Misses ------------------------ %d\n", cache_lookup_fail);
  1948. Cli_Printf("Successful Response Message Sent to Peers -- %d\n", query_response_write);
  1949. Cli_Printf("\n");
  1950. return CLI_OK;
  1951. }
  1952. // show proxy-stats sub-command
  1953. int
  1954. ShowCacheStats()
  1955. {
  1956. //variable delaration
  1957. TSInt bytes_used = -1;
  1958. TSInt bytes_total = -1;
  1959. TSInt ram_cache_total_bytes = -1;
  1960. TSInt ram_cache_bytes_used = -1;
  1961. TSInt ram_cache_hits = -1;
  1962. TSInt ram_cache_misses = -1;
  1963. TSInt lookup_active = -1;
  1964. TSInt lookup_success = -1;
  1965. TSInt lookup_failure = -1;
  1966. TSInt read_active = -1;
  1967. TSInt read_success = -1;
  1968. TSInt read_failure = -1;
  1969. TSInt write_active = -1;
  1970. TSInt write_success = -1;
  1971. TSInt write_failure = -1;
  1972. TSInt update_active = -1;
  1973. TSInt update_success = -1;
  1974. TSInt update_failure = -1;
  1975. TSInt remove_active = -1;
  1976. TSInt remove_success = -1;
  1977. TSInt remove_failure = -1;
  1978. //get values
  1979. Cli_RecordGetInt("proxy.process.cache.bytes_used", &bytes_used);
  1980. Cli_RecordGetInt("proxy.process.cache.bytes_total", &bytes_total);
  1981. Cli_RecordGetInt("proxy.process.cache.ram_cache.total_bytes", &ram_cache_total_bytes);
  1982. Cli_RecordGetInt("proxy.process.cache.ram_cache.bytes_used", &ram_cache_bytes_used);
  1983. Cli_RecordGetInt("proxy.process.cache.ram_cache.hits", &ram_cache_hits);
  1984. Cli_RecordGetInt("proxy.process.cache.ram_cache.misses", &ram_cache_misses);
  1985. Cli_RecordGetInt("proxy.process.cache.lookup.active", &lookup_active);
  1986. Cli_RecordGetInt("proxy.process.cache.lookup.success", &lookup_success);
  1987. Cli_RecordGetInt("proxy.process.cache.lookup.failure", &lookup_failure);
  1988. Cli_RecordGetInt("proxy.process.cache.read.active", &read_active);
  1989. Cli_RecordGetInt("proxy.process.cache.read.success", &read_success);
  1990. Cli_RecordGetInt("proxy.process.cache.read.failure", &read_failure);
  1991. Cli_RecordGetInt("proxy.process.cache.write.active", &write_active);
  1992. Cli_RecordGetInt("proxy.process.cache.write.success", &write_success);
  1993. Cli_RecordGetInt("proxy.process.cache.write.failure", &write_failure);
  1994. Cli_RecordGetInt("proxy.process.cache.update.active", &update_active);
  1995. Cli_RecordGetInt("proxy.process.cache.update.success", &update_success);
  1996. Cli_RecordGetInt("proxy.process.cache.update.failure", &update_failure);
  1997. Cli_RecordGetInt("proxy.process.cache.remove.active", &remove_active);
  1998. Cli_RecordGetInt("proxy.process.cache.remove.success", &remove_success);
  1999. Cli_RecordGetInt("proxy.process.cache.remove.failure", &remove_failure);
  2000. //display values
  2001. Cli_Printf("\n");
  2002. Cli_Printf("Bytes Used --- %d GB\n", bytes_used / (1024 * 1024 * 1024));
  2003. Cli_Printf("Cache Size --- %d GB\n", bytes_total / (1024 * 1024 * 1024));
  2004. Cli_Printf("--RAM Cache--\n");
  2005. Cli_Printf("Total Bytes -- %" PRId64 "\n", ram_cache_total_bytes);
  2006. Cli_Printf("Bytes Used --- %" PRId64 "\n", ram_cache_bytes_used);
  2007. Cli_Printf("Hits --------- %d\n", ram_cache_hits);
  2008. Cli_Printf("Misses ------- %d\n", ram_cache_misses);
  2009. Cli_Printf("--Lookups--\n");
  2010. Cli_Printf("In Progress -- %d\n", lookup_active);
  2011. Cli_Printf("Hits --------- %d\n", lookup_success);
  2012. Cli_Printf("Misses ------- %d\n", lookup_failure);
  2013. Cli_Printf("--Reads--\n");
  2014. Cli_Printf("In Progress -- %d\n", read_active);
  2015. Cli_Printf("Hits --------- %d\n", read_success);
  2016. Cli_Printf("Misses ------- %d\n", read_failure);
  2017. Cli_Printf("--Writes--\n");
  2018. Cli_Printf("In Progress -- %d\n", write_active);
  2019. Cli_Printf("Hits --------- %d\n", write_success);
  2020. Cli_Printf("Misses ------- %d\n", write_failure);
  2021. Cli_Printf("--Updates--\n");
  2022. Cli_Printf("In Progress -- %d\n", update_active);
  2023. Cli_Printf("Hits --------- %d\n", update_success);
  2024. Cli_Printf("Misses ------- %d\n", update_failure);
  2025. Cli_Printf("--Removes--\n");
  2026. Cli_Printf("In Progress -- %d\n", remove_active);
  2027. Cli_Printf("Hits --------- %d\n", remove_success);
  2028. Cli_Printf("Misses ------- %d\n", remove_failure);
  2029. Cli_Printf("\n");
  2030. return CLI_OK;
  2031. }
  2032. // show proxy-stats sub-command
  2033. int
  2034. ShowHostDbStats()
  2035. {
  2036. //variables
  2037. TSFloat hit_ratio = -1.0;
  2038. TSFloat lookups_per_second = -1.0;
  2039. //get values
  2040. Cli_RecordGetFloat("proxy.node.hostdb.hit_ratio", &hit_ratio);
  2041. Cli_RecordGetFloat("proxy.node.dns.lookups_per_second", &lookups_per_second);
  2042. //display values
  2043. Cli_Printf("\n");
  2044. Cli_Printf("Host Database hit Rate -- %f %% *\n", 100 * hit_ratio);
  2045. Cli_Printf("DNS Lookups Per Second -- %f\n", lookups_per_second);
  2046. Cli_Printf("\n* Value reprensents 10 second average.\n");
  2047. Cli_Printf("\n");
  2048. return CLI_OK;
  2049. }
  2050. // show proxy-stats sub-command
  2051. int
  2052. ShowDnsStats()
  2053. {
  2054. TSFloat lookups_per_second = -1.0;
  2055. Cli_RecordGetFloat("proxy.node.dns.lookups_per_second", &lookups_per_second);
  2056. Cli_Printf("\n");
  2057. Cli_Printf("DNS Lookups Per Second -- %f\n", lookups_per_second);
  2058. Cli_Printf("\n");
  2059. return CLI_OK;
  2060. }
  2061. // show proxy-stats sub-command
  2062. int
  2063. ShowLoggingStats()
  2064. {
  2065. TSCounter log_file_open = -1;
  2066. TSInt log_files_space_used = -1;
  2067. TSCounter event_log_access = -1;
  2068. TSCounter event_log_access_skip = -1;
  2069. TSCounter event_log_error = -1;
  2070. Cli_RecordGetCounter("proxy.process.log.log_files_open", &log_file_open);
  2071. Cli_RecordGetInt("proxy.process.log.log_files_space_used", &log_files_space_used);
  2072. Cli_RecordGetCounter("proxy.process.log.event_log_access", &event_log_access);
  2073. Cli_RecordGetCounter("proxy.process.log.event_log_access_skip", &event_log_access_skip);
  2074. Cli_RecordGetCounter("proxy.process.log.event_log_error", &event_log_error);
  2075. Cli_Printf("\n");
  2076. Cli_Printf("Current Open Log Files ----------- %d\n", log_file_open);
  2077. Cli_Printf("Space Used For Log Files --------- %d\n", log_files_space_used);
  2078. Cli_Printf("Number of Access Events Logged --- %d\n", event_log_access);
  2079. Cli_Printf("Number of Access Events Skipped -- %d\n", event_log_access_skip);
  2080. Cli_Printf("Number of Error Events Logged ---- %d\n", event_log_error);
  2081. Cli_Printf("\n");
  2082. return CLI_OK;
  2083. }
  2084. // show:alarms sub-command
  2085. int
  2086. ShowAlarms()
  2087. {
  2088. TSList events;
  2089. int count, i;
  2090. char *name;
  2091. events = TSListCreate();
  2092. TSError status = TSActiveEventGetMlt(events);
  2093. if (status != TS_ERR_OKAY) {
  2094. if (events) {
  2095. TSListDestroy(events);
  2096. }
  2097. Cli_Error(ERR_ALARM_LIST);
  2098. return CLI_ERROR;
  2099. }
  2100. count = TSListLen(events);
  2101. if (count > 0) {
  2102. Cli_Printf("\nActive Alarms\n");
  2103. for (i = 0; i < count; i++) {
  2104. name = (char *) TSListDequeue(events);
  2105. Cli_Printf(" %d. %s\n", i + 1, name);
  2106. }
  2107. Cli_Printf("\n");
  2108. } else {
  2109. Cli_Printf("\nNo active alarms.\n\n");
  2110. }
  2111. TSListDestroy(events);
  2112. return CLI_OK;
  2113. }