Check-in [4184e47799]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added client implementation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:4184e477999d9bee8c12a31eb35ced76364982e6
User & Date: densch 2015-04-17 02:46:37
Context
2015-04-17
03:20
Implemented the webservice using memcached check-in: bc0159264b user: densch tags: trunk
03:16
Create new branch named "apc" Closed-Leaf check-in: a32437fb56 user: densch tags: apc
02:46
Added client implementation check-in: 4184e47799 user: densch tags: trunk
02:34
Added htpasswd file for basic http authentication check-in: a15ea2d674 user: densch tags: trunk
Changes

Added rcmobiesp/remoteclient/MobileESPRemoteClient.inc.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

class MobileESPRemoteClient {

    private $url;
    private $curl;
    private $features;

    /**
     * @param String $url URL of the webservice (http://example.com/webservice/)
     * @param String $username
     * @param String $password
     */
    function __construct($url, $username, $password)
    {
        $this->url = $url;
        $this->curl = curl_init();
        $header[] = isset($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : "";
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($this->curl, CURLOPT_USERPWD, "$username:$password"); 
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
        // TODO if pregmatch(^https, $url) { set options for SSL }
    }

    function __destruct()
    {
        curl_close($this->curl);
    }

    /**
     * @param String $methods List of MobileESP methods, separated by |, to call in the remote server
     */
    function run($methods)
    {
        curl_setopt($this->curl, CURLOPT_URL, $this->url . "?methods=$methods");
        $result = curl_exec($this->curl);
        $this->features = json_decode($result, true);
    }

    /**
     * @return Boolean true if the requested feature was detected by MobileESP
     */
    function is($f)
    {
        if ($this->features == NULL) return false;
        return $this->features['Detect' . $f];
    }

}

?>

Added rcmobiesp/remoteclient/config/MobileESPRemoteClient.ini.







































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
; Configuration file for the MobileESP remote client example
; Should be stored outside of the public

[id]
domain = "example.com"
fromemail = "noreply@example.com"
toemail = "you@example.com"

; if url points to a https url you should also set cacert to point to the
; location of your CA certificate (in PEM format), if not using SSL cacert is
; ignored
[auth]
url = "http://localhost/rcm/webservice/"
username = "Aladdin"
password = "Open Sesame"
cacert = "/usr/local/www/apache24/private/yourCAcert.crt"

[debug]
log = TRUE

Added rcmobiesp/remoteclient/example.php.

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

// Path to the config file, ideally outside of the public view (DocumentRoot in Apache)
if (!($ini = parse_ini_file('/usr/local/www/apache24/private/MobileESPRemoteClient.ini'))) {
    die('Fatal error: Unable to parse .ini file');
}

if (isset($_COOKIE['website_version'])) {
    switch ($_COOKIE['website_version']) {
        case 'mobile':
            header("Location: http://m." . $ini['domain'] . "/");
            exit;
        case 'desktop':
            break;
    }
} else {
    try {
        if (!include('MobileESPRemoteClient.inc')) {
            throw new Exception("Included file couldn't be included");
        }

        $device = new MobileESPRemoteClient($ini['url'], $ini['username'], $ini['password']);

        if (!$device) { throw new Exception('Cannot create remote client'); };

        $device->run("DetectMobileQuick|DetectTierTablet");

        if($device->is("MobileQuick") && !$device->is("TierTablet")) {
            header("Location: http://m." . $ini['domain'] . "/");
            setcookie('website_version', 'mobile', 0, '/', '.' . $ini['domain']);
            exit;
        } else {
            setcookie('website_version', 'desktop',0, '/', '.' . $ini['domain']);
        }

    } catch (Exception $e) {
        // mail failure message to someone who cares
        mail($ini['toemail'], "MobileESP Remote Client error at " . $ini['domain'],
            $e->getMessage(), 'From: ' . $ini['fromemail']);

    }
}
?>
<html>
    <body>
        <h1>Hello Desktop Browser!</h1>
    </body>
</html>