예제 #1
0
파일: server.c 프로젝트: jeanpetric/easydns
void update()
{
    struct string ip = ip_address();
    str_trim_right(&ip.ptr);

    url_upload(&ip);

    free(ip.ptr);
}
예제 #2
0
파일: easyconfig.c 프로젝트: 960/minipro
int Config_open(const char *path) {
	int ret=0, counter=0, counter1=1;
	char temp[LINE_LENGTH], *result;

	config_content = (struct conf*)calloc(1, sizeof(struct conf));
	config_path = (char*) path;

	if(!(pFile=fopen(config_path,"r"))) {
		return 1;
	}
	while (fgets(temp,LINE_LENGTH,pFile)) {
		config_lines_qty++;
	}

	config_content = (struct conf*)realloc(config_content, (config_lines_qty+50)*sizeof(struct conf));

	int i;
	for (i=0;i<config_lines_qty+50;i++) {
		strcpy(config_content[i].config_line, "");
		strcpy(config_content[i].param_name, "");
		strcpy(config_content[i].param_value, "");
	}
	
	rewind(pFile);
	while (fgets(temp,LINE_LENGTH,pFile)) {
		if (strlen(temp)>LINE_LENGTH) { printf("Config error. Too long line: %d\n", counter1); ret=1; break; }  
		if (strlen(temp)<4) { 
			counter1++;
			continue;
		}

		strcpy(config_content[counter].config_line,temp);
		result=strtok(temp,"="); 
		result=str_trim_right(result);
		if (!result) { printf("Config error. Line: %d\n", counter1); ret=1; break; }
		strcpy(config_content[counter].param_name,result);
		result=strtok(NULL,"\n"); 
		result=str_trim_left(result);
		if (!result) { printf("Config error. Line: %d\n", counter1); ret=1; break; }
		strcpy(config_content[counter].param_value,result);
		
		counter++; counter1++;
	}
	fclose(pFile);
	return ret;
}
예제 #3
0
void
show_userlist(char *server) {
	int connid, error, i;
	struct ncp_file_server_info info;
	struct ncp_bindery_object user;
	time_t login_time;
	struct ipx_addr addr;
	u_int8_t conn_type;

	connid = ncp_get_connid(server, 0);
	if (connid < 0) return;
	if (ncp_get_file_server_information(connid, &info) != 0) {
		perror("Could not get server information");
		return;
	}
	printf("User information for server %s\n",info.ServerName);
	printf("\n%-6s%-21s%-27s%-12s\n"
	       "---------------------------------------------"
	       "---------------------------------\n",
	       "Conn",
	       "User name",
	       "Station Address",
	       "Login time");
	for (i = 1; i <= info.MaximumServiceConnections; i++) {
		char name[49];
		name[48] = '\0';
		error = ncp_get_stations_logged_info(connid, i, &user, &login_time);
		if (error) continue;
		memset(&addr, 0, sizeof(addr));
		error = ncp_get_internet_address(connid, i, &addr, &conn_type);
		if (error) continue;
		memcpy(name, user.object_name, 48);
		str_trim_right(name, ' ');
		printf("%4d: %-20s ", i, name);
		ipx_print_addr(&addr);
		printf(" ");
		printf("%s", ctime(&login_time));
	}

	return;
}
예제 #4
0
void vfu_read_archive_files( int a_recursive )
{
  char line[2048] = "";
  struct stat st;
  memset( &st, 0, sizeof(st));

  if ( a_recursive )
    archive_path = ""; /* cannot have path when recursing archive */

  VString s;
  s = "rx_auto ";
  s += ( a_recursive ) ? "v \"" : "l \"";
  s += archive_name;
  s += "\" \"";
  s += archive_path;
  s += "\" 2> /dev/null";
  /* NOTE: calling rx_* should be safe and result should be proper
     all bugs must be traced outside VFU ...
  */
  FILE *f = popen( s, "r" );
  s = "";
  if ( !f )
    {
    say2( "Archive cannot be recognized or cannot be read" );
    } else
  while( fgets(line, 2048-1, f) )
    {
    str_cut( line, "\n\r" );
    if ( strncmp( line, "NAME:", 5 ) == 0 )
      {
      s = line+5;
      if ( str_get_ch( s, -1 ) == '/' ) /* i.e. last char */
        {
        str_trim_right( s, 1 );
        st.st_mode |= S_IFDIR;
        }
        /* FIXME: my man page for stat() says S_IFDIR is not POSIX?! */
      } else
    if ( strncmp( line, "SIZE:", 5 ) == 0 )
      {
      st.st_size = atoi( line+5 );
      } else
    if ( strncmp( line, "TIME:", 5 ) == 0 )
      {
      struct tm t;
      memset( &t, 0, sizeof(t) );
      VRegexp r( "^(....)(..)(..)(..)(..)(..)?" );
      r.m( line + 5 );
      t.tm_year = atoi( r[1] ) - 1900;  //r[0] is whole
      t.tm_mon  = atoi( r[2] ) - 1;
      t.tm_mday = atoi( r[3] );
      t.tm_hour = atoi( r[4] );
      t.tm_min  = atoi( r[5] );
      t.tm_sec  = atoi( r[6] );
      //for (int x=0;x<7; x++) printf( "%s ", (const char *)r[x]);
      st.st_mtime = st.st_ctime = st.st_atime = mktime( &t );
      //printf( "%d \n", st.st_atime);
      } else
    if ( line[0] == 0 )
      {
      if ( str_len( s ) > 0 )
        vfu_add_file( s, &st, 0 ); /* FIXME: there's no links for now */
      s = "";
      memset( &st, 0, sizeof(st) );
      }

    }
  pclose( f );
};
예제 #5
0
void tree_view()
{
  VString str;
  if (dir_tree.count() == 0)
    {
    tree_load();
    if (dir_tree.count() == 0) 
      tree_rebuild();
    }
  say1( " " );
  int new_pos = tree_index( work_path );
  if ( new_pos == -1 )
    new_pos = 0;

  BSet set; /* used for searching */
  set.set_range1( 'a', 'z' );
  set.set_range1( 'A', 'Z' );
  set.set_range1( '0', '9' );
  set.set_str1( "._-~" );
  set.set_str1( "?*>[]" );
  
  ScrollPos scroll;
  scroll.set_min_max( 0, dir_tree.count()-1 );
  scroll.set_pagesize( PS+2 );
  scroll.go( new_pos );
  
  int key = 0;
  int opos = -1;
  int opage = -1;
  while( key != 27 && key != 13 && key != '-' && 
         toupper( key ) != 'Q' && toupper( key ) != 'X' && key != KEY_ALT_X )
    {
    if ( key >= 'A' && key <= 'Z' ) key = tolower( key );
    if ( key == 's' )
      {
        str = "";
        say1( "Enter search pattern: ( use TAB to advance )" );
        key = con_getch();
        while( set.in( key ) || key == 8 || key == KEY_BACKSPACE || key == 9 )
          {
          if ( key == 8 || key == KEY_BACKSPACE )
            str_trim_right( str, 1 );
          else
          if ( key != 9 )
            str_add_ch( str, key );
          say2( str );
          
          if ( dir_tree.count() == 0 ) { key = con_getch(); continue; }
          
          int z;
          if ( key == 9 )
            {
            z = scroll.pos() + 1;
            if (z > scroll.max() ) z = scroll.min();
            }
          else
            z = scroll.pos();
          int direction = 1;
          int found = 0;
          int loops = 0;
          VString s_mask = str;
          vfu_expand_mask( s_mask );
          while(1)
            {
            if ( z > scroll.max() ) z = scroll.min();
            if ( z < scroll.min() ) z = scroll.max();
            
            VString str1 = dir_tree[z];
            str_trim_right( str1, 1 );
            int j = str_rfind(str1,'/');
            if (j < 0) 
              str1 = "";
            else
              str_trim_left( str1, j+1 );
            found = ( FNMATCH( s_mask, str1 ) == 0 );
            if ( found ) break;
            z += direction;
            if ( loops++ > dir_tree.count() ) break;
            }
          if (found)
            {
            scroll.go(z);
            tree_draw_page( scroll );
            tree_draw_pos( scroll, opos );
            }
          key = con_getch();
          }
        say1( "" );
        say2( "" );
      }
    else
    switch( key )
      {
      case KEY_UP     : scroll.up(); break;
      case KEY_DOWN   : scroll.down(); break;
      case KEY_PPAGE  : scroll.ppage(); break;
      case KEY_NPAGE  : scroll.npage(); break;
      case KEY_HOME   : scroll.home(); break;
      case KEY_END    : scroll.end(); break;
      case 'r'        : tree_rebuild();
                        scroll.set_min_max( 0, dir_tree.count()-1 );
                        scroll.home();
                        say1( "Rebuild done." );
                        break;
      case 'w'        : tree_save(); break;
      case 'l'        : tree_load(); 
                        scroll.set_min_max( 0, dir_tree.count()-1 );
                        scroll.home();
                        break;
      case 'z'        : 
      case KEY_CTRL_Z :
                        str = dir_tree[scroll.pos()];
                        str_tr( str, "\\", "/" );
                        size_cache_set( str, vfu_dir_size( str ) );
                        tree_draw_page( scroll );
                        tree_draw_pos( scroll, opos );
                        say1( "Done." );
                        break;
      }
    if (opage != scroll.page()) 
      tree_draw_page( scroll );
    if (opos != scroll.pos() - scroll.page() || opage != scroll.page()) 
      tree_draw_pos( scroll, opos );
    opos = scroll.pos() - scroll.page();
    opage = scroll.page();
    key = con_getch();
    }
  if ( key == 13 )
    {
    str = dir_tree[scroll.pos()];
    str_tr( str, "\\", "/" );
    vfu_chdir( str );
    }
  do_draw = 2;
};
예제 #6
0
void tree_draw_item( int page, int index, int hilite )
{
  if ( page + index >= dir_tree.count() ) return;
  VString s1 = dir_tree[page+index];
  str_trim_right(s1,1);
  VString s2 = s1;
  int j = str_rfind( s1,'/');
  str_trim_right(s1,str_len(s2)-j-1);
  str_trim_left(s2,j+1);
  for(j = 0; j < str_len(s1); j++)
    {
    if (s1[j] == '/')
      str_set_ch(s1,j, '|');
    else
    if (s1[j] == '\\')
      str_set_ch(s1,j, '\\');
    else
      str_set_ch(s1,j, '+');
    }
  if (opt.tree_compact)
    {
    str_replace(s1,"+", "");
    str_replace(s1,"|", "|  ");
    str_replace(s1,"\\","   ");
    str_trim_right(s1,2);
    s1 += "--";
    }
  else
    {
    str_replace(s1,"+", " ");
    str_replace(s1,"\\", " ");
    s1 += "--";
    }

  VString str = dir_tree[page+index];
  str_tr( str,"\\", "/" );
  
  VString sz;
  sz.fi( size_cache_get( str ) );
  if ( sz == "-1" )
    sz = "n/a";
  else
    str_comma( sz );
  str_pad( sz, 14 );
  
  s1 = sz + " " + s1;

  int m = con_max_x() - 1; /* doesn't speed the code... :) */
  if ( str_len( s1 ) > m )
    {
    str_sleft( s1, m );
    s2 = "";
    }
  else if ( str_len( s1 ) + str_len( s2 ) > m )
    {
    str_sleft( s2, m - str_len( s1 ) );
    }

  con_xy(1,3+1+index);
  if (hilite)
    {
    con_puts( s1, cBAR );
    con_puts( s2, cBAR );
    con_ce( cBAR );
    }
  else
    {
    con_puts( s1, cSTATUS );
    con_puts( s2, cMESSAGE );
    con_ce( cSTATUS );
    }
}
int
main(int argc, char **argv)
{
	struct ncp_conn *conn;
	int opt;
	long err;
	struct ncp_file_server_info info;
	struct ncp_bindery_object user;
	time_t login_time;
	int i;
	int do_help = 0;
	int print_addr = 0;
	int print_id = 0;
	int print_file = 0;
	int print_techinfo = 0;
	int print_details = 0;
	int print_dos = 0;
	int print_semaphores = 0;
	int print_stat = 0;
	int print_stat_k = 0;

	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
	
	progname = argv[0];

	if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
	{
		com_err(argv[0], err, _("when initializing"));
		goto finished;
	}
	while ((opt = getopt(argc, argv, "h?aqftdDsiH")) != EOF)
	{
		switch (opt)
		{
		case 'h':
			if (!do_help) {
				do_help = 1;
				break;
			}
		case '?':
			help();
			goto finished;
		case 'a':
			print_addr = 1;
			break;
		case 'q':
			print_id = 1;
			break;
		case 'f':
			print_file = 1;
			break;
		case 't':
			print_techinfo = 1;
			break;
		case 'd':
			print_details = 1;
			break;
		case 'D':
			print_dos = 1;
			break;
		case 's':
			print_semaphores = 1;
			break;
		case 'i':
			print_stat = 1;
			break;
		case 'H':
			print_stat_k = 2;
			break;
		default:
			usage();
			goto finished;
		}
	}
	if (do_help) {
		if (!print_stat || print_stat_k) {
			help();
			goto finished;
		}
		print_stat_k = 1;
	}
	if (ncp_get_file_server_information(conn, &info) != 0)
	{
		perror(_("Could not get server information"));
		ncp_close(conn);
		return 1;
	}
	
	if (isatty(1))
	{
		switch (print_id * 2 + print_addr) {
			case 0:
			printf(_("\n%-6s%-21s%-12s\n"
			       "---------------------------------------------"
			       "------\n"),
			       _("Conn"),
			       _("User name"),
			       _("Login time"));
			break;
			case 1:
			printf(_("\n%-6s%-21s%-27s%-12s\n"
			       "---------------------------------------------"
			       "---------------------------------\n"),
			       _("Conn"),
			       _("User name"),
			       _("Station Address"),
			       _("Login time"));
			break;
			case 2:
			printf(_("\n%-6s%-9s%-21s%-12s\n"
			       "------------------------------------------------------"
			       "------\n"),
			       _("Conn"),
			       _("ObjectID"),
			       _("User name"),
			       _("Login time"));
			break;
			case 3:
			printf(_("\n%-6s%-9s%-21s%-27s%-12s\n"
			       "------------------------------------------------------"
			       "---------------------------------\n"),
			       _("Conn"),
			       _("ObjectID"),
			       _("User name"),
			       _("Station Address"),
			       _("Login time"));
			break;
		}
	}
	for (i = 0; i <= info.MaximumServiceConnections; i++)
	{
		char name[49];
		name[48] = '\0';
		if (ncp_get_stations_logged_info(conn, i, &user,
						 &login_time) != 0)
		{
			continue;
		}
		memcpy(name, user.object_name, 48);
		str_trim_right(name, ' ');
		if (print_id)
			printf(_("%4d: %08X %-20s "), i, (unsigned int)user.object_id, name);
		else
			printf(_("%4d: %-20s "), i, name);

		if (print_addr != 0)
		{
			union ncp_sockaddr addr;
			u_int8_t conn_type;

			memset(&addr, 0, sizeof(addr));
			if (ncp_get_internet_address(conn, i, &addr.any, &conn_type)) {
				printf("XXXXXXXX:YYZZYYXXTTXX:QQQQ");
			} else switch (addr.any.sa_family) {
#ifdef NCP_IPX_SUPPORT
				case AF_IPX:	ipx_print_saddr(&addr.ipx);
						break;
#endif
#ifdef NCP_IN_SUPPORT
				case AF_INET:	{
							char q[30];
							u_int32_t sa = ntohl(addr.inet.sin_addr.s_addr);
							sprintf(q, "%d.%d.%d.%d/%d", (u_int8_t)(sa >> 24), (u_int8_t)(sa >> 16),
										     (u_int8_t)(sa >> 8), (u_int8_t)(sa), 
										     ntohs(addr.inet.sin_port));
     							printf("%-26s", q);
     						}
     						break;
#endif
				default:	printf("%-26s", _("Unknown format"));
						break;
			}
			printf(" ");
		}
		{
			char text_login_time[200];
			struct tm* tm;
			
			tm = localtime(&login_time);
			my_strftime(text_login_time, sizeof(text_login_time), "%c", tm);
			printf("%s\n", text_login_time);
		}
		if (print_file) {
			OPEN_FILE_CONN_CTRL ofcc;
			OPEN_FILE_CONN ofc;
			nuint16 ih;
			
			ih = 0;
			while (!NWScanOpenFilesByConn2(conn, i, &ih, &ofcc, &ofc)) {
				char tmp[1000];
				NWCCODE err2;
				char* fname;
				
				err2 = ncp_ns_get_full_name(conn, NW_NS_DOS, print_dos ? NW_NS_DOS : ofc.nameSpace, 1, 
					ofc.volNumber, ofc.dirEntry, NULL, 0, tmp, sizeof(tmp));
				if (err2) {
					fname = ofc.fileName;
				} else {
					fname = tmp;
				}
				if (print_techinfo) {
					printf(_("        File: (%02X:%08X) %s\n"), ofc.volNumber, ofc.dirEntry, fname);
				} else {
					printf(_("        File: %s\n"), fname);
				}
				if (print_details) {
					static const char* lock_bits[] = {N_("locked"), N_("open shareable"),
					                                 N_("logged"), N_("open normal"),
									 N_("rsvd"), N_("rsvd"),
									 N_("TTS locked"), N_("TTS")};
					static const char* acc_bits[] = {N_("read"), N_("write"),
									 N_("deny read"), N_("deny write"),
									 N_("detached"), N_("TTS holding detach"),
									 N_("TTS holding open"), N_("rsvd")};
					char lstr[200];
					char accstr[200];
					char* l2str;
					const char* nmstr;
					char* p;
					int li;
					
					p = NULL;
					for (li = 0; li < 8; li++) {
						if (ofc.lockType & (1 << li)) {
							if (p) {
								strcpy(p, ", ");
								p = strchr(p, 0);
							} else {
								p = lstr;
							}
							strcpy(p, _(lock_bits[li]));
							p = strchr(p, 0);
						}
					}
					if (!p) {
						strcpy(p, _("unlocked"));
					}
					switch (ofc.lockFlag) {
						case 0x00:	l2str = _("Not locked"); break;
						case 0xFE:	l2str = _("Locked by a file lock"); break;
						case 0xFF:	l2str = _("Locked by Begin Share File Set"); break;
						default:	l2str = _("Unknown lock state"); break;
					}
					nmstr = ncp_namespace_to_str(NULL, ofc.nameSpace);
					p = NULL;
					for (li = 0; li < 8; li++) {
						if (ofc.accessControl & (1 << li)) {
							if (p) {
								strcpy(p, ", ");
								p = strchr(p, 0);
							} else {
								p = accstr;
							}
							strcpy(p, _(acc_bits[li]));
							p = strchr(p, 0);
						}
					}
					if (!p) {
						strcpy(p, _("unlocked"));
					}
					if (print_techinfo) {
						printf(_("          Task: %-5u             Lock:   (%02X) %s\n"), ofc.taskNumber, ofc.lockType, lstr);
						printf(_("          Fork count: %-3u                 (%02X) %s\n"), ofc.forkCount, ofc.lockFlag, l2str);
						printf(_("          Namespace:  (%02X) %-5s  Access: (%02X) %s\n"), ofc.nameSpace, nmstr, ofc.accessControl, accstr);
					} else {
						printf(_("          Task: %-5u        Lock:   %s\n"), ofc.taskNumber, lstr);
						printf(_("          Fork count: %-3u            %s\n"), ofc.forkCount, l2str);
						printf(_("          Namespace:  %-5s  Access: %s\n"), nmstr, accstr);
					}
				}
			}
		}
		if (print_semaphores) {
			CONN_SEMAPHORES css;
			CONN_SEMAPHORE cs;
			nuint16 ih;
			
			ih = 0;
			while (!NWScanSemaphoresByConn(conn, i, &ih, &cs, &css) && cs.openCount) {
				printf(_("        Semaphore: %s\n"), cs.semaphoreName);
				if (print_details) {
					printf(_("          Task: %-5u     Value: %-5d     Open Count: %-5u\n"),
						cs.taskNumber, cs.semaphoreValue, cs.openCount);
				}
			}
		}
		if (print_stat) {
			NWFSE_USER_INFO fseui;
			
			err = NWGetUserInfo(conn, i, NULL, &fseui);
			if (!err) {
#define ui fseui.userInfo				
				if (print_techinfo) {
					printf(_("        Type: (%02X) %-9.9s Status: (%08X) %s\n"),
						ui.connServiceType, conntype(ui.connServiceType),
						ui.status, connstatus(ui.status));
					printf(_("        Use count: %-9u ExpTime: %08X  ObjType: %08X\n"), ui.useCount,
						ui.expirationTime, ui.objType);
					printf(_("        Transaction flag: %9u  Filler: %18u\n"),
						ui.transactionFlag, ui.filler);
					printf(_("        Logical lock threshold: %3u  Record lock threshold: %3u\n"),
						ui.logicalLockThreshold, ui.recordLockThreshold);
					printf(_("        File write flags:      0x%02X  File write state:     0x%02X\n"),
						ui.fileWriteFlags, ui.fileWriteState);
					printf(_("        File lock count: %10u  Record lock count: %7u\n"),
						ui.fileLockCount, ui.recordLockCount);
				} else {
					printf(_("        Type: %-14s Status: %s\n"),
						conntype(ui.connServiceType),
						connstatus(ui.status));
				}
				print_value(print_stat_k, _("Bytes read:"), _("B"), ui.totalBytesRead);
				print_value(print_stat_k, _("Bytes written:"), _("B"), ui.totalBytesWritten);
				print_value(print_stat_k, _("Requests:"), "", ui.totalRequests);
				if (ui.heldRequests || ui.heldBytesRead || ui.heldBytesWritten) {
					print_value(print_stat_k, _("Held bytes read:"), _("B"), ui.heldBytesRead);
					print_value(print_stat_k, _("Held bytes written:"), _("B"), ui.heldBytesWritten);
					print_value(print_stat_k, _("Held requests:"), "", ui.heldRequests);
				}
#undef ui
			}
		}
	}

finished:
	ncp_close(conn);
	return 0;
}
예제 #8
0
파일: strutil.cpp 프로젝트: mvisat/SVM
std::string str_trim(const std::string &s) {
    return str_trim_left(str_trim_right(s));
}