{"id":191,"date":"2011-12-22T11:04:08","date_gmt":"2011-12-22T17:04:08","guid":{"rendered":"http:\/\/csmartonline.com\/blog\/?p=191"},"modified":"2011-12-27T23:20:26","modified_gmt":"2011-12-28T05:20:26","slug":"clearos-edit-knockd-configuration-from-webconfig","status":"publish","type":"post","link":"http:\/\/csmartonline.com\/blog\/2011\/12\/22\/clearos-edit-knockd-configuration-from-webconfig\/","title":{"rendered":"ClearOS: Edit knockd configuration from webconfig"},"content":{"rendered":"<p>Today I will show you how to add an admin page to edit knockd&#8217;s configuration file from ClearOS&#8217;s webconfig:<\/p>\n<p><a href=\"http:\/\/csmartonline.com\/blog\/wp-content\/uploads\/2011\/12\/knockd_conf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-211\" title=\"Knockd Configuration\" src=\"http:\/\/csmartonline.com\/blog\/wp-content\/uploads\/2011\/12\/knockd_conf.png\" alt=\"\" width=\"996\" height=\"538\" srcset=\"http:\/\/csmartonline.com\/blog\/wp-content\/uploads\/2011\/12\/knockd_conf.png 996w, http:\/\/csmartonline.com\/blog\/wp-content\/uploads\/2011\/12\/knockd_conf-300x162.png 300w\" sizes=\"auto, (max-width: 996px) 100vw, 996px\" \/><\/a><\/p>\n<p>I&#8217;ve copied most of these files&#8217; contents from other admin pages and am not exactly sure what some functions do (like the number at the end of the menu file). However, I have not encountered any problems. Nonetheless, USE AT YOUR OWN RISK!<\/p>\n<p>Let&#8217;s start with the language file:<\/p>\n<pre class=\"snippet-code\">\r\n#vi \/var\/webconfig\/htdocs\/admin\/lang\/knockd-conf.en_US\r\n<\/pre>\n<p>Paste the following into the file:<\/p>\n<pre class=\"snippet-code\">\r\n&lt;?php\r\n\/\/ Generated by export.php.\r\ndefine(\"WEB_LANG_PAGE_INTRO\", \"This page allows you to edit your knockd configuration. WARNING: Please ensure you have stopped the knockd service before editing the configuration file!\");\r\ndefine(\"WEB_LANG_PAGE_TITLE\", \"Knockd Configuration\");\r\ndefine(\"WEB_LANG_KNOCKD_HEADING\", \"Knockd Configuration\");\r\ndefine(\"WEB_LANG_KNOCKD_LABEL\", \"Current Configuration\");\r\n\/\/ vi: syntax=php ts=4\r\n?&gt;\r\n<\/pre>\n<p>Now let&#8217;s move on to the menu:<\/p>\n<pre class=\"snippet-code\">\r\n#vi \/var\/webconfig\/htdocs\/menus\/knockd-conf.en_US\r\n<\/pre>\n<p>Paste the following:<\/p>\n<pre class=\"snippet-code\">\r\nNetwork|Firewall|Knockd Configuration|knockd-conf.php|configuration|3150\r\n<\/pre>\n<p>Lastly, our main script:<\/p>\n<pre class=\"snippet-code\">\r\n#vi \/var\/webconfig\/htdocs\/admin\/knockd-conf.php\r\n<\/pre>\n<p>Paste the following into it:<\/p>\n<pre class=\"snippet-code\">\r\n&lt;?php\r\nrequire_once(\"..\/..\/gui\/Webconfig.inc.php\");\r\nrequire_once(GlobalGetLanguageTemplate(__FILE__));\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/\r\n\/\/ Header\r\n\/\/\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nWebAuthenticate();\r\nWebHeader(WEB_LANG_PAGE_TITLE);\r\nWebDialogIntro(WEB_LANG_PAGE_TITLE, \"\/images\/icon-knockd-conf.png\", WEB_LANG_PAGE_INTRO);\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/\r\n\/\/ Handle Update\r\n\/\/\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nif(isset($_POST['text'])){\r\n$string= isset($_POST['text']) ? $_POST['text'] : \"\";\r\n$file = fopen(\"\/etc\/knockd.conf\",\"w\");\r\nfwrite($file, $string);\r\nfclose($file);\r\n};\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/\r\n\/\/ Main\r\n\/\/\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n$file = fopen(\"\/etc\/knockd.conf\",\"r\");\r\n$text = fread($file,filesize(\"\/etc\/knockd.conf\"));\r\nfclose($file);\r\nknockd_conf($text);\r\nWebFooter();\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/ F U N C T I O N S\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nfunction knockd_conf($text)\r\n{\r\nWebFormOpen();\r\nWebTableOpen(WEB_LANG_KNOCKD_HEADING, \"100%\");\r\necho \"\r\n&lt;tr&gt;\r\n&lt;td valign='top' class='mytablesubheader' nowrap&gt;\" . WEB_LANG_KNOCKD_LABEL\u00a0 . \"&lt;\/td&gt;\r\n&lt;td&gt;&lt;textarea rows='19' cols='80' name='text' spellcheck='false'&gt;$text&lt;\/textarea&gt;&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;tr&gt;\r\n&lt;td class='mytablesubheader' nowrap&gt;&amp;nbsp; &lt;\/td&gt;\r\n&lt;td&gt;\" . WebButtonUpdate(\"Update\") . \"&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n\";\r\nWebTableClose(\"100%\");\r\nWebFormClose();\r\n}\r\n\/\/ vim: syntax=php ts=4\r\n?&gt;\r\n<\/pre>\n<p>Almost done! We still have one last thing to do before we can test it out. We need to make sure that the user &#8216;<strong>webconfig<\/strong>&#8216; can write to our kncockd installation&#8217;s configuration file. For me, the easiest way to do this was to make webconfig the owner of the configuration file:<\/p>\n<pre class=\"snippet-code\">\r\n#chown webconfig \/etc\/knockd.conf\r\n<\/pre>\n<p>Some may say this is insecure or a bad idea but, as I see it, no one from the outside world is going to have access to webconfig and it is therefore secure. If you know of a better way, then by all means use it.<\/p>\n<p>The &#8216;User Guide&#8217; and &#8216;ClearCare Support&#8217; links wont work of course. I left them there mainly because I don&#8217;t know how to remove them and for aesthetics. Also, the icon image used is the same as the &#8216;Outgoing&#8217; page&#8217;s icon since I didn&#8217;t want to re-create one and that one seemed to fit best.<\/p>\n<p><strong>Be sure to stop the service before editing the configuration file to avoid headaches.<\/strong> Checking the service&#8217;s status directly from the newly created configuration page is far beyond my current skill set. However, you can add the knockd daemon to the services page quite easily: <a title=\"Installing knockd for ClearOS\" href=\"http:\/\/csmartonline.com\/blog\/2011\/12\/21\/install-knockd-for-clearos\/#service\" target=\"_blank\">Installing knockd for ClearOS<\/a><\/p>\n<p>That&#8217;s it! Congratulations, we are done!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I will show you how to add an admin page to edit knockd&#8217;s configuration file from ClearOS&#8217;s webconfig: I&#8217;ve copied most of these files&#8217; contents from other admin pages and am not exactly sure what some functions do (like &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/csmartonline.com\/blog\/2011\/12\/22\/clearos-edit-knockd-configuration-from-webconfig\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[45,60,65,66,30,59,26,41,68],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-tiptrick","tag-clearos","tag-daemon","tag-firewall","tag-forward-port","tag-interface","tag-knockd","tag-menu","tag-port","tag-webconfig"],"_links":{"self":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":21,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":197,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/191\/revisions\/197"}],"wp:attachment":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}