wmclockmon: rename `DFLAGS` `debug_CFLAGS`
[dockapps.git] / yawmppp / src / gtksetup / applet.c
blob8953caa1b63b49b5cd77d86dd934e5987728d1eb
1 /*
3 YAWMPPP - PPP dock app/helper for WindowMaker
4 Copyright (C) 2000,2001:
6 Author: Felipe Bergo (bergo@seul.org)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 $Id: applet.c,v 1.2 2001/04/21 18:29:33 bergo Exp $
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <ctype.h>
30 #include <unistd.h>
31 #include <fcntl.h>
32 #include <signal.h>
33 #include <sys/stat.h>
34 #include <sys/types.h>
35 #include <sys/wait.h>
36 #include <gtk/gtk.h>
37 #include "applet.h"
38 #include "isprc.h"
39 #include "about.h"
40 #include "msgbox.h"
42 #include "stepphone.xpm"
43 #include "pppdoc.xpm"
44 #include "padlock.xpm"
46 /* straight from the Gimp... */
47 #include "cmd_new.xpm"
48 #include "cmd_dup.xpm"
49 #include "cmd_del.xpm"
50 #include "cmd_up.xpm"
51 #include "cmd_down.xpm"
53 GtkWidget *applet,*nbook;
54 GtkWidget *isp_list,*rem_button,*dup_button,
55 *up_button,*dn_button;
56 GtkWidget *right_pane[8];
58 GtkWidget *ppp_pw[31];
60 struct YAWMPPP_ISP_INFO rc_entries[MAX_ISPS];
61 struct PREF_ISP_INFO pref_entries[MAX_ISPS];
62 struct PREF_PPP_OPT pppo;
63 int isp_count;
65 int selected_entry=-1;
67 char chat_path[512];
68 char pppd_path[512];
70 int man_flag[6]={0,0,0,0,0,0};
71 char *man_help[6];
73 GdkFont *fixedfont=NULL;
75 int
76 main(int argc, char **argv)
78 int i;
80 gtk_init(&argc,&argv);
81 find_out_paths();
83 create_preferences_panel();
84 load_rc_entries();
85 set_ppp_pane();
87 if (gdk_screen_width()>800)
88 fixedfont=gdk_font_load("-*-fixed-medium-r-normal--15-*-*-*-*-*-*");
89 else
90 fixedfont=gdk_font_load("-*-fixed-medium-r-normal--10-*-*-*-*-*-*");
92 gtk_main();
94 gdk_font_unref(fixedfont);
96 for(i=0;i<6;i++)
97 if (man_flag[i])
98 g_free(man_help[i]);
100 return 0;
103 void
104 create_preferences_panel(void)
106 GtkWidget *mvb;
107 GtkWidget *hs,*bhb,*cb[5],*lt,*up,*down,*nl[2];
108 GtkWidget *mhb,*svb,*sw,*aw[30],*rp,*vs,*ghb,*abo,*pppp,*hel;
110 GtkStyle *style;
111 GdkBitmap *mask;
112 GdkPixmap *myicon,*tp;
114 GtkTooltips *tips;
116 int i;
118 applet=gtk_window_new(GTK_WINDOW_TOPLEVEL);
119 gtk_widget_set_usize (applet, 550, 430);
120 gtk_window_set_title (GTK_WINDOW (applet), "YAWMPPP Configuration");
121 gtk_window_set_wmclass(GTK_WINDOW(applet),"yawmppp","pref");
122 gtk_container_set_border_width(GTK_CONTAINER(applet),4);
123 gtk_widget_show (applet);
125 style=gtk_widget_get_style(applet);
126 myicon = gdk_pixmap_create_from_xpm_d (applet->window, &mask,
127 &style->bg[GTK_STATE_NORMAL],
128 (gchar **) stepphone_xpm);
129 gdk_window_set_icon (applet->window, NULL, myicon, mask);
130 gdk_window_set_icon_name(applet->window,"yawmppp");
132 mvb=gtk_vbox_new(FALSE,2);
133 gtk_container_add(GTK_CONTAINER(applet),mvb);
135 nbook=gtk_notebook_new();
136 gtk_box_pack_start(GTK_BOX(mvb),nbook,TRUE,TRUE,0);
138 mhb=gtk_hbox_new(FALSE,2);
140 nl[0]=gtk_label_new("Dialing Entries");
141 gtk_notebook_append_page(GTK_NOTEBOOK(nbook),mhb,nl[0]);
143 nl[1]=gtk_label_new("PPP Options");
144 pppp=make_ppp_pane();
145 gtk_notebook_append_page(GTK_NOTEBOOK(nbook),pppp,nl[1]);
147 /* LEFT PANE */
149 svb=gtk_vbox_new(FALSE,2);
150 gtk_box_pack_start(GTK_BOX(mhb),svb,TRUE,TRUE,2);
152 aw[0]=hlabel_new("YAWMPPP Dialing Entries:");
153 gtk_box_pack_start(GTK_BOX(svb),aw[0],FALSE,TRUE,2);
155 sw=gtk_scrolled_window_new(NULL,NULL);
156 gtk_box_pack_start(GTK_BOX(svb),sw,TRUE,TRUE,4);
157 gtk_widget_show(sw);
158 gtk_container_set_border_width(GTK_CONTAINER(sw),0);
160 isp_list=gtk_clist_new(2);
161 gtk_clist_set_shadow_type(GTK_CLIST(isp_list),GTK_SHADOW_IN);
162 gtk_clist_set_selection_mode(GTK_CLIST(isp_list),GTK_SELECTION_SINGLE);
163 gtk_clist_column_titles_passive(GTK_CLIST(isp_list));
164 gtk_clist_column_titles_hide(GTK_CLIST(isp_list));
165 gtk_clist_set_column_width(GTK_CLIST(isp_list),0,34);
166 gtk_clist_set_column_width(GTK_CLIST(isp_list),1,110);
167 gtk_clist_set_row_height(GTK_CLIST(isp_list),36);
168 gtk_clist_set_column_auto_resize(GTK_CLIST(isp_list),1,TRUE);
169 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
170 GTK_POLICY_AUTOMATIC,
171 GTK_POLICY_ALWAYS);
172 gtk_container_add(GTK_CONTAINER(sw),isp_list);
173 gtk_widget_show(isp_list);
175 lt=gtk_hbox_new(TRUE,0);
176 gtk_box_pack_start(GTK_BOX(svb),lt,FALSE,FALSE,2);
178 /* NEW */
179 tp=gdk_pixmap_create_from_xpm_d (applet->window, &mask,
180 &style->bg[GTK_STATE_NORMAL],
181 (gchar **) cmd_new_xpm);
182 up=gtk_pixmap_new(tp,mask); gtk_widget_show(up); gdk_pixmap_unref(tp);
183 aw[1]=gtk_button_new();
184 gtk_container_add(GTK_CONTAINER(aw[1]),up);
186 /* DEL */
187 tp=gdk_pixmap_create_from_xpm_d (applet->window, &mask,
188 &style->bg[GTK_STATE_NORMAL],
189 (gchar **) cmd_del_xpm);
190 up=gtk_pixmap_new(tp,mask); gtk_widget_show(up); gdk_pixmap_unref(tp);
191 rem_button=aw[2]=gtk_button_new();
192 gtk_container_add(GTK_CONTAINER(aw[2]),up);
194 /* DUP */
195 tp=gdk_pixmap_create_from_xpm_d (applet->window, &mask,
196 &style->bg[GTK_STATE_NORMAL],
197 (gchar **) cmd_dup_xpm);
198 up=gtk_pixmap_new(tp,mask); gtk_widget_show(up); gdk_pixmap_unref(tp);
199 dup_button=aw[19]=gtk_button_new();
200 gtk_container_add(GTK_CONTAINER(aw[19]),up);
202 /* UP */
203 tp=gdk_pixmap_create_from_xpm_d (applet->window, &mask,
204 &style->bg[GTK_STATE_NORMAL],
205 (gchar **) cmd_up_xpm);
206 up=gtk_pixmap_new(tp,mask); gtk_widget_show(up); gdk_pixmap_unref(tp);
207 up_button=aw[20]=gtk_button_new();
208 gtk_container_add(GTK_CONTAINER(aw[20]),up);
210 /* DOWN */
211 tp=gdk_pixmap_create_from_xpm_d (applet->window, &mask,
212 &style->bg[GTK_STATE_NORMAL],
213 (gchar **) cmd_down_xpm);
214 down=gtk_pixmap_new(tp,mask); gtk_widget_show(down); gdk_pixmap_unref(tp);
215 dn_button=aw[21]=gtk_button_new();
216 gtk_container_add(GTK_CONTAINER(aw[21]),down);
218 gtk_box_pack_start(GTK_BOX(lt),aw[1],FALSE,TRUE,0);
219 gtk_box_pack_start(GTK_BOX(lt),aw[19],FALSE,TRUE,0);
220 gtk_box_pack_start(GTK_BOX(lt),aw[2],FALSE,TRUE,0);
221 gtk_box_pack_start(GTK_BOX(lt),aw[21],FALSE,TRUE,0);
222 gtk_box_pack_start(GTK_BOX(lt),aw[20],FALSE,TRUE,0);
224 /* TIPS */
225 tips=gtk_tooltips_new();
226 gtk_tooltips_set_tip(tips,aw[1],"New entry",NULL);
227 gtk_tooltips_set_tip(tips,aw[19],"Duplicate entry",NULL);
228 gtk_tooltips_set_tip(tips,aw[2],"Delete entry",NULL);
229 gtk_tooltips_set_tip(tips,aw[21],"Move down",NULL);
230 gtk_tooltips_set_tip(tips,aw[20],"Move up",NULL);
232 vs=gtk_vseparator_new();
233 gtk_box_pack_start(GTK_BOX(mhb),vs,FALSE,TRUE,2);
235 /* RIGHT PANE */
237 aw[3]=hlabel_new("Selected Entry:");
239 rp=gtk_vbox_new(FALSE,0);
240 gtk_box_pack_start(GTK_BOX(mhb),rp,TRUE,TRUE,2);
242 aw[4]=hlabel_new("Description");
243 aw[6]=hlabel_new("Display Handle");
244 aw[8]=hlabel_new("Phone number");
245 aw[10]=hlabel_new("Modem device");
246 aw[12]=hlabel_new("Username");
247 aw[14]=hlabel_new("Password");
249 right_pane[0]=aw[5]=gtk_entry_new_with_max_length(128);
250 right_pane[1]=aw[7]=gtk_entry_new_with_max_length(16);
251 right_pane[2]=aw[9]=gtk_entry_new_with_max_length(32);
252 right_pane[3]=aw[11]=gtk_entry_new_with_max_length(64);
253 right_pane[4]=aw[13]=gtk_entry_new_with_max_length(32);
254 right_pane[5]=aw[15]=gtk_entry_new_with_max_length(32);
256 gtk_entry_set_visibility(GTK_ENTRY(aw[15]),FALSE);
258 right_pane[6]=aw[16]=gtk_check_button_new_with_label("Pulse dialing");
260 aw[17]=gtk_hbox_new(FALSE,2);
262 for(i=3;i<=17;i++)
263 gtk_box_pack_start(GTK_BOX(rp),aw[i],FALSE,TRUE,(i<4)?2:1);
265 right_pane[7]=aw[18]=gtk_button_new_with_label(" More settings... ");
266 gtk_box_pack_end(GTK_BOX(aw[17]),aw[18],FALSE,FALSE,2);
268 /* BOTTOM */
270 hs=gtk_hseparator_new();
271 gtk_box_pack_start(GTK_BOX(mvb),hs,FALSE,FALSE,2);
273 ghb=gtk_hbox_new(FALSE,2);
274 gtk_box_pack_start(GTK_BOX(mvb),ghb,FALSE,FALSE,2);
275 abo=gtk_button_new_with_label(" ... ");
276 gtk_box_pack_start(GTK_BOX(ghb),abo,FALSE,FALSE,2);
277 hel=gtk_button_new_with_label(" Help ");
278 gtk_box_pack_start(GTK_BOX(ghb),hel,FALSE,FALSE,4);
280 bhb=gtk_hbox_new(TRUE,4);
281 gtk_box_pack_start(GTK_BOX(ghb),bhb,TRUE,TRUE,2);
283 cb[0]=gtk_button_new_with_label(" Apply ");
284 cb[1]=gtk_button_new_with_label(" Cancel ");
285 cb[2]=gtk_button_new_with_label(" OK");
287 cb[3]=gtk_label_new(" ");
288 cb[4]=gtk_label_new(" ");
290 gtk_box_pack_start(GTK_BOX(bhb),cb[3],FALSE,TRUE,4);
291 gtk_box_pack_start(GTK_BOX(bhb),cb[4],FALSE,TRUE,4);
292 gtk_box_pack_start(GTK_BOX(bhb),cb[0],FALSE,TRUE,4);
293 gtk_box_pack_start(GTK_BOX(bhb),cb[1],FALSE,TRUE,4);
294 gtk_box_pack_start(GTK_BOX(bhb),cb[2],FALSE,TRUE,4);
296 gtk_tooltips_set_tip(tips,abo,"About...",NULL);
298 for(i=0;i<5;i++)
299 gtk_widget_show(cb[i]);
300 for(i=0;i<22;i++)
301 gtk_widget_show(aw[i]);
302 for(i=0;i<2;i++)
303 gtk_widget_show(nl[i]);
304 gtk_widget_show(bhb);
305 gtk_widget_show(abo);
306 gtk_widget_show(hel);
307 gtk_widget_show(ghb);
308 gtk_widget_show(rp);
309 gtk_widget_show(lt);
310 gtk_widget_show(vs);
311 gtk_widget_show(hs);
312 gtk_widget_show(svb);
313 gtk_widget_show(mhb);
314 gtk_widget_show(nbook);
315 gtk_widget_show(mvb);
317 /* signal plumbing */
318 gtk_signal_connect (GTK_OBJECT (applet), "delete_event",
319 GTK_SIGNAL_FUNC (applet_kill), NULL);
320 gtk_signal_connect (GTK_OBJECT (applet), "destroy",
321 GTK_SIGNAL_FUNC (applet_destroy), NULL);
323 gtk_signal_connect (GTK_OBJECT (isp_list), "select_row",
324 GTK_SIGNAL_FUNC (list_select), NULL);
325 gtk_signal_connect (GTK_OBJECT (isp_list), "unselect_row",
326 GTK_SIGNAL_FUNC (list_unselect), NULL);
328 gtk_signal_connect (GTK_OBJECT (dn_button), "clicked",
329 GTK_SIGNAL_FUNC (list_movedown), NULL);
330 gtk_signal_connect (GTK_OBJECT (up_button), "clicked",
331 GTK_SIGNAL_FUNC (list_moveup), NULL);
332 gtk_signal_connect (GTK_OBJECT (rem_button), "clicked",
333 GTK_SIGNAL_FUNC (list_remove), NULL);
334 gtk_signal_connect (GTK_OBJECT (dup_button), "clicked",
335 GTK_SIGNAL_FUNC (list_duplicate), NULL);
336 gtk_signal_connect (GTK_OBJECT (aw[1]), "clicked",
337 GTK_SIGNAL_FUNC (list_add), NULL);
338 gtk_signal_connect (GTK_OBJECT (right_pane[7]), "clicked",
339 GTK_SIGNAL_FUNC (pop_advanced), NULL);
341 gtk_signal_connect (GTK_OBJECT (right_pane[0]), "changed",
342 GTK_SIGNAL_FUNC (isp_rename), NULL);
344 gtk_signal_connect (GTK_OBJECT (cb[0]), "clicked",
345 GTK_SIGNAL_FUNC (applet_apply), NULL);
346 gtk_signal_connect (GTK_OBJECT (cb[1]), "clicked",
347 GTK_SIGNAL_FUNC (applet_destroy), NULL);
348 gtk_signal_connect (GTK_OBJECT (cb[2]), "clicked",
349 GTK_SIGNAL_FUNC (applet_save_and_quit), NULL);
351 gtk_signal_connect (GTK_OBJECT (abo), "clicked",
352 GTK_SIGNAL_FUNC (applet_about), (gpointer)GTK_WINDOW(applet));
353 gtk_signal_connect (GTK_OBJECT (hel), "clicked",
354 GTK_SIGNAL_FUNC (pop_help), NULL);
355 gtk_notebook_set_page(GTK_NOTEBOOK(nbook),0);
358 gint
359 applet_kill (GtkWidget * widget, GdkEvent * event, gpointer data)
361 return FALSE;
364 void
365 applet_destroy (GtkWidget * widget, gpointer data)
367 gtk_main_quit();
370 void
371 list_select(GtkCList *cl,
372 gint row,
373 gint column,
374 GdkEventButton *geb,
375 gpointer data)
377 selected_entry=row;
378 update_right_pane();
381 void
382 list_unselect(GtkCList *cl,
383 gint row,
384 gint column,
385 GdkEventButton *geb,
386 gpointer data)
388 commit_back_to_db();
389 selected_entry=-1;
390 clear_and_disable_right_pane();
393 GtkWidget *
394 hlabel_new(char *s)
396 GtkWidget *h,*l;
397 h=gtk_hbox_new(FALSE,0);
398 l=gtk_label_new(s);
399 gtk_label_set_justify(GTK_LABEL(l),GTK_JUSTIFY_LEFT);
400 gtk_box_pack_start(GTK_BOX(h),l,FALSE,FALSE,0);
401 gtk_container_set_border_width(GTK_CONTAINER(h),1);
402 gtk_widget_show(l);
403 return(h);
406 void
407 clear_and_disable_right_pane(void)
409 int i;
411 for(i=0;i<6;i++) {
412 gtk_editable_select_region(GTK_EDITABLE(right_pane[i]),0,-1);
413 gtk_editable_delete_selection(GTK_EDITABLE(right_pane[i]));
414 gtk_widget_set_sensitive(right_pane[i],FALSE);
417 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(right_pane[6]),FALSE);
418 gtk_widget_set_sensitive(right_pane[6],FALSE);
419 gtk_widget_set_sensitive(right_pane[7],FALSE);
420 gtk_widget_set_sensitive(rem_button,FALSE);
421 gtk_widget_set_sensitive(up_button,FALSE);
422 gtk_widget_set_sensitive(dn_button,FALSE);
423 gtk_widget_set_sensitive(dup_button,FALSE);
426 void
427 update_right_pane(void)
429 int i;
431 if (selected_entry<0) {
432 clear_and_disable_right_pane();
433 return;
436 for(i=0;i<8;i++)
437 gtk_widget_set_sensitive(right_pane[i],TRUE);
439 gtk_entry_set_text(GTK_ENTRY(right_pane[0]),
440 pref_entries[selected_entry].LongName);
441 gtk_entry_set_text(GTK_ENTRY(right_pane[1]),
442 pref_entries[selected_entry].ShortName);
443 gtk_entry_set_text(GTK_ENTRY(right_pane[2]),
444 pref_entries[selected_entry].Phone);
445 gtk_entry_set_text(GTK_ENTRY(right_pane[3]),
446 pref_entries[selected_entry].Device);
447 gtk_entry_set_text(GTK_ENTRY(right_pane[4]),
448 pref_entries[selected_entry].Username);
449 gtk_entry_set_text(GTK_ENTRY(right_pane[5]),
450 pref_entries[selected_entry].Password);
452 if (atoi(pref_entries[selected_entry].PulseDial))
453 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(right_pane[6]),TRUE);
454 else
455 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(right_pane[6]),FALSE);
456 gtk_widget_set_sensitive(rem_button,TRUE);
457 gtk_widget_set_sensitive(up_button,(selected_entry!=0));
458 gtk_widget_set_sensitive(dn_button,(selected_entry<(isp_count-1)));
459 gtk_widget_set_sensitive(dup_button,TRUE);
462 void
463 commit_back_to_db(void)
465 if (selected_entry<0)
466 return;
468 strcpy(pref_entries[selected_entry].LongName,
469 gtk_entry_get_text(GTK_ENTRY(right_pane[0])));
470 strcpy(pref_entries[selected_entry].ShortName,
471 gtk_entry_get_text(GTK_ENTRY(right_pane[1])));
472 strcpy(pref_entries[selected_entry].Phone,
473 gtk_entry_get_text(GTK_ENTRY(right_pane[2])));
474 strcpy(pref_entries[selected_entry].Device,
475 gtk_entry_get_text(GTK_ENTRY(right_pane[3])));
476 strcpy(pref_entries[selected_entry].Username,
477 gtk_entry_get_text(GTK_ENTRY(right_pane[4])));
478 strcpy(pref_entries[selected_entry].Password,
479 gtk_entry_get_text(GTK_ENTRY(right_pane[5])));
481 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(right_pane[6])))
482 strcpy(pref_entries[selected_entry].PulseDial,"1");
483 else
484 strcpy(pref_entries[selected_entry].PulseDial,"0");
487 void
488 load_rc_entries(void)
490 char p[512],*q;
491 int i;
493 q=getenv("HOME");
494 sprintf(p,"%s/.yawmppp2/yawmppprc",q);
495 isp_count=GetISPInfo(p,&rc_entries[0],MAX_ISPS);
497 read_ppp_options_from_rc(p);
499 for(i=0;i<isp_count;i++)
500 xlate_ppp_to_pref(&rc_entries[i],&pref_entries[i]);
502 clear_and_disable_right_pane();
504 fill_list();
507 void
508 xlate_ppp_to_pref(struct YAWMPPP_ISP_INFO *wii,struct PREF_ISP_INFO *pii)
510 FILE *f;
511 int i;
512 char tmp[512],*p;
514 /* defaults if we need to jump out of the train */
515 memset(pii,0,sizeof(struct PREF_ISP_INFO));
516 strcpy(pii->Device,"/dev/modem");
517 if ((p=getenv("USER"))!=NULL)
518 strcpy(pii->Username,p);
519 strcpy(pii->ModemInit1,"ATZ");
520 strcpy(pii->ModemInit2,"ATM1L2");
521 strcpy(pii->PulseDial,"0");
522 strcpy(pii->UserString,"ogin:");
523 strcpy(pii->PassString,"word:");
524 strcpy(pii->ModemSpeed,"115200");
525 pii->nExpectPairs=0;
527 memcpy(&(pii->ppp),&(wii->ppp),sizeof(struct ISP_PPP));
529 /* entry name */
530 strcpy(pii->LongName,wii->LongName);
531 strcpy(pii->ShortName,wii->ShortName);
532 pii->nologin=wii->nologin;
534 /* get device and chat script filename from "Start" file */
535 f=fopen(wii->PPPLine,"r");
536 if (!f) return;
538 fgets(pii->Device,63,f); strtok(pii->Device,"\n");
539 fgets(pii->ModemSpeed,15,f); strtok(pii->ModemSpeed,"\n");
540 fgets(pii->PulseDial,7,f); strtok(pii->PulseDial,"\n");
541 fgets(pii->Phone,31,f); strtok(pii->Phone,"\n");
542 fgets(pii->ModemInit1,255,f); strtok(pii->ModemInit1,"\n");
543 fgets(pii->ModemInit2,255,f); strtok(pii->ModemInit2,"\n");
545 fgets(pii->UserString,31,f); strtok(pii->UserString,"\n");
546 fgets(pii->Username,31,f); strtok(pii->Username,"\n");
548 fgets(pii->PassString,31,f); strtok(pii->PassString,"\n");
549 fgets(pii->Password,31,f); strtok(pii->Password,"\n");
551 fgets(tmp,511,f); strtok(tmp,"\n"); pii->nExpectPairs=atoi(tmp);
552 for(i=0;i<pii->nExpectPairs;i++) {
553 fgets(pii->s_expect[i],31,f); strtok(pii->s_expect[i],"\n");
554 fgets(pii->s_send[i],31,f); strtok(pii->s_send[i],"\n");
556 fclose(f);
559 void
560 list_moveup(GtkWidget *gw,gpointer data)
562 int j;
563 struct PREF_ISP_INFO tmp;
564 j=selected_entry;
565 commit_back_to_db();
566 selected_entry=-1;
567 clear_and_disable_right_pane();
569 memcpy(&tmp,&pref_entries[j],sizeof(struct PREF_ISP_INFO));
570 memcpy(&pref_entries[j],&pref_entries[j-1],sizeof(struct PREF_ISP_INFO));
571 memcpy(&pref_entries[j-1],&tmp,sizeof(struct PREF_ISP_INFO));
573 fill_list();
574 gtk_clist_select_row(GTK_CLIST(isp_list),j-1,0);
577 void
578 list_movedown(GtkWidget *gw,gpointer data)
580 int j;
581 struct PREF_ISP_INFO tmp;
582 j=selected_entry;
583 commit_back_to_db();
584 selected_entry=-1;
585 clear_and_disable_right_pane();
587 memcpy(&tmp,&pref_entries[j],sizeof(struct PREF_ISP_INFO));
588 memcpy(&pref_entries[j],&pref_entries[j+1],sizeof(struct PREF_ISP_INFO));
589 memcpy(&pref_entries[j+1],&tmp,sizeof(struct PREF_ISP_INFO));
591 fill_list();
592 gtk_clist_select_row(GTK_CLIST(isp_list),j+1,0);
595 void
596 fill_list(void)
598 int i;
599 char *q,*pp[2];
600 GtkStyle *style;
601 GdkBitmap *mask;
602 GdkPixmap *tp;
604 style=gtk_widget_get_style(applet);
605 tp = gdk_pixmap_create_from_xpm_d (applet->window, &mask,
606 &style->bg[GTK_STATE_NORMAL],
607 (gchar **) pppdoc_xpm);
609 gtk_clist_freeze(GTK_CLIST(isp_list));
610 gtk_clist_clear(GTK_CLIST(isp_list));
612 for(i=0;i<isp_count;i++) {
613 q=pref_entries[i].LongName;
614 pp[0]=pp[1]=q;
615 gtk_clist_append(GTK_CLIST(isp_list),&q);
616 gtk_clist_set_pixmap(GTK_CLIST(isp_list),i,0,tp,mask);
617 gtk_clist_set_text(GTK_CLIST(isp_list),i,1,q);
618 gtk_clist_set_shift(GTK_CLIST(isp_list),i,0,-1,0);
619 gtk_clist_set_shift(GTK_CLIST(isp_list),i,1,11,0);
622 gtk_clist_thaw(GTK_CLIST(isp_list));
623 gdk_pixmap_unref(tp);
626 void
627 list_remove(GtkWidget *gw,gpointer data)
629 int i,j;
631 j=selected_entry;
632 selected_entry=-1;
633 clear_and_disable_right_pane();
635 for(i=j;i<(isp_count-1);i++)
636 memcpy(&pref_entries[i],&pref_entries[i+1],
637 sizeof(struct PREF_ISP_INFO));
638 isp_count--;
639 fill_list();
642 void
643 list_duplicate(GtkWidget *gw,gpointer data)
645 char tmp[128];
646 int i;
648 if (isp_count>=MAX_ISPS) {
649 message_box(GTK_WINDOW(applet),
650 ERR_MAX_ISPS,"Error",
651 MSGBOX_OK,MSGBOX_ICON_EXCLAMATION);
652 return;
655 commit_back_to_db();
656 i=selected_entry;
657 memcpy(&pref_entries[isp_count],&pref_entries[i],
658 sizeof(struct PREF_ISP_INFO));
659 selected_entry=-1;
660 clear_and_disable_right_pane();
661 sprintf(tmp,"copy of %s",pref_entries[isp_count].LongName);
662 strcpy(pref_entries[isp_count].LongName,tmp);
663 isp_count++;
664 fill_list();
665 gtk_clist_select_row(GTK_CLIST(isp_list),i,0);
668 void
669 list_add(GtkWidget *gw,gpointer data)
671 int i;
672 struct PREF_ISP_INFO *ne;
674 if (isp_count>=MAX_ISPS) {
675 message_box(GTK_WINDOW(applet),
676 ERR_MAX_ISPS,"Error",
677 MSGBOX_OK,MSGBOX_ICON_EXCLAMATION);
678 return;
681 i=selected_entry;
682 commit_back_to_db();
683 selected_entry=-1;
684 clear_and_disable_right_pane();
686 ne=&pref_entries[isp_count];
687 memset(ne,0,sizeof(struct PREF_ISP_INFO));
689 strcpy(ne->LongName,"New Entry");
690 strcpy(ne->ShortName,"ISP");
691 strcpy(ne->Device,"/dev/modem");
692 strcpy(ne->ModemInit1,"ATZ");
693 strcpy(ne->ModemInit2,"ATM1L2");
694 strcpy(ne->UserString,"ogin:");
695 strcpy(ne->PassString,"word:");
696 strcpy(ne->ModemSpeed,"57600");
697 ne->nExpectPairs=0;
699 ne->ppp.override=0;
700 ne->ppp.noipdefault=1;
701 ne->ppp.noauth=1;
702 ne->ppp.passive=0;
703 ne->ppp.defaultroute=1;
704 ne->ppp.chap=AUTH_DONTCARE;
705 ne->ppp.pap=AUTH_DONTCARE;
707 isp_count++;
708 fill_list();
709 if (i>=0)
710 gtk_clist_select_row(GTK_CLIST(isp_list),i,0);
713 GtkWidget *adv_e[7],*advdlg,*adv_w[20],*adv_nl;
714 struct PREF_ISP_INFO adv_regret;
716 void
717 pop_advanced(GtkWidget *gw,gpointer data)
719 GtkWidget *dlg,*l[7],*hs,*bhb,*bt[4],*esp,*esb;
720 GtkWidget *av[30];
721 GSList *pap,*chap;
722 char tmp[128];
723 int i;
724 struct PREF_ISP_INFO *pii;
726 memcpy(&adv_regret,&pref_entries[selected_entry],sizeof(struct PREF_ISP_INFO));
728 advdlg=dlg=gtk_window_new(GTK_WINDOW_DIALOG);
729 gtk_window_set_transient_for(GTK_WINDOW(advdlg),GTK_WINDOW(applet));
730 sprintf(tmp,"Settings: %s",pref_entries[selected_entry].LongName);
731 gtk_window_set_title(GTK_WINDOW(dlg),tmp);
732 gtk_window_set_policy(GTK_WINDOW(dlg),TRUE,TRUE,TRUE);
733 gtk_container_set_border_width(GTK_CONTAINER(dlg),4);
735 /* main vbox */
736 av[0]=gtk_vbox_new(FALSE,2);
737 gtk_container_add(GTK_CONTAINER(dlg),av[0]);
739 av[1]=gtk_hbox_new(FALSE,1);
741 /* first vbox */
742 av[2]=gtk_vbox_new(FALSE,1);
743 /* second vbox */
744 av[3]=gtk_vbox_new(FALSE,1);
745 av[4]=gtk_vseparator_new();
747 gtk_box_pack_start(GTK_BOX(av[0]),av[1],FALSE,TRUE,1);
748 gtk_box_pack_start(GTK_BOX(av[1]),av[2],FALSE,TRUE,1);
749 gtk_box_pack_start(GTK_BOX(av[1]),av[4],FALSE,TRUE,1);
750 gtk_box_pack_start(GTK_BOX(av[1]),av[3],FALSE,TRUE,1);
752 l[0]=hlabel_new("Modem Init String #1");
753 l[1]=hlabel_new("Modem Init String #2 (sent after #1)");
754 l[2]=hlabel_new("Port/Modem speed (bps)");
755 l[3]=hlabel_new("Send username when this string is received:");
756 l[4]=hlabel_new("Send password when this string is received:");
758 adv_e[0]=gtk_entry_new_with_max_length(256);
759 adv_e[1]=gtk_entry_new_with_max_length(256);
760 adv_e[2]=gtk_entry_new_with_max_length(16);
761 adv_e[3]=gtk_entry_new_with_max_length(32);
762 adv_e[4]=gtk_entry_new_with_max_length(32);
764 esb=gtk_hbox_new(FALSE,2);
765 esp=gtk_button_new_with_label(" Additional conversation... ");
767 adv_nl=gtk_check_button_new_with_label("Don't generate login/password pairs");
769 for(i=0;i<5;i++) {
770 gtk_box_pack_start(GTK_BOX(av[2]),l[i],FALSE,FALSE,1);
771 gtk_box_pack_start(GTK_BOX(av[2]),adv_e[i],FALSE,FALSE,1);
773 if (i==4) {
774 gtk_box_pack_start(GTK_BOX(av[2]),esb,FALSE,TRUE,1);
775 gtk_box_pack_end(GTK_BOX(esb),esp,FALSE,TRUE,1);
776 gtk_widget_show(esb);
777 gtk_widget_show(esp);
778 gtk_box_pack_start(GTK_BOX(av[2]),adv_nl,FALSE,TRUE,1);
779 gtk_widget_show(adv_nl);
782 gtk_widget_show(l[i]);
783 gtk_widget_show(adv_e[i]);
786 /* second pane */
788 av[5]=gtk_label_new(" ISP PPP Options ");
790 av[6]=gtk_hseparator_new();
791 adv_w[0]=av[7]=gtk_check_button_new_with_label("Override global PPP options");
792 av[8]=gtk_hseparator_new();
794 adv_w[1]=av[9]=gtk_check_button_new_with_label("defaultroute");
795 adv_w[2]=av[10]=gtk_check_button_new_with_label("passive");
796 adv_w[3]=av[11]=gtk_check_button_new_with_label("noauth");
797 adv_w[4]=av[12]=gtk_check_button_new_with_label("noipdefault");
798 av[13]=gtk_frame_new(" CHAP Authentication ");
799 av[14]=gtk_frame_new(" PAP Authentication ");
801 av[15]=gtk_vbox_new(FALSE,1);
802 av[16]=gtk_vbox_new(FALSE,1);
804 gtk_frame_set_shadow_type(GTK_FRAME(av[13]),GTK_SHADOW_ETCHED_IN);
805 gtk_frame_set_shadow_type(GTK_FRAME(av[14]),GTK_SHADOW_ETCHED_IN);
807 gtk_container_add(GTK_CONTAINER(av[13]),av[15]);
808 gtk_container_add(GTK_CONTAINER(av[14]),av[16]);
810 for(i=5;i<=14;i++)
811 gtk_box_pack_start(GTK_BOX(av[3]),av[i],FALSE,FALSE,1);
813 adv_w[5]=av[20]=gtk_radio_button_new_with_label(NULL,"require CHAP ");
814 chap=gtk_radio_button_group(GTK_RADIO_BUTTON(av[20]));
815 adv_w[6]=av[21]=gtk_radio_button_new_with_label(chap,"refuse CHAP ");
816 chap=gtk_radio_button_group(GTK_RADIO_BUTTON(av[21]));
817 adv_w[7]=av[22]=gtk_radio_button_new_with_label(chap,"don't care ");
819 gtk_box_pack_start(GTK_BOX(av[15]),av[20],FALSE,TRUE,1);
820 gtk_box_pack_start(GTK_BOX(av[15]),av[21],FALSE,TRUE,1);
821 gtk_box_pack_start(GTK_BOX(av[15]),av[22],FALSE,TRUE,1);
823 adv_w[8]=av[23]=gtk_radio_button_new_with_label(NULL,"require PAP ");
824 pap=gtk_radio_button_group(GTK_RADIO_BUTTON(av[23]));
825 adv_w[9]=av[24]=gtk_radio_button_new_with_label(pap,"refuse PAP ");
826 pap=gtk_radio_button_group(GTK_RADIO_BUTTON(av[24]));
827 adv_w[10]=av[25]=gtk_radio_button_new_with_label(pap,"don't care ");
829 gtk_box_pack_start(GTK_BOX(av[16]),av[23],FALSE,TRUE,1);
830 gtk_box_pack_start(GTK_BOX(av[16]),av[24],FALSE,TRUE,1);
831 gtk_box_pack_start(GTK_BOX(av[16]),av[25],FALSE,TRUE,1);
833 for(i=20;i<=25;i++)
834 gtk_widget_show(av[i]);
836 /* second pane */
838 hs=gtk_hseparator_new();
839 gtk_box_pack_start(GTK_BOX(av[0]),hs,FALSE,FALSE,4);
841 bhb=gtk_hbox_new(TRUE,4);
843 gtk_box_pack_start(GTK_BOX(av[0]),bhb,FALSE,FALSE,4);
845 bt[0]=gtk_button_new_with_label(" Help ");
846 bt[1]=gtk_label_new(" ");
847 bt[2]=gtk_button_new_with_label(" OK ");
848 bt[3]=gtk_button_new_with_label(" Cancel ");
850 for(i=0;i<4;i++) {
851 gtk_box_pack_start(GTK_BOX(bhb),bt[i],FALSE,TRUE,4);
852 gtk_widget_show(bt[i]);
855 gtk_widget_show(bhb);
856 gtk_widget_show(hs);
857 for(i=0;i<17;i++)
858 gtk_widget_show(av[i]);
860 gtk_widget_show(dlg);
861 gtk_widget_grab_focus(adv_e[0]);
863 pii=&pref_entries[selected_entry];
864 gtk_entry_set_text(GTK_ENTRY(adv_e[0]),pii->ModemInit1);
865 gtk_entry_set_text(GTK_ENTRY(adv_e[1]),pii->ModemInit2);
866 gtk_entry_set_text(GTK_ENTRY(adv_e[2]),pii->ModemSpeed);
867 gtk_entry_set_text(GTK_ENTRY(adv_e[3]),pii->UserString);
868 gtk_entry_set_text(GTK_ENTRY(adv_e[4]),pii->PassString);
870 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[0]),!!(pii->ppp.override));
871 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[1]),!!(pii->ppp.defaultroute));
872 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[2]),!!(pii->ppp.passive));
873 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[3]),!!(pii->ppp.noauth));
874 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[4]),!!(pii->ppp.noipdefault));
875 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[5+pii->ppp.chap]),TRUE);
876 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_w[8+pii->ppp.pap]),TRUE);
878 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(adv_nl),!!(pii->nologin));
880 if (!(pii->ppp.override))
881 enable_local_ppp(FALSE);
883 gtk_signal_connect (GTK_OBJECT (bt[0]), "clicked",
884 GTK_SIGNAL_FUNC (pop_help), NULL);
885 gtk_signal_connect (GTK_OBJECT (bt[2]), "clicked",
886 GTK_SIGNAL_FUNC (adv_ok), NULL);
887 gtk_signal_connect (GTK_OBJECT (bt[3]), "clicked",
888 GTK_SIGNAL_FUNC (adv_cancel), NULL);
889 gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
890 GTK_SIGNAL_FUNC (adv_destroy), NULL);
892 gtk_signal_connect (GTK_OBJECT (esp), "clicked",
893 GTK_SIGNAL_FUNC (pop_expect), NULL);
895 gtk_signal_connect (GTK_OBJECT (adv_w[0]), "toggled",
896 GTK_SIGNAL_FUNC (ppp_override_toggle), NULL);
898 gtk_grab_add(dlg);
901 void
902 enable_local_ppp(gboolean e)
904 int i;
905 for(i=1;i<11;i++)
906 gtk_widget_set_sensitive(adv_w[i],e);
909 void
910 ppp_override_toggle(GtkToggleButton *gtb,gpointer data)
912 enable_local_ppp(gtb->active);
915 void
916 adv_ok (GtkWidget * widget, gpointer data)
918 struct PREF_ISP_INFO *pii;
920 pii=&pref_entries[selected_entry];
921 strcpy(pii->ModemInit1,gtk_entry_get_text(GTK_ENTRY(adv_e[0])));
922 strcpy(pii->ModemInit2,gtk_entry_get_text(GTK_ENTRY(adv_e[1])));
923 strcpy(pii->ModemSpeed,gtk_entry_get_text(GTK_ENTRY(adv_e[2])));
924 strcpy(pii->UserString,gtk_entry_get_text(GTK_ENTRY(adv_e[3])));
925 strcpy(pii->PassString,gtk_entry_get_text(GTK_ENTRY(adv_e[4])));
927 pii->nologin=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_nl));
929 pii->ppp.override=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[0]));
930 pii->ppp.defaultroute=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[1]));
931 pii->ppp.passive=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[2]));
932 pii->ppp.noauth=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[3]));
933 pii->ppp.noipdefault=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[4]));
935 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[5])))
936 pii->ppp.chap=AUTH_REQUIRE;
937 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[6])))
938 pii->ppp.chap=AUTH_REFUSE;
939 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[7])))
940 pii->ppp.chap=AUTH_DONTCARE;
942 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[8])))
943 pii->ppp.pap=AUTH_REQUIRE;
944 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[9])))
945 pii->ppp.pap=AUTH_REFUSE;
946 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(adv_w[10])))
947 pii->ppp.pap=AUTH_DONTCARE;
949 gtk_widget_destroy(advdlg);
952 void
953 adv_cancel (GtkWidget * widget, gpointer data)
955 memcpy(&pref_entries[selected_entry],&adv_regret,sizeof(struct PREF_ISP_INFO));
956 gtk_widget_destroy(advdlg);
959 void
960 adv_destroy (GtkWidget * widget, gpointer data)
962 gtk_grab_remove(widget);
963 advdlg=NULL;
966 void
967 isp_rename(GtkEditable *ge,gpointer data)
969 if (selected_entry<0) return;
970 strcpy(pref_entries[selected_entry].LongName,
971 gtk_entry_get_text(GTK_ENTRY(ge)));
972 gtk_clist_set_text(GTK_CLIST(isp_list),selected_entry,1,
973 pref_entries[selected_entry].LongName);
977 write_and_apply_data(void)
979 char tmp[256],aux[768],yet[512],v_home[512],v_user[64];
980 struct stat ss;
981 FILE *f;
982 int i,j,needroot;
983 struct PREF_PPP_OPT modippp;
985 get_ppp_pane();
986 if (selected_entry>=0)
987 commit_back_to_db();
989 sprintf(tmp,"%s/.yawmppp2",getenv("HOME"));
991 if (stat(tmp,&ss)<0) {
992 if (mkdir(tmp,0700)<0) {
993 message_box(GTK_WINDOW(applet),ERR_CANT_MKDIR,"Error",
994 MSGBOX_OK,
995 MSGBOX_ICON_ERROR);
996 return(-1);
998 } else
999 chmod(tmp,0700);
1001 /* the yawmppprc file */
1002 sprintf(aux,"%s/yawmppprc",tmp);
1003 f=fopen(aux,"w");
1004 if (!f) {
1005 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1006 MSGBOX_OK,
1007 MSGBOX_ICON_ERROR);
1008 } else {
1010 /* FILE 1: YAWMPPPRC mode 600 */
1012 fprintf(f,"# yawmppprc : configuration for yawmppp generated by\n");
1013 fprintf(f,"# yawmppp.pref version %s. You should avoid editing this manually.\n",
1014 VERSION);
1015 fprintf(f,"# Use the yawmppp.pref program instead.\n");
1016 fprintf(f,"#\n# BTW, the format changed from YAWMPPP 1.x.x to 2.x.x,\n");
1017 fprintf(f,"# copying old yawmppprc files to this directory is a bad idea\n\n");
1019 for(i=0;i<isp_count;i++) {
1020 fprintf(f,"ISP.BEGIN\n");
1021 fprintf(f,"\t%s %s\n",KEY_LONGNAME,pref_entries[i].LongName);
1022 fprintf(f,"\t%s %s\n",KEY_SHORTNAME,pref_entries[i].ShortName);
1024 sprintf(yet,"%s/start.%d",tmp,i);
1025 fprintf(f,"\t%s %s\n",KEY_STARTACTION,yet);
1027 sprintf(yet,"%s/stop.%d",tmp,i);
1028 fprintf(f,"\t%s %s\n",KEY_STOPACTION,yet);
1030 sprintf(yet,"%s/ifdown.%d",tmp,i);
1031 fprintf(f,"\t%s %s\n",KEY_IFDOWNACTION,yet);
1033 sprintf(yet,"%s/opts.%d",tmp,i);
1034 fprintf(f,"\t%s %s\n",KEY_PPPSTUFF,yet);
1036 sprintf(yet,"%s/chat.%d",tmp,i);
1037 fprintf(f,"\t%s %s\n",KEY_CHATSTUFF,yet);
1039 fprintf(f,"\t%s %s\n",KEY_IFDOWNACTION,yet);
1040 fprintf(f,"\t%s %s\n",KEY_SPEEDACTION,"/etc/ppp/yagetmodemspeed");
1041 fprintf(f,"\t%s %s\n",KEY_USER,pref_entries[i].Username);
1042 fprintf(f,"\t%s %s\n",KEY_PHONE,pref_entries[i].Phone);
1044 fprintf(f,"\t%s %d\n",KEY_PPP_OVER,pref_entries[i].ppp.override);
1045 fprintf(f,"\t%s %d\n",KEY_PPP_DEFAULTROUTE,pref_entries[i].ppp.defaultroute);
1046 fprintf(f,"\t%s %d\n",KEY_PPP_PASSIVE,pref_entries[i].ppp.passive);
1047 fprintf(f,"\t%s %d\n",KEY_PPP_NOAUTH,pref_entries[i].ppp.noauth);
1048 fprintf(f,"\t%s %d\n",KEY_PPP_NOIPDEFAULT,pref_entries[i].ppp.noipdefault);
1049 fprintf(f,"\t%s %d\n",KEY_PPP_CHAP,pref_entries[i].ppp.chap);
1050 fprintf(f,"\t%s %d\n",KEY_PPP_PAP,pref_entries[i].ppp.pap);
1051 fprintf(f,"\t%s %d\n",KEY_NOLOGIN,pref_entries[i].nologin);
1053 fprintf(f,"ISP.END\n\n");
1056 /* write ppp pane */
1057 fprintf(f,"Note: if you were meant to edit the line below I would have\n");
1058 fprintf(f,"made it readable by humans.\n");
1059 fprintf(f,"PPPOPTIONS %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
1060 pppo.defaultroute,
1061 pppo.lock,
1062 pppo.passive,
1063 pppo.debug,
1064 pppo.kdebug,
1065 pppo.noauth,
1066 pppo.noipdefault,
1067 pppo.linectl,
1068 pppo.flowctl,
1069 pppo.mtu,
1070 pppo.mru,
1071 pppo.lcp[0],
1072 pppo.lcp[1],
1073 pppo.lcp[2],
1074 pppo.lcp[3],
1075 pppo.lcp[4],
1076 pppo.usepeerdns);
1078 fclose(f);
1079 chmod(aux,0600);
1082 /* the start.x, stop.x, ifdown.x , chat.x and opts.x files */
1083 for(i=0;i<isp_count;i++) {
1085 /* FILE 2 : start.x mode 700 */
1087 sprintf(aux,"%s/start.%d",tmp,i);
1088 f=fopen(aux,"w");
1089 if (!f) {
1090 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1091 MSGBOX_OK,
1092 MSGBOX_ICON_ERROR);
1093 return(-1);
1095 fprintf(f,"#!/bin/sh\n");
1096 fprintf(f,"# YAWMPPP dialing script generated by yawmppp.pref\n");
1097 fprintf(f,"# version %s. If possible, do not edit manually.\n\n",VERSION);
1099 fprintf(f,"%s call %s_yawmppp_isp%d\n",pppd_path,getenv("USER"),i);
1100 fclose(f);
1101 chmod(aux,0700);
1103 /* FILE 3 : opts.x mode 600 */
1105 sprintf(aux,"%s/opts.%d",tmp,i);
1106 f=fopen(aux,"w");
1107 if (!f) {
1108 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1109 MSGBOX_OK,
1110 MSGBOX_ICON_ERROR);
1111 return(-1);
1114 fprintf(f,"%s\n",pref_entries[i].Device);
1115 fprintf(f,"%s\n",pref_entries[i].ModemSpeed);
1116 fprintf(f,"%s\n",pref_entries[i].PulseDial);
1117 fprintf(f,"%s\n",pref_entries[i].Phone);
1118 fprintf(f,"%s\n",pref_entries[i].ModemInit1);
1119 fprintf(f,"%s\n",pref_entries[i].ModemInit2);
1120 fprintf(f,"%s\n",pref_entries[i].UserString);
1121 fprintf(f,"%s\n",pref_entries[i].Username);
1122 fprintf(f,"%s\n",pref_entries[i].PassString);
1123 fprintf(f,"%s\n",pref_entries[i].Password);
1124 fprintf(f,"%d\n",pref_entries[i].nExpectPairs);
1125 for(j=0;j<pref_entries[i].nExpectPairs;j++) {
1126 fprintf(f,"%s\n",pref_entries[i].s_expect[j]);
1127 fprintf(f,"%s\n",pref_entries[i].s_send[j]);
1130 fclose(f);
1131 chmod(aux,0600);
1133 /* FILE 4 : stop.x mode 700 */
1135 sprintf(aux,"%s/stop.%d",tmp,i);
1136 f=fopen(aux,"w");
1137 if (!f) {
1138 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1139 MSGBOX_OK,
1140 MSGBOX_ICON_ERROR);
1141 return(-1);
1144 fprintf(f,"#!/bin/sh\n");
1145 fprintf(f,"# YAWMPPP dialing script generated by yawmppp.pref\n");
1146 fprintf(f,"# version %s. If possible, do not edit manually.\n\n",VERSION);
1148 fprintf(f,"DEVICE=ppp0\n\n");
1149 fprintf(f,"if [ -r /var/run/$DEVICE.pid ]; then\n");
1150 fprintf(f,"\tkill -INT `cat /var/run/$DEVICE.pid`\n\n");
1151 fprintf(f,"\tif [ ! \"$?\" = \"0\" ]; then\n");
1152 fprintf(f,"\t\trm -f /var/run/$DEVICE.pid\n");
1153 fprintf(f,"\t\techo >/dev/console \"ERROR: Removed stale pid file\"\n");
1154 fprintf(f,"\t\texit 1\n");
1155 fprintf(f,"\tfi\n\n");
1156 fprintf(f,"\techo >/dev/console \"PPP link to $DEVICE terminated.\"\n");
1157 fprintf(f,"\texit 0\n");
1158 fprintf(f,"fi\n\n");
1159 fprintf(f,"echo >/dev/console \"ERROR: PPP link not active on $DEVICE\"\n");
1160 fprintf(f,"exit 1\n");
1161 fclose(f);
1162 chmod(aux,0700);
1164 /* FILE 5 : ifdown.x mode 700 */
1166 sprintf(aux,"%s/ifdown.%d",tmp,i);
1167 f=fopen(aux,"w");
1168 if (!f) {
1169 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1170 MSGBOX_OK,
1171 MSGBOX_ICON_ERROR);
1172 return(-1);
1175 fprintf(f,"#!/bin/sh\n");
1176 fprintf(f,"# YAWMPPP dialing script generated by yawmppp.pref\n");
1177 fprintf(f,"# version %s. If possible, do not edit manually.\n\n",VERSION);
1179 fprintf(f,"# uncomment the line below to have yawmppp restart\n");
1180 fprintf(f,"# connections automatically\n\n");
1181 fprintf(f,"# source %s/start.%d\n",tmp,i);
1182 fclose(f);
1183 chmod(aux,0700);
1185 /* FILE 6 : user_chat.x mode 700 */
1187 sprintf(aux,"%s/%s_chat.%d",tmp,getenv("USER"),i);
1188 f=fopen(aux,"w");
1189 if (!f) {
1190 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1191 MSGBOX_OK,
1192 MSGBOX_ICON_ERROR);
1193 return(-1);
1195 fprintf(f,"ABORT \"NO CARRIER\"\n");
1196 fprintf(f,"ABORT \"NO DIALTONE\"\n");
1197 fprintf(f,"ABORT \"BUSY\"\n");
1198 fprintf(f,"ABORT \"ERROR\"\n");
1199 fprintf(f,"ABORT \"NO ANSWER\"\n");
1200 fprintf(f,"ABORT \"Username/Password Incorrect\"\n");
1201 fprintf(f,"ABORT \"Authentication Failure\"\n");
1202 fprintf(f,"ABORT \"Bad password\"\n");
1203 fprintf(f,"ABORT \"Bad Password\"\n");
1204 fprintf(f,"REPORT CARRIER\n");
1205 fprintf(f,"REPORT CONNECT\n");
1206 fprintf(f,"\"\" \"at\"\n");
1207 fprintf(f,"OK \"%s\"\n",pref_entries[i].ModemInit1);
1208 fprintf(f,"OK \"%s\"\n",pref_entries[i].ModemInit2);
1209 fprintf(f,"OK \"ATD%c%s\"\n",
1210 (atoi(pref_entries[i].PulseDial)?'P':'T'),
1211 pref_entries[i].Phone);
1213 if (!pref_entries[i].nologin) {
1214 fprintf(f,"\"%s\" \"%s\"\n",
1215 pref_entries[i].UserString,
1216 pref_entries[i].Username);
1217 fprintf(f,"\"%s\" \"%s\"\n",
1218 pref_entries[i].PassString,
1219 pref_entries[i].Password);
1220 } else {
1221 if (!pref_entries[i].nExpectPairs)
1222 fprintf(f,"CONNECT \"\"\n");
1225 for(j=0;j<pref_entries[i].nExpectPairs;j++)
1226 fprintf(f,"\"%s\" \"%s\"\n",
1227 pref_entries[i].s_expect[j],
1228 pref_entries[i].s_send[j]);
1230 fclose(f);
1231 chmod(aux,0700);
1234 /* FILE 7 : user_yawmppp_isp# mode 600 */
1236 for(i=0;i<isp_count;i++) {
1237 sprintf(aux,"%s/%s_yawmppp_isp%d",tmp,getenv("USER"),i);
1238 f=fopen(aux,"w");
1239 if (!f) {
1240 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1241 MSGBOX_OK,
1242 MSGBOX_ICON_ERROR);
1243 return(-1);
1246 memcpy(&modippp,&pppo,sizeof(struct PREF_PPP_OPT));
1247 if (pref_entries[i].ppp.override) {
1248 modippp.defaultroute=pref_entries[i].ppp.defaultroute;
1249 modippp.passive=pref_entries[i].ppp.passive;
1250 modippp.noauth=pref_entries[i].ppp.noauth;
1251 modippp.noipdefault=pref_entries[i].ppp.noipdefault;
1252 modippp.chap=pref_entries[i].ppp.chap;
1253 modippp.pap=pref_entries[i].ppp.pap;
1256 fprintf(f,
1257 "%s\n%s\nuser \"%s\"\n%sconnect '%s -v -f"\
1258 " /etc/ppp/peers/%s_chat.%d'\n",
1259 pref_entries[i].Device,
1260 pref_entries[i].ModemSpeed,
1261 pref_entries[i].Username,
1262 mk_ppp_string(&modippp,"\n"),
1263 chat_path,
1264 getenv("USER"),
1266 fclose(f);
1267 chmod(aux,0600);
1270 /* FILE 8 : root_apply.sh mode 700 */
1271 sprintf(aux,"%s/root_apply.sh",tmp);
1272 f=fopen(aux,"w");
1273 if (!f) {
1274 message_box(GTK_WINDOW(applet),ERR_CANT_WRITE,"Error",
1275 MSGBOX_OK,
1276 MSGBOX_ICON_ERROR);
1277 return(-1);
1280 fprintf(f,"#!/bin/sh\n");
1281 fprintf(f,"\n# this script was generated by yawmppp.pref (the YAWMPPP\n");
1282 fprintf(f,"# GUI configuration app) and will copy some files from\n");
1283 fprintf(f,"# ~/.yawmppp2 to /etc/ppp/peers , because pppd will only\n");
1284 fprintf(f,"# acknowledge input files in that directory.\n");
1285 fprintf(f,"#\n\n");
1287 strcpy(v_user,getenv("USER"));
1288 strcpy(v_home,getenv("HOME"));
1290 fprintf(f,"# create /etc/ppp/peers if missing\n");
1291 fprintf(f,"if [ ! -d /etc/ppp/peers ]; then mkdir -m 0755 -p /etc/ppp/peers; fi\n\n");
1293 for(i=0;i<isp_count;i++) {
1295 fprintf(f,"# ISP entry %d\n",i);
1297 sprintf(yet,"%s_yawmppp_isp%d",v_user,i);
1298 fprintf(f,"chown root %s/.yawmppp2/%s\n",v_home,yet);
1299 fprintf(f,"cp -f %s/.yawmppp2/%s /etc/ppp/peers/%s\n",v_home,yet,yet);
1300 fprintf(f,"chown %s /etc/ppp/peers/%s\n",v_user,yet);
1301 fprintf(f,"chown %s %s/.yawmppp2/%s\n",v_user,v_home,yet);
1302 fprintf(f,"chmod 600 /etc/ppp/peers/%s\n\n",yet);
1304 sprintf(yet,"%s_chat.%d",v_user,i);
1305 fprintf(f,"chown root %s/.yawmppp2/%s\n",v_home,yet);
1306 fprintf(f,"cp -f %s/.yawmppp2/%s /etc/ppp/peers/%s\n",v_home,yet,yet);
1307 fprintf(f,"chown %s /etc/ppp/peers/%s\n",v_user,yet);
1308 fprintf(f,"chown %s %s/.yawmppp2/%s\n",v_user,v_home,yet);
1309 fprintf(f,"chmod 700 /etc/ppp/peers/%s\n\n",yet);
1313 fprintf(f,"\n# remove tag file (to tell graphical interface this script did its job)\n");
1314 fprintf(f,"rm -f %s/.yawmppp2/.root_didnt_run_it\n",v_home);
1316 fclose(f);
1317 chmod(aux,0700);
1319 /* FILE 9 : consist check */
1320 sprintf(aux,"%s/.root_didnt_run_it",tmp);
1321 f=fopen(aux,"w");
1322 if (f) {
1323 fprintf(f,"flag file\n");
1324 fclose(f);
1327 /* send signal to yawmppp dock applet (so it rereads the config) */
1328 sprintf(aux,"%s/yawmppp.pid",tmp);
1329 f=fopen(aux,"r");
1330 if (f) {
1331 fgets(aux,512,f);
1332 fclose(f);
1333 i=atoi(aux);
1334 if (i)
1335 kill(i,SIGUSR1);
1337 check_client();
1339 /* check if root stuff must be really done
1340 /bin/sh -c needed because some OSs still use the archaic C shell
1341 as the default shell. They even use the archaic BSD license. eek! */
1342 needroot=0;
1343 for(i=0;i<isp_count;i++) {
1344 sprintf(aux,"/bin/sh -c \"diff -q /etc/ppp/peers/%s_yawmppp_isp%d %s/%s_yawmppp_isp%d >/dev/null 2>/dev/null\"",
1345 v_user,i,tmp,v_user,i);
1346 if (system(aux)) {
1347 sprintf(aux,"/bin/sh -c \"cp -f %s/%s_yawmppp_isp%d /etc/ppp/peers/%s_yawmppp_isp%d >/dev/null 2>/dev/null\"",
1348 tmp,v_user,i,v_user,i);
1349 if (system(aux))
1350 needroot=1;
1352 if (needroot)
1353 break;
1354 sprintf(aux,"/bin/sh -c \"diff -q /etc/ppp/peers/%s_chat.%d %s/%s_chat.%d >/dev/null 2>/dev/null\"",
1355 v_user,i,tmp,v_user,i);
1356 if (system(aux)) {
1357 sprintf(aux,"/bin/sh -c \"cp -f %s/%s_chat.%d /etc/ppp/peers/%s_chat.%d >/dev/null 2>/dev/null\"",
1358 tmp,v_user,i,v_user,i);
1359 if (system(aux))
1360 needroot=1;
1362 if (needroot)
1363 break;
1366 if (needroot) {
1367 sprintf(aux,"%s/root_apply.sh",tmp);
1368 run_as_root(aux);
1369 sprintf(aux,"%s/.root_didnt_run_it",tmp);
1370 f=fopen(aux,"r");
1371 if (f!=NULL) {
1372 fclose(f);
1373 unlink(aux);
1375 } else {
1376 sprintf(aux,"%s/root_apply.sh",tmp);
1377 unlink(aux);
1378 sprintf(aux,"%s/.root_didnt_run_it",tmp);
1379 unlink(aux);
1381 return 0;
1384 void
1385 applet_apply (GtkWidget * widget, gpointer data)
1387 write_and_apply_data();
1390 void
1391 applet_save_and_quit (GtkWidget * widget, gpointer data)
1393 int i;
1394 i=write_and_apply_data();
1395 if (i<0)
1396 if (message_box(GTK_WINDOW(applet),ERR_DIDNT_WRITE,"Confirmation",
1397 MSGBOX_YESNO,
1398 MSGBOX_ICON_QUESTION)==MSGBOX_R_NO)
1399 return;
1400 gtk_widget_destroy(applet);
1403 void
1404 check_client(void)
1406 char *p;
1407 char temp[128];
1408 FILE *f;
1410 p=getenv("HOME");
1411 strcpy (temp, p);
1412 strcat (temp, "/.yawmppp2/.delayedupdate");
1414 usleep(100000L);
1416 f=fopen(temp,"r");
1417 if (!f) return;
1418 fclose(f);
1419 unlink(temp);
1421 message_box(GTK_WINDOW(applet),
1422 INFO_CANT_APPLY_NOW,
1423 "Apply request acknowledged",
1424 MSGBOX_OK,
1425 MSGBOX_ICON_INFO);
1429 file_exists(char *s)
1431 FILE *f;
1433 f=fopen(s,"r");
1434 if (!f)
1435 return 0;
1436 fclose(f);
1437 return 1;
1440 void
1441 find_out_paths(void)
1443 strcpy(chat_path,"/usr/sbin/chat");
1444 strcpy(pppd_path,"/usr/sbin/pppd");
1446 test_set_path(chat_path,"/bin/chat");
1447 test_set_path(chat_path,"/usr/bin/chat");
1448 test_set_path(chat_path,"/usr/local/bin/chat");
1449 test_set_path(chat_path,"/usr/local/sbin/chat");
1450 test_set_path(chat_path,"/sbin/chat");
1451 test_set_path(chat_path,"/usr/sbin/chat");
1453 test_set_path(pppd_path,"/bin/pppd");
1454 test_set_path(pppd_path,"/usr/bin/pppd");
1455 test_set_path(pppd_path,"/usr/local/bin/pppd");
1456 test_set_path(pppd_path,"/usr/local/sbin/pppd");
1457 test_set_path(pppd_path,"/sbin/pppd");
1458 test_set_path(pppd_path,"/usr/sbin/pppd");
1461 void
1462 test_set_path(char *dest,char *path)
1464 if (file_exists(path))
1465 strcpy(dest,path);
1468 /* PPP PANE */
1470 GtkWidget *
1471 make_ppp_pane(void)
1473 GtkWidget *bv,*h,*v[4];
1474 GtkTooltips *tt;
1475 int i;
1476 GtkWidget *wi[40],*ew[20];
1477 GSList *modem,*flow;
1479 bv=gtk_vbox_new(FALSE,0);
1481 tt=gtk_tooltips_new();
1483 ew[0]=gtk_label_new("These options are set to a safe default."\
1484 " Don't change them unless you know what you are\n"\
1485 "doing. All options are documented in pppd's man"\
1486 " page. Hit the Help button for details.");
1487 gtk_label_set_justify(GTK_LABEL(ew[0]),GTK_JUSTIFY_LEFT);
1489 ew[1]=gtk_hseparator_new();
1491 gtk_box_pack_start(GTK_BOX(bv),ew[0],FALSE,TRUE,1);
1492 gtk_box_pack_start(GTK_BOX(bv),ew[1],FALSE,TRUE,1);
1494 h=gtk_hbox_new(TRUE,2);
1495 gtk_box_pack_start(GTK_BOX(bv),h,TRUE,TRUE,1);
1497 v[0]=gtk_vbox_new(FALSE,1);
1498 v[1]=gtk_vbox_new(FALSE,1);
1499 v[2]=gtk_vbox_new(FALSE,1);
1500 v[3]=gtk_vbox_new(FALSE,1);
1501 gtk_box_pack_start(GTK_BOX(h),v[0],FALSE,TRUE,4);
1502 gtk_box_pack_start(GTK_BOX(h),v[1],FALSE,TRUE,4);
1503 gtk_box_pack_start(GTK_BOX(h),v[2],FALSE,TRUE,4);
1504 gtk_box_pack_start(GTK_BOX(h),v[3],FALSE,TRUE,4);
1506 wi[0]=gtk_check_button_new_with_label("defaultroute");
1507 wi[1]=gtk_check_button_new_with_label("lock");
1508 wi[2]=gtk_check_button_new_with_label("passive");
1509 wi[3]=gtk_check_button_new_with_label("debug");
1510 wi[4]=gtk_check_button_new_with_label("kdebug : general");
1511 wi[5]=gtk_check_button_new_with_label("kdebug : receive");
1512 wi[6]=gtk_check_button_new_with_label("kdebug : send");
1513 wi[7]=gtk_check_button_new_with_label("noauth");
1514 wi[8]=gtk_check_button_new_with_label("noipdefault");
1515 wi[30]=gtk_check_button_new_with_label("usepeerdns");
1517 gtk_tooltips_set_tip(tt,wi[0],
1518 "add a default route to the system routing tables",
1519 NULL);
1520 gtk_tooltips_set_tip(tt,wi[1],
1521 "create lock file for exclusive device access",
1522 NULL);
1523 gtk_tooltips_set_tip(tt,wi[2],
1524 "wait passively for LCP packet from peer",
1525 NULL);
1526 gtk_tooltips_set_tip(tt,wi[3],
1527 "logs the control packets sent and received "\
1528 "in human readable form",
1529 NULL);
1530 gtk_tooltips_set_tip(tt,wi[4],
1531 "kernel level debugging",
1532 NULL);
1533 gtk_tooltips_set_tip(tt,wi[5],
1534 "kernel level debugging",
1535 NULL);
1536 gtk_tooltips_set_tip(tt,wi[6],
1537 "kernel level debugging",
1538 NULL);
1539 gtk_tooltips_set_tip(tt,wi[7],
1540 "do not require peer to authenticate itself",
1541 NULL);
1542 gtk_tooltips_set_tip(tt,wi[8],
1543 "require IP address to be negotiated via IPCP",
1544 NULL);
1545 gtk_tooltips_set_tip(tt,wi[30],
1546 "ask DNS server info to peer, requires pppd 2.3.10 or newer, 2.3.11 recommended",
1547 NULL);
1549 /* --- */
1551 ew[2]=gtk_frame_new("Line control");
1552 gtk_frame_set_shadow_type(GTK_FRAME(ew[2]),GTK_SHADOW_ETCHED_IN);
1553 ew[3]=gtk_vbox_new(TRUE,1);
1555 gtk_container_add(GTK_CONTAINER(ew[2]),ew[3]);
1557 wi[9]=gtk_radio_button_new_with_label(NULL,"modem ");
1558 modem=gtk_radio_button_group(GTK_RADIO_BUTTON(wi[9]));
1559 wi[10]=gtk_radio_button_new_with_label(modem,"local ");
1560 gtk_box_pack_start(GTK_BOX(ew[3]),wi[9],FALSE,TRUE,1);
1561 gtk_box_pack_start(GTK_BOX(ew[3]),wi[10],FALSE,TRUE,1);
1563 gtk_tooltips_set_tip(tt,wi[9],
1564 "use modem control lines (CD/DTR)",
1565 NULL);
1566 gtk_tooltips_set_tip(tt,wi[10],
1567 "don't use modem control lines (ignores CD/DTR)",
1568 NULL);
1570 /* --- */
1572 ew[4]=gtk_frame_new("Flow control");
1573 gtk_frame_set_shadow_type(GTK_FRAME(ew[4]),GTK_SHADOW_ETCHED_IN);
1574 ew[5]=gtk_vbox_new(TRUE,1);
1575 gtk_container_add(GTK_CONTAINER(ew[4]),ew[5]);
1577 wi[11]=gtk_radio_button_new_with_label(NULL,"crtscts");
1578 flow=gtk_radio_button_group(GTK_RADIO_BUTTON(wi[11]));
1580 wi[12]=gtk_radio_button_new_with_label(flow,"xonxoff");
1581 flow=gtk_radio_button_group(GTK_RADIO_BUTTON(wi[12]));
1583 wi[13]=gtk_radio_button_new_with_label(flow,"nocrtscts");
1584 flow=gtk_radio_button_group(GTK_RADIO_BUTTON(wi[13]));
1586 wi[14]=gtk_radio_button_new_with_label(flow,"don't care");
1588 gtk_box_pack_start(GTK_BOX(ew[5]),wi[11],FALSE,TRUE,1);
1589 gtk_box_pack_start(GTK_BOX(ew[5]),wi[12],FALSE,TRUE,1);
1590 gtk_box_pack_start(GTK_BOX(ew[5]),wi[13],FALSE,TRUE,1);
1591 gtk_box_pack_start(GTK_BOX(ew[5]),wi[14],FALSE,TRUE,1);
1593 gtk_tooltips_set_tip(tt,wi[11],
1594 "use hardware flow control (RTS/CTS)",
1595 NULL);
1596 gtk_tooltips_set_tip(tt,wi[12],
1597 "use software flow control (XON/XOFF)",
1598 NULL);
1599 gtk_tooltips_set_tip(tt,wi[13],
1600 "disable hardware flow control (RTS/CTS)",
1601 NULL);
1603 /* -- */
1605 wi[15]=hlabel_new("MTU (minimum 128)");
1606 wi[16]=hlabel_new("MRU (minimum 128)");
1608 wi[17]=hlabel_new("lcp-echo-failure\n(0 disables)");
1609 wi[18]=hlabel_new("lcp-echo-interval\n(0 disables)");
1610 wi[19]=hlabel_new("lcp-max-configure");
1611 wi[20]=hlabel_new("lcp-max-terminate");
1612 wi[21]=hlabel_new("lcp-restart");
1614 wi[22]=gtk_entry_new_with_max_length(12);
1615 wi[23]=gtk_entry_new_with_max_length(12);
1617 wi[24]=gtk_entry_new_with_max_length(12);
1618 wi[25]=gtk_entry_new_with_max_length(12);
1619 wi[26]=gtk_entry_new_with_max_length(12);
1620 wi[27]=gtk_entry_new_with_max_length(12);
1621 wi[28]=gtk_entry_new_with_max_length(12);
1623 gtk_tooltips_set_tip(tt,wi[22],
1624 "Maximum Transfer Unit (bytes)",NULL);
1625 gtk_tooltips_set_tip(tt,wi[23],
1626 "Maximum Receive Unit (bytes)",NULL);
1628 for(i=15;i<17;i++) {
1629 gtk_box_pack_start(GTK_BOX(v[2]),wi[i],FALSE,TRUE,0);
1630 gtk_box_pack_start(GTK_BOX(v[2]),wi[i+7],FALSE,FALSE,0);
1633 for(i=17;i<22;i++) {
1634 gtk_box_pack_start(GTK_BOX(v[3]),wi[i],FALSE,TRUE,0);
1635 gtk_box_pack_start(GTK_BOX(v[3]),wi[i+7],FALSE,FALSE,0);
1638 /* - */
1640 wi[29]=gtk_button_new_with_label("Set defaults");
1641 gtk_box_pack_end(GTK_BOX(v[3]),wi[29],FALSE,TRUE,4);
1643 for(i=0;i<9;i++) {
1644 gtk_box_pack_start(GTK_BOX(v[0]),wi[i],FALSE,FALSE,1);
1645 gtk_widget_show(wi[i]);
1647 gtk_box_pack_start(GTK_BOX(v[0]),wi[30],FALSE,FALSE,1);
1648 gtk_widget_show(wi[30]);
1650 gtk_box_pack_start(GTK_BOX(v[1]),ew[2],FALSE,TRUE,4);
1651 gtk_box_pack_start(GTK_BOX(v[1]),ew[4],FALSE,TRUE,4);
1653 for(i=9;i<30;i++)
1654 gtk_widget_show(wi[i]);
1656 for(i=0;i<6;i++)
1657 gtk_widget_show(ew[i]);
1659 for(i=0;i<4;i++)
1660 gtk_widget_show(v[i]);
1662 gtk_widget_show(h);
1663 gtk_widget_show(bv);
1665 for(i=0;i<31;i++)
1666 ppp_pw[i]=wi[i];
1668 gtk_signal_connect(GTK_OBJECT(wi[29]),"clicked",
1669 GTK_SIGNAL_FUNC(make_ppp_default),NULL);
1671 return bv;
1674 void
1675 make_ppp_default(GtkWidget *w,gpointer data)
1677 pppo.defaultroute=1;
1678 pppo.lock=1;
1679 pppo.passive=0;
1680 pppo.debug=0;
1681 pppo.kdebug=0;
1682 pppo.noauth=1;
1683 pppo.noipdefault=1;
1684 pppo.flowctl=3;
1685 pppo.mtu=1500;
1686 pppo.mru=1500;
1687 pppo.lcp[0]=0;
1688 pppo.lcp[1]=0;
1689 pppo.lcp[2]=10;
1690 pppo.lcp[3]=10;
1691 pppo.lcp[4]=3;
1692 pppo.chap=AUTH_DONTCARE;
1693 pppo.pap=AUTH_DONTCARE;
1694 pppo.usepeerdns=1;
1695 if (w!=NULL)
1696 set_ppp_pane();
1699 void get_ppp_pane(void)
1701 int i;
1702 pppo.defaultroute=!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[0]));
1703 pppo.lock =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[1]));
1704 pppo.passive =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[2]));
1705 pppo.debug =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[3]));
1706 pppo.kdebug =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[4]))<<0;
1707 pppo.kdebug |=!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[5]))<<1;
1708 pppo.kdebug |=!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[6]))<<2;
1709 pppo.noauth =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[7]));
1710 pppo.noipdefault =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[8]));
1712 pppo.linectl =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[10]));
1713 pppo.usepeerdns =!!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[30]));
1715 for(i=11;i<15;i++)
1716 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ppp_pw[i])))
1717 pppo.flowctl=i-11;
1719 pppo.mtu=atoi(gtk_entry_get_text(GTK_ENTRY(ppp_pw[22])));
1720 pppo.mru=atoi(gtk_entry_get_text(GTK_ENTRY(ppp_pw[23])));
1722 for(i=0;i<5;i++)
1723 pppo.lcp[i]=atoi(gtk_entry_get_text(GTK_ENTRY(ppp_pw[24+i])));
1726 void set_ppp_pane(void)
1728 int i;
1729 char b[32];
1731 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[0]),pppo.defaultroute);
1732 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[1]),pppo.lock);
1733 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[2]),pppo.passive);
1734 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[3]),pppo.debug);
1735 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[4]),pppo.kdebug&0x01);
1736 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[5]),pppo.kdebug&0x02);
1737 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[6]),pppo.kdebug&0x04);
1738 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[7]),pppo.noauth);
1739 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[8]),pppo.noipdefault);
1740 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[30]),pppo.usepeerdns);
1742 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[9+pppo.linectl]),TRUE);
1743 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ppp_pw[11+pppo.flowctl]),TRUE);
1745 sprintf(b,"%d",pppo.mtu);
1746 gtk_entry_set_text(GTK_ENTRY(ppp_pw[22]),b);
1747 sprintf(b,"%d",pppo.mru);
1748 gtk_entry_set_text(GTK_ENTRY(ppp_pw[23]),b);
1750 for(i=0;i<5;i++) {
1751 sprintf(b,"%d",pppo.lcp[i]);
1752 gtk_entry_set_text(GTK_ENTRY(ppp_pw[24+i]),b);
1756 char *
1757 mk_ppp_string(struct PREF_PPP_OPT *modi,char *sep)
1759 static char here[512];
1760 char local[256];
1762 here[0]=0;
1763 if (modi->defaultroute) {
1764 strcat(here,"defaultroute");
1765 strcat(here,sep);
1767 if (modi->lock) {
1768 strcat(here,"lock");
1769 strcat(here,sep);
1771 if (modi->passive) {
1772 strcat(here,"passive");
1773 strcat(here,sep);
1775 if (modi->debug) {
1776 strcat(here,"debug");
1777 strcat(here,sep);
1779 if (modi->kdebug) {
1780 sprintf(local,"kdebug %d",modi->kdebug);
1781 strcat(here,local);
1782 strcat(here,sep);
1784 if (modi->noauth) {
1785 strcat(here,"noauth");
1786 strcat(here,sep);
1788 if (modi->noipdefault) {
1789 strcat(here,"noipdefault");
1790 strcat(here,sep);
1793 switch(modi->chap) {
1794 case AUTH_REQUIRE:
1795 strcat(here,"require-chap");
1796 strcat(here,sep);
1797 break;
1798 case AUTH_REFUSE:
1799 strcat(here,"refuse-chap");
1800 strcat(here,sep);
1801 break;
1804 switch(modi->pap) {
1805 case AUTH_REQUIRE:
1806 strcat(here,"require-pap");
1807 strcat(here,sep);
1808 break;
1809 case AUTH_REFUSE:
1810 strcat(here,"refuse-pap");
1811 strcat(here,sep);
1812 break;
1815 if (modi->linectl)
1816 strcat(here,"local");
1817 else
1818 strcat(here,"modem");
1819 strcat(here,sep);
1821 switch(modi->flowctl) {
1822 case 0: strcat(here,"crtscts"); break;
1823 case 1: strcat(here,"xonxoff"); break;
1824 case 2: strcat(here,"nocrtscts"); break;
1826 strcat(here,sep);
1828 sprintf(local,"mtu %d%smru %d%s",
1829 modi->mtu,sep,
1830 modi->mru,sep);
1832 strcat(here,local);
1834 if (modi->lcp[0]) {
1835 sprintf(local,"lcp-echo-failure %d",modi->lcp[0]);
1836 strcat(here,local);
1837 strcat(here,sep);
1839 if (modi->lcp[1]) {
1840 sprintf(local,"lcp-echo-interval %d",modi->lcp[1]);
1841 strcat(here,local);
1842 strcat(here,sep);
1844 sprintf(local,"lcp-max-configure %d",modi->lcp[2]);
1845 strcat(here,local);
1846 strcat(here,sep);
1847 sprintf(local,"lcp-max-terminate %d",modi->lcp[3]);
1848 strcat(here,local);
1849 strcat(here,sep);
1850 sprintf(local,"lcp-restart %d",modi->lcp[4]);
1851 strcat(here,local);
1852 strcat(here,sep);
1854 if (modi->usepeerdns) {
1855 strcat(here,"usepeerdns");
1856 strcat(here,sep);
1858 return(here);
1861 void
1862 read_ppp_options_from_rc(char *p)
1864 FILE *f;
1865 char b[512],*t;
1866 int i;
1868 make_ppp_default(NULL,NULL);
1870 f=fopen(p,"r");
1871 if (!f)
1872 return;
1874 while(fgets(b,511,f)) {
1875 if (strstr(b,"PPPOPTIONS")==&b[0]) {
1876 t=wrapped_strtok(b," \t\n");
1877 t=wrapped_strtok(NULL," \t\n"); pppo.defaultroute=atoi(t);
1878 t=wrapped_strtok(NULL," \t\n"); pppo.lock=atoi(t);
1879 t=wrapped_strtok(NULL," \t\n"); pppo.passive=atoi(t);
1880 t=wrapped_strtok(NULL," \t\n"); pppo.debug=atoi(t);
1881 t=wrapped_strtok(NULL," \t\n"); pppo.kdebug=atoi(t);
1882 t=wrapped_strtok(NULL," \t\n"); pppo.noauth=atoi(t);
1883 t=wrapped_strtok(NULL," \t\n"); pppo.noipdefault=atoi(t);
1884 t=wrapped_strtok(NULL," \t\n"); pppo.linectl=atoi(t);
1885 t=wrapped_strtok(NULL," \t\n"); pppo.flowctl=atoi(t);
1886 t=wrapped_strtok(NULL," \t\n"); pppo.mtu=atoi(t);
1887 t=wrapped_strtok(NULL," \t\n"); pppo.mru=atoi(t);
1888 for(i=0;i<5;i++) {
1889 t=wrapped_strtok(NULL," \t\n");
1890 pppo.lcp[i]=atoi(t);
1892 t=wrapped_strtok(NULL," \t\n"); pppo.usepeerdns=atoi(t);
1893 break;
1896 fclose(f);
1899 char *
1900 wrapped_strtok(char *a,char *b)
1902 char *pt;
1903 static int wasnull=0;
1904 static char zero[]="0";
1906 if ((a==NULL)&&(wasnull))
1907 return zero;
1908 if (a!=NULL)
1909 wasnull=0;
1911 pt=strtok(a,b);
1912 if (pt==NULL) {
1913 wasnull=1;
1914 return(zero);
1915 } else
1916 return pt;
1919 /* expect/send dialog */
1921 GtkWidget *exsdlg,*exp_cl,*exp_ctl[5];
1922 int exp_sel=-1;
1923 struct PREF_ISP_INFO exp_regret;
1925 void pop_expect(GtkWidget *w,gpointer data)
1927 GtkWidget *dlg,*v1,*hs,*bhb,*bt[4],*bb,*lb[5],*wl;
1928 GtkWidget *sw,*cl;
1929 GtkStyle *style;
1930 GdkBitmap *mask;
1931 GdkPixmap *tp;
1932 GtkWidget *px;
1933 char tmp[128];
1934 int i;
1936 memcpy(&exp_regret,&pref_entries[selected_entry],sizeof(struct PREF_ISP_INFO));
1938 exsdlg=dlg=gtk_window_new(GTK_WINDOW_DIALOG);
1939 gtk_window_set_transient_for(GTK_WINDOW(advdlg),GTK_WINDOW(advdlg));
1940 gtk_window_set_default_size(GTK_WINDOW(dlg),400,370);
1941 gtk_widget_realize(dlg);
1943 v1=gtk_vbox_new(FALSE,1);
1944 gtk_container_add(GTK_CONTAINER(dlg),v1);
1946 sprintf(tmp,"Conversation: %s",pref_entries[selected_entry].LongName);
1947 gtk_window_set_title(GTK_WINDOW(dlg),tmp);
1948 gtk_window_set_policy(GTK_WINDOW(dlg),TRUE,TRUE,TRUE);
1949 gtk_container_set_border_width(GTK_CONTAINER(dlg),4);
1951 wl=gtk_label_new("You only need to add something here if your connection has\n"\
1952 "has non-standard prompt/timing between the login and the\n"\
1953 "start of the PPP session. All expect/send pairs are placed\n"\
1954 "right after the user/password ones in the chat script.\n"\
1955 "If you checked the Don't generate login/password pairs\n"\
1956 "checkbox then the expect/send pairs defined here will be the\n"\
1957 "only ones in the chat script.");
1959 gtk_box_pack_start(GTK_BOX(v1),wl,FALSE,FALSE,1);
1961 /* list */
1962 sw=gtk_scrolled_window_new(NULL,NULL);
1963 gtk_box_pack_start(GTK_BOX(v1),sw,TRUE,TRUE,4);
1964 gtk_widget_show(sw);
1965 gtk_container_set_border_width(GTK_CONTAINER(sw),4);
1967 exp_cl=cl=gtk_clist_new(2);
1968 gtk_clist_set_shadow_type(GTK_CLIST(cl),GTK_SHADOW_IN);
1969 gtk_clist_set_selection_mode(GTK_CLIST(cl),GTK_SELECTION_SINGLE);
1970 gtk_clist_set_column_title(GTK_CLIST(cl),0,"Expect");
1971 gtk_clist_set_column_title(GTK_CLIST(cl),1,"Send");
1972 gtk_clist_column_titles_passive(GTK_CLIST(cl));
1973 gtk_clist_column_titles_show(GTK_CLIST(cl));
1974 gtk_clist_set_column_width(GTK_CLIST(cl),0,120);
1975 gtk_clist_set_column_width(GTK_CLIST(cl),1,120);
1976 gtk_clist_set_column_auto_resize(GTK_CLIST(cl),0,FALSE);
1977 gtk_clist_set_column_auto_resize(GTK_CLIST(cl),1,FALSE);
1978 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
1979 GTK_POLICY_AUTOMATIC,
1980 GTK_POLICY_ALWAYS);
1981 gtk_container_add(GTK_CONTAINER(sw),cl);
1982 gtk_widget_show(cl);
1983 /* list */
1985 bb=gtk_hbox_new(FALSE,0);
1986 gtk_box_pack_start(GTK_BOX(v1),bb,FALSE,TRUE,2);
1988 exp_ctl[0]=lb[0]=gtk_button_new_with_label(" Add pair ");
1989 exp_ctl[1]=lb[1]=gtk_button_new_with_label(" Add delay ");
1990 exp_ctl[2]=lb[2]=gtk_button_new_with_label(" Remove ");
1993 exp_ctl[3]=lb[3]=gtk_button_new();
1994 exp_ctl[4]=lb[4]=gtk_button_new();
1996 style=gtk_widget_get_style(dlg);
1998 tp=gdk_pixmap_create_from_xpm_d (dlg->window, &mask,
1999 &style->bg[GTK_STATE_NORMAL],
2000 (gchar **) cmd_up_xpm);
2001 px=gtk_pixmap_new(tp,mask); gtk_widget_show(px); gdk_pixmap_unref(tp);
2002 gtk_container_add(GTK_CONTAINER(lb[3]),px);
2004 tp=gdk_pixmap_create_from_xpm_d (dlg->window, &mask,
2005 &style->bg[GTK_STATE_NORMAL],
2006 (gchar **) cmd_down_xpm);
2007 px=gtk_pixmap_new(tp,mask); gtk_widget_show(px); gdk_pixmap_unref(tp);
2008 gtk_container_add(GTK_CONTAINER(lb[4]),px);
2010 for(i=0;i<5;i++) {
2011 gtk_box_pack_start(GTK_BOX(bb),lb[i],FALSE,TRUE,2);
2012 gtk_widget_show(lb[i]);
2015 hs=gtk_hseparator_new();
2016 gtk_box_pack_start(GTK_BOX(v1),hs,FALSE,FALSE,4);
2018 bhb=gtk_hbox_new(TRUE,4);
2020 gtk_box_pack_start(GTK_BOX(v1),bhb,FALSE,FALSE,4);
2022 bt[0]=gtk_button_new_with_label(" Help ");
2023 bt[1]=gtk_label_new(" ");
2024 bt[2]=gtk_button_new_with_label(" OK ");
2025 bt[3]=gtk_button_new_with_label(" Cancel ");
2027 for(i=0;i<4;i++) {
2028 gtk_box_pack_start(GTK_BOX(bhb),bt[i],FALSE,TRUE,4);
2029 gtk_widget_show(bt[i]);
2032 gtk_widget_show(bb);
2033 gtk_widget_show(bhb);
2034 gtk_widget_show(hs);
2035 gtk_widget_show(wl);
2036 gtk_widget_show(v1);
2037 gtk_widget_show(dlg);
2039 exp_update();
2041 gtk_signal_connect (GTK_OBJECT (bt[0]), "clicked",
2042 GTK_SIGNAL_FUNC (pop_help), NULL);
2043 gtk_signal_connect (GTK_OBJECT (bt[2]), "clicked",
2044 GTK_SIGNAL_FUNC (exp_ok), NULL);
2045 gtk_signal_connect (GTK_OBJECT (bt[3]), "clicked",
2046 GTK_SIGNAL_FUNC (exp_cancel), NULL);
2047 gtk_signal_connect (GTK_OBJECT (dlg), "destroy",
2048 GTK_SIGNAL_FUNC (exp_destroy), NULL);
2050 gtk_signal_connect (GTK_OBJECT (lb[0]), "clicked",
2051 GTK_SIGNAL_FUNC (exp_add), NULL);
2052 gtk_signal_connect (GTK_OBJECT (lb[1]), "clicked",
2053 GTK_SIGNAL_FUNC (exp_add_delay), NULL);
2054 gtk_signal_connect (GTK_OBJECT (lb[2]), "clicked",
2055 GTK_SIGNAL_FUNC (exp_remove), NULL);
2057 gtk_signal_connect (GTK_OBJECT (lb[3]), "clicked",
2058 GTK_SIGNAL_FUNC (exp_up), NULL);
2059 gtk_signal_connect (GTK_OBJECT (lb[4]), "clicked",
2060 GTK_SIGNAL_FUNC (exp_down), NULL);
2062 gtk_signal_connect (GTK_OBJECT (cl), "select_row",
2063 GTK_SIGNAL_FUNC (exp_select), NULL);
2064 gtk_signal_connect (GTK_OBJECT (cl), "unselect_row",
2065 GTK_SIGNAL_FUNC (exp_unselect), NULL);
2068 gtk_grab_add(dlg);
2071 void
2072 exp_update(void)
2074 int i;
2075 struct PREF_ISP_INFO *pii;
2076 char *pp[2];
2078 pii=&pref_entries[selected_entry];
2080 gtk_clist_freeze(GTK_CLIST(exp_cl));
2081 gtk_clist_clear(GTK_CLIST(exp_cl));
2082 for(i=0;i<pii->nExpectPairs;i++) {
2083 pp[0]=pii->s_expect[i];
2084 pp[1]=pii->s_send[i];
2085 if (!strlen(pp[0])) {
2086 pp[0]="<delay>";
2087 pp[1]="<delay>";
2089 gtk_clist_append(GTK_CLIST(exp_cl),pp);
2091 gtk_clist_thaw(GTK_CLIST(exp_cl));
2092 exp_sel=-1;
2093 exp_disable();
2096 void
2097 exp_ok (GtkWidget * widget, gpointer data)
2099 gtk_widget_destroy(exsdlg);
2102 void
2103 exp_cancel (GtkWidget * widget, gpointer data)
2105 memcpy(&pref_entries[selected_entry],&exp_regret,sizeof(struct PREF_ISP_INFO));
2106 gtk_widget_destroy(exsdlg);
2109 void
2110 exp_destroy (GtkWidget * widget, gpointer data)
2112 gtk_grab_remove(widget);
2113 exsdlg=NULL;
2116 void
2117 exp_up(GtkWidget *widget,gpointer data)
2119 char aux[2][32];
2120 struct PREF_ISP_INFO *pii;
2121 int nsel;
2123 pii=&pref_entries[selected_entry];
2125 strcpy(aux[0],pii->s_expect[exp_sel]);
2126 strcpy(aux[1],pii->s_send[exp_sel]);
2128 strcpy(pii->s_expect[exp_sel],pii->s_expect[exp_sel-1]);
2129 strcpy(pii->s_send[exp_sel],pii->s_send[exp_sel-1]);
2130 strcpy(pii->s_expect[exp_sel-1],aux[0]);
2131 strcpy(pii->s_send[exp_sel-1],aux[1]);
2132 nsel=--exp_sel;
2133 exp_update();
2134 gtk_clist_select_row(GTK_CLIST(exp_cl),nsel,0);
2137 void
2138 exp_down(GtkWidget *widget,gpointer data)
2140 char aux[2][32];
2141 struct PREF_ISP_INFO *pii;
2142 int nsel;
2143 pii=&pref_entries[selected_entry];
2145 strcpy(aux[0],pii->s_expect[exp_sel]);
2146 strcpy(aux[1],pii->s_send[exp_sel]);
2148 strcpy(pii->s_expect[exp_sel],pii->s_expect[exp_sel+1]);
2149 strcpy(pii->s_send[exp_sel],pii->s_send[exp_sel+1]);
2150 strcpy(pii->s_expect[exp_sel+1],aux[0]);
2151 strcpy(pii->s_send[exp_sel+1],aux[1]);
2152 nsel=++exp_sel;
2153 exp_update();
2154 gtk_clist_select_row(GTK_CLIST(exp_cl),nsel,0);
2157 void
2158 exp_disable(void)
2160 gtk_widget_set_sensitive(exp_ctl[2],FALSE);
2161 gtk_widget_set_sensitive(exp_ctl[3],FALSE);
2162 gtk_widget_set_sensitive(exp_ctl[4],FALSE);
2165 void
2166 exp_enable(void)
2168 int n;
2169 n=pref_entries[selected_entry].nExpectPairs;
2170 n--;
2171 gtk_widget_set_sensitive(exp_ctl[2],TRUE);
2172 gtk_widget_set_sensitive(exp_ctl[3],!!(exp_sel>0));
2173 gtk_widget_set_sensitive(exp_ctl[4],!(exp_sel==n));
2176 void
2177 exp_select(GtkCList *cl,gint row,gint column,
2178 GdkEventButton *geb,gpointer data)
2180 exp_sel=row;
2181 exp_enable();
2184 void
2185 exp_unselect(GtkCList *cl,gint row,gint column,
2186 GdkEventButton *geb,gpointer data)
2188 exp_sel=-1;
2189 exp_disable();
2192 void
2193 exp_add_delay(void)
2195 struct PREF_ISP_INFO *pii;
2196 pii=&pref_entries[selected_entry];
2197 pii->s_expect[pii->nExpectPairs][0]=0;
2198 pii->s_send[pii->nExpectPairs][0]=0;
2199 pii->nExpectPairs++;
2200 exp_update();
2203 void
2204 exp_remove(void)
2206 struct PREF_ISP_INFO *pii;
2207 int i;
2208 pii=&pref_entries[selected_entry];
2209 pii->nExpectPairs--;
2210 for(i=exp_sel;i<pii->nExpectPairs;i++) {
2211 strcpy(pii->s_send[i],pii->s_send[i+1]);
2212 strcpy(pii->s_expect[i],pii->s_expect[i+1]);
2214 exp_sel=-1;
2215 exp_update();
2218 GtkWidget *expa,*expa_e[2];
2220 void
2221 exp_add(void)
2223 GtkWidget *v1,*ea[15];
2224 int i;
2226 expa=gtk_window_new(GTK_WINDOW_DIALOG);
2227 gtk_window_set_title(GTK_WINDOW(expa),"Add expect/send pair");
2228 gtk_window_set_transient_for(GTK_WINDOW(expa),GTK_WINDOW(exsdlg));
2229 gtk_window_set_default_size(GTK_WINDOW(expa),220,110);
2230 gtk_widget_realize(expa);
2232 v1=gtk_vbox_new(FALSE,0);
2233 gtk_container_add(GTK_CONTAINER(expa),v1);
2234 ea[0]=gtk_hbox_new(FALSE,0);
2235 ea[1]=gtk_label_new("Expect:");
2236 expa_e[0]=ea[2]=gtk_entry_new();
2238 ea[3]=gtk_hbox_new(FALSE,0);
2239 ea[4]=gtk_label_new("Send:");
2240 expa_e[1]=ea[5]=gtk_entry_new();
2242 gtk_box_pack_start(GTK_BOX(v1),ea[0],FALSE,TRUE,1);
2243 gtk_box_pack_start(GTK_BOX(ea[0]),ea[1],FALSE,FALSE,0);
2244 gtk_box_pack_start(GTK_BOX(v1),ea[2],FALSE,TRUE,1);
2246 gtk_box_pack_start(GTK_BOX(v1),ea[3],FALSE,TRUE,1);
2247 gtk_box_pack_start(GTK_BOX(ea[3]),ea[4],FALSE,FALSE,0);
2248 gtk_box_pack_start(GTK_BOX(v1),ea[5],FALSE,TRUE,1);
2250 ea[6]=gtk_hseparator_new();
2251 ea[7]=gtk_hbox_new(TRUE,4);
2253 ea[8]=gtk_label_new(" ");
2254 ea[9]=gtk_label_new(" ");
2255 ea[10]=gtk_button_new_with_label(" OK ");
2256 ea[11]=gtk_button_new_with_label(" Cancel ");
2258 gtk_box_pack_start(GTK_BOX(v1),ea[6],FALSE,TRUE,2);
2259 gtk_box_pack_start(GTK_BOX(v1),ea[7],FALSE,TRUE,1);
2261 for(i=0;i<4;i++)
2262 gtk_box_pack_start(GTK_BOX(ea[7]),ea[8+i],FALSE,TRUE,4);
2264 for(i=0;i<12;i++)
2265 gtk_widget_show(ea[i]);
2266 gtk_widget_show(v1);
2267 gtk_widget_show(expa);
2269 gtk_widget_grab_focus(ea[2]);
2270 gtk_grab_add(expa);
2272 gtk_signal_connect(GTK_OBJECT(ea[10]),"clicked",
2273 GTK_SIGNAL_FUNC(expa_ok),NULL);
2274 gtk_signal_connect(GTK_OBJECT(ea[11]),"clicked",
2275 GTK_SIGNAL_FUNC(expa_cancel),NULL);
2276 gtk_signal_connect(GTK_OBJECT(expa),"destroy",
2277 GTK_SIGNAL_FUNC(expa_destroy),NULL);
2280 void
2281 expa_ok (GtkWidget * widget, gpointer data)
2283 struct PREF_ISP_INFO *pii;
2284 pii=&pref_entries[selected_entry];
2285 strncpy(pii->s_expect[pii->nExpectPairs],gtk_entry_get_text(GTK_ENTRY(expa_e[0])),31);
2286 strncpy(pii->s_send[pii->nExpectPairs],gtk_entry_get_text(GTK_ENTRY(expa_e[1])),31);
2287 pii->nExpectPairs++;
2288 gtk_widget_destroy(expa);
2289 exp_update();
2292 void
2293 expa_cancel (GtkWidget * widget, gpointer data)
2295 gtk_widget_destroy(expa);
2298 void
2299 expa_destroy (GtkWidget * widget, gpointer data)
2301 gtk_grab_remove(widget);
2302 expa=NULL;
2305 void
2306 extract_delimited_string(char *dest,char *src,int count,char delim,int max)
2308 char *p,*it;
2309 int cur,on;
2310 char last;
2312 dest[0]=0;
2314 p=dest;
2315 it=src;
2316 last=0;
2317 on=0;
2319 for(cur=0;it[0]!=0;it++) {
2320 if ((it[0]==delim)&&(last!='\\')) {
2321 if (!on)
2322 cur++;
2323 on=!on;
2324 last=it[0];
2325 continue;
2328 if ((on)&&(cur==count)) {
2329 p[0]=it[0];
2330 p[1]=0;
2331 p++;
2332 if (strlen(dest)>=max)
2333 return;
2336 last=it[0];
2340 GtkWidget *helpwnd=NULL;
2342 void
2343 pop_help (GtkWidget * widget, gpointer data)
2345 GtkWidget *cw[40];
2346 int i;
2348 if (helpwnd!=NULL) {
2349 gdk_window_raise(helpwnd->window);
2350 return;
2353 helpwnd=gtk_window_new(GTK_WINDOW_TOPLEVEL);
2354 gtk_window_set_title(GTK_WINDOW(helpwnd),"YAWMPPP Help");
2356 if (gdk_screen_width()>800)
2357 gtk_window_set_default_size(GTK_WINDOW(helpwnd),800,420);
2358 else
2359 gtk_window_set_default_size(GTK_WINDOW(helpwnd),630,420);
2361 gtk_window_set_position(GTK_WINDOW(helpwnd),GTK_WIN_POS_CENTER);
2362 gtk_widget_realize(helpwnd);
2364 cw[0]=gtk_vbox_new(FALSE,1);
2365 gtk_container_add(GTK_CONTAINER(helpwnd),cw[0]);
2366 gtk_container_set_border_width(GTK_CONTAINER(helpwnd),4);
2368 cw[1]=gtk_notebook_new();
2370 /* the help pages */
2372 cw[2]=gtk_label_new("man yawmppp");
2373 cw[3]=gtk_hbox_new(FALSE,1);
2374 cw[4]=gtk_text_new(NULL,NULL);
2375 cw[7]=gtk_vscrollbar_new(GTK_TEXT(cw[4])->vadj);
2376 gtk_box_pack_start(GTK_BOX(cw[3]),cw[4],TRUE,TRUE,1);
2377 gtk_box_pack_start(GTK_BOX(cw[3]),cw[7],FALSE,TRUE,1);
2378 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[3],cw[2]);
2380 cw[8]=gtk_label_new("man pppd");
2381 cw[9]=gtk_hbox_new(FALSE,1);
2382 cw[10]=gtk_text_new(NULL,NULL);
2383 cw[11]=gtk_vscrollbar_new(GTK_TEXT(cw[10])->vadj);
2384 gtk_box_pack_start(GTK_BOX(cw[9]),cw[10],TRUE,TRUE,1);
2385 gtk_box_pack_start(GTK_BOX(cw[9]),cw[11],FALSE,TRUE,1);
2386 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[9],cw[8]);
2388 cw[12]=gtk_label_new("man chat");
2389 cw[13]=gtk_hbox_new(FALSE,1);
2390 cw[14]=gtk_text_new(NULL,NULL);
2391 cw[15]=gtk_vscrollbar_new(GTK_TEXT(cw[14])->vadj);
2392 gtk_box_pack_start(GTK_BOX(cw[13]),cw[14],TRUE,TRUE,1);
2393 gtk_box_pack_start(GTK_BOX(cw[13]),cw[15],FALSE,TRUE,1);
2394 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[13],cw[12]);
2396 cw[16]=gtk_label_new("README");
2397 cw[17]=gtk_hbox_new(FALSE,1);
2398 cw[18]=gtk_text_new(NULL,NULL);
2399 cw[19]=gtk_vscrollbar_new(GTK_TEXT(cw[18])->vadj);
2400 gtk_box_pack_start(GTK_BOX(cw[17]),cw[18],TRUE,TRUE,1);
2401 gtk_box_pack_start(GTK_BOX(cw[17]),cw[19],FALSE,TRUE,1);
2402 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[17],cw[16]);
2404 cw[20]=gtk_label_new("FAQ");
2405 cw[21]=gtk_hbox_new(FALSE,1);
2406 cw[22]=gtk_text_new(NULL,NULL);
2407 cw[23]=gtk_vscrollbar_new(GTK_TEXT(cw[22])->vadj);
2408 gtk_box_pack_start(GTK_BOX(cw[21]),cw[22],TRUE,TRUE,1);
2409 gtk_box_pack_start(GTK_BOX(cw[21]),cw[23],FALSE,TRUE,1);
2410 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[21],cw[20]);
2412 cw[24]=gtk_label_new("License");
2413 cw[25]=gtk_hbox_new(FALSE,1);
2414 cw[26]=gtk_text_new(NULL,NULL);
2415 cw[27]=gtk_vscrollbar_new(GTK_TEXT(cw[26])->vadj);
2416 gtk_box_pack_start(GTK_BOX(cw[25]),cw[26],TRUE,TRUE,1);
2417 gtk_box_pack_start(GTK_BOX(cw[25]),cw[27],FALSE,TRUE,1);
2418 gtk_notebook_append_page(GTK_NOTEBOOK(cw[1]),cw[25],cw[24]);
2421 gtk_box_pack_start(GTK_BOX(cw[0]),cw[1],TRUE,TRUE,4);
2422 cw[5]=gtk_hbox_new(FALSE,4);
2423 cw[6]=gtk_button_new_with_label(" Dismiss ");
2425 gtk_box_pack_start(GTK_BOX(cw[0]),cw[5],FALSE,TRUE,2);
2426 gtk_box_pack_end(GTK_BOX(cw[5]),cw[6],FALSE,FALSE,4);
2428 for(i=0;i<28;i++)
2429 gtk_widget_show(cw[i]);
2430 gtk_widget_show(helpwnd);
2431 gtk_grab_add(helpwnd);
2433 gtk_signal_connect(GTK_OBJECT(helpwnd),"destroy",
2434 GTK_SIGNAL_FUNC(help_dead),NULL);
2435 gtk_signal_connect(GTK_OBJECT(cw[6]),"clicked",
2436 GTK_SIGNAL_FUNC(help_die),NULL);
2438 gtk_window_set_title(GTK_WINDOW(helpwnd),
2439 "YAWMPPP Help (retrieving man yawmppp...)");
2440 add_man("yawmppp",cw[4],0);
2441 gtk_window_set_title(GTK_WINDOW(helpwnd),
2442 "YAWMPPP Help (retrieving man pppd...)");
2443 add_man("pppd",cw[10],1);
2444 gtk_window_set_title(GTK_WINDOW(helpwnd),
2445 "YAWMPPP Help (retrieving man chat...)");
2446 add_man("chat",cw[14],2);
2447 gtk_window_set_title(GTK_WINDOW(helpwnd),
2448 "YAWMPPP Help (retrieving README...)");
2449 add_docfile("README",cw[18],3);
2450 gtk_window_set_title(GTK_WINDOW(helpwnd),
2451 "YAWMPPP Help (retrieving FAQ...)");
2452 add_docfile("FAQ",cw[22],4);
2453 gtk_window_set_title(GTK_WINDOW(helpwnd),
2454 "YAWMPPP Help (retrieving GPL...)");
2455 add_docfile("COPYING",cw[26],5);
2456 gtk_window_set_title(GTK_WINDOW(helpwnd),
2457 "YAWMPPP Help");
2460 void
2461 help_die (GtkWidget * widget, gpointer data)
2463 gtk_grab_remove(helpwnd);
2464 gtk_widget_destroy(helpwnd);
2467 void
2468 help_dead (GtkWidget * widget, gpointer data)
2470 helpwnd=NULL;
2473 #define YAWMPPP_CANT_MAN "help system: unable to retrieve document"
2475 void
2476 add_man(char *manpage,GtkWidget *text,int index)
2478 char *buf;
2479 char line[512];
2480 FILE *man;
2481 long blen,tlen;
2483 if (man_flag[index]) {
2484 gtk_text_freeze(GTK_TEXT(text));
2485 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,man_help[index],
2486 strlen(man_help[index]));
2487 gtk_text_thaw(GTK_TEXT(text));
2488 while(gtk_events_pending())
2489 gtk_main_iteration();
2490 return;
2493 sprintf(line,"man %s",manpage);
2494 man=popen(line,"r");
2496 while(gtk_events_pending()) /* let man,troff,etc. work a little */
2497 gtk_main_iteration();
2499 gtk_text_freeze(GTK_TEXT(text));
2500 if (man) {
2501 buf=(char *)g_malloc(blen=(128<<10));
2502 buf[0]=0; tlen=0;
2503 while(fgets(line,511,man)) {
2504 unman(line);
2505 strcat(buf,line);
2506 tlen+=strlen(line);
2507 if (tlen>(blen-(4<<10)))
2508 buf=(char *)g_realloc(buf,blen+=(10<<10));
2510 pclose(man);
2511 buf=g_realloc(buf,strlen(buf)+4);
2512 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,buf,strlen(buf));
2513 man_help[index]=buf;
2514 man_flag[index]=1;
2515 } else {
2516 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,YAWMPPP_CANT_MAN,
2517 strlen(YAWMPPP_CANT_MAN));
2519 gtk_text_thaw(GTK_TEXT(text));
2520 while(gtk_events_pending())
2521 gtk_main_iteration();
2524 void
2525 add_docfile(char *source,GtkWidget *text,int index)
2527 FILE *f;
2528 char *buf;
2529 char line[512];
2530 long tlen,blen;
2532 if (man_flag[index]) {
2533 gtk_text_freeze(GTK_TEXT(text));
2534 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,man_help[index],
2535 strlen(man_help[index]));
2536 gtk_text_thaw(GTK_TEXT(text));
2537 while(gtk_events_pending())
2538 gtk_main_iteration();
2539 return;
2542 sprintf(line,"%s/doc/yawmppp-%s/%s",IPREFIX,VERSION,source);
2543 f=fopen(line,"r");
2545 gtk_text_freeze(GTK_TEXT(text));
2546 if (f) {
2547 buf=(char *)g_malloc(blen=(128<<10));
2548 buf[0]=0; tlen=0;
2549 while(fgets(line,511,f)) {
2550 strcat(buf,line);
2551 tlen+=strlen(line);
2552 if (tlen>(blen-(4<<10)))
2553 buf=(char *)g_realloc(buf,blen+=(10<<10));
2555 fclose(f);
2556 buf=g_realloc(buf,strlen(buf)+4);
2557 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,buf,strlen(buf));
2558 man_help[index]=buf;
2559 man_flag[index]=1;
2560 } else {
2561 gtk_text_insert(GTK_TEXT(text),fixedfont,NULL,NULL,YAWMPPP_CANT_MAN,
2562 strlen(YAWMPPP_CANT_MAN));
2564 gtk_text_thaw(GTK_TEXT(text));
2565 while(gtk_events_pending())
2566 gtk_main_iteration();
2569 void
2570 unman(char *s)
2572 int i,fs;
2573 fs=strlen(s);
2574 for(i=0;i<fs;i++)
2575 if (s[i]==8) {
2576 memmove(s+i-1,s+i+1,fs-i);
2577 fs-=2;
2581 GtkWidget *wpwd,*pwdb[3];
2582 int pwd_over;
2583 char cmdtorun[512];
2585 void
2586 run_as_root(char *what)
2588 GtkWidget *mv,*lb,*hs,*hb,*b[3],*ehb,*pix;
2589 char z[1024];
2590 GdkPixmap *padlock;
2591 GdkBitmap *mask;
2592 GtkStyle *style;
2594 strcpy(cmdtorun,what);
2596 wpwd=gtk_window_new(GTK_WINDOW_DIALOG);
2597 gtk_window_set_transient_for(GTK_WINDOW(wpwd),GTK_WINDOW(applet));
2598 gtk_window_set_title(GTK_WINDOW(wpwd),"Apply Changes");
2599 gtk_window_set_policy(GTK_WINDOW(wpwd),TRUE,TRUE,TRUE);
2600 gtk_container_set_border_width(GTK_CONTAINER(wpwd),4);
2601 gtk_widget_realize(wpwd);
2602 style=gtk_widget_get_style(wpwd);
2603 padlock = gdk_pixmap_create_from_xpm_d (wpwd->window, &mask,
2604 &style->bg[GTK_STATE_NORMAL],
2605 (gchar **) padlock_xpm);
2607 /* main vbox */
2608 mv=gtk_vbox_new(FALSE,2);
2609 gtk_container_add(GTK_CONTAINER(wpwd),mv);
2611 sprintf(z,"To commit the changes made to the configuration\n"\
2612 "YAWMPPP must run some actions with superuser\n"\
2613 "privileges to write down PPP configuration to the\n"\
2614 "/etc/ppp/peers directory. The script that will be\n"\
2615 "run is %s.\n"\
2616 "If you click 'Proceed' an xterm window will pop up\n"\
2617 "asking the root password to run the script.\n"\
2618 "You can 'Skip' and run the script on your own,\n"\
2619 "but the configuration changes will only take effect\n"\
2620 "after the script is properly run as root.\n"\
2621 "You can examine the script that will be run clicking the\n"\
2622 "'View Script' button.",what);
2624 ehb=gtk_hbox_new(FALSE,8);
2625 gtk_box_pack_start(GTK_BOX(mv),ehb,FALSE,TRUE,4);
2627 pix=gtk_pixmap_new(padlock,mask);
2628 gtk_box_pack_start(GTK_BOX(ehb),pix,FALSE,TRUE,4);
2630 lb=gtk_label_new(z);
2631 gtk_label_set_justify(GTK_LABEL(lb),GTK_JUSTIFY_LEFT);
2633 gtk_box_pack_start(GTK_BOX(ehb),lb,FALSE,TRUE,4);
2635 hs=gtk_hseparator_new();
2636 gtk_box_pack_start(GTK_BOX(mv),hs,FALSE,TRUE,4);
2638 hb=gtk_hbox_new(TRUE,8);
2639 gtk_box_pack_start(GTK_BOX(mv),hb,FALSE,TRUE,4);
2641 b[0]=gtk_button_new_with_label("Proceed");
2642 b[1]=gtk_button_new_with_label("Skip");
2643 b[2]=gtk_button_new_with_label("View Script");
2645 gtk_box_pack_start(GTK_BOX(hb),b[0],FALSE,TRUE,2);
2646 gtk_box_pack_start(GTK_BOX(hb),b[1],FALSE,TRUE,2);
2647 gtk_box_pack_start(GTK_BOX(hb),b[2],FALSE,TRUE,2);
2649 gtk_widget_show(mv);
2650 gtk_widget_show(hs);
2651 gtk_widget_show(lb);
2652 gtk_widget_show(pix);
2653 gtk_widget_show(ehb);
2654 gtk_widget_show(hb);
2655 gtk_widget_show(b[0]);
2656 gtk_widget_show(b[1]);
2657 gtk_widget_show(b[2]);
2658 gtk_widget_show(wpwd);
2660 gtk_grab_add(wpwd);
2662 gtk_signal_connect (GTK_OBJECT (wpwd), "delete_event",
2663 GTK_SIGNAL_FUNC (pwd_kill), NULL);
2665 gtk_signal_connect (GTK_OBJECT (b[0]), "clicked",
2666 GTK_SIGNAL_FUNC (pwd_ok), NULL);
2667 gtk_signal_connect (GTK_OBJECT (b[1]), "clicked",
2668 GTK_SIGNAL_FUNC (pwd_cancel), NULL);
2669 gtk_signal_connect (GTK_OBJECT (b[2]), "clicked",
2670 GTK_SIGNAL_FUNC (pwd_view), NULL);
2672 pwdb[0]=b[0];
2673 pwdb[1]=b[1];
2674 pwdb[2]=b[2];
2676 pwd_over=0;
2677 while(!pwd_over)
2678 if (gtk_events_pending())
2679 gtk_main_iteration();
2682 gint
2683 pwd_kill (GtkWidget * widget, GdkEvent * event, gpointer data)
2685 return TRUE;
2688 void
2689 pwd_cancel(GtkWidget *gw,gpointer data)
2691 gtk_grab_remove(wpwd);
2692 gtk_widget_destroy(wpwd);
2693 wpwd=0;
2694 pwd_over=1;
2697 void
2698 pwd_ok(GtkWidget *gw,gpointer data)
2700 gtk_widget_set_sensitive(pwdb[0],0);
2701 gtk_widget_set_sensitive(pwdb[1],0);
2702 gtk_widget_set_sensitive(pwdb[2],0);
2704 if (try_run_script(cmdtorun)) {
2705 gtk_grab_remove(wpwd);
2706 gtk_widget_destroy(wpwd);
2707 wpwd=0;
2708 pwd_over=1;
2709 } else {
2710 message_box(GTK_WINDOW(wpwd),
2711 ERR_CANT_SU,"Error",
2712 MSGBOX_OK,MSGBOX_ICON_EXCLAMATION);
2713 gtk_widget_set_sensitive(pwdb[0],TRUE);
2714 gtk_widget_set_sensitive(pwdb[1],TRUE);
2715 gtk_widget_set_sensitive(pwdb[2],TRUE);
2719 GtkWidget *swnd;
2721 void
2722 pwd_view(GtkWidget *gw,gpointer data)
2724 char z[512],x[256];
2725 FILE *f;
2726 GtkWidget *v,*txt,*hs,*hb,*b_close,*hh,*vsb;
2727 GdkFont *fixed;
2729 fixed=gdk_font_load("-*-fixed-medium-r-normal--14-*-*-*-*-*-*");
2731 sprintf(z,"View Script: %s",cmdtorun);
2733 swnd=gtk_window_new(GTK_WINDOW_DIALOG);
2734 gtk_window_set_default_size(GTK_WINDOW(swnd),600,500);
2735 gtk_window_set_transient_for(GTK_WINDOW(swnd),GTK_WINDOW(wpwd));
2736 gtk_window_set_title(GTK_WINDOW(swnd),z);
2737 gtk_window_set_policy(GTK_WINDOW(swnd),TRUE,TRUE,TRUE);
2738 gtk_container_set_border_width(GTK_CONTAINER(swnd),4);
2740 v=gtk_vbox_new(FALSE,2);
2741 gtk_container_add(GTK_CONTAINER(swnd),v);
2743 hh=gtk_hbox_new(FALSE,0);
2744 txt=gtk_text_new(NULL,NULL);
2745 vsb=gtk_vscrollbar_new(GTK_TEXT(txt)->vadj);
2747 gtk_box_pack_start(GTK_BOX(hh),txt,TRUE,TRUE,0);
2748 gtk_box_pack_start(GTK_BOX(hh),vsb,FALSE,TRUE,0);
2749 gtk_box_pack_start(GTK_BOX(v),hh,TRUE,TRUE,2);
2751 hs=gtk_hseparator_new();
2752 gtk_box_pack_start(GTK_BOX(v),hs,FALSE,FALSE,4);
2754 hb=gtk_hbox_new(FALSE,8);
2755 gtk_box_pack_start(GTK_BOX(v),hb,FALSE,TRUE,4);
2757 b_close=gtk_button_new_with_label(" Close ");
2758 gtk_box_pack_end(GTK_BOX(hb),b_close,FALSE,TRUE,4);
2760 GTK_WIDGET_SET_FLAGS(b_close,GTK_CAN_DEFAULT);
2762 gtk_text_freeze(GTK_TEXT(txt));
2763 f=fopen(cmdtorun,"r");
2764 if (f) {
2765 while(fgets(x,255,f))
2766 gtk_text_insert(GTK_TEXT(txt),fixed,NULL,NULL,x,-1);
2767 fclose(f);
2770 gtk_text_thaw(GTK_TEXT(txt));
2772 gtk_widget_show(b_close);
2773 gtk_widget_show(hb);
2774 gtk_widget_show(txt);
2775 gtk_widget_show(vsb);
2776 gtk_widget_show(hh);
2777 gtk_widget_show(hs);
2778 gtk_widget_show(v);
2779 gtk_widget_show(swnd);
2781 gtk_grab_add(swnd);
2782 gtk_widget_grab_default(b_close);
2784 gtk_signal_connect (GTK_OBJECT (swnd), "delete_event",
2785 GTK_SIGNAL_FUNC (pwd_kill), NULL);
2786 gtk_signal_connect (GTK_OBJECT (b_close), "clicked",
2787 GTK_SIGNAL_FUNC (spwd_close), NULL);
2789 if (fixed)
2790 gdk_font_unref(fixed);
2793 void
2794 spwd_close(GtkWidget *gw,gpointer data)
2796 gtk_grab_remove(swnd);
2797 gtk_widget_destroy(swnd);
2801 try_run_script(char *cmd)
2803 int xtermpid,status;
2804 char fcmd[512],aux[256];
2805 FILE *f;
2807 xtermpid=fork();
2808 if (xtermpid<0) return 0;
2810 if (xtermpid) {
2811 /* parent */
2812 while (!waitpid(xtermpid,&status,WNOHANG))
2813 if (gtk_events_pending())
2814 gtk_main_iteration();
2815 else
2816 usleep(100000L);
2818 if (WIFEXITED(status))
2819 if (WEXITSTATUS(status))
2820 return 0;
2822 /* check if script ran successfully */
2823 sprintf(aux,"%s/.yawmppp2/.root_didnt_run_it",getenv("HOME"));
2824 f=fopen(aux,"r");
2825 if (f) {
2826 fclose(f);
2827 return 0;
2830 return 1;
2831 } else {
2832 /* child */
2833 sprintf(fcmd,"echo \"(YAWMPPP)\" ; echo \"Enter root password for running %s\" ; su -c %s",
2834 cmd,cmd);
2835 execlp("xterm","xterm",
2836 "-geometry","75x10",
2837 "-fn","-*-fixed-medium-r-normal--15-*-*-*-*-*-*",
2838 "-title","xterm - YAWMPPP [Apply Changes]",
2839 "-e","/bin/sh","-c",fcmd,0);
2840 execlp("rxvt","rxvt",
2841 "-geometry","75x10",
2842 "-fn","-*-fixed-medium-r-normal--15-*-*-*-*-*-*",
2843 "-title","xterm - YAWMPPP [Apply Changes]",
2844 "-e","/bin/sh","-c",fcmd,0);
2845 execlp("aterm","aterm",
2846 "-geometry","75x10",
2847 "-fn","-*-fixed-medium-r-normal--15-*-*-*-*-*-*",
2848 "-title","xterm - YAWMPPP [Apply Changes]",
2849 "-e","/bin/sh","-c",fcmd,0);
2850 execlp("eterm","eterm",
2851 "-geometry","75x10",
2852 "-fn","-*-fixed-medium-r-normal--15-*-*-*-*-*-*",
2853 "-title","xterm - YAWMPPP [Apply Changes]",
2854 "-e","/bin/sh","-c",fcmd,0);
2855 /* well, we really tried ... */
2856 exit(1);