Esempio n. 1
0
void* PnpP2pProc( void* p )
{
    int iRet = 0;
    char temp[256];

    if ( ( sem_init( &p2pportsem, 0, 0 ) ) != 0 )
    {
        printf( "sem init failed\n" );
    }

    while ( 1 )
    {
        //printf("upnpflag=%d  enable = %d\n",upnpflag,bparam.stUpnpParam.byEnable);
        sem_wait( &p2pportsem );

        if ( bupnpp2pport > 0 )
        {
            memset( temp, 0x00, 256 );
            sprintf( temp, "/system/system/bin/upnpc-static -d %d UDP", bupnpp2pport );
            iRet = DoSystem( temp );
        }

        if ( upnpp2pport > 0 )
        {
            memset( temp, 0x00, 256 );
            sprintf( temp, "/system/system/bin/upnpc-static -a %s %d %d UDP", bparam.stNetParam.szIpAddr, upnpp2pport, upnpp2pport );
            iRet = DoSystem( temp );
        }
    }
}
Esempio n. 2
0
void RmmodUvcDriver()
{
    Textout("=================Rmmod uvc driver==================");
    DoSystem("rmmod uvcvideo");
    DoSystem("rmmod videodev");
    DoSystem("rmmod v4l1-compat");
    DoSystem("rmmod compat_ioctl32");
    DoSystem("rmmod v4l2-common");
}
Esempio n. 3
0
void JpegInit( void )
{
    char temp[64];
    memset( temp, 0x00, 64 );
    sprintf( temp, "chmod a+x /system/system/bin/jpeg" );
    DoSystem( temp );
    memset( temp, 0x00, 64 );
    sprintf( temp, "/system/system/bin/jpeg &" );
    DoSystem( temp );
}
Esempio n. 4
0
int FtpsendAlarm( char* capfilename, char* filename )
{
    int     iRet = 0;
    char param[4];
    //ftplock();
    Textout("7");
    ftp_dbg( "alarm upload40\n", 0 );
    iRet = FtpConfigAlarm( 0x00, capfilename, filename );

    if ( -1 == iRet )
    {
		Textout("FtpConfigAlarm failed");
        return iRet;
    }

    // (iRet == 0){
    ftp_dbg( "alarm upload41\n", 0 );
    //gnal(SIGCHLD,SIG_IGN);
    //gnal(SIGCHLD,SIG_DFL);
    //FtpWrite(param,4);
    Textout("8");
    iRet = DoSystem( "/tmp/ftpupdate.sh &" );
    ftp_dbg( "alarm upload42\n", 0 ); 
    //}
    //ftpunlock();
    Textout("9 - FTP Over");
    return iRet;
}
Esempio n. 5
0
void emailtest( void )
{
    DoSystem( "echo \"mail test ok\"|/system/system/bin/mailx -v -s \"mail test\" [email protected]" );
#if 0
    system( "sendmail -s \"test\" -H 517929728:[email protected]:25 -f [email protected] < /tmp/dhcp.txt -t [email protected] -a /tmp/ssmtp.conf" );
#endif
}
Esempio n. 6
0
int UPnPStart( void )
{
    int iRet = -1;

    if ( bparam.stUpnpParam.byEnable == 0x01 )
    {
        char temp[256];
        //printf("start upnp web...\n");
        memset( temp, 0x00, 256 );
        sprintf( temp, "/system/system/bin/upnpc-static -a %s %d %d TCP", bparam.stNetParam.szIpAddr, bparam.stNetParam.nPort,
                 bparam.stNetParam.nPort );
        iRet = DoSystem( temp );
        printf( "iRet %d upnp:%s\n", iRet, temp );

        if ( iRet == 0 )
        {
            upnpflag = 0x00;
            bparam.stStatusParam.upnpstat = 0x01;
        }

        else
        {
            bparam.stStatusParam.upnpstat = 0x03;
        }

#if 0
        memset( temp, 0x00, 256 );
        sprintf( temp, "/system/system/bin/upnpc-static -d %d UDP", bupnpp2pport );
        iRet = DoSystem( temp );
        memset( temp, 0x00, 256 );
        sprintf( temp, "/system/system/bin/upnpc-static -a %s %d %d UDP", bparam.stNetParam.szIpAddr, upnpp2pport, upnpp2pport );
        iRet = DoSystem( temp );
#endif
#if 0
        //printf("start upnp cmd...\n");
        memset( temp, 0x00, 256 );
        sprintf( temp, "upnpc-static -a %s %d %d TCP 1\n", bparam.stNetParam.szIpAddr, bparam.stNetParam.CmdPort,
                 bparam.stNetParam.CmdPort );
        iRet += DoSystem( temp );
        //printf("cmd:%s\n",temp);
        //printf("start upnp data...\n");
        memset( temp, 0x00, 256 );
        sprintf( temp, "upnpc-static -a %s %d %d TCP 2\n", bparam.stNetParam.szIpAddr, bparam.stNetParam.DatPort,
                 bparam.stNetParam.DatPort );
        iRet += DoSystem( temp );
        memset( temp, 0x00, 256 );
        sprintf( temp, "upnpc-static -a %s %d %d TCP\n", bparam.stNetParam.szIpAddr, bparam.stNetParam.rtspport,
                 bparam.stNetParam.rtspport );
        iRet += DoSystem( temp );
        myWriteLogIp( 0x7f000001, "UPnP is start..." );
        upnpflag = 0x01;
#endif
        //printf("data:%s\n",temp);
    }

    return iRet;
}
Esempio n. 7
0
int DoFtpTest( void )
{
    int     iRet = 0;
    iRet = FtpConfig( 0x01, NULL );

    if ( iRet == 0 )
    {
        char cmd[128];
        memset(cmd, 0, 128);
        sprintf(cmd, "/tmp/ftpupdate1.sh > %s", FILE_FTP_TEST_RESULT);
        iRet = DoSystem(cmd);
        //iRet = DoSystem( "/tmp/ftpupdate1.sh > /tmp/ftpret.txt" );
    }

    return iRet;
}
Esempio n. 8
0
int Ftpsend( char* filename )
{
    int     iRet = 0;
    //ftplock();
    iRet = FtpConfig( 0x00, filename );

    if ( iRet == 0 )
    {
        //gnal(SIGCHLD,SIG_DFL);
        iRet = DoSystem( "/tmp/ftpupdate1.sh &" );
        //gnal(SIGCHLD,SIG_IGN);
    }

    //ftpunlock();
    return iRet;
}
Esempio n. 9
0
void ProcSystem()
{
    char        *start;
    size_t      len;
    int         loc;

    loc = 0;
    if( CurrToken == T_DIV ) {
        Scan();
        loc = ScanCmd( SystemOps );
        if( loc == 0 ) {
            Error( ERR_LOC, LIT( ERR_BAD_OPTION ), GetCmdName( CMD_SYSTEM ) );
        }
        if( loc == 2 ) loc = -1;
    }
    ScanItem( FALSE, &start, &len );
    ReqEOC();
    DoSystem( start, len, loc );
}
Esempio n. 10
0
void InsmodUvcDriver()
{
    Textout("=================Insmod uvc driver==================");
    DoSystem("insmod /lib/modules/2.6.21/kernel/drivers/media/video/v4l2-common.ko");
    DoSystem("insmod /lib/modules/2.6.21/kernel/drivers/media/video/compat_ioctl32.ko");
    DoSystem("insmod /lib/modules/2.6.21/kernel/drivers/media/video/v4l1-compat.ko");
    DoSystem("insmod /lib/modules/2.6.21/kernel/drivers/media/video/videodev.ko");
    #ifdef SENSOR_3861
    DoSystem("insmod /lib/modules/2.6.21/kernel/drivers/media/video/uvc/uvcvideo.ko");
	Textout("=================Insmod uvc driver SENSOR_3861 end==================");
    #else
    DoSystem("insmod /system/system/lib/uvcvideo.ko");
	Textout("=================Insmod uvc driver 8433 end==================");
    #endif
    
}
Esempio n. 11
0
int GetFtpTestResult()
{
    int iRet = 0;

    int nIntervalTime=0;
    while(nIntervalTime < 5)
    {
        iRet = access( FILE_FTP_TEST_RESULT, F_OK );
        if ( iRet == 0 )
        {
            Textout("Get the result file of FTP test");
            break;
        }
        else
        {
            nIntervalTime++;
            sleep(1);
            Textout("nIntervalTime = %d", nIntervalTime);
        }
    } 

    iRet = GetFtpResult();
    Textout( "Ftp result=%d", iRet );


    /* BEGIN: Added by Baggio.wu, 2013/10/25 */
    //DoSystem( "rm /tmp/ftpret.txt" );

    //rm result file
    if(1)
    {
        char cmd[32];
        memset(cmd, 0, 32);
        sprintf(cmd, "rm %s", FILE_FTP_TEST_RESULT);
        DoSystem(cmd);
    }


    return iRet;
}
Esempio n. 12
0
void DhcpRouteStop( void )
{
    DoSystem( "killall udhcpd" );
}
Esempio n. 13
0
int GetMailTestResult()
{
    int iRet =0;
    FILE*	fp = NULL;
    unsigned char value = 0;

    int nIntervalTime=0;
    while(nIntervalTime < 5)
    {
        iRet = access( FILE_MAIL_TEST_RESULT, F_OK );
        if ( iRet == 0 )
        {
            Textout("Get the result file of mail test");
            break;
        }
        else
        {
            nIntervalTime++;
            sleep(1);
            Textout("nIntervalTime = %d", nIntervalTime);
        }
    }

    fp = fopen( FILE_MAIL_TEST_RESULT, "rb" );

    if ( fp == NULL )
    {
        return -1;
    }

    value = 0;
    fread( &value, 1, 1, fp );

    if ( value == 0x30 )
    {
        iRet = 0;
    }

    else
    {
        iRet = -1;
    }

    fclose( fp );

    /* BEGIN: Added by Baggio.wu, 2013/10/25 */

    //DoSystem( "rm /tmp/mrt.txt" );

    //rm result file
    {
        char cmd[32];
        memset(cmd, 0, 32);
        sprintf(cmd, "rm %s", FILE_MAIL_TEST_RESULT);
        DoSystem(cmd);
    }
    /* END:   Added by Baggio.wu, 2013/10/25 */

    Textout( "sed mail iRet=%d, get mrt.txt value=%d\n", iRet, value );
    return iRet;
}
Esempio n. 14
0
int DownloadFirmware(char *server_ip, int nPort, char *file_path)
{
    struct  sockaddr_in daddr;
    int     sock;
    int     iRet = 0;
    //char  szBuffer[1024] = {"GET /FM/system/TH-sys-48.2.64.178.zip HTTP/1.1\r\nHost:cd.gocam.so\r\nConnection:Close\r\n\r\n"};
    char    szBuffer[1024] = {0};
    struct  timeval    TimeOut;
    int nFlag;

    FILE* file = NULL;
    int recvlen = 0;

    sprintf( szBuffer, "GET %s HTTP/1.1\r\nHost: %s\r\nConnection:Close\r\n\r\n",
             file_path,
             server_ip );
    Textout( "szBuffer = [%s]", szBuffer );

    sock = socket( AF_INET, SOCK_STREAM, 0 );
    bzero( &daddr, sizeof( struct sockaddr_in ) );

    nFlag = 1;
    setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, ( void* )&nFlag, sizeof( int ) );
	
    TimeOut.tv_sec = 30;
    TimeOut.tv_usec = 0;
    setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, ( char* )&TimeOut, sizeof( TimeOut ) );


    if ( iRet != 0 )
    {
        CloseSocket( sock );
        return -1;
    }

    daddr.sin_family        = AF_INET;
    daddr.sin_port          = htons( nPort );
    daddr.sin_addr.s_addr   = inet_addr( server_ip );

    if ( connect( sock, ( struct sockaddr* )&daddr, sizeof( struct sockaddr ) ) == -1 )
    {
        Textout( "connect download server failed\n" );
        CloseSocket( sock );
        return -1;
    }

    send( sock, szBuffer, strlen( szBuffer ), 0 );

    DoSystem( "rm -f /tmp/download.bin" );
    file = fopen( "/tmp/download.bin", "wb" );

    if ( file == NULL )
    {
        printf( "dbg file open failed\n" );
        return -1;
    }

    while ( 1 )
    {
        iRet = recv( sock, szBuffer, 1024, 0 );

        if ( iRet > 0 )
        {
            recvlen += iRet;
            fwrite( szBuffer, 1, iRet, file );
        }

        else
        {
            break;
        }
    }

    printf( "download file recv len=%d\n", recvlen );
    fclose( file );

    CloseSocket( sock );

	ProcessDownloadFile(recvlen);

	return 0;
}
Esempio n. 15
0
void ProcessDownloadFile(int nTotalSize)
{
	FILE *f = fopen("/tmp/download.bin", "rb");
	if ( f == NULL )
	{
		Textout("Not Found download.bin");
		return;
	}

	/////////////////////////////////////////////////////
	//
	//Process .....Copy or mv and etc.
	//
	/////////////////////////////////////////////////////

	TDownloadFileHead head;
	fread(&head, 1, sizeof(TDownloadFileHead), f);
	if ( head.nStartByte != REQUEST_START_BYTE || head.nTotalSize != nTotalSize )
	{
		Textout("download.bin Format ERROR");
		fclose(f);
		DoSystem("rm /tmp/download.bin");
		return;
	}

	int i = 0, k = 0;
	int nItemCount = head.nFileItemCount;
	int nPos1 = sizeof(TDownloadFileHead);
	int nPos2 = sizeof(TDownloadFileHead) + nItemCount * sizeof(TDownloadFileItem);
	char command[128] = {0};
	TDownloadFileItem item;	
	FILE *f2 = NULL;
	for ( i = 0; i < nItemCount; i++, nPos1 += sizeof(TDownloadFileItem) )
	{
		fseek( f, nPos1, SEEK_SET );
		fread(&item, 1, sizeof(TDownloadFileItem), f);
		switch(item.nOperator)
		{
			case DOP_KILL:		//killall:
				sprintf(command, "killall %s", item.szPath);
				Textout("Do-->[%s]", command);
				DoSystem(command);
				break;
			case DOP_MOVE:		//rm -rf 
				sprintf(command, "rm -rf %s", item.szPath);
				Textout("Do-->[%s]", command);
				DoSystem(command);
				break;
			case DOP_MKDIR:		//mkdir -p 
				sprintf(command, "mkdir -p %s", item.szPath);
				Textout("Do-->[%s]", command);
				DoSystem(command);
				break;
			case DOP_BACKUP:	//copy this file to /tmp/filename, then restore it
				sprintf(command, "cp %s /tmp/backup.%d.bak", item.szPath, item.nFileSize);
				Textout("Do-->[%s]", command);
				DoSystem(command);
				break;
			case DOP_RESTORE:	//restore it
				sprintf(command, "mv -f /tmp/backup.%d.bak %s", item.nFileSize, item.szPath);
				Textout("Do-->[%s]", command);
				DoSystem(command);
				break;

			case DOP_REBOOT:
				goto REBOOT_NOW;
				
			case DOP_REPLACE:	//replace current file, then chmod a+x
			case DOP_REPLACEMOD:
				fseek( f, nPos2, SEEK_SET );
				nPos2 += item.nFileSize;
				f2 = fopen("/tmp/tempfile", "wb");
				if ( f2 != NULL )
				{
					int nWriteBytes = 0;
					int nTotalWriteBytes = 0;
					char pbuffer[1024];
					while ( nTotalWriteBytes < item.nFileSize )
				    {
				        nWriteBytes = fread( pbuffer, 1, 1024, f );
				        fwrite( pbuffer, 1, nWriteBytes, f2 );
				        nTotalWriteBytes += nWriteBytes;
				    }
					fclose(f2);
					sprintf(command, "mv -f /tmp/tempfile %s", item.szPath);
					Textout("Do-->[%s]", command);
					DoSystem(command);

					if ( item.nOperator == DOP_REPLACEMOD )
					{
						sprintf(command, "chmod a+x %s", item.szPath);
						Textout("Do-->[%s]", command);
						DoSystem(command);
					}
				}
				else
				{
					Textout("Replace File [%s] ERROR", item.szPath);
					fclose(f);
					DoSystem("rm /tmp/download.bin");
					return;
				}
				break;
		}
	}
	
	/////////////////////////////////////////////////////
	//
	//Process Over.....
	//
	/////////////////////////////////////////////////////
	
REBOOT_NOW:

	fclose(f);
	Textout("Download Over, Success...");
	
	DoSystem("cp /tmp/gps.txt /system/www/gps.txt");	//Silice Reboot
	
	sleep(1);
	Textout("Download Success, So Reboot....");
    SetRebootCgi();
}
Esempio n. 16
0
//Dhcp Route start
void DhcpRouteStart( void )
{
    DoSystem( "udhcpd -fS /tmp/udhcpd.conf &" );
}
Esempio n. 17
0
void customFtpSend(char AlarmType,
	char* filename1,
	char* filename2,
	char* filename3)
{
	int     iRet = 0;
    char param[4];
	char target_filename1[256];
	char target_filename2[256];
	char target_filename3[256];
	int nFileNameLen = 0;

	char    cmd[128];
    FILE*	fp = NULL;
    struct stat     stStat;

    if ( bparam.stFtpParam.szFtpSvr[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpUser[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpPwd[0] == 0x00 )
    {
        return -1;
    }

    iRet = access( "/tmp/ftpupdate3.sh", X_OK );
    if ( iRet )
    {
        Textout("file exist, rm -f /tmp/ftpupdate3.sh");
        DoSystem( "rm -f /tmp/ftpupdate3.sh" );
    }

    fp = fopen( "/tmp/ftpupdate3.sh", "wb" );
    if ( fp == NULL )
    {
        printf( "ftp config failed\n" );
        return -1;
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "/system/system/bin/ftp -n<<!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "open %s %d\n", bparam.stFtpParam.szFtpSvr, bparam.stFtpParam.nFtpPort );
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "user %s %s\n", bparam.stFtpParam.szFtpUser, bparam.stFtpParam.szFtpPwd );
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "binary\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    if ( bparam.stFtpParam.byMode == 1 ) 	//passive
    {
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "pass\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }


#if 1//def	CREATE_FTP_SUBDIRECTORY

    //filename1=[/tmp/20130131110813_4.jpg]
    if ( 1 )
    {
		char filename[256];
        char szTemp[128];
        nFileNameLen=strlen(filename1);
		if ( nFileNameLen == 0 )
		{
			Textout("No File, return");
			return 1;
		}

        memset(filename, 0, 256);
        strcpy(filename, filename1);

        memset( szTemp, 0, 128 );
        memcpy( szTemp, filename + 5, 8 );
		Textout("FileName = {%s}", filename);
        Textout( "FTP Sub Directory = [%s]", szTemp );
        memset( cmd, 0x00, 128 );

        sprintf( cmd, "mkdir %s\n", szTemp );

        fwrite( cmd, 1, strlen( cmd ), fp );
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "cd %s\n", szTemp );
        fwrite( cmd, 1, strlen( cmd ), fp );

		///////

        memset( szTemp, 0, 128 );
		sprintf(szTemp, "%s", bparam.stIEBaseParam.dwDeviceID);
        Textout( "FTP Sub Directory = [%s]", szTemp );
        memset( cmd, 0x00, 128 );

        sprintf( cmd, "mkdir %s\n", szTemp );

        fwrite( cmd, 1, strlen( cmd ), fp );
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "cd %s\n", szTemp );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

	memset(target_filename1, 0, 256);
	memset(target_filename2, 0, 256);
	memset(target_filename3, 0, 256);

    if ( filename1[0] != 0 )
    {
		sprintf(target_filename1,
			"%c"
			"%c%c%c%c%c%c"
			"%c%c%c%c%c%c"
			"%c"
			"%c.jpg",
			( AlarmType == GPIO_ALARM || AlarmType == MOTION_ALARM ) ? 'A' : 'P',
			filename1[7],
			filename1[8],
			filename1[9],
			filename1[10],
			filename1[11],
			filename1[12],
			filename1[13],
			filename1[14],
			filename1[15],
			filename1[16],
			filename1[17],
			filename1[18],
			'1',	//0:SD,1:FTP,2:EMAIL
			filename1[nFileNameLen - 5]);
		Textout("target_filename 1 = [%s]", target_filename1);
		//Textout("filename1 = [%s]", filename1);
		//Textout("", );
    }
	if ( filename2[0] != 0 )
    {
		sprintf(target_filename2,
			"%c"
			"%c%c%c%c%c%c"
			"%c%c%c%c%c%c"
			"%c"
			"%c.jpg",
			( AlarmType == GPIO_ALARM || AlarmType == MOTION_ALARM ) ? 'A' : 'P',
			filename2[7],
			filename2[8],
			filename2[9],
			filename2[10],
			filename2[11],
			filename2[12],
			filename2[13],
			filename2[14],
			filename2[15],
			filename2[16],
			filename2[17],
			filename2[18],
			'1',	//0:SD,1:FTP,2:EMAIL
			filename2[nFileNameLen - 5]);
		Textout("target_filename 2 = [%s]", target_filename2);
    }
	if ( filename3[0] != 0 )
    {
		sprintf(target_filename3,
			"%c"
			"%c%c%c%c%c%c"
			"%c%c%c%c%c%c"
			"%c"
			"%c.jpg",
			( AlarmType == GPIO_ALARM || AlarmType == MOTION_ALARM ) ? 'A' : 'P',
			filename3[7],
			filename3[8],
			filename3[9],
			filename3[10],
			filename3[11],
			filename3[12],
			filename3[13],
			filename3[14],
			filename3[15],
			filename3[16],
			filename3[17],
			filename3[18],
			'1',	//0:SD,1:FTP,2:EMAIL
			filename3[nFileNameLen - 5]);
		Textout("target_filename 3 = [%s]", target_filename3);
    }

#endif

    /* END:   Added by wupm, 2013/2/1 */
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "lcd /tmp\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

	/*
    if ( test == 0x01 )
    {
        FtpFileTest();
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "put ftptest.txt\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

    else*/
    {
        char    localfile[128];
        //char   filename2[128];

		if ( filename1[0] != 0 )
		{
	        memset( localfile, 0x00, 128 );
	        memcpy( localfile, filename1 + 5, strlen( filename1 ) - 5 );
	        //memset( filename2, 0x00, 128 );
	        //memcpy( filename2, capfilename + 5, strlen( capfilename ) - 5 );

	        memset( cmd, 0x00, 128 );
	        sprintf( cmd, "put %s %s\n", localfile, target_filename1);
			Textout("COMMAND = [%s]", cmd);
	        fwrite( cmd, 1, strlen( cmd ), fp );
		}

		if ( filename2[0] != 0 )
		{
	        memset( localfile, 0x00, 128 );
	        memcpy( localfile, filename2 + 5, strlen( filename2 ) - 5 );
	        //memset( filename2, 0x00, 128 );
	        //memcpy( filename2, capfilename + 5, strlen( capfilename ) - 5 );

	        memset( cmd, 0x00, 128 );
	        sprintf( cmd, "put %s %s\n", localfile, target_filename2);
			Textout("COMMAND = [%s]", cmd);
	        fwrite( cmd, 1, strlen( cmd ), fp );
		}

		if ( filename3[0] != 0 )
		{
	        memset( localfile, 0x00, 128 );
	        memcpy( localfile, filename3 + 5, strlen( filename3 ) - 5 );
	        //memset( filename2, 0x00, 128 );
	        //memcpy( filename2, capfilename + 5, strlen( capfilename ) - 5 );

	        memset( cmd, 0x00, 128 );
	        sprintf( cmd, "put %s %s\n", localfile, target_filename3);
			Textout("COMMAND = [%s]", cmd);
	        fwrite( cmd, 1, strlen( cmd ), fp );
		}
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "close\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "bye\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

	/* BEGIN: Added by wupm, 2013/4/25 */
    memset( cmd, 0x00, 128 );
	//sprintf(cmd, "rm -f %s", capfilename);
	sprintf(cmd, "rm -f %s", filename1);
    fwrite( cmd, 1, strlen( cmd ), fp );

    memset( cmd, 0x00, 128 );
	//sprintf(cmd, "rm -f %s", capfilename);
	sprintf(cmd, "rm -f %s", filename2);
    fwrite( cmd, 1, strlen( cmd ), fp );

	memset( cmd, 0x00, 128 );
	//sprintf(cmd, "rm -f %s", capfilename);
	sprintf(cmd, "rm -f %s", filename3);
    fwrite( cmd, 1, strlen( cmd ), fp );

    fclose( fp );
    iRet = access( "/tmp/ftpupdate3.sh", X_OK );
    if ( iRet )
    {
        DoSystem( "chmod a+x /tmp/ftpupdate3.sh" );
    }

    /*return 0;
    if ( -1 == iRet )
    {
        return iRet;
    }*/

    // (iRet == 0){
    ftp_dbg( "alarm upload41\n", 0 );
    //gnal(SIGCHLD,SIG_IGN);
    //gnal(SIGCHLD,SIG_DFL);
    //FtpWrite(param,4);
    iRet = DoSystem( "/tmp/ftpupdate3.sh" );
    ftp_dbg( "alarm upload42\n", 0 );
    //}
    //ftpunlock();
    return iRet;
}
Esempio n. 18
0
int FtpConfigAlarm( char test, char* capfilename, char* filename )
{
    char    cmd[128];
    FILE*	fp = NULL;
    struct stat     stStat;
    int iRet;
	int flag = 0;

    if ( bparam.stFtpParam.szFtpSvr[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpUser[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpPwd[0] == 0x00 )
    {
        return -1;
    }

    fp = fopen( "/tmp/ftpupdate.sh", "wb" );

    if ( fp == NULL )
    {
        printf( "ftp config failed\n" );
        return -1;
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "/system/system/bin/ftp -n<<!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "open %s %d\n", bparam.stFtpParam.szFtpSvr, bparam.stFtpParam.nFtpPort );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "user %s %s\n", bparam.stFtpParam.szFtpUser, bparam.stFtpParam.szFtpPwd );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "binary\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    if ( bparam.stFtpParam.byMode == 1 ) 	//passive
    {
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "pass\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }
#ifdef CUSTOM_DIR
	char sub_temp[ 128 ];
	memset(sub_temp, 0, 128);
	sprintf(sub_temp, "%s/%s", bparam.stFtpParam.szFtpDir,bparam.stIEBaseParam.dwDeviceID); 
	//strcpy(sub_temp, bparam.stFtpParam.szFtpDir);

    flag = sub_dir(fp,sub_temp);
	if(flag){
   		memset( cmd, 0x00, 128 );
    	sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir );
    	fwrite( cmd, 1, strlen( cmd ), fp );
	}
#else
		memset( cmd, 0x00, 128 );
    	sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir );
    	fwrite( cmd, 1, strlen( cmd ), fp );

#endif

#ifdef	CREATE_FTP_SUBDIRECTORY

    /* BEGIN: Added by wupm, 2013/2/1   Version:6 */
    //filename=[/tmp/00_3a_58_19_3E_00__1_20130131110813_4.jpg]
    //[         /tmp/00_02_2A_F3_08_DC_JWEV-007533-LVFBH_0_20130425053328_8.jpg
    if ( 1 )
    {
        int nFileNameLen = 0;
        char szTemp[128];
        memset( szTemp, 0, 128 );

	/* BEGIN: Added by wupm, 2013/6/14 */
	#ifdef	FTP_SUBDIRECTORY_UID_OR_MAC
		if ( bparam.stIEBaseParam.dwDeviceID[0] == 0 )
		{
			memcpy(szTemp, bparam.stIEBaseParam.szMac, 17);
			szTemp[2] = '-';
			szTemp[5] = '-';
			szTemp[8] = '-';
			szTemp[11] = '-';
			szTemp[14] = '-';
		}
		else
		{
			/* BEGIN: Modified by wupm, 2013/7/1 */
			//strcpy(szTemp, bparam.stIEBaseParam.dwDeviceID[0]);
			strcpy(szTemp, bparam.stIEBaseParam.dwDeviceID);
		}
        Textout( "FTP Sub Directory = [%s]", szTemp );
        memset( cmd, 0x00, 128 );
	#else
		/* BEGIN: Modified by wupm, 2013/4/25 */
        //nFileNameLen = strlen( szTemp );
        nFileNameLen = strlen( filename );

        memcpy( szTemp, filename + nFileNameLen - 20, 8 );
		Textout("FileName = {%s}", filename);
		Textout("cap File name = [%s]", capfilename);
        Textout( "FTP Sub Directory = [%s]", szTemp );
        memset( cmd, 0x00, 128 );
	#endif

		/* BEGIN: Modified by wupm, 2013/4/25 */
        //sprintf( cmd, "mkdir -p %s\n", szTemp );
        sprintf( cmd, "mkdir %s\n", szTemp );

        fwrite( cmd, 1, strlen( cmd ), fp );
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "cd %s\n", szTemp );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

#endif

    /* END:   Added by wupm, 2013/2/1 */
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "lcd /tmp\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    if ( test == 0x01 )
    {
        FtpFileTest();
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "put ftptest.txt\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

    else
    {
        char    filename1[128];
        char   filename2[32];
        memset( filename1, 0x00, 128 );
        memcpy( filename1, filename + 5, strlen( filename ) - 5 );
        memset( filename2, 0x00, 32 );
        memcpy( filename2, capfilename + 5, strlen( capfilename ) - 5 );
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "put %s %s\n", filename2, filename1 );
		Textout("COMMAND = [%s]", cmd);
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "close\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "bye\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

	/* BEGIN: Added by wupm, 2013/4/25 */
    /* BEGIN: Deleted by Baggio.wu, 2013/7/19 */
    //move to where file create
    #if 0
    memset( cmd, 0x00, 128 );
	sprintf(cmd, "rm -f %s", capfilename);
    fwrite( cmd, 1, strlen( cmd ), fp );
    #endif
    
    fclose( fp );
    iRet = access( "/tmp/ftpupdate.sh", X_OK );

    if ( iRet )
    {
        DoSystem( "chmod a+x /tmp/ftpupdate.sh" );
    }

    return 0;
}
Esempio n. 19
0
int FtpConfig( char test, char* filename )
{
    char    cmd[128];
    FILE*	fp = NULL;
    struct stat     stStat;
    int iRet;
	int flag = 0;

    if ( bparam.stFtpParam.szFtpSvr[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpUser[0] == 0x00 )
    {
        return -1;
    }

    if ( bparam.stFtpParam.szFtpPwd[0] == 0x00 )
    {
        return -1;
    }

    fp = fopen( "/tmp/ftpupdate1.sh", "wb" );

    if ( fp == NULL )
    {
        printf( "ftp config failed\n" );
        return -1;
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "/system/system/bin/ftp -n<<!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "open %s %d\n", bparam.stFtpParam.szFtpSvr, bparam.stFtpParam.nFtpPort );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "user %s %s\n", bparam.stFtpParam.szFtpUser, bparam.stFtpParam.szFtpPwd );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "binary\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    if ( bparam.stFtpParam.byMode == 1 ) 	//passive
    {
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "pass\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }
#ifdef CUSTOM_DIR

	char sub_temp[ 128 ];
	memset(sub_temp, 0, 128);
	//strcpy(sub_temp, bparam.stFtpParam.szFtpDir);
	sprintf(sub_temp, "%s/%s", bparam.stFtpParam.szFtpDir,bparam.stIEBaseParam.dwDeviceID); 

    flag = sub_dir(fp,sub_temp);
	if(flag){
		memset( cmd, 0x00, 128 );
    	sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir );
    	fwrite( cmd, 1, strlen( cmd ), fp );
	}
#else
	memset( cmd, 0x00, 128 );
    sprintf( cmd, "cd %s\n", bparam.stFtpParam.szFtpDir );
    fwrite( cmd, 1, strlen( cmd ), fp );

#endif
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "lcd /tmp\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );

    if ( test == 0x01 )
    {
        FtpFileTest();
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "put ftptest.txt\n" );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

    else
    {
        char    filename1[128];
        memset( filename1, 0x00, 128 );
        memcpy( filename1, filename + 5, strlen( filename ) - 5 );
        memset( cmd, 0x00, 128 );
        sprintf( cmd, "put %s\n", filename1 );
        fwrite( cmd, 1, strlen( cmd ), fp );
    }

    memset( cmd, 0x00, 128 );
    sprintf( cmd, "close\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "bye\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    memset( cmd, 0x00, 128 );
    sprintf( cmd, "!\n" );
    fwrite( cmd, 1, strlen( cmd ), fp );
    fclose( fp );
    iRet = access( "/tmp/ftpupdate1.sh", X_OK );

    if ( iRet )
    {
        DoSystem( "chmod a+x /tmp/ftpupdate1.sh" );
    }

    return 0;
}
Esempio n. 20
0
//init Dhcp Route
void InitDhcpRoute( void )
{
    DhcpServerConfig();
    DoSystem( "mkdir -p /var/lib/misc" );
    DhcpReleaseFile();
}