Cross-platform Data Synchronization under enterprise security policies1 Introduction The benefits of the B-S development model have been discussed a lot, and the application of Intranet automation tools in modern enterprise office automation is becoming more and more popular. With the development of modern enterprises in an international and group direction, the division of labor among various departments of modern enterprises has become increasingly refined and distributed globally. The trend of refined division of labor and global distribution makes it difficult to find a complete and shareable data between different departments and a tool suitable for independent management between different departments, when developing their own intranet automation tools, each department selects its own intranet publishing platform based on its own characteristics and resource conditions. On the one hand, the original data publishing platform of the Department affects the Department's choice of the Intranet publishing platform to a certain extent; on the other hand, while choosing its own intranet publishing platform, departments that share data with other departments also select their own data publishing platforms. At the same time, the collaboration between various departments in modern enterprises is getting closer and closer, and the data that needs to be accessed between different departments can be updated synchronously, or at least data can be synchronized within a certain interval. Although most database products have their own TCP/IP-based access methods, under the enterprise's security policy, each department usually changes the configuration of access methods for IP Ports, and develop their own internal data access tools; some departments seldom disclose the user name and password for database access even if they use the default settings of database products. Therefore, direct cross-platform Data Access and synchronization between departments using database client access tools is almost impossible. This article is a summary of the solutions to the data synchronization problem that I encountered during the design and development of the Intranet automation tool during my internship at Motorola China Software Center. 2 cross-platform Data Synchronization Solutions Before introducing common cross-platform Data Synchronization methods, it is necessary to briefly introduce the design purpose and status of the developed Intranet automation tool. The developed Intranet automation tool is an ASP application running on the Windows NT platform. It is designed to track the change request tracking (Change Request tracking) on the local Windows NT platform) access database and rational clearddts (Distributed defects tracking system) with Cr tracking information on the U.S. UNIX platform, distributed Error Tracking System. (DDTs) databases are synchronously updated to implement local web access and tracking of CR information. The functions required during data synchronization include obtaining new data from the DDTs database for addition of Access database and obtaining the field values specified in the DDTs database for updating the ACCESS database. Before taking over further development of the Intranet automation tool, the project team has an intranet tool for Cr tracking, which can be used for Cr input, modification, query, and list statistics. This intranet tool requires Cr-related personnel to take the initiative to use the DDTs tool to query CR information, and enter the information on the web entry page to the local database on the web server, for CR tracking. The data synchronization method used by this Intranet tool is to use the DDTs data access tool for manual data synchronization. The data synchronization method is simple, but complicated. In particular, similar SQL statements need to be input repeatedly during queries, making this work boring. Strictly speaking, this is not a cross-platform Data Synchronization solution. Considering that most database products have their own TCP/IP-based access methods, it may be a simple method for cross-platform data synchronization to require relevant departments to Open Database IP port access and restricted user names and passwords to intranet developers. To use this method, you only need to install the corresponding ODBC driver on the Windows NT Web server, and then use ADO programming when designing ASP programs, you can perform cross-platform Data Synchronization by simply querying, adding, and modifying data. The design is very simple. However, this method has two problems: first, when the user name and password for database IP port access are opened, it brings security risks to the department where the database is located, once the Web server is attacked and the user name and password are stolen, the Open Database is at the risk of being attacked; second, some departments use database-based tools developed by third parties (such as DDTs tools). Their departments do not have database management permissions, so they cannot add user names and assign permissions. During development, cross-platform Data Synchronization Based on socket communication is adopted. Three cross-platform Data Synchronization Methods Based on socket communication The cross-platform Data Synchronization Method Based on socket communication adopts the concept of Client/Server. The socket server responsible for listening and the Socket Client responsible for connection are developed on computers of different platforms in different departments. Take the field value specified in the DDTs database as an example. When the client and the server are connected successfully, the client sends the related keyword CR and the field name to be obtained to the server, the server obtains the field data required by the client by calling the corresponding commands of the DDTs tool and sends it to the client. The socket server runs on the unix host in the United States where DDTs is located and adopts multi-process programming. The key code for implementing socket listening, connection, and data transmission is as follows (taking obtaining the field value specified in the DDTs database as an example ): Void fireman ()/* clear dead processes */ { Signal (sigchld, fireman ); While (waitpid (-1, null, wnohang)> 0) ; } Int main () { /* ...... Variable declaration and initialization */ Signal (sigchld, fireman);/* specify the signal processing handle to clear dead processes */ If (sockfd = socket (af_inet, sock_stream, 0) <0) Return printf ("can not open TCP socket! "); Bzero (char *) & serv_addr, sizeof (serv_addr )); Serv_addr.sin_family = af_inet; Serv_addr.sin_addr.s_addr = htonl (inaddr_any ); Serv_addr.sin_port = htons (portnum);/* specify the port number */ If (BIND (sockfd, (struct sockaddr *) & serv_addr, sizeof (serv_addr) <0) Return printf ("bind socket error! "); Listen (sockfd, 5 ); For (; { If (newsockfd = accept (sockfd) <0)/* establish a connection */ { If (errno = eintr)/* eintr might happen on accept (),*/ Continue;/* try again */ Return printf ("can not accept newsocket");/* bad */ Exit (1 ); } If (childpid = fork () = 0) { Close (sockfd ); Socketopen = 1; While (socketopen = 1 ){ Readn (newsockfd, Buf, 10 ); Buf [10] = 0; Strcpy (cr_no, Buf ); Writen (newsockfd, "OK", 2 ); Readn (newsockfd, Buf, 3 ); Buffer [3] = 0; Len = atoi (BUF ); Writen (newsockfd, "OK", 2 ); Readn (newsockfd, Buf, Len ); Buf [Len] = 0; Strcpy (field_name, Buf);/* obtain socket request data */ Strcpy (CMD, home ); Strcat (CMD, "get_ddts_field defects "); Strcat (CMD, cr_no ); Strcat (CMD ,""); Strcat (CMD, field_name ); PTR = popen (CMD, "R");/* run the query script */ Memset (BUF, 0, bufsiz ); I = fread (BUF, bufsiz, 1, PTR ); If (strlen (BUF) = 0) Strcpy (BUF, "not exist! "); Writen (newsockfd, Buf, strlen (BUF)-1);/* Send query results */ Pclose (PTR ); } Exit (0 ); } Else Close (newsockfd ); Continue; } } In the code, the processing of eintr errors that are generated when a connection is established and the processing of sigchld signals is critical, the process will be frozen after the connection cannot be closed for multiple times. During the development process, use the popen function to run a Perl script get_ddts_field and send the result to the program through the pipeline. The script uses the DDTs tool for database query. This method makes full use of the flexibility of existing tools and the Perl language. To ensure that the listening program is always running, we add a command to the crontab of the UNIX host so that the system checks whether the listening program scksvr is running every minute, and restart the instance if it is interrupted due to system exceptions. Use the crontab command to add a command to the system crontab to execute a specific command every minute as follows: > Crontab * ***/Home/ANT1/a16635/bin/start_scksvr.sh For the crontab command usage, refer to the Unix help documentation. Check whether the listening program scksvr is running the shell script start_scksvr.sh as follows: #! /Bin/sh /Bin/PS-ef-O comm | grep "^/. */scksvr">/dev/null 2>/dev/null If [$? -Ne 0] Then /Home/ANT1/a16635/bin/scksvr &>/dev/null 2>/dev/null Fi The client runs on the Windows NT platform and uses the Microsoft Visual C ++ ATL (Active Template Library) template com development and MFC socket programming to form a COM component. By using COM components, you can avoid using the Winsock ActiveX control in multiple ASP files for programming and code reuse. The COM component is also used for some VBScript scripts that use the COM component and access the local database for data synchronization. Use the scheduale server of Windows NT to regularly run these VBScript scripts to implement timed and automatic data synchronization. In Visual C ++, the COM component development process using the ATL template is as follows: in the Visual C ++ create dialog box, select the atl com Appwizard in the projects panel, enter the project name and press OK to enter the ATL COM Appwizard dialog box. In the ATL COM Appwizard dialog box, select support MFC to enable socket programming using the csocket class. Create a full control using the new ATL object in the Insert menu in the generated ATL Project. Visual C ++ automatically generates an interface definition IDL file and a class corresponding to the full control. Right-click the newly created full control in classview to add a method or attribute. Visual C ++ automatically adds the corresponding interface to the IDL file, add the description and definition of the implementation of reading and writing methods or attributes to the corresponding class. The following code adds methods or attributes to read and write. For socket programming using the MFC csocket class, refer to the implementation code of the Connect Method and the getcrfield method of crtool: Stdmethodimp ccrtool: connect () { Afx_manage_state (afxgetstaticmodulestate ()) Uses_conversion; // String Conversion If (m_bconnected) Return s_ OK; If (! Afxsocketinit ()) { M_bconnected = false; Return s_ OK; } M_psocket = new csocket (); If (! M_psocket-> Create ()) { Delete m_psocket; M_psocket = NULL; M_bconnected = false; Return s_ OK; } While (! M_psocket-> connect (ole2a (m_strhost), m_nport )) { Delete m_psocket; M_psocket = NULL; M_bconnected = false; Return s_ OK; } M_bconnected = true; Return s_ OK; } Stdmethodimp ccrtool: getcrfield (variant * pcrno, short lengthoffieldname, variant * pfieldname, variant * pfieldvalue) { Afx_manage_state (afxgetstaticmodulestate ()) Uses_conversion; // String Conversion Char sendbuffer [4], receivebuffer [1, 4097]; Memset (sendbuffer, 0, 4 ); Memset (receivebuffer, 0, 4097 ); // Send the crno M_psocket-> send (ole2a (pcrno-> bstrval), 10 ); M_psocket-> receive (receivebuffer, 2 ); // Length of fieldname Sprintf (char *) sendbuffer, "% 3d", lengthoffieldname ); M_psocket-> send (sendbuffer, 3 ); M_psocket-> receive (receivebuffer, 2 ); // Send the fieldname M_psocket-> send (ole2a (pfieldname-> bstrval), lengthoffieldname ); // Receive the fieldvalue Memset (receivebuffer, 0, 4097 ); M_psocket-> receive (receivebuffer, 4096 ); Pfieldvalue-> bstrval = sysallocstring (a2ole (receivebuffer )); /* A2ole allocates memory off the stack, which is Automatically freed when your method exits. You need to use sysallocstring. */ Return s_ OK; } Use variant * type variables to pass the getcrfield return value because only variant type variables in ASP and VBScript allow the method passed to the COM component by reference. In addition, you should use sysallocstring to allocate memory when returning results. 4 Conclusion This article analyzes the problems faced by cross-platform Data Synchronization under enterprise security policies and several data synchronization methods, based on the analysis of the advantages and disadvantages of manual synchronization and open database access IP port, a data synchronization solution based on socket communication is proposed. During data synchronization based on socket communication, A Socket Client COM component is designed using the Visual C ++ ATL template based on the needs of the Intranet automation tool. This article briefly introduces how to use the Visual C ++ ATL template for COM component development in windows and the MFC csocket class for socket programming. This article also provides tips for using the ps command and grep command in UNIX to determine whether a specific program is running or how to use the crontab command to automatically run a specific program on a regular basis, which has a certain reference value. References: 1. how to program socket, http://cgisss.533.net/learn/others/socket.htm 2. Active Template Library (ATL) reference, msdn, Microsoft 3. csocket, Microsoft Foundation Class Library, msdn, Microsoft Data Synchronization over different platforms under enterprise security policy Geng changyu1, Zhu yunwen2, Hong jiandong2, Ju ti1 (1. Nanjing University of Post and Telecommunications, Nanjing Jiangsu, 210003; 2. Software Center, Motorola, China, Nanjing Jiangsu, 210029) Abstract: This paper discusses methods of data synchronization over different platforms. then it gives an example to illuminate the application of Implementation of Data Synchronization over different platforms under enterprise security policy in the design of Intranet automatic IC tools. Key words: enterprise security policy, Intranet automatic tools, socket communication, Componential Programming Author profile: Yan Changyu, a master's degree in computer science and technology from Nanjing Post and Telecommunications students. His research direction is Rapid Acquisition and Processing of computer data; Zhu yunwen, Senior Programmer of Motorola China Software Center; Hong jiandong, system analyst at Motorola China Software Center; he is a professor at the Department of Computer Science and Technology of Nanjing Post and Telecommunications students and a Master's degree tutor. His research direction is the application of computer in TMN and the Rapid Acquisition and Processing of computer data.
Author member name: kingmario |