/gui/tools/webmail/plugins/show_user_and_ip/functions.php

https://github.com/BenBE/ispCP · PHP · 246 lines · 203 code · 43 blank · 0 comment · 54 complexity · f5d80b0fc3c0686d89d9c455b9e4cc0e MD5 · raw file

  1. <?php
  2. include_once(SM_PATH . 'functions/i18n.php');
  3. include_once(SM_PATH . 'plugins/show_user_and_ip/config.php');
  4. function sui_last_load()
  5. {
  6. global $username, $data_dir, $sui_last_ip, $sui_last_host, $sui_last_date,
  7. $show_user_on_left_pane, $show_ip_on_left_pane, $show_host_on_left_pane;
  8. $sui_last_ip = getPref($data_dir, $username, 'sui_last_ip');
  9. $sui_last_host = getPref($data_dir, $username, 'sui_last_host');
  10. $sui_last_date = getPref($data_dir, $username, 'sui_last_date');
  11. $show_user_on_left_pane = getPref($data_dir, $username, 'show_user_on_left_pane');
  12. $show_ip_on_left_pane = getPref($data_dir, $username, 'show_ip_on_left_pane');
  13. $show_host_on_left_pane = getPref($data_dir, $username, 'show_host_on_left_pane');
  14. if ( strlen($show_user_on_left_pane) == 0 )
  15. $show_user_on_left_pane = 0;
  16. if ( strlen($show_ip_on_left_pane) == 0 )
  17. $show_ip_on_left_pane = 0;
  18. if ( strlen($show_host_on_left_pane) == 0 )
  19. $show_host_on_left_pane = 0;
  20. }
  21. function sui_show_ui()
  22. {
  23. global $username, $show_user_on_left_pane, $show_ip_on_left_pane,
  24. $show_host_on_left_pane, $sui_font_size, $sui_align;
  25. if( $show_user_on_left_pane || $show_ip_on_left_pane ||
  26. ( $show_host_on_left_pane && gethostbyaddr($_SERVER['REMOTE_ADDR']) != $_SERVER['REMOTE_ADDR'] ) )
  27. {
  28. bindtextdomain('show_user_and_ip', SM_PATH . 'plugins/show_user_and_ip/locale');
  29. textdomain('show_user_and_ip');
  30. echo '<p><div align="' . $sui_align . '"><font size="' . $sui_font_size . '">' . "\n"
  31. . ' <hr>' . "\n";
  32. if ( $show_user_on_left_pane )
  33. {
  34. echo ' <strong>' . _("Your username:") . '</strong><br>' . "\n"
  35. . "$username" . "\n";
  36. }
  37. if ( $show_user_on_left_pane && $show_ip_on_left_pane )
  38. echo ' <br><br>' . "\n";
  39. if ( $show_ip_on_left_pane )
  40. {
  41. echo ' <strong>' . _("Your IP address:") . '</strong><br>' . "\n"
  42. . $_SERVER['REMOTE_ADDR'] . "\n";
  43. }
  44. if ( $show_host_on_left_pane )
  45. {
  46. $sui_host_left = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  47. if ( $sui_host_left != $_SERVER['REMOTE_ADDR'] )
  48. {
  49. if ( $show_user_on_left_pane || $show_ip_on_left_pane )
  50. echo ' <br><br>' . "\n";
  51. echo ' <strong>' . _("Your Hostname:") . '</strong><br>' . "\n"
  52. . $sui_host_left . "\n";
  53. }
  54. }
  55. echo '<hr>' . "\n"
  56. . '</font></div></p>' . "\n";
  57. bindtextdomain('squirrelmail', SM_PATH . 'locale');
  58. textdomain('squirrelmail');
  59. }
  60. }
  61. function sui_show_last()
  62. {
  63. global $color, $username, $motd, $sui_last_ip, $sui_last_host, $sui_last_date,
  64. $sui_show_host_on_motd, $sui_motd_greet_with_welcome;
  65. if ( strlen($sui_last_date) > 0 )
  66. {
  67. $sui_display_format = _("D, F j, Y G:i");
  68. $sui_display_date = date(_("D, F j, Y G:i"), $sui_last_date);
  69. if ( !strstr($sui_display_format, "F") === FALSE )
  70. {
  71. $sui_display_date = str_replace("January", _("January"), $sui_display_date);
  72. $sui_display_date = str_replace("February", _("February"), $sui_display_date);
  73. $sui_display_date = str_replace("March", _("March"), $sui_display_date);
  74. $sui_display_date = str_replace("April", _("April"), $sui_display_date);
  75. $sui_display_date = str_replace("May", _("May"), $sui_display_date);
  76. $sui_display_date = str_replace("June", _("June"), $sui_display_date);
  77. $sui_display_date = str_replace("July", _("July"), $sui_display_date);
  78. $sui_display_date = str_replace("August", _("August"), $sui_display_date);
  79. $sui_display_date = str_replace("September", _("September"), $sui_display_date);
  80. $sui_display_date = str_replace("October", _("October"), $sui_display_date);
  81. $sui_display_date = str_replace("November", _("November"), $sui_display_date);
  82. $sui_display_date = str_replace("December", _("December"), $sui_display_date);
  83. }
  84. elseif ( !strstr($sui_display_format, "M") === FALSE )
  85. {
  86. $sui_display_date = str_replace("Jan", _("Jan"), $sui_display_date);
  87. $sui_display_date = str_replace("Feb", _("Feb"), $sui_display_date);
  88. $sui_display_date = str_replace("Mar", _("Mar"), $sui_display_date);
  89. $sui_display_date = str_replace("Apr", _("Apr"), $sui_display_date);
  90. $sui_display_date = str_replace("May", _("May"), $sui_display_date);
  91. $sui_display_date = str_replace("Jun", _("Jun"), $sui_display_date);
  92. $sui_display_date = str_replace("Jul", _("Jul"), $sui_display_date);
  93. $sui_display_date = str_replace("Aug", _("Aug"), $sui_display_date);
  94. $sui_display_date = str_replace("Sep", _("Sep"), $sui_display_date);
  95. $sui_display_date = str_replace("Oct", _("Oct"), $sui_display_date);
  96. $sui_display_date = str_replace("Nov", _("Nov"), $sui_display_date);
  97. $sui_display_date = str_replace("Dec", _("Dec"), $sui_display_date);
  98. }
  99. if ( !strstr($sui_display_format, "l") === FALSE )
  100. {
  101. $sui_display_date = str_replace("Monday", _("Monday"), $sui_display_date);
  102. $sui_display_date = str_replace("Tuesday", _("Tuesday"), $sui_display_date);
  103. $sui_display_date = str_replace("Wednesday", _("Wednesday"), $sui_display_date);
  104. $sui_display_date = str_replace("Thursday", _("Thursday"), $sui_display_date);
  105. $sui_display_date = str_replace("Friday", _("Friday"), $sui_display_date);
  106. $sui_display_date = str_replace("Saturday", _("Saturday"), $sui_display_date);
  107. $sui_display_date = str_replace("Sunday", _("Sunday"), $sui_display_date);
  108. }
  109. elseif ( !strstr($sui_display_format, "D") === FALSE )
  110. {
  111. $sui_display_date = str_replace("Mon", _("Mon"), $sui_display_date);
  112. $sui_display_date = str_replace("Tue", _("Tue"), $sui_display_date);
  113. $sui_display_date = str_replace("Wed", _("Wed"), $sui_display_date);
  114. $sui_display_date = str_replace("Thu", _("Thu"), $sui_display_date);
  115. $sui_display_date = str_replace("Fri", _("Fri"), $sui_display_date);
  116. $sui_display_date = str_replace("Sat", _("Sat"), $sui_display_date);
  117. $sui_display_date = str_replace("Sun", _("Sun"), $sui_display_date);
  118. }
  119. bindtextdomain('show_user_and_ip', SM_PATH . 'plugins/show_user_and_ip/locale');
  120. textdomain('show_user_and_ip');
  121. if ( $sui_last_host != "-1" && $sui_show_host_on_motd )
  122. $sui_last_host_formatted = " ($sui_last_host)";
  123. else
  124. $sui_last_host_formatted = "";
  125. if ( strlen($motd) > 0 )
  126. $sui_motd_append_before = "<br><br>";
  127. else
  128. $sui_motd_append_before = "";
  129. if ( $sui_motd_greet_with_welcome )
  130. $sui_motd_greet = _("Welcome,") . " ";
  131. else
  132. $sui_motd_greet = "<strong>" . _("INFO:") . "</strong> ";
  133. $sui_append_motd = sprintf(_("your last connection was from <strong>%s%s</strong> on <strong>%s</strong>."), $sui_last_ip, $sui_last_host_formatted, $sui_display_date);
  134. $motd .= $sui_motd_append_before . $sui_motd_greet . $sui_append_motd;
  135. bindtextdomain('squirrelmail', SM_PATH . 'locale');
  136. textdomain('squirrelmail');
  137. }
  138. }
  139. function sui_left_opt()
  140. {
  141. global $show_user_on_left_pane, $show_ip_on_left_pane, $show_host_on_left_pane;
  142. bindtextdomain('show_user_and_ip', SM_PATH . 'plugins/show_user_and_ip/locale');
  143. textdomain('show_user_and_ip');
  144. echo '<tr><td align="right" nowrap valign="top">' . _("Show username under folders list:")
  145. . '</td><td>'
  146. . '<label><input type="radio" name="check_show_user_on_left_pane" value="1"';
  147. if ( $show_user_on_left_pane == 1 ) echo ' CHECKED';
  148. echo '>&nbsp;' . _("Yes") . '</label>&nbsp;&nbsp;&nbsp;&nbsp;';
  149. echo '<label><input type="radio" name="check_show_user_on_left_pane"';
  150. if ( $show_user_on_left_pane == 0) echo ' CHECKED';
  151. echo '>&nbsp;' . _("No") . '</label></td></tr>';
  152. echo '<tr><td align="right" nowrap valign="top">' . _("Show IP address under folders list:")
  153. . '</td><td>'
  154. . '<label><input type="radio" name="check_show_ip_on_left_pane" value="1"';
  155. if ( $show_ip_on_left_pane == 1 ) echo ' CHECKED';
  156. echo '>&nbsp;' . _("Yes") . '</label>&nbsp;&nbsp;&nbsp;&nbsp;';
  157. echo '<label><input type="radio" name="check_show_ip_on_left_pane"';
  158. if ( $show_ip_on_left_pane == 0) echo ' CHECKED';
  159. echo '>&nbsp;' . _("No") . '</label></td></tr>';
  160. echo '<tr><td align="right" nowrap valign="top">' . _("Show hostname under folders list:")
  161. . '</td><td>'
  162. . '<label><input type="radio" name="check_show_host_on_left_pane" value="1"';
  163. if ( $show_host_on_left_pane == 1 ) echo ' CHECKED';
  164. echo '>&nbsp;' . _("Yes") . '</label>&nbsp;&nbsp;&nbsp;&nbsp;';
  165. echo '<label><input type="radio" name="check_show_host_on_left_pane"';
  166. if ( $show_host_on_left_pane == 0) echo ' CHECKED';
  167. echo '>&nbsp;' . _("No") . '</label></td></tr>';
  168. bindtextdomain('squirrelmail', SM_PATH . 'locale');
  169. textdomain('squirrelmail');
  170. }
  171. function sui_left_opt_save()
  172. {
  173. global $username, $data_dir;
  174. if ( $_POST['check_show_user_on_left_pane'] == 0 )
  175. setPref($data_dir, $username, "show_user_on_left_pane", "0");
  176. elseif ( $_POST['check_show_user_on_left_pane'] == 1 )
  177. setPref($data_dir, $username, "show_user_on_left_pane", "1");
  178. if ( $_POST['check_show_ip_on_left_pane'] == 0 )
  179. setPref($data_dir, $username, "show_ip_on_left_pane", "0");
  180. elseif ( $_POST['check_show_ip_on_left_pane'] == 1 )
  181. setPref($data_dir, $username, "show_ip_on_left_pane", "1");
  182. if ( $_POST['check_show_host_on_left_pane'] == 0 )
  183. setPref($data_dir, $username, "show_host_on_left_pane", "0");
  184. elseif ( $_POST['check_show_host_on_left_pane'] == 1 )
  185. setPref($data_dir, $username, "show_host_on_left_pane", "1");
  186. }
  187. function sui_last_save()
  188. {
  189. global $username, $data_dir;
  190. if ( !isset($_SESSION["sui_last_date_saved"]) || $_SESSION["sui_last_date_saved"] != "1" )
  191. {
  192. $sui_last_date = strtotime("now");
  193. setPref($data_dir, $username, "sui_last_ip", $_SERVER['REMOTE_ADDR']);
  194. $sui_remote_host = gethostbyaddr($_SERVER['REMOTE_ADDR']);
  195. if ( $sui_remote_host != $_SERVER['REMOTE_ADDR'] )
  196. setPref($data_dir, $username, "sui_last_host", $sui_remote_host);
  197. else
  198. setPref($data_dir, $username, "sui_last_host", "-1");
  199. setPref($data_dir, $username, "sui_last_date", $sui_last_date);
  200. $_SESSION["sui_last_date_saved"] = 1;
  201. }
  202. }
  203. ?>