"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "xdialppp/xppp_init.c" of archive xdialppp-0.4.4.src.nolib.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 #include "xppp_init.h"
    2 #include "mytokens.h"
    3 #include <ctype.h>
    4 #include <string.h>
    5 #include <stdio.h>
    6 
    7 int postHandler(FL_OBJECT *obj, int event, FL_Coord myX, FL_Coord myY, int key, void *xev)
    8 {
    9   char *a;
   10   if (obj==pro1)
   11 	a="Enter here the prompt which\nyour ISP asks your username with.";
   12   else if (obj==pro2)
   13 	a="Enter here the prompt which\nyour ISP asks your password with.";
   14   else if (obj==ans1)
   15 	a="Enter here your username.";
   16   else if(obj==ans2)
   17 	a="Enter here your password.\n(invisible).";
   18   else if (obj==ans22)
   19 	a="Enter again your password.";
   20   else if (obj==pro3)
   21 	a="Enter here any prompt that your ISP\nissues you after identifying.\nIn my case is a \'>\'";
   22   else if (obj==ans3)
   23 	a="Answer to the extra prompt.\nIn my case is a \'ppp\'";
   24   else if (obj==locI)
   25 	a="Local IP\nLeave 0.0.0.0 for\ndynamic IP assignament.";
   26   else if (obj==remI)
   27 	a="Remote IP\nLeave 0.0.0.0 for\ndynamic IP assignament.";
   28   else if (obj==netI)
   29 	a="Netmask\nAdecuate this to your network class.\n255.255.255.0 should work fine.";
   30   else if (obj==aonoiB)
   31 	a="Leave ON for dynamic IP asignament.";
   32   else if (obj==aodefB)
   33 	a="Leave ON to add the ISP's address\nto your kernel routing table\nas default getaway.";
   34   else if (obj==aotimI)
   35 	a="Timeout to wait\nfor connection (seconds).";
   36   else if (obj==aortsB)
   37 	a="Leave ON to use hardware\nRTS/CTS flow control.";
   38   else if (obj==aoasyI)
   39 	a="Caracters that can not be transmitted.\nDo not change if not sure!";
   40   else if (obj==aoescI)
   41 	a="Escape secuences.\nDo not change if not sure!";
   42   else if (obj==genB)
   43 	a="Press to generate the \nppp connection script.";
   44   else if (obj==advB)
   45 	a="Press to set some\ncommunication options.";
   46   else if (obj==ipaB)
   47 	a="Press to set\n IP options";
   48   else
   49 	a="Sorry, feature not implemented yet.\nIf you need it, contact the author.";
   50 
   51   if (event==FL_ENTER)
   52 	fl_show_oneliner(a, obj->form->x + obj->x , obj->form->y + obj->y + obj->h + 1);
   53   else
   54 	if (event!=FL_MOTION)
   55 		fl_hide_oneliner();
   56 
   57 }
   58 
   59 void initXppp()
   60 {
   61    if(parsed)
   62    {
   63 	fl_set_input(pro1,"Username:");
   64 	fl_set_input(pro2,"Password:");
   65 
   66 	if (strlen(options[0]))
   67 		fl_set_input(phone,options[0]);
   68 	if (strlen(options[1]))
   69 		fl_set_input(pro1,options[1]);
   70 	if (strlen(options[2]))
   71 		fl_set_input(ans1,options[2]);
   72 	if (strlen(options[3]))
   73 		fl_set_input(pro2,options[3]);
   74 	if (strlen(options[4]))
   75 	{
   76 		fl_set_input(ans2,options[4]);
   77 		fl_set_input(ans22,options[4]);
   78 	}
   79 	if (strlen(options[5]))
   80 		fl_set_input(pro3,options[5]);
   81 	if (strlen(options[6]))
   82 		fl_set_input(ans3,options[6]);
   83 	if (strlen(options[7]))
   84 		fl_set_input(pro4,options[7]);
   85 	if (strlen(options[8]))
   86 		fl_set_input(ans4,options[8]);
   87 
   88    }
   89    else
   90    {
   91 	fl_set_input(pro1,"Username:");
   92 	fl_set_input(pro2,"Password:");
   93    }
   94 	fl_set_object_posthandler(pro1,postHandler);
   95 	fl_set_object_posthandler(pro2,postHandler);
   96 	fl_set_object_posthandler(ans1,postHandler);
   97 	fl_set_object_posthandler(ans2,postHandler);
   98 	fl_set_object_posthandler(ans22,postHandler);
   99 	fl_set_object_posthandler(pro3,postHandler);
  100 	fl_set_object_posthandler(ans3,postHandler);
  101 	fl_set_object_posthandler(ipaB,postHandler);
  102 	fl_set_object_posthandler(advB,postHandler);
  103 	fl_set_object_posthandler(genB,postHandler);
  104 }
  105 
  106 void initIPa()
  107 {
  108    if(parsed)
  109    {
  110 	if (strlen(options[9]))
  111 		fl_set_input(locI,options[9]);
  112 	else
  113 		fl_set_input(locI,"0.0.0.0");
  114 	if (strlen(options[10]))
  115 		fl_set_input(remI,options[10]);
  116 	else
  117 		fl_set_input(remI,"0.0.0.0");
  118 	if (strlen(options[11]))
  119 		fl_set_input(netI,options[11]);
  120 	else
  121 		fl_set_input(netI,"255.255.255.0");
  122 	if(strlen(options[22]))
  123 		fl_set_input(preI,options[22]);
  124 	if(strlen(options[23]))
  125 		fl_set_input(preI,options[23]);
  126 
  127    }
  128    else
  129    {
  130 	fl_set_input(locI,"0.0.0.0");
  131 	fl_set_input(remI,"0.0.0.0");
  132 	fl_set_input(netI,"255.255.255.0");
  133    }
  134 
  135    fl_set_object_posthandler(locI,postHandler);
  136    fl_set_object_posthandler(remI,postHandler);
  137    fl_set_object_posthandler(netI,postHandler);
  138    fl_set_object_posthandler(aonoiB,postHandler);
  139    fl_set_object_posthandler(aodefB,postHandler);
  140 
  141    fl_set_object_posthandler(preI,postHandler);
  142    fl_set_object_posthandler(posI,postHandler);
  143    fl_deactivate_object(preI);//temporal
  144    fl_deactivate_object(posI);//temporal
  145 }
  146 
  147 
  148 void initAo()
  149 {
  150    if(parsed)
  151    {
  152 	fl_set_button(s115,0);
  153 	fl_set_button(s57,0);
  154 	fl_set_button(s38,0);
  155 	fl_set_button(s19,0);
  156 	fl_set_button(s9,0);
  157 	fl_set_button(soth,0);
  158 	fl_deactivate_object(aospeI);
  159 
  160 	fl_set_button(aopulB,0);
  161 	fl_set_button(aotonB,0);
  162 
  163 	fl_set_button(aovol0,0);
  164 	fl_set_button(aovol1,0);
  165 	fl_set_button(aovol2,0);
  166 	fl_set_button(aovol3,0);
  167 
  168 	if (strlen(options[12]))
  169 		fl_set_input(aodevI,options[12]);
  170 	else
  171 		fl_set_input(aodevI,"/dev/modem");
  172 	if (strlen(options[13]))
  173 	{
  174 		if (!strcmp(options[13],"115200"))
  175 			fl_set_button(s115,1);
  176 		else if (!strcmp(options[13],"57600"))
  177 			fl_set_button(s57,1);
  178 		else if (!strcmp(options[13],"38400"))
  179 			fl_set_button(s38,1);
  180 		else if (!strcmp(options[13],"19200"))
  181 			fl_set_button(s19,1);
  182 		else if (!strcmp(options[13],"9600"))
  183 			fl_set_button(s9,1);
  184 		else
  185 		{
  186 			fl_activate_object(aospeI);
  187 			fl_set_input(aospeI,options[13]);
  188 			fl_set_button(soth,1);
  189 		}
  190 	}
  191 	else
  192 	{
  193 		fl_set_button(s115,1);
  194 	}
  195 	if (strlen(options[14]))
  196 		fl_set_input(aotimI,options[14]);
  197 	else
  198 		fl_set_input(aotimI,"30");
  199 	if (strlen(options[15]))
  200 		if (!strcmp(options[15],"P"))
  201 			fl_set_button(aopulB,1);
  202 		else
  203 			fl_set_button(aotonB,1);
  204 	else
  205 		fl_set_button(aotonB,1);
  206 	if (strlen(options[16]))
  207 		if (!strcmp(options[16],"L0"))
  208 			fl_set_button(aovol0,1);
  209 		else if (!strcmp(options[16],"L3"))
  210 			fl_set_button(aovol3,1);
  211 		else if (!strcmp(options[16],"L2"))
  212 			fl_set_button(aovol2,1);
  213 		else
  214 			fl_set_button(aovol1,1);
  215 	else
  216 		fl_set_button(aovol1,1);
  217 
  218 	if (strlen(options[17]))
  219 		fl_set_button(aortsB,1);
  220 	else
  221 		fl_set_button(aortsB,0);
  222 
  223 	if (strlen(options[18]))
  224 		fl_set_input(aoasyI,options[18]);
  225 	else
  226 		fl_set_input(aoasyI,"");
  227 	if (strlen(options[19]))
  228 		fl_set_input(aoescI,options[19]);
  229 	else
  230 		fl_set_input(aoescI,"");
  231 	if (strlen(options[20]))
  232 		fl_set_button(aonoiB,1);
  233 	else
  234 		fl_set_button(aonoiB,0);
  235 	if (strlen(options[21]))
  236 		fl_set_button(aodefB,1);
  237 	else
  238 		fl_set_button(aodefB,0);
  239    }
  240    else
  241    {
  242 		/*	device, timeout		*/
  243 	fl_set_input(aodevI,"/dev/modem");
  244 	fl_set_input(aotimI,"30");
  245 		/*  	connection speed 	*/
  246 	fl_set_button(s115,1);
  247 	fl_set_button(s57,0);
  248 	fl_set_button(s38,0);
  249 	fl_set_button(s19,0);
  250 	fl_set_button(s9,0);
  251 	fl_set_button(soth,0);
  252 	fl_set_input(aospeI,"");
  253 	fl_deactivate_object(aospeI);
  254 		/*	asyncmap , escape	*/
  255 	fl_set_input(aoasyI,"20A0000");
  256 	fl_set_input(aoescI,"FF");
  257 		/*	dialing mode		*/
  258 	fl_set_button(aotonB,1);
  259 	fl_set_button(aopulB,0);
  260 		/*	speaker volume		*/
  261 	fl_set_button(aovol0,0);
  262 	fl_set_button(aovol1,1);
  263 	fl_set_button(aovol2,0);
  264 	fl_set_button(aovol3,0);
  265 		/*	flow ctrl, noipdefault, defaultroute	*/
  266 	fl_set_button(aortsB,1);
  267 	fl_set_button(aonoiB,1);
  268 	fl_set_button(aodefB,1);
  269 
  270    }
  271 
  272    fl_set_object_posthandler(aotimI,postHandler);
  273    fl_set_object_posthandler(aortsB,postHandler);
  274    fl_set_object_posthandler(aoasyI,postHandler);
  275    fl_set_object_posthandler(aoescI,postHandler);
  276 }
  277 
  278 
  279 void initLaunch()
  280 {
  281    int flag=0;
  282 	//if temporal file exists, delete it.
  283   if((aux=fopen(temporal,"r")))
  284   {
  285 	char tmp[255];
  286 	sprintf(tmp,"rm %s",temporal);
  287 	fclose(aux);
  288 	fl_exe_command(tmp,1);
  289   }
  290 
  291 // search for configuration files : xppprc , specific.xppprc , specific.ppp-init
  292 // and specific.ppp-on-dialer
  293 
  294   //first : xppprc
  295   if(!(xppprc=fopen(configrc,"r")))
  296   {
  297 	char tmp[255];
  298 	sprintf(tmp,"Couldn't open configuration file: %s",configrc);
  299 	fl_show_alert(tmp,"Please configurate your connection first. (Configurate button)","",0);
  300 	flag=1;
  301   }
  302   else
  303   {
  304 	char tmp[255];
  305 	fscanf(xppprc,"%s",tmp);
  306 	if (!strlen(tmp))		//does it contain data ?
  307 	{
  308 		char tmp[255];
  309 		sprintf(tmp,"Corrupted data in configuration file : %s",configrc);
  310 		fl_show_alert(tmp,"Couldn't get info.","Please configurate your connection first. (Configurate button)",0);
  311 		flag=1;
  312 
  313 	}
  314 	else				//yes, it contains data
  315 	{
  316 		strcpy(specific,tmp);
  317 		if(!(spec=fopen(specific,"r")))	//can specific file be opened
  318 		{
  319 			char tmp[255];
  320 			sprintf(tmp,"Couldn't open config file : %s",specific);
  321 			fl_show_alert(tmp,"","Please configurate your connection first. (Configurate button)",0);
  322 			flag=1;
  323 		}
  324 		else				// yes
  325 		{
  326 			char a[255],*b;
  327 			/*search for PPP_SCRIPT*/
  328 			fgets(a,250,spec);
  329 			//printf("%s-",a); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
  330 			if( !(getToken(tmp,a,"PPP_SCRIPT=")) )	//1st label ?
  331 			{
  332 				char tmp[255];
  333 				sprintf(tmp,"Corrupted data in configuration file : %s",specific);
  334 				fl_show_alert(tmp,"PPP_SCRIPT   line not found.","Please configurate your connection first. (Configurate button)",0);
  335 				flag=1;
  336 			}
  337 			else							// Yes
  338 			{
  339 				removeToken(pppScript,tmp,'\n'); //tiene un newline de mas
  340 				//printf("%s - %s\n",b,pppScript);
  341 
  342 								/*search for DIAL_SCRIPT*/
  343 				fgets(a,250,spec);
  344 				//printf(a);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
  345 				if( !(getToken(tmp,a,"DIAL_SCRIPT=")) )
  346 				{
  347 					char tmp[255];
  348 					sprintf(tmp,"Corrupted data in configuration file : %s",specific);
  349 					fl_show_alert(tmp,"DIAL_SCRIPT   line not found.","Please configurate your connection first. (Configurate button)",0);
  350 					flag=1;
  351 				}
  352 				else				//Yes
  353 				{
  354 					removeToken(dialScript,tmp,'\n');//sacar newline
  355 					//printf("%s - %s\n",tmp,dialScript);
  356 					//printf("%d - %s-",ppps,pppScript);
  357 					if (!(ppps=fopen(pppScript,"r")))
  358 					{
  359 						fl_show_alert("ppp script not found !",pppScript,"Please configurate your connection first. (Configurate button)",0);
  360 						flag=1;
  361 					}
  362 					else
  363 					{
  364 						if (!(dials=fopen(dialScript,"r")))
  365 						{
  366 							fl_show_alert("dialing script not found !",dialScript,"Please configurate your connection first. (Configurate button)",0);
  367 							flag=1;
  368 						}
  369 						else
  370 						{
  371 							char tmp[255],aux[255];
  372 							fgets(tmp,200,spec);
  373 							if(!getToken(aux,tmp,"CONNAME="))
  374 							{
  375 								char tmp[255];
  376 								sprintf(tmp,"Corrupted data in configuration file : %s",specific);
  377 								fl_show_alert(tmp, "CONNAME   line not found.","Please configurate your connection first. (Configurate button)",0);
  378 								flag=1;
  379 							}
  380 							else
  381 							{
  382 								removeToken(conname,aux,'\'');
  383 							}
  384 						}//dial script opened
  385 					}// ppp script opened
  386 				}// DIAL_SCRIPT found in specific
  387 			}// PPP_SCRIPT found in specific
  388 
  389 			fclose(spec);
  390 
  391 		}//sspecific file opened OK
  392 	}//xppprc contains data
  393 
  394   	fclose(xppprc);
  395 
  396   }// file opened OK
  397 
  398   if (flag)
  399   {
  400 	fl_deactivate_object(cconnB);
  401 	strcpy(conname,"Connection1");
  402 	strcpy(specific,"conn1.xppprc");
  403   }
  404   else
  405   {
  406 		/*Everyting OK*/
  407 	char text[255], result[255];
  408 	int i;
  409 	fl_set_object_label(ppptext,specific);
  410 	fl_set_object_label(dialtext,conname);
  411 	/*Here comes the loading of data from scripts (I hope...)*/
  412 	/*ppp script first*/
  413 	while(!feof(ppps))
  414 	{
  415 		fgets(text, 250,ppps);
  416 		if(!beginsWith(text,'#'))
  417 		{
  418 			//printf("%s\n",text);
  419 			for(i=0;i<24;i++)
  420 			if(getToken(result,text,variables[i]))
  421 			{
  422 				removeToken(options[i],result,'\'');
  423 				//printf(" - %s --- %s\n",text, options[i]);
  424 			}
  425 		}
  426 
  427 
  428 	}
  429 
  430   fclose(ppps);
  431   fclose(dials);
  432   parsed=1;
  433   }
  434 
  435   fl_set_pixmap_file(mysite,xpmmysite);
  436   fl_set_pixmap_file(myISP,xpmmyISP);
  437   fl_set_pixmap_file(phoneline,xpmnoline);
  438 
  439   fl_deactivate_object(cdisB);
  440 
  441 
  442 
  443 
  444 /*These are temporal hidings ... */
  445 
  446   fl_deactivate_object(cselB);
  447   fl_hide_object(cselB);
  448 
  449 
  450 /*End Of Temporal hidings*/
  451 
  452 }
  453 
  454 
  455 
  456 void restoreIPa()
  457 {
  458 	initIPa();	//TODO !!!!!!!!!!!!!
  459 }
  460 
  461 void restoreAo()
  462 {
  463 	initAo();	//TODO !!!!!!!!!!!!!
  464 }
  465 
  466 
  467 
  468 
  469 void initializeForms()
  470 {
  471 	int i;
  472 	parsed=0;
  473 	mutex=1;
  474   	for (i=0;i<22;i++)
  475 		strcpy(options[i],"\0");
  476 
  477 	strcpy(variables[0],"PHONE=");
  478 	strcpy(variables[1],"PROMPT1=");
  479 	strcpy(variables[2],"USERNAME=");
  480 	strcpy(variables[3],"PROMPT2=");
  481 	strcpy(variables[4],"PASSWORD=");
  482 	strcpy(variables[5],"PROMPT3=");
  483 	strcpy(variables[6],"ANSWER3=");
  484 	strcpy(variables[7],"PROMPT4=");
  485 	strcpy(variables[8],"ANSWER4=");
  486 	strcpy(variables[9],"LOCALIP=");
  487 	strcpy(variables[10],"REMOTEIP=");
  488 	strcpy(variables[11],"NETMASK=");
  489 	strcpy(variables[12],"DEVICE=");
  490 	strcpy(variables[13],"SPEED=");
  491 	strcpy(variables[14],"TIMEOUT=");
  492 	strcpy(variables[15],"DIALMODE=");
  493 	strcpy(variables[16],"VOLUME=");
  494 	strcpy(variables[17],"FLOWCTRL=");
  495 	strcpy(variables[18],"ASYNCMAP=");
  496 	strcpy(variables[19],"ESCAPE=");
  497 	strcpy(variables[20],"NOIPDEFAULT=");
  498 	strcpy(variables[21],"DEFAULTROUTE=");
  499 	strcpy(variables[22],"PRECOMMAND=");
  500 	strcpy(variables[23],"POSTCOMMAND=");
  501 
  502 	strcpy(dirname,"/usr/local/lib/xdialppp");
  503 	sprintf(fname1,"%s/ppp-init",dirname);
  504 	sprintf(fname2,"%s/ppp-on-dialer",dirname);
  505 	sprintf(configrc,"%s/xppprc",dirname);
  506 	sprintf(temporal,"%s/xppptmp",dirname);
  507 	sprintf(disconn,"%s/ppp-off",dirname);
  508 	sprintf(messages,"/var/log/messages");
  509 
  510 	sprintf(xpmline0,"%s/pix/line0.xpm",dirname);
  511 	sprintf(xpmline1,"%s/pix/line1.xpm",dirname);
  512 	sprintf(xpmline2,"%s/pix/line2.xpm",dirname);
  513 	sprintf(xpmline3,"%s/pix/line3.xpm",dirname);
  514 	sprintf(xpmline4,"%s/pix/line4.xpm",dirname);
  515 	sprintf(xpmline5,"%s/pix/line5.xpm",dirname);
  516 	sprintf(xpmline6,"%s/pix/line6.xpm",dirname);
  517 	sprintf(xpmline7,"%s/pix/line7.xpm",dirname);
  518 	sprintf(xpmdial0,"%s/pix/dialing0.xpm",dirname);
  519 	sprintf(xpmdial1,"%s/pix/dialing1.xpm",dirname);
  520 	sprintf(xpmdial2,"%s/pix/dialing2.xpm",dirname);
  521 	sprintf(xpmmysite,"%s/pix/mysite.xpm",dirname);
  522 	sprintf(xpmmyISP,"%s/pix/myISP.xpm",dirname);
  523 	sprintf(xpmnoline,"%s/pix/phoneline.xpm",dirname);
  524 	sprintf(xpmdaemon,"%s/pix/pppdaemon.xpm",dirname);
  525 
  526 
  527 	initLaunch();
  528 	initXppp();
  529 	initIPa();
  530 	initAo();
  531 }
  532 
  533 
  534 int  checknum(char * myStr)
  535 {
  536    char copied[80];
  537    int flag=0,i=0,clen;
  538    strcpy(copied,myStr);
  539    clen=strlen(copied);
  540    while( i<clen && isdigit(copied[i]) )
  541 	i++;
  542    if (i==clen)
  543 	return 1;
  544    else
  545 	return 0;
  546 }
  547 
  548 int  isIP(char * myStr)
  549 {
  550   char copied[80],*a,*b,*c,*d;
  551   int flag=0,i;
  552   strcpy(copied,myStr);
  553   a=strtok(copied,".");
  554   b=strtok(NULL,".");
  555   c=strtok(NULL,".");
  556   d=strtok(NULL,".");
  557   if (a!=NULL && b!=NULL && c!=NULL && d!=NULL)
  558   	if (checknum(a) && checknum(b) && checknum(c) && checknum(d))
  559 		if( (atol(a) < 256) && (atol(b) < 256) && (atol(c) < 256) && (atol(d) < 256) )
  560   			return 1;
  561   return 0;
  562 }
  563 
  564 
  565 void doStop(char* message, FL_FORM* whichForm)
  566 {
  567 	fl_set_object_label(stext, message);
  568 	lastDeactForm=whichForm;
  569 	fl_deactivate_form(lastDeactForm);
  570 	fl_show_form(stoping,1,1,"Xdialppp Stop");
  571 }
  572 
  573 
  574 
  575 
  576