-/* SmoothWall libsmooth.\r
- *\r
- * This program is distributed under the terms of the GNU General Public\r
- * Licence. See the file COPYING for details.\r
- *\r
- * (c) Lawrence Manning, 2001\r
- * Contains library functions.\r
- * \r
- * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $\r
- * \r
- */\r
- \r
-#include "libsmooth.h"\r
-\r
-extern FILE *flog;\r
-extern char *mylog;\r
-\r
-extern char **ctr;\r
- \r
-/* reboot(). reboots. */\r
-void reboot(void)\r
-{\r
- mysystem("/etc/halt");\r
-}\r
-\r
-/* stripnl(). Replaces \n with \0 */\r
-void stripnl(char *s)\r
-{\r
- char *t = strchr(s, '\n');\r
- if (t) *t = '\0';\r
-}\r
-\r
-/* Little wrapper. */\r
-int mysystem(char *command)\r
-{\r
- char mycommand[STRING_SIZE];\r
- \r
- snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);\r
- fprintf(flog, "Running command: %s\n", command);\r
- return system(mycommand);\r
-}\r
-\r
-void errorbox(char *message)\r
-{\r
- newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message);\r
-}\r
-\r
-void statuswindow(int width, int height, char *title, char *text, ...)\r
-{\r
- newtComponent t, f;\r
- char *buf = NULL;\r
- int size = 0;\r
- int i = 0;\r
- va_list args;\r
-\r
- va_start(args, text);\r
-\r
- do {\r
- size += 1000;\r
- if (buf) free(buf);\r
- buf = malloc(size);\r
- i = vsnprintf(buf, size, text, args);\r
- } while (i == size);\r
-\r
- va_end(args);\r
-\r
- newtCenteredWindow(width, height, title);\r
-\r
- t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);\r
- newtTextboxSetText(t, buf);\r
- f = newtForm(NULL, NULL, 0);\r
-\r
- free(buf);\r
-\r
- newtFormAddComponent(f, t);\r
-\r
- newtDrawForm(f);\r
- newtRefresh();\r
- newtFormDestroy(f);\r
-}\r
-\r
-int runcommandwithstatus(char *command, char *message)\r
-{\r
- int rc;\r
- char title[STRING_SIZE];\r
- \r
- sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);\r
- statuswindow(60, 4, title, message);\r
- rc = mysystem(command);\r
- newtPopWindow();\r
- \r
- return rc;\r
-}\r
-\r
-int runhiddencommandwithstatus(char *command, char *message)\r
-{\r
- int rc;\r
- char title[STRING_SIZE];\r
- char mycommand[STRING_SIZE];\r
- \r
- sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);\r
- statuswindow(60, 4, title, message);\r
- snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);\r
- fprintf(flog, "Running command: ***** HIDDEN *****\n");\r
- rc = system(mycommand);\r
- newtPopWindow();\r
- \r
- return rc;\r
-}\r
-\r
-/* This one borrowed from redhat installer. */\r
-int runcommandwithprogress(int width, int height, char *title, char *command,\r
- int lines, char *text, ...)\r
-{\r
- newtComponent t, f, s;\r
- char *buf = NULL;\r
- int size = 0;\r
- int i = 0;\r
- va_list args;\r
- int rc = 0;\r
- FILE *p;\r
- char buffer[STRING_SIZE];\r
- int progress = 0;\r
- char mycommand[STRING_SIZE];\r
-\r
- va_start(args, text);\r
-\r
- do {\r
- size += 1000;\r
- if (buf) free(buf);\r
- buf = malloc(size);\r
- i = vsnprintf(buf, size, text, args);\r
- } while (i == size);\r
-\r
- va_end(args);\r
-\r
- newtCenteredWindow(width, height, title);\r
-\r
- t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);\r
- newtTextboxSetText(t, buf);\r
- f = newtForm(NULL, NULL, 0);\r
-\r
- free(buf);\r
-\r
- newtFormAddComponent(f, t);\r
- \r
- s = newtScale(1, 3, width - 2, lines);\r
- newtScaleSet(s, progress);\r
- \r
- newtFormAddComponent(f, s);\r
-\r
- newtDrawForm(f);\r
- newtRefresh();\r
- \r
- snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog);\r
- fprintf(flog, "Running command: %s\n", command);\r
- \r
- if (!(p = popen(command, "r")))\r
- {\r
- rc = 1;\r
- goto EXIT;\r
- }\r
- setvbuf(p, NULL, _IOLBF, 255);\r
- \r
- while (fgets(buffer, STRING_SIZE, p))\r
- {\r
- newtScaleSet(s, ++progress);\r
- newtRefresh(); \r
- fprintf(flog, "%s", buffer);\r
- }\r
- \r
- rc = pclose(p);\r
- \r
-EXIT:\r
- newtFormDestroy(f);\r
- newtPopWindow();\r
- \r
- return rc;\r
-}\r
-\r
-int checkformodule(char *module)\r
-{\r
- FILE *file;\r
- char buffer[STRING_SIZE];\r
- int result = 0;\r
- \r
- if (!(file = fopen("/proc/modules", "r")))\r
- {\r
- fprintf(flog, "Unable to open /proc/modules in checkformodule()\n");\r
- return 0;\r
- }\r
- \r
- while (fgets(buffer, STRING_SIZE, file))\r
- {\r
- if (strncmp(buffer, module, strlen(module)) == 0)\r
- {\r
- if (buffer[strlen(module)] == ' ')\r
- {\r
- result = 1;\r
- goto EXIT;\r
- }\r
- }\r
- }\r
- \r
-EXIT:\r
- fclose(file);\r
- \r
- return result;\r
-} \r
- \r
-int _replace_string(char string[], char *from, char *to)\r
-{\r
- int fromlen = strlen(from);\r
- int tolen = strlen(to);\r
- char *start, *p1, *p2;\r
- for(start = string; *start != '\0'; start++)\r
- {\r
- p1 = from;\r
- p2 = start;\r
- while(*p1 != '\0')\r
- {\r
- if(*p1 != *p2)\r
- break;\r
- p1++;\r
- p2++;\r
- }\r
- if(*p1 == '\0')\r
- {\r
- if(fromlen != tolen)\r
- {\r
- memmove(start + tolen, start + fromlen,\r
- strlen(start + fromlen) + 1);\r
- }\r
- for(p1 = to; *p1 != '\0'; p1++)\r
- *start++ = *p1;\r
- return 1;\r
- }\r
- }\r
- return 0;\r
-}\r
-\r
-int replace(char filename1[], char *from, char *to)\r
-{\r
- FILE *file1, *file2;\r
- char filename2[1000];\r
- char temp[1000];\r
- int ret = 0;\r
-\r
- /* Open the source and destination files */\r
- strcpy (filename2, filename1);\r
- strcat (filename2, ".new");\r
- if (!(file1 = fopen (filename1, "r"))) return 1;\r
- if (!(file2 = fopen (filename2, "w"))) {\r
- fclose(file1);\r
- return -1;\r
- }\r
-\r
- /* Start reading in lines */\r
- while (fgets (temp, 1000, file1) != NULL) {\r
-\r
- if (strlen(to) > 0) {\r
- /* Replace string */\r
- ret = _replace_string (temp, from, to);\r
- \r
- /* Write string to new file */\r
- fputs(temp, file2);\r
- } else {\r
- /* Remove string when to is NULL */\r
- if (!strstr(temp, from)) \r
- fputs(temp, file2);\r
- }\r
- }\r
-\r
- /* Close source and destination */\r
- fclose (file1);\r
- fclose (file2);\r
-\r
- /* Move the file */\r
- rename (filename2, filename1);\r
- \r
- return (ret);\r
-}\r
-\r
-/* Include enabled languages */\r
-#ifdef LANG_EN_ONLY\r
- #include "lang_en.c"\r
-#elifdef LANG_ALL\r
- #include "lang_bz.c"\r
- #include "lang_cs.c"\r
- #include "lang_da.c"\r
- #include "lang_de.c"\r
- #include "lang_en.c"\r
- #include "lang_es.c"\r
- #include "lang_fi.c"\r
- #include "lang_fr.c"\r
- #include "lang_el.c"\r
- #include "lang_it.c"\r
- #include "lang_hu.c"\r
- #include "lang_la.c"\r
- #include "lang_nl.c"\r
- #include "lang_no.c"\r
- #include "lang_pl.c"\r
- #include "lang_pt.c"\r
- #include "lang_sk.c"\r
- #include "lang_so.c"\r
- #include "lang_sv.c"\r
- #include "lang_tr.c"\r
- #include "lang_vi.c"\r
-#else\r
- #include "lang_de.c"\r
- #include "lang_en.c"\r
-\r
-#endif\r
-// returns a pointer to the actual running version number of IPCop.\r
-// Successive updates increase effective version but not VERSION !\r
-char g_title[STRING_SIZE] = "";\r
-char* get_version(void) {\r
- FILE *f_title;\r
- if ((f_title = fopen ("/etc/issue", "r"))) {\r
- fgets (g_title, STRING_SIZE, f_title);\r
- fclose (f_title);\r
- if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0';\r
- } else {\r
- sprintf (g_title, "%s v%s - %s", NAME, VERSION, SLOGAN);\r
- }\r
- return g_title;\r
-}\r
+/* SmoothWall libsmooth.
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * (c) Lawrence Manning, 2001
+ * Contains library functions.
+ *
+ * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $
+ *
+ */
+
+#include "libsmooth.h"
+
+extern FILE *flog;
+extern char *mylog;
+
+extern char **ctr;
+
+/* reboot(). reboots. */
+void reboot(void)
+{
+ mysystem("/etc/halt");
+}
+
+/* stripnl(). Replaces \n with \0 */
+void stripnl(char *s)
+{
+ char *t = strchr(s, '\n');
+ if (t) *t = '\0';
+}
+
+/* Little wrapper. */
+int mysystem(char *command)
+{
+ char mycommand[STRING_SIZE];
+
+ snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
+ fprintf(flog, "Running command: %s\n", command);
+ return system(mycommand);
+}
+
+void errorbox(char *message)
+{
+ newtWinMessage(ctr[TR_ERROR], ctr[TR_OK], message);
+}
+
+int scrollmsgbox(int width, int height, char *title, char *text, ...)
+{
+ int rc = 0;
+ newtComponent t, f, b, c;
+ char *buf = NULL;
+ char checkbox;
+ int size = 0;
+ int i = 0;
+ va_list args;
+
+ va_start(args, text);
+
+ do {
+ size += 40000;
+ if (buf) free(buf);
+ buf = malloc(size);
+ i = vsnprintf(buf, size, text, args);
+ } while (i == size);
+
+ va_end(args);
+
+ newtCenteredWindow(width, height, title);
+
+ b = newtCompactButton(width - 15 ,height - 2, ctr[TR_OK]);
+ c = newtCheckbox(3, height - 2, ctr[TR_LICENSE_ACCEPT], ' ', " *", &checkbox);
+
+ t = newtTextbox(1, 1, width - 2, height - 4, NEWT_TEXTBOX_WRAP+NEWT_TEXTBOX_SCROLL);
+ newtTextboxSetText(t, buf);
+
+ f = newtForm(NULL, NULL, 0);
+ free(buf);
+
+ newtFormAddComponent(f, c);
+ newtFormAddComponent(f, b);
+ newtFormAddComponent(f, t);
+
+ newtRunForm(f);
+ if (checkbox=='*') rc=1;
+ newtFormDestroy(f);
+ return rc;
+}
+
+int disclaimerbox(char *message)
+{
+ int rc;
+ char title[STRING_SIZE];
+
+ sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
+ rc = scrollmsgbox(75, 20, title, message);
+ newtPopWindow();
+
+ return rc;
+}
+
+
+void statuswindow(int width, int height, char *title, char *text, ...)
+{
+ newtComponent t, f;
+ char *buf = NULL;
+ int size = 0;
+ int i = 0;
+ va_list args;
+
+ va_start(args, text);
+
+ do {
+ size += 1000;
+ if (buf) free(buf);
+ buf = malloc(size);
+ i = vsnprintf(buf, size, text, args);
+ } while (i == size);
+
+ va_end(args);
+
+ newtCenteredWindow(width, height, title);
+
+ t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
+ newtTextboxSetText(t, buf);
+ f = newtForm(NULL, NULL, 0);
+
+ free(buf);
+
+ newtFormAddComponent(f, t);
+
+ newtDrawForm(f);
+ newtRefresh();
+ newtFormDestroy(f);
+}
+
+int runcommandwithstatus(char *command, char *message)
+{
+ int rc;
+ char title[STRING_SIZE];
+
+ sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
+ statuswindow(60, 4, title, message);
+ rc = mysystem(command);
+ newtPopWindow();
+
+ return rc;
+}
+
+int runhiddencommandwithstatus(char *command, char *message)
+{
+ int rc;
+ char title[STRING_SIZE];
+ char mycommand[STRING_SIZE];
+
+ sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
+ statuswindow(60, 4, title, message);
+ snprintf(mycommand, STRING_SIZE, "%s >>%s 2>>%s", command, mylog, mylog);
+ fprintf(flog, "Running command: ***** HIDDEN *****\n");
+ rc = system(mycommand);
+ newtPopWindow();
+
+ return rc;
+}
+
+/* This one borrowed from redhat installer. */
+int runcommandwithprogress(int width, int height, char *title, char *command,
+ int lines, char *text, ...)
+{
+ newtComponent t, f, s;
+ char *buf = NULL;
+ int size = 0;
+ int i = 0;
+ va_list args;
+ int rc = 0;
+ FILE *p;
+ char buffer[STRING_SIZE];
+ int progress = 0;
+ char mycommand[STRING_SIZE];
+
+ va_start(args, text);
+
+ do {
+ size += 1000;
+ if (buf) free(buf);
+ buf = malloc(size);
+ i = vsnprintf(buf, size, text, args);
+ } while (i == size);
+
+ va_end(args);
+
+ newtCenteredWindow(width, height, title);
+
+ t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
+ newtTextboxSetText(t, buf);
+ f = newtForm(NULL, NULL, 0);
+
+ free(buf);
+
+ newtFormAddComponent(f, t);
+
+ s = newtScale(1, 3, width - 2, lines);
+ newtScaleSet(s, progress);
+
+ newtFormAddComponent(f, s);
+
+ newtDrawForm(f);
+ newtRefresh();
+
+ snprintf(mycommand, STRING_SIZE, "%s 2>>%s", command, mylog);
+ fprintf(flog, "Running command: %s\n", command);
+
+ if (!(p = popen(command, "r")))
+ {
+ rc = 1;
+ goto EXIT;
+ }
+ setvbuf(p, NULL, _IOLBF, 255);
+
+ while (fgets(buffer, STRING_SIZE, p))
+ {
+ newtScaleSet(s, ++progress);
+ newtRefresh();
+ fprintf(flog, "%s", buffer);
+ }
+
+ rc = pclose(p);
+
+EXIT:
+ newtFormDestroy(f);
+ newtPopWindow();
+
+ return rc;
+}
+
+int checkformodule(char *module)
+{
+ FILE *file;
+ char buffer[STRING_SIZE];
+ int result = 0;
+
+ if (!(file = fopen("/proc/modules", "r")))
+ {
+ fprintf(flog, "Unable to open /proc/modules in checkformodule()\n");
+ return 0;
+ }
+
+ while (fgets(buffer, STRING_SIZE, file))
+ {
+ if (strncmp(buffer, module, strlen(module)) == 0)
+ {
+ if (buffer[strlen(module)] == ' ')
+ {
+ result = 1;
+ goto EXIT;
+ }
+ }
+ }
+
+EXIT:
+ fclose(file);
+
+ return result;
+}
+
+int _replace_string(char string[], char *from, char *to)
+{
+ int fromlen = strlen(from);
+ int tolen = strlen(to);
+ char *start, *p1, *p2;
+ for(start = string; *start != '\0'; start++)
+ {
+ p1 = from;
+ p2 = start;
+ while(*p1 != '\0')
+ {
+ if(*p1 != *p2)
+ break;
+ p1++;
+ p2++;
+ }
+ if(*p1 == '\0')
+ {
+ if(fromlen != tolen)
+ {
+ memmove(start + tolen, start + fromlen,
+ strlen(start + fromlen) + 1);
+ }
+ for(p1 = to; *p1 != '\0'; p1++)
+ *start++ = *p1;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int replace(char filename1[], char *from, char *to)
+{
+ FILE *file1, *file2;
+ char filename2[1000];
+ char temp[1000];
+ int ret = 0;
+
+ /* Open the source and destination files */
+ strcpy (filename2, filename1);
+ strcat (filename2, ".new");
+ if (!(file1 = fopen (filename1, "r"))) return 1;
+ if (!(file2 = fopen (filename2, "w"))) {
+ fclose(file1);
+ return -1;
+ }
+
+ /* Start reading in lines */
+ while (fgets (temp, 1000, file1) != NULL) {
+
+ if (strlen(to) > 0) {
+ /* Replace string */
+ ret = _replace_string (temp, from, to);
+
+ /* Write string to new file */
+ fputs(temp, file2);
+ } else {
+ /* Remove string when to is NULL */
+ if (!strstr(temp, from))
+ fputs(temp, file2);
+ }
+ }
+
+ /* Close source and destination */
+ fclose (file1);
+ fclose (file2);
+
+ /* Move the file */
+ rename (filename2, filename1);
+
+ return (ret);
+}
+
+/* Include enabled languages */
+#ifdef LANG_EN_ONLY
+ #include "lang_en.c"
+#else
+ #include "lang_de.c"
+ #include "lang_en.c"
+ #include "lang_es.c"
+ #include "lang_fr.c"
+#endif
+
+// returns a pointer to the actual running version number of IPFire.
+// Successive updates increase effective version but not VERSION !
+char g_title[STRING_SIZE] = "";
+char* get_version(void) {
+ FILE *f_title;
+ if ((f_title = fopen ("/etc/issue", "r"))) {
+ fgets (g_title, STRING_SIZE, f_title);
+ fclose (f_title);
+ if (g_title[strlen(g_title) - 1] == '\n') g_title[strlen(g_title) - 1] = '\0';
+ } else {
+ sprintf (g_title, "%s %s - %s", NAME, VERSION, SLOGAN);
+ }
+ return g_title;
+}