]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/install+setup/libsmooth/main.c
1 /* SmoothWall libsmooth.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Contains library functions.
9 * $Id: main.c,v 1.6.2.9 2005/12/09 22:31:41 franck78 Exp $
13 #include "libsmooth.h"
20 /* reboot(). reboots. */
23 mysystem("/etc/halt");
26 /* stripnl(). Replaces \n with \0 */
29 char *t
= strchr(s
, '\n');
34 int mysystem(char *command
)
36 char mycommand
[STRING_SIZE
];
38 snprintf(mycommand
, STRING_SIZE
, "%s >>%s 2>>%s", command
, mylog
, mylog
);
39 fprintf(flog
, "Running command: %s\n", command
);
40 return system(mycommand
);
43 void errorbox(char *message
)
45 newtWinMessage(ctr
[TR_ERROR
], ctr
[TR_OK
], message
);
48 int scrollmsgbox(int width
, int height
, char *title
, char *text
, ...)
51 newtComponent t
, f
, b
, c
;
64 i
= vsnprintf(buf
, size
, text
, args
);
69 newtCenteredWindow(width
, height
, title
);
71 b
= newtCompactButton(width
- 15 ,height
- 2, ctr
[TR_OK
]);
72 c
= newtCheckbox(3, height
- 2, ctr
[TR_LICENSE_ACCEPT
], ' ', " *", &checkbox
);
74 t
= newtTextbox(1, 1, width
- 2, height
- 4, NEWT_TEXTBOX_WRAP
+NEWT_TEXTBOX_SCROLL
);
75 newtTextboxSetText(t
, buf
);
77 f
= newtForm(NULL
, NULL
, 0);
80 newtFormAddComponent(f
, c
);
81 newtFormAddComponent(f
, b
);
82 newtFormAddComponent(f
, t
);
85 if (checkbox
=='*') rc
=1;
90 int disclaimerbox(char *message
)
93 char title
[STRING_SIZE
];
95 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
96 rc
= scrollmsgbox(75, 20, title
, message
);
103 void statuswindow(int width
, int height
, char *title
, char *text
, ...)
111 va_start(args
, text
);
117 i
= vsnprintf(buf
, size
, text
, args
);
122 newtCenteredWindow(width
, height
, title
);
124 t
= newtTextbox(1, 1, width
- 2, height
- 2, NEWT_TEXTBOX_WRAP
);
125 newtTextboxSetText(t
, buf
);
126 f
= newtForm(NULL
, NULL
, 0);
130 newtFormAddComponent(f
, t
);
137 int runcommandwithstatus(char *command
, char *message
)
140 char title
[STRING_SIZE
];
142 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
143 statuswindow(60, 4, title
, message
);
144 rc
= mysystem(command
);
150 int runhiddencommandwithstatus(char *command
, char *message
)
153 char title
[STRING_SIZE
];
154 char mycommand
[STRING_SIZE
];
156 sprintf (title
, "%s v%s - %s", NAME
, VERSION
, SLOGAN
);
157 statuswindow(60, 4, title
, message
);
158 snprintf(mycommand
, STRING_SIZE
, "%s >>%s 2>>%s", command
, mylog
, mylog
);
159 fprintf(flog
, "Running command: ***** HIDDEN *****\n");
160 rc
= system(mycommand
);
166 /* This one borrowed from redhat installer. */
167 int runcommandwithprogress(int width
, int height
, char *title
, char *command
,
168 int lines
, char *text
, ...)
170 newtComponent t
, f
, s
;
177 char buffer
[STRING_SIZE
];
179 char mycommand
[STRING_SIZE
];
181 va_start(args
, text
);
187 i
= vsnprintf(buf
, size
, text
, args
);
192 newtCenteredWindow(width
, height
, title
);
194 t
= newtTextbox(1, 1, width
- 2, height
- 2, NEWT_TEXTBOX_WRAP
);
195 newtTextboxSetText(t
, buf
);
196 f
= newtForm(NULL
, NULL
, 0);
200 newtFormAddComponent(f
, t
);
202 s
= newtScale(1, 3, width
- 2, lines
);
203 newtScaleSet(s
, progress
);
205 newtFormAddComponent(f
, s
);
210 snprintf(mycommand
, STRING_SIZE
, "%s 2>>%s", command
, mylog
);
211 fprintf(flog
, "Running command: %s\n", command
);
213 if (!(p
= popen(command
, "r")))
218 setvbuf(p
, NULL
, _IOLBF
, 255);
220 while (fgets(buffer
, STRING_SIZE
, p
))
222 newtScaleSet(s
, ++progress
);
224 fprintf(flog
, "%s", buffer
);
236 int checkformodule(char *module
)
239 char buffer
[STRING_SIZE
];
242 if (!(file
= fopen("/proc/modules", "r")))
244 fprintf(flog
, "Unable to open /proc/modules in checkformodule()\n");
248 while (fgets(buffer
, STRING_SIZE
, file
))
250 if (strncmp(buffer
, module
, strlen(module
)) == 0)
252 if (buffer
[strlen(module
)] == ' ')
266 int _replace_string(char string
[], char *from
, char *to
)
268 int fromlen
= strlen(from
);
269 int tolen
= strlen(to
);
270 char *start
, *p1
, *p2
;
271 for(start
= string
; *start
!= '\0'; start
++)
286 memmove(start
+ tolen
, start
+ fromlen
,
287 strlen(start
+ fromlen
) + 1);
289 for(p1
= to
; *p1
!= '\0'; p1
++)
297 int replace(char filename1
[], char *from
, char *to
)
300 char filename2
[1000];
304 /* Open the source and destination files */
305 strcpy (filename2
, filename1
);
306 strcat (filename2
, ".new");
307 if (!(file1
= fopen (filename1
, "r"))) return 1;
308 if (!(file2
= fopen (filename2
, "w"))) {
313 /* Start reading in lines */
314 while (fgets (temp
, 1000, file1
) != NULL
) {
316 if (strlen(to
) > 0) {
318 ret
= _replace_string (temp
, from
, to
);
320 /* Write string to new file */
323 /* Remove string when to is NULL */
324 if (!strstr(temp
, from
))
329 /* Close source and destination */
334 rename (filename2
, filename1
);
339 /* Include enabled languages */
351 // returns a pointer to the actual running version number of IPFire.
352 // Successive updates increase effective version but not VERSION !
353 char g_title
[STRING_SIZE
] = "";
354 char* get_version(void) {
356 if ((f_title
= fopen ("/etc/issue", "r"))) {
357 fgets (g_title
, STRING_SIZE
, f_title
);
359 if (g_title
[strlen(g_title
) - 1] == '\n') g_title
[strlen(g_title
) - 1] = '\0';
361 sprintf (g_title
, "%s %s - %s", NAME
, VERSION
, SLOGAN
);