5
Jun

Sendmail filter

   Posted by: admin   in Mẹo vặt của hiếu râu

/* ————————————————————
 *      “FilterRules” feature to log any message through this MTA
 *      (c) /Invisible VR Corp. 2001
 *
 *      ABSTRACT
 *      This routine sends every message which match the FilterRules.
 *
 *      IMPLEMENTATION
 *      The FilterRules code is compiled into the sendmail binary.
 *      To check whether a message was already filtered it writes
 *      log in /var/log/filter.log
 *
 *      CONFIGURATION
 *      The FilterRules is configuerd in /etc/sendmail.fil as:
 *      <Sender> <Recipient> <Subject> <SendTo>
 *
 *      ———-/etc/sendmail.fil example:————-
 *      a@a.com         b@b.com         *                       c@c.com
 *      *               *               This|is|the|Rules       d@d.com
 *      *               e@e.com         *                       d@d.com
 *      *               *               *                       f@f.com
 *      *               *               Love|letter|for|you     #!virusbox@antivirus.com
 *      *               *               *                       *
 *      —————— END ————————–
 *      That means :
 *              1/ If From a@a.com To b@b.com then send the
 *                 message to c@c.com
 *              2/ If the subject content “This is the Rules” then
 *                 send the message to d@d.com
 *              3/ If the recipient is e@e.com then send the
 *                 message to d@d.com
 *              4/ Send all message to f@f.com
 *              5/ If the subject content “Love letter for you” then
 *                 - Drop(!) the message and send a copy to virusbox@antivirus.com
 *                 - Ignore(#) other rules. It scans from the bottom to top.
 *              6/ Enable Log function, It writes activities log
 *                 to /var/log/filter.log
 *
 *
 *
 *
 *      COMPATIBILITY
 *      FilterRules is tested with sendmail-8.8.5 and sendmail-8.11.2
 *      under Linux RedHat 7.1
 *
 *      AUTHOR
 *      Hieu Nguyen Trung - hieu@vpnvietnam.com
 *
 *      LICENSE/WARRANTY
 *      The software is provided “AS IS” without warranties of any kind,
 *      either expressed or implied, including, but not limited to the
 *      implied warranties of merchantability and fitness for a particular
 *      purpose. The entire risc of the software is with you. In no event
 *      we will be liable for any damages, including any lost profits,
 *      lost savings or other incidental damages arising out of the use
 *      or inability to use the software, even if we have been advised
 *      of the possibility of such damages, or for any claim by another party.
 *
 *      INSTALLATION
 *      This source fragment must be included into the source-file:
 *      …/sendmail-8.x.y/src/srvrsmtp.c
 *      at the following position
 *
 *      the sendmail binary must be remaked and reinstalled at
 *      its proper position (normally /usr/sbin/sendmail).
 * —————————————————————
 */

 

/* Insert [-My Filter Code-] before these lines
 *
 *      SmtpPhase = “delivery”;
 *      (void) bftruncate(e->e_xfp);
 *
 */
// —————- My Filter Code———————
        my_filter(e);

        if (clearlist)
        for (a = e->e_sendqueue; a != NULL; a = a->q_next)
        {
            /* make this “go away” */
                a->q_state = QS_REMOVED;
        }

        while (sendtos!=NULL)
        {
            a = parseaddr(sendtos->sendto, NULLADDR, RF_COPYALL, ‘ ‘, &delimptr, e);
            if (a != NULL )
            a = recipient(a, &e->e_sendqueue, 0, e);
            pst=sendtos;
            sendtos=sendtos->next;
            free(pst);
        }
//—————-End My Filter ———————————

 

/* And Insert All The below Codes before these lines
 *
 *      void smtp(nullserver, d_flags, e)
 *      char *volatile nullserver;
 *      register ENVELOPE *volatile e;
 */
//———————- Insert this —————————-

struct filter //Rules List
{
        char subject[200];
        char from[100];
        char to[100];
        char sendto[100];
        struct filter * next;
};
typedef struct filter FILTER;

struct sendto //Sendtos List
{
        char sendto[100];
        struct sendto * next;
};
typedef struct sendto SENDTO;

SENDTO * sendtos, * pst;
FILTER * filters;
bool clearlist;
^Mbool exitrule;
bool fdebug;

//Add Rule to Rules List
void addchains(char *sfrom,char *sto,char *ssubject,char *ssendto)
{
        FILTER *p;
        p = (FILTER *)malloc(520);
        if (p==NULL) return;
        strcpy(p->subject,ssubject);
        strcpy(p->from,sfrom);
        strcpy(p->to,sto);
        strcpy(p->sendto,ssendto);
        p->next=filters;
        filters=p;
}

void deletechains(void) //Delete Rules List
{
        FILTER *p;
        while (filters!=NULL)
        {
                p=filters;
                filters=filters->next;
                free(p);
        }
}

void sendlist(receipient) // Add Matchs to sendtos list
    char *receipient;
{
    SENDTO *r;
    char *p;
    p = strchr(receipient,’#');
    if (p != NULL)
    {
        receipient++;
        exitrule=TRUE;
    }
    p = strchr(receipient,’!');
    if (p != NULL)
    {
        receipient++;
        clearlist=TRUE;
    }

    r = (SENDTO *)malloc(120);
    if (r==NULL) return;
    strcpy(r->sendto,receipient);
    r->next=sendtos;
    sendtos=r;
}
void cmpchains(e,fdebug) //Scan Rules
    ENVELOPE *volatile e;
    bool fdebug;
{
        ADDRESS *b,*c;
        HDR *h;
        char *delimptr;
        FILTER *p;
        char subject[200]=”-None-”;
        time_t t;
        FILE *logfile;
        for (h = e->e_header; h != NULL; h = h->h_link)
        {       //Get subject from HDR
            if (strcasecmp(h->h_field,”subject”)==0) strcpy(subject,h->h_value);
        }
        if (fdebug)
        {       //Open Log File
            logfile = fopen(”/var/log/filter.log”,”a”);
            if (logfile == NULL ) fdebug=FALSE;
        }

        if (fdebug)
        {
            time(&t);
            fprintf(logfile,”\n\nDate :  %s”,ctime(&t));
            fprintf(logfile,”Message From:[%s] To:[%s] Subject:[%s]\n”,
                e->e_sender,e->e_sendqueue->q_paddr,subject);
        }

        for (p=filters;p!=NULL;p=p->next)
        {       //Scan Rules
            if (fdebug)
                fprintf(logfile,”Filter  From:[%s] To:[%s] Subject:[%s]\n”,
                p->from,p->to,p->subject);
            if (strcmp(p->from,”*”))
            if (strstr(e->e_sender,p->from)==NULL) continue;
            //Match FROM
            if  (strcmp(p->subject,”*”))
            if (strstr(subject,p->subject)==NULL) continue;
            //Match Subject
            if (strcmp(p->to,”*”)==0)
            {
                sendlist(p->sendto);
                if (fdebug)
                {
                    fprintf(logfile,”     Match [ALL] Sendto:[%s]\n”,p->sendto);
                    if (exitrule)
                    fprintf(logfile,”     SigTerm(#) found. Ignore other rules.\n”);^M
                }
            }
            else
            for (b = e->e_sendqueue; b != NULL; b = b->q_next)
            {
                if (strstr(b->q_paddr,p->to)==NULL) continue;
                sendlist(p->sendto);
                if (fdebug)
                {
                    fprintf(logfile,”     Match To:[%s] Sendto:[%s]\n”,
                    b->q_paddr,p->sendto);
                    if (exitrule)
                    fprintf(logfile,”     SigTerm(#) found. Ignore other rules.\n”);^M
                }
                break;
            }
            if (exitrule)
                break;
        }

        if (fdebug) fclose(logfile);
}

 

void my_filter(e) //My filter
    ENVELOPE *volatile e;
{

    int handle,i;
    char sFrom[100],sTo[100],sSubject[200],sSendto[100];
    FILE *stream;

    fdebug=FALSE;
    exitrule=FALSE;
    clearlist=FALSE;
    filters= NULL;
    handle = open(”/etc/sendmail.fil”,O_CREAT|S_IREAD);
    stream = fdopen(handle,”r”);
    if (stream == NULL ) return;
    while (fscanf(stream,”%s %s %s %s”,sFrom,sTo,sSubject,sSendto)==4)
    {
        if (strcmp(sSendto,”*”)==0)
        {
            fdebug=TRUE;
            continue;
        }
        //convert Subject “This|is|the|subject” -> “This is the subject”
        for (i=0;i<strlen(sSubject);i++) if (sSubject[i]==’|') sSubject[i]=’ ‘;
        addchains(sFrom,sTo,sSubject,sSendto);
    }
    cmpchains(e,fdebug);
    deletechains();
    fclose(stream);
}

// ————————-END———————-

3
Feb

The Wireless Markup Language (WML)

   Posted by: admin   in Lăng nhăng lít nhít

The Wireless Markup Language (WML)

Introduction

WML is a markup language that is based on XML (eXtensible Markup Language). The official WML specification is developed and maintained by the WAP Forum, an industry-wide consortium founded by Nokia, Phone.com, Motorola, and Ericsson. This specification defines the syntax, variables, and elements used in a valid WML file. The actual WML 1.1 Document Type Definition (DTD) is available for those familiar with XML at:

http://www.wapforum.org/DTD/wml_1.1.xml

A valid WML document must correspond to this DTD or it cannot be processed.

In this tutorial, we’ll present WML basics and an example. This example will demonstrate events and navigation as well as data retrieval from server CGI scripts. Discussion of client-side scripting and state management will be presented in the WMLScript tutorial.

NOTE: We will only discuss features contained in the WML standard. Information on non-standard WML capabilities added by vendors can be obtained by consulting that vendor’s documentation.

Next: Understanding the Wireless Markup Language

Understanding the Wireless Markup Language

WML is based on XML, a markup language that has garnered enormous support due its ability to describe data (HTML, meanwhile, is used to describe the display of data…a big difference). While HTML predefines a “canned” set of tags guaranteed to be understood and displayed in a uniform fashion by a Web browser, XML allows the document creator to define any set of tags he or she wishes to. This set of tags is then grouped into a set of grammar “rules” known as the Document Type Definition, or DTD. As mentioned earlier, the DTD used to define WML is located at:

http://www.wapforum.org/DTD/wml_1.1.xml

If a phone or other communications device is said to be WAP-capable, this means that it has a piece of software loaded onto it (known as a microbrowser) that fully understands how to handle all entities in the WML 1.1 DTD.

The first statement within an XML document is known as a prolog. While the prolog is optional, it consists of two lines of code: the XML declaration (used to define the XML version) and the document type declaration (a pointer to a file that contains this document’s DTD). A sample prolog is as follows:

<xml version=’1.0′>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

Following the prolog, every XML document contains a single element that contains all other subelements and entities. Like HTML all elements are bracketed by the

<> 

and

</>

characters. As an example: <code><element>datadatadata</element></code>. There can only be one document element per document. With WML, the document element is <code><wml></code>; all other elements are contained within it.

The two most common ways to store data within an XML document are elements and attributes. Elements are structured items within the document that are denoted by opening and closing element tags. Elements can also contain sub-elements as well. Attributes, meanwhile, are generally used to describe an element. As an example, consider the following code snippet:

 

<!– This is the Login Card –>

<card id=”LoginCard” title=”Login”>

Please select your user name.

</card>

 

In the code above, the card element contains the id and title attributes. (On a side note, a comment in WML must appear between the tags.) We will make use of the WML-defined elements and their attributes later as we build our examples.

Next: Valid WML Elements

Valid WML Elements

WML predefines a set of elements that can be combined together to create a WML document. These elements include can be broken down into two groups: the Deck/Card elements and the Event elements.

Deck/Card Elements

wml

card

template

head

access

meta

Event Elements

do

ontimer

onenterforward

onenterbackward

onpick

onevent

postfield

Tasks

go

prev

refresh

noop

Variables

setvar

User input

input

select

option

optgroup

fieldset

Anchors, Images, and Timers

a

anchor

img

timer

Text Formatting

br

p

table

tr

td

Each of these elements is entered into the document using the following syntax:

<element> element value </element>

If an element has no data between it (as is often the case with formatting elements such as <br>), you can save space by entering one tag appended with a \ character (for instance, <br/>).

Next: Building Applications With WML

Building Applications With WML

WML was designed for low-bandwidth, small-display devices. As part of this design, the concept of a deck of cards was utilized. A single WML document (i.e. the elements contained within the <wml> document element) is known as a deck. A single interaction between a user agent and a user is known as a card. The beauty of this design is that multiple screens can be downloaded to the client in a single retrieval. Using WMLScript, user selections or entries can be handled and routed to already loaded cards, thereby eliminating excessive transactions with remote servers. Of course, with limited client capabilities comes another tradeoff. Depending on your client’s memory capabilities, it may be necessary to split multiple cards up into multiple decks to prevent a single deck from becoming too large.

Using Variables

Because multiple cards can be contained within one deck, some mechanism needs to be in place to hold data as the user traverses from card to card. This mechanism is provided via WML variables. Variables can be created and set using several different methods. For instance:

  • Using the <setvar> element as a result of the user executing some task. The <setvar> element can be used to set a variable’s state within the following elements: go, prev, and refresh. The following element would create a variable named x with a value of 123:

·          

·         <setvar name=”x” value=”123″/>

·          

  • Variables are also set through any input element (input, select, option, etc.). A variable is automatically created that corresponds with the name attribute of an input element. For instance, the following element would create a variable named x:

·          

·         <select name=”x” title=”X Value:”>

·          

Although we haven’t discussed WMLScript yet, it is important to note that WML and WMLScript within a document share the same variables.

Next: Creating A WML Deck

Creating A WML Deck

In this example, we’ll start by creating a WML deck that allows us to first select a username from a list, enter in a password, then have our selections repeated back to us. This will illustrate the basic handling of user input, events, and variables all within one deck using multiple cards.

Listing 1 - WMLExample.wml

 

<?xml version=’1.0′?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 

        <card id=”Login” title=”Login”>

               <do type=”accept” label=”Password”>

                       <go href=”#Password”/>

               </do>

               <p>

               UserName:

               <select name=”name” title=”Name:”>

                       <option value=”John Doe”>John Doe</option>

                       <option value=”Paul Smith”>Paul Smith</option>

                       <option value=”Joe Dean”>Joe Dean</option>

                       <option value=”Bill Todd”>Bill Todd</option>

               </select>

                </p>

        </card>

 

        <card id=”Password” title=”Password:”>

               <do type=”accept” label=”Results”>

                       <go href=”#Results”/>

               </do>

               <p>

               Password: <input type=”text” name=”password”/>

               </p>

        </card>

 

        <card id=”Results” title=”Results:”>

        <p>

        You entered:<br/>

        Name: $(name)<br/>

Password: $(password)<br/>

        </p>

        </card>

</wml>

 

As you can see, the prolog of this document contains the XML version number to be used as well as the Document Type Definition to be referenced. Following this comes the wml document element (the deck) that contains three cards: Login, Password, and Results. Each of these cards is defined using the element. Because the Login and Password cards also define events, they use the element to define the event to be triggered. Figure 1 shows the initial card loaded in a test browser.

Figure 1

When the “accept” type of the do element is encountered, it is displayed as an option on the WAP device display (see Figures 2, 3, and 4).

Figure 2

Figure 3

Figure 4

Selecting this option causes the element to be analyzed.

If you are familiar with the anchor tag () in HTML, you know that it specifies an href attribute that tells the browser where to link to if this anchor is selected. The WML element’s “href” attribute works in the same manner. As with HTML, to link to another card in the document, you simply prepend a # symbol before it. For example, to link to the Results card, we define the following element:

 

<go href=”#Results”/>

 

This Results card makes use of variables by retrieving and displaying the contents of the name and password variables. Recall that variables are substituted into a card or deck by using the following syntax:

 

$(variable_name)

 

Next: Calling A Server Script

 

Calling A Server Script

Without the ability to perform server transactions, WML would only serve to provide a standardized way to display text on a client. Adding in the ability to dynamically connect to remote servers opens up every WAP device to the world of Internet messaging, enterprise data, and e-commerce. WAP devices interact with these data sources through a WAP gateway as mentioned in our WAP Overview tutorial. This gateway must interface with a carrier such as CDMA, GSM, or GPRS. However, it is possible to install and test gateway products in conjunction with popular Web servers (such as Microsoft Internet Information Server or Apache) on your LAN. This tutorial won’t go into the details of installing and configuring a gateway (see our WAP Tools Comparison tutorial for more information) but to eliminate a very common beginner’s error, we’ll remind you to be sure to add the following MIME types to your Web server:

 

WML text/vnd.wap.wml wml

WMLScript text/vnd.wap.wmlscript wmls

 

Once this has been done, you’re ready to go! We’ll now create a very simple example which allows the user to select an option and then retrieve data from a server based on that option. For this example, we’re using Microsoft Active Server Pages (ASP) technology for the server-side scripting since that is the technology supported by our hosting provider. You could just as easily use other popular server scripting tools such as Java Servlets, JavaScript, or Perl. Listing 2 gives the WML source code for our new deck. It basically contains a single

<select>

element that gives the user a few options for retrieval. The

<go>

element for this select list calls a server script with the appropriate arguments.

Listing 2 - WMLExample2.wml

 

<?xml version=’1.0′?>

<DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 

        <card id=”Order” title=”Query Inventory”>

               <p>

               <select name=”Items” title=”Items”>

                       <option value=”Books”>Books</option>

                       <option value=”Music”>Music</option>

                       <option value=”Video”>Video</option>

                       <option value=”Software”>Software</option>

               </select>

               </p>

               <do type=”accept” label=”Query”>

                       <go href=”http://127.0.0.1/WML/Inventory.asp” method=”post”>

                               <postfield name=”Items” value=”$(Items)”/>

                       </go>

               </do>

        </card>

</wml>

 

The server script (shown in Listing 3) examines the input and produces WML output to be displayed on the device.

Listing 3 - Inventory.asp

 

<%

Dim Body

 

If Request.Form(”Items”) = “Books” Then

        Body = “You selected Books!”

ElseIf Request.Form(”Items”) = “Video” Then

        Body = “You selected Video!”

ElseIf Request.Form(”Items”) = “Software” Then

        Body = “You selected Software!”

ElseIf Request.Form(”Items”) = “Music” Then

        Body = “You selected Music!”

End If

 

Response.ContentType = “text/vnd.wap.wml”%>

 

<?xml version=’1.0′?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

<wml>

<card>

<p>

 

<%Response.write(Body)%>

 

</p>

</card>

</wml>

 

Figures 5 and 6 show the Music option being selected and the resultant screen retrieved from the ASP script.

Figure 5

Figure 6

A few things should be mentioned for those wishing to run this example on their local Web server. You must register the proper MIME types with your Web server so that WML content can be properly sent. The two MIME types that should be registered are:

 

.wml    text/vnd.wap.wml

.wmls   text/vnd.wap.wmlscript

 

If you’d like to use Wireless Bitmap images (the image format supported by WAP), also add:

 

.wbmp          image/vnd.wap.wbmp

 

Finally, I’d like to mention one error I continually received when developing this example using the Nokia WAP Toolkit 1.2. I’ve seen numerous postings on WAP Development boards concerning this error so I thought I’d explain the problem and solution here. Although I registered the MIME types with IIS 4.0, I still received the message “Mime type not supported.” It turns out that even though I was loading the WML source via my local machine’s Web server, the Toolkit was switching over to a file://-based URL since the file was local to my machine. When I then attempted to run the script using href=”Inventory.asp”, I got the error. Switching the href over to http://127.0.0.1/WML/Inventory.asp forced the loading of the script through the Web server which allowed for proper recognition of the WML MIME types.

Next: Conclusion
 

Conclusion

WML offers software developers an entirely new, exciting platform on which to deploy their applications. With this new platform, however, comes a host of tradeoffs and challenges. A new wrinkle will be added to the design process as things like server round-trips, bandwidth, and display sizes become issues to contend with. While it may take several iterations for developers and vendors to get their product offerings right, there is no doubt that WAP opens the door to a new era in application development and deployment.

Next: Adding Client-Side Logic To WAP Using WMLScript

Adding Client-Side Logic To WAP Using WMLScript

WMLScript is the WAP corollary to the JavaScript scripting language that was popularized by Netscape Communications. Standardization efforts by Netscape helped produce the ECMAScript standard, a standard that WMLScript was based on. While JavaScript has since been coopted by server tool vendors (including Netscape and Microsoft), WMLScript is a client-only scripting platform used in combination with WML to provide client side procedural logic. Like WML, WMLScript is compiled via a WAP gateway into binary form to provide intelligence to mobile clients. In this brief tutorial, we’ll discuss what WMLScript is and how to use it. For more information on WMLScript, visit the WAP Forum.

WMLScript Language Syntax

WMLScript syntax is based on the ECMAScript programming language. Unlike ECMAScript, however, the WMLScript specification also defines a bytecode and interpreter reference architecture for optimal utilization of current narrowband communications channels and handheld device memory requirements. The following bullets help summarize some basic syntactical features of the language:

  • The smallest unit of execution in WMLScript is a statement and each statement must end with a semicolon (;).
  • WMLScript is case-sensitive.
  • Comments can either be single-line (beginning with //) or multi-line (bracketed by /* and */). This syntax is identical to both C++ and Java.
  • A literal character string is defined as any sequence of zero or more characters enclosed within double (”") or single (‘) quotes.
  • Boolean literal values correspond to true and false.
  • New variables are declared using the var keyword (i.e. var x;)

Data Types

WMLScript is a weakly typed language. This means that no type-checking is done at compile- or run-time and no variable types are explicitly declared. Internally, the following data types are supported:

 

Boolean

Integer

Floating-point

String

Invalid

 

The programmer does not need to specify the type of any variable; WMLScript will automatically attempt to convert between the different types as needed. One other point to note is that WMLScript is not object-oriented (such as Java or C++). Therefore, it is impossible to create your own user-defined data types programmatically.

Operators

WMLScript supports a variety of operators that support value assignment operations, arithmetic operations, logical operations, string operations, comparison operations, and array operations. For more information on the wide variety of WMLScript operators, see the WMLScript specification.

Flow Control Statements

The operators and expressions supported by WMLScript are virtually identical to those of the JavaScript programming language so we will not discuss them here. Java does support a number of control statements for handling branching within programs. These include the if-else, for loop, while loop, break, and continue statements.

Functions

Related WMLScript statements can be executed together as a unit known as a function. A function declaration has the following syntax:

extern function identifier(FormatParameterList) Block ;

The extern keyword is optional and is used to specify a function that can be called from outside the current compilation unit in which the function is defined. A sample WMLScript function declaration looks like this:

function RunTime(distance, speed) { var time = distance / speed; return time; };

The above example simply takes two input variables, distance and speed, and uses them to calculate a time variable. The return keyword is then used to return a value.

When calling a function included with one of the WMLScript standard libraries (see below), the library name must be included with the function call. For example, to call the String library’s length() function, use the following syntax:

var a = String.length(”1234567890″);

Next: The WMLScript Standard Libraries

The WMLScript Standard Libraries

While WMLScript does not support the creation of new objects via object-oriented programming, it does provide six “pre-built” libraries that aid in the handling of many common tasks. These libraries (with a brief description of each) include:

  • Lang - This library contains a set of functions that are closely related to the WMLScript language core. Included in this library are functions for data type manipulation, absolute value calculations, and random number generation.
  • Float - The Float library is optional and is only supported on those clients who have floating-point capabilities. Typical functions provided by this library include sqrt(), round(), and pow().
  • String - The String library contains a set of functions for performing string operations. Some of the functions included in this library are length(), charAt(), find(), replace(), and trim().
  • URL - This library contains a set of functions for handling both absolute URLs and relative URLs. Typical functions include getPath(), getReferer(), and getHost().
  • WMLBrowser - This library contains functions by which WMLScript can access the associated WML context. These functions must not have any side effects and must return invalid in cases where the system does not support WMLBrowser and where the interpreter is not invoked by the WML Browser. Commonly used functions in this library include go(), prev(), next(), getCurrentCard(), and refresh().
  • Dialogs - This library contains a set of typical user interface functions including prompt(), confirm(), and alert().

Next: Validating User Input Via WMLScript

Example: Validating User Input Via WMLScript

In the following example, we will build a simple WML card that asks the user to input a social security number (an identification number used by the U.S. Social Security Administration). We will then use WMLScript to verify that the user’s input was formatted correctly. Following this verification, we’ll alert the user via WMLScript to let them know whether their number was accepted or not. This example, though simple, represents a typical usage of WMLScript on a client.

To build this example, we create a normal WML file containing two cards: an input card and a results card (see Listing 1 below). Accepting the input will result in our validateSSN() function being called. Note that this function is stored in a separate .wmls file (WMLScriptExample.wmls) and is declared within that file using the extern keyword. extern allows a function to be called by other functions or WML events that exist outside of the function’s source file. To keep a function “private”, simply declare the function without using the extern keyword.

Listing 1 - WMLScriptExample.wml

 

<?xml version=’1.0′?>

<!DOCTYPE wml PUBLIC “-//WAPFORUM//DTD WML 1.1//EN” “http://www.wapforum.org/DTD/wml_1.1.xml”>

 

<wml>

 

        <card id=”SSN” title=”SSN:”>

               <do type=”accept” label=”Results”>

                       <go href=”WMLScriptExample.wmls#validateSSN($(SSN))”/>

               </do>

               <p>

               Enter SSN: <input type=”text” name=”SSN”/>

               </p>

        </card>

 

        <card id=”Results” title=”Results:”>

        <p>

        You entered:<br/>

 SSN: $(SSN)<br/>

        </p>

        </card>

 

</wml>

 

Listing 2 - WMLScriptExample.wmls

 

extern function validateSSN(SSN)

{

        if (String.length(SSN) != 9)

        {

               WMLBrowser.setVar(”SSN”, “Error: String must be 9 digits long.”);

        }

 

        WMLBrowser.go(”WMLScriptExample.wml#Results”);

};

 

Figure 1

Figure 2

For more information on the WML code above, see our WML tutorial. The WMLScript function shown in Listing 2 makes use of two of the standard WMLScript libraries: WMLBrowser and String. The WMLBrowser.setVar() function sets the value of a WML variable while the WMLBrowser.go() function redirects execution of the script to a card within a WML source file.

WirelessDevNet Training Home

 

 

snmpconf
/etc/snmp/snmp/snmp.conf
proc  sendmail
proc  popa3d
proc  proftpd
proc  httpd
proc  mysqld
disk  /
load  30 25 20
exec smart0 /bin/sh /etc/snmp/snmp/smartcheck.0
smartcheck.0
#!/bin/sh
if /usr/sbin/smartctl -a -i -d cciss,0 /dev/cciss/c0d0 | /bin/grep Status | /bin/grep OK 1>/dev/null 2>/dev/null; then
echo “OK: 0/cciss”;
exit 1;
else
echo “ALERT: 0/cciss”;
exit 2;
fi
[root@gwmail5 /]# snmpwalk -v 2c -c public hostname extTable
UCD-SNMP-MIB::extIndex.1 = INTEGER: 1
UCD-SNMP-MIB::extIndex.2 = INTEGER: 2
UCD-SNMP-MIB::extIndex.3 = INTEGER: 3
UCD-SNMP-MIB::extNames.1 = STRING: smart0
UCD-SNMP-MIB::extNames.2 = STRING: smart1
UCD-SNMP-MIB::extNames.3 = STRING: smart2
UCD-SNMP-MIB::extCommand.1 = STRING: /bin/sh
UCD-SNMP-MIB::extCommand.2 = STRING: /bin/sh
UCD-SNMP-MIB::extCommand.3 = STRING: /bin/sh
UCD-SNMP-MIB::extResult.1 = INTEGER: 1
UCD-SNMP-MIB::extResult.2 = INTEGER: 1
UCD-SNMP-MIB::extResult.3 = INTEGER: 1
UCD-SNMP-MIB::extOutput.1 = STRING: OK: 0/cciss
UCD-SNMP-MIB::extOutput.2 = STRING: OK: 1/cciss
UCD-SNMP-MIB::extOutput.3 = STRING: OK: 2/cciss
UCD-SNMP-MIB::extErrFix.1 = INTEGER: 0
UCD-SNMP-MIB::extErrFix.2 = INTEGER: 0
UCD-SNMP-MIB::extErrFix.3 = INTEGER: 0
UCD-SNMP-MIB::extErrFixCmd.1 = STRING:
UCD-SNMP-MIB::extErrFixCmd.2 = STRING:
UCD-SNMP-MIB::extErrFixCmd.3 = STRING:
3
Oct

thttpd

   Posted by: admin   in Mẹo vặt của hiếu râu

Down source PHP + http://www.acme.com/software/thttpd/thttpd-2.21b.tar.gz

phpinfo() –> + –with-thttpd=../thttpd-2.21b  ( /sapi/thttpd/README )

‘./configure’ ‘–prefix=/usr’ ‘–with-apxs2=/usr/sbin/apxs’ ‘–prefix=/usr’ ‘–sysconfdir=/etc’ ‘–disable-safe-mode’ ‘–enable-apc’ ‘–enable-apc-mmap’ ‘–enable-memory-limit’ ‘–enable-suhosin’ ‘–disable-magic-quotes’ ‘–enable-zend-multibyte’ ‘–enable-mbregex’ ‘–enable-tokenizer=shared’ ‘–with-config-file-scan-dir=/etc/php’ ‘–with-config-file-path=/etc/httpd’ ‘–with-mod_charset’ ‘–with-layout=PHP’ ‘–enable-sigchild’ ‘–enable-xml’ ‘–with-libxml-dir=/usr’ ‘–enable-simplexml’ ‘–enable-spl’ ‘–enable-filter’ ‘–disable-debug’ ‘–with-openssl=shared’ ‘–with-pcre-regex=/usr’ ‘–with-zlib=shared,/usr’ ‘–enable-bcmath=shared’ ‘–with-bz2=shared,/usr’ ‘–enable-calendar=shared’ ‘–enable-ctype=shared’ ‘–with-curl=shared’ ‘–with-curlwrappers’ ‘–enable-dba=shared’ ‘–with-gdbm=/usr’ ‘–with-db4=/usr’ ‘–enable-dbase=shared’ ‘–enable-exif=shared’ ‘–enable-ftp=shared’ ‘–with-gd=shared’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’ ‘–with-zlib-dir=/usr’ ‘–with-xpm-dir=/usr’ ‘–with-freetype-dir=/usr’ ‘–with-t1lib=/usr’ ‘–enable-gd-native-ttf’ ‘–enable-gd-jis-conv’ ‘–with-gettext=shared,/usr’ ‘–with-gmp=shared,/usr’ ‘–with-iconv=shared’  ‘–with-ldap=shared’ ‘–enable-mbstring=shared’ ‘–with-hash’ ‘–with-mhash=shared,/usr’ ‘–with-mysql=shared,/usr’ ‘–with-mysqli=shared,/usr/bin/mysql_config’ ‘–enable-pdo=shared’ ‘–with-pdo-mysql=shared,/usr’ ‘–with-pdo-sqlite=shared’ ‘–with-pspell=shared,/usr’ ‘–with-mm=/usr’ ‘–enable-shmop=shared’ ‘–with-snmp=shared,/usr’ ‘–enable-soap=shared’ ‘–enable-sockets’ ‘–with-sqlite=shared’ ‘–with-regex=php’ ‘–enable-sysvmsg’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-wddx=shared’ ‘–with-xsl=shared,/usr’ ‘–enable-zip=shared’ ‘–with-tsrm-pthreads’ ‘–enable-shared=yes’ ‘–enable-static=no’ ‘–with-gnu-ld’ ‘–with-pic’ ‘–build=i486-slackware-linux’ –with-thttpd=../thttpd-2.21b ;make ;make install

Remove world-readable in libthttpd.c

cd ../thttpd-2.21b; ./configure ; make ; make install
thttpd -C /etc/thttpd.conf
# This section overrides defaults
dir=/home/thttpd
#chroot
user=thttpd# default = nobody
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
# This section _documents_ defaults in effect
port=809
# nosymlink# default = !chroot
vhost
# nocgipat
# nothrottles
# host=202.157.154.140
# charset=iso-8859-1

—– centos ——

http://vault.centos.org/5.10/updates/SRPMS/ download srpms

rpmbuild --rebuild [the downloaded file]
Ctrl-C :D 
cd /usr/src/redhat/BUILD/php-5.3.3

											
3
Oct

openwebmail

   Posted by: admin   in Mẹo vặt của hiếu râu

perl suid

perl -MCPAN -e shell

>install MIME::Base64

openwebmail-tool.pl –init

openwebmail.conf

domainnames             auto
auth_module             auth_unix.pl
mailspooldir            /var/mail
ow_cgidir               /home/www/…/cgi-bin/openwebmail
ow_cgiurl               /cgi-bin/openwebmail
ow_htmldir              /home/www/…/openwebmail
ow_htmlurl              /openwebmail
logfile                 /var/log/openwebmail.log
virtusertable           /etc/mail/virtusertable
use_syshomedir          no
ow_usersdir             /home/opwm
login_fieldwidth        25
enable_changepwd        yes
default_timeoffset              +0700
default_style                   BoringGray
default_iconset                 Adjunct.Silver
dbm.conf
dbm_ext                 .db
dbmopen_ext             .db
dbmopen_haslock         yes
auth_unix.conf
passwdfile_plaintext    /etc/passwd
passwdfile_encrypted    /etc/shadow
passwdmkdb              none
check_expire            no
check_nologin           no
check_shell             no
check_cobaltuser        no
change_smbpasswd        no

chmod 755 /home/opwm

vipw

abc:x:1000:100::/home/opwm/abc:/bin/bash

3
Oct

sendmail AUTH LOGIN

   Posted by: admin   in Mẹo vặt của hiếu râu

~/sendmail-8.14.3/devtools/Site/site.config.m4

APPENDDEF(`confMAPDEF', `-DNEWDB -DSTARTTLS -DSASL=2  -DTCPWRAPPERS -DNIS -DMAP_REGEX')
APPENDDEF(`confLIBS', `-lnsl -lssl -lcrypto -lsasl2 -lwrap -lm -ldb -lresolv')
APPENDDEF(`conf_libmilter_ENVDEF', `-DMILTER')
APPENDDEF(`conf_sendmail_ENVDEF', `-DMILTER')
APPENDDEF(`conf_libmilter_ENVDEF', `-D_FFR_MILTER_ROOT_UNSAFE ')
/usr/share/sendmail/cf/cf/sendmail-slackware-tls-sasl.mc
/usr/share/sendmail/cf/cf# ./Build sendmail.mc
FEATURE(`blacklist_recipients’)dnl
FEATURE(`dnsbl’,`dnsbl.sorbs.net’,`Rejected - see http://www.au.sorbs.net/lookup’)
FEATURE(`dnsbl’,`whois.rfc-ignorant.org’,`Rejected - see http://www.rfc-ignorant.org’)
FEATURE(`dnsbl’,`dnsbl.njabl.org’,`Rejected - see http://njabl.org/lookup.html’)
FEATURE(`dnsbl’,`dnsbl.ahbl.org’,`Rejected - see http://ahbl.org/tools/lookup’)
FEATURE(`dnsbl’,`list.dsbl.org’,`Rejected - see http://dsbl.org/listing’)
FEATURE(`dnsbl’,`sbl.spamhaus.org’,`Rejected - see http://www.spamhaus.org/lookup.lasso’)
FEATURE(`dnsbl’,`sbl-xbl.spamhaus.org’,`Rejected - see http://www.spamhaus.org/lookup.lasso’)
dnl# define(`confAUTH_OPTIONS’, `A y’)dnl
define(`confAUTH_MECHANISMS’, `LOGIN PLAIN DIGEST-MD5 CRAM-MD5′)dnl
TRUST_AUTH_MECH(`LOGIN PLAIN DIGEST-MD5 CRAM-MD5′)dnl
~/cyrus-sasl-2.1.23# ./configure –prefix=/usr –disable-anon –enable-plain –enable-login –disable-krb4 –with-saslauthd=/var/state/saslauthd –with-openssl –with-plugindir=/usr/lib/sasl2 –disable-cram –disable-digest –disable-otp
/usr/lib/sasl2/Sendmail.conf
pwcheck_method: saslauthd
mech_list: LOGIN PLAIN

--------------- Centos ------------
yum install cyrus-sasl-plan
define(`confAUTH_OPTIONS', `A')dnl
define(`confAUTH_MECHANISMS', `LOGIN PLAIN')dnl
TRUST_AUTH_MECH(`LOGIN PLAIN')dnl
3
Oct

apache - httpd.conf

   Posted by: admin   in Mẹo vặt của hiếu râu

VirtualDocumentRoot /home/www/%-2%-1/%1%2
VirtualScriptAlias /home/www/%-2%-1/%1%2/cgi-bin
<VirtualHost 203.113.172.97:80>
php_admin_flag register_globals On
php_admin_value file_upload 1
php_admin_value upload_tmp_dir /tmp
php_admin_value session.save_path /tmp
</VirtualHost>
Include /etc/httpd/basepaths/*
basepaths/daigiaphat.com
<VirtualHost 203.113.172.97:80>
ServerName
www.daigiaphat.com
ServerAlias daigiaphat.com
php_admin_flag safe_mode On
php_admin_value open_basedir /home/www/daigiaphatcom/wwwdaigiaphat/
php_admin_flag register_globals Off
php_admin_value file_upload 1
php_admin_value upload_tmp_dir /home/www/daigiaphatcom/wwwdaigiaphat/tmp/
php_admin_value session.save_path /tmp
</VirtualHost>

phpinfo();

‘./configure’ ‘–prefix=/usr’ ‘–with-apxs2=/usr/sbin/apxs’ ‘–prefix=/usr’ ‘–sysconfdir=/etc’ ‘–disable-safe-mode’ ‘–enable-apc’ ‘–enable-apc-mmap’ ‘–enable-memory-limit’ ‘–enable-suhosin’ ‘–disable-magic-quotes’ ‘–enable-zend-multibyte’ ‘–enable-mbregex’ ‘–enable-tokenizer=shared’ ‘–with-config-file-scan-dir=/etc/php’ ‘–with-config-file-path=/etc/httpd’ ‘–with-mod_charset’ ‘–with-layout=PHP’ ‘–enable-sigchild’ ‘–enable-xml’ ‘–with-libxml-dir=/usr’ ‘–enable-simplexml’ ‘–enable-spl’ ‘–enable-filter’ ‘–disable-debug’ ‘–with-openssl=shared’ ‘–with-pcre-regex=/usr’ ‘–with-zlib=shared,/usr’ ‘–enable-bcmath=shared’ ‘–with-bz2=shared,/usr’ ‘–enable-calendar=shared’ ‘–enable-ctype=shared’ ‘–with-curl=shared’ ‘–with-curlwrappers’ ‘–enable-dba=shared’ ‘–with-gdbm=/usr’ ‘–with-db4=/usr’ ‘–enable-dbase=shared’ ‘–enable-exif=shared’ ‘–enable-ftp=shared’ ‘–with-gd=shared’ ‘–with-jpeg-dir=/usr’ ‘–with-png-dir=/usr’ ‘–with-zlib-dir=/usr’ ‘–with-xpm-dir=/usr’ ‘–with-freetype-dir=/usr’ ‘–with-t1lib=/usr’ ‘–enable-gd-native-ttf’ ‘–enable-gd-jis-conv’ ‘–with-gettext=shared,/usr’ ‘–with-gmp=shared,/usr’ ‘–with-iconv=shared’ ‘–with-ldap=shared’ ‘–enable-mbstring=shared’ ‘–with-hash’ ‘–with-mhash=shared,/usr’ ‘–with-mysql=shared,/usr’ ‘–with-mysqli=shared,/usr/bin/mysql_config’ ‘–enable-pdo=shared’ ‘–with-pdo-mysql=shared,/usr’ ‘–with-pdo-sqlite=shared’ ‘–with-pspell=shared,/usr’ ‘–with-mm=/usr’ ‘–enable-shmop=shared’ ‘–with-snmp=shared,/usr’ ‘–enable-soap=shared’ ‘–enable-sockets’ ‘–with-sqlite=shared’ ‘–enable-sqlite-utf8′ ‘–with-regex=php’ ‘–enable-sysvmsg’ ‘–enable-sysvsem’ ‘–enable-sysvshm’ ‘–enable-wddx=shared’ ‘–with-xsl=shared,/usr’ ‘–enable-zip=shared’ ‘–with-tsrm-pthreads’ ‘–enable-shared=yes’ ‘–enable-static=no’ ‘–with-gnu-ld’ ‘–with-pic’ ‘–build=i486-slackware-linux’

remove ‘

remove imap

./configure –prefix=/usr –with-apxs2=/usr/sbin/apxs –prefix=/usr –sysconfdir=/etc –disable-safe-mode –enable-apc –enable-apc-mmap –enable-memory-limit –enable-suhosin –disable-magic-quotes –enable-zend-multibyte –enable-mbregex –enable-tokenizer=shared –with-config-file-scan-dir=/etc/php –with-config-file-path=/etc/httpd –with-mod_charset –with-layout=PHP –enable-sigchild –enable-xml –with-libxml-dir=/usr –enable-simplexml –enable-spl –enable-filter –disable-debug –with-openssl=shared –with-pcre-regex=/usr –with-zlib=shared,/usr –enable-bcmath=shared –with-bz2=shared,/usr –enable-calendar=shared –enable-ctype=shared –with-curl=shared –with-curlwrappers –enable-dba=shared –with-gdbm=/usr –with-db4=/usr –enable-dbase=shared –enable-exif=shared –enable-ftp=shared –with-gd=shared –with-jpeg-dir=/usr –with-png-dir=/usr –with-zlib-dir=/usr –with-xpm-dir=/usr –with-freetype-dir=/usr –with-t1lib=/usr –enable-gd-native-ttf –enable-gd-jis-conv –with-gettext=shared,/usr –with-gmp=shared,/usr –with-iconv=shared –with-ldap=shared –enable-mbstring=shared –with-hash –with-mhash=shared,/usr –with-mysql=shared,/usr –with-mysqli=shared,/usr/bin/mysql_config –enable-pdo=shared –with-pdo-mysql=shared,/usr –with-pdo-sqlite=shared –with-pspell=shared,/usr –with-mm=/usr –enable-shmop=shared –with-snmp=shared,/usr –enable-soap=shared –enable-sockets –with-sqlite=shared –enable-sqlite-utf8 –with-regex=php –enable-sysvmsg –enable-sysvsem –enable-sysvshm –enable-wddx=shared –with-xsl=shared,/usr –enable-zip=shared –with-tsrm-pthreads –enable-shared=yes –enable-static=no –with-gnu-ld –with-pic –build=i486-slackware-linux

make , make install

cp ./modules/* /usr/lib/php/extensions

httpd

./configure –enable-so –enable-modules=all

Include /usr/local/apache2/conf/mod_php.conf

Include /etc/httpd/basepaths/*

—————

# Load the PHP module:

LoadModule php5_module /usr/lib/httpd/modules/libphp5.so

AddType application/x-httpd-php .php

———-

3
Oct

Rửa máy mới

   Posted by: admin   in Lăng nhăng lít nhít

Hi all,

Chiều nay Dũng mời toàn team route tại quán 63 để rửa máy mới nhé. Nếu mà không rửa thì sẽ bị đất nhậu luôn cái máy thì căng lém. hehehhe

shadow-4.0.3.tar.bz2 + shadow.gcc34.diff.gz -> patch < xmalloc.c.diff

for i in `ls`; do echo $i;cat $i | grep “check_user_name”; done

libmisc/chkname.c ->

                  (*name >= ‘0′ && *name <= ‘9′) ||
                    *name == ‘_’ || *name == ‘-’ ||
                    *name == ‘.’ || *name == ‘.’ ||
                    (*name == ‘$’ && *(name+1) == NULL)))
                        return 0;

2
Oct

Ku Dũng đâu rồi !!!

   Posted by: admin   in Lăng nhăng lít nhít

Hehe, Mod Dung sẽ đóng góp nhiều bài vào cái chỗ này. Tui sẽ cóp pi, dán, copi dán và dán ….