IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Linux executer une commande avec php


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    412
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 412
    Points : 79
    Points
    79
    Par défaut Linux executer une commande avec php
    Bonjour,

    Je suis sous Linux debian Squezze 2.6.39.4.
    Le problème est que je n'arrive pas a executer une commande linux avec php ca marche pas

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <?php
    // test execute commande 
    exec('/usr/bin/cm15 e1 on');
    ?>
    et la pareil, marche pas.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <?php
    // test execute commande 
    exec('cp /home/serveur/liste.txt  /home/serveur/liste-test2.txt');
    ?>
    Mais dans le shell ca marche
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    root@debian:~# /usr/bin/cm15 e1 on
    root@debian:~#
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    root@debian:/home/serveur# cp -v /home/serveur/liste.txt  /home/serveur/liste-test.txt
    `/home/serveur/liste.txt' -> `/home/serveur/liste-test.txt'
    root@debian:/home/serveur#
    Pourtant j'ai fait :
    puis
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    root@debian:/home/serveur# chown -R root:www-data /var/www
    root@debian:/home/serveur# find /var/www -type f -print0 | xargs -0 chmod -t,a-rwxs,u+rw,g+r
    root@debian:/home/serveur# find /var/www -type d -print0 | xargs -0 chmod -t,a-rwxs,u+rwx,g+rx
    root@debian:/home/serveur#
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    root@debian:/home/serveur# chown -R www-data:www-data /var/www
    root@debian:/home/serveur# find /var/www -type f -print0 | xargs -0 chmod -t,a-rwxs,u+rw
    root@debian:/home/serveur# find /var/www -type d -print0 | xargs -0 chmod -t,a-rwxs,u+rwx
    root@debian:/home/serveur#
    Mais ca marche toujours pas

    Y a t'il une quelque chose dans php a installer ou a activé ?


    Merci.
    Intel I7 960 | 6 Go Ram | 5 HDD au total 3636 Go | Windows 7 Edition intégral x64 | WampServer 2.0c | Apache 2.2.8 | Php 5.2.6 | MySQL 5.0.51b
    DreamPlug | 512 mo ram | SSD 16 GO | Linux debian 2.6.39.4 | armv5tel | Lamp | PHP 5.3.3-7 | Apache 2.2.16 | Mysql 14.14

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2009
    Messages
    736
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2009
    Messages : 736
    Points : 1 101
    Points
    1 101
    Par défaut
    Essai avec
    A la recherche d'un film : http://chercher-un-film.com

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    412
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 412
    Points : 79
    Points
    79
    Par défaut
    Bonjour,

    Merci de votre réponse.

    Ca ne marche pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <?php
    exec_shell('cp /home/serveur/liste.txt  /home/serveur/liste-test2.txt');
    ?>
    Merci
    Intel I7 960 | 6 Go Ram | 5 HDD au total 3636 Go | Windows 7 Edition intégral x64 | WampServer 2.0c | Apache 2.2.8 | Php 5.2.6 | MySQL 5.0.51b
    DreamPlug | 512 mo ram | SSD 16 GO | Linux debian 2.6.39.4 | armv5tel | Lamp | PHP 5.3.3-7 | Apache 2.2.16 | Mysql 14.14

  4. #4
    Membre à l'essai
    Homme Profil pro
    Etudiant-chercheur
    Inscrit en
    Janvier 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Etudiant-chercheur

    Informations forums :
    Inscription : Janvier 2011
    Messages : 12
    Points : 21
    Points
    21
    Par défaut
    Bonsoir,

    Qu'entendez-vous par "ça ne marche pas" ? Est-ce qu'il y a un message d'erreur (si oui lequel) ? Ou est-ce que rien ne s'affiche ?

    Enfin, pourrait-on avoir un peu plus d'informations notamment quant à :
    • Votre hébergeur;
    • Ce que vous cherchez à faire;
    • Votre version de PHP, et les modules activés.


    Cordialement,

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    412
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 412
    Points : 79
    Points
    79
    Par défaut
    Bonsoir;

    Qu'entendez-vous par "ça ne marche pas" ? Est-ce qu'il y a un message d'erreur (si oui lequel) ? Ou est-ce que rien ne s'affiche ?
    non il se passe rien et rie ne s'affiche.

    Votre hébergeur
    Mon serveur en local dans /var/www/

    Ce que vous cherchez à faire
    Je cherche a faire executer une commande linux dans une page php

    Votre version de PHP, et les modules activés.
    PHP Version 5.3.3-7+squeeze8
    Apache Version Apache/2.2.16 (Debian)
    Quel est le nom de module qu'il faut que je regarde dans phpinfo ?

    L'installation est fait par défaut
    apt-get install apache2
    apt-get install php5
    apt-get install mysql-server
    apt-get install phpmyadmin

    Je n'ai pas touché au module je ne sais pas comment on fait sous linux ?

    Ma distribution Linux debian Squezze 2.6.39.4.
    J'ai une DreamPlug Processeur ARM , il y a n'y clavier, ecran, souris, on ce connecte dessus en ssh depuis un pc.

    Merci.
    Intel I7 960 | 6 Go Ram | 5 HDD au total 3636 Go | Windows 7 Edition intégral x64 | WampServer 2.0c | Apache 2.2.8 | Php 5.2.6 | MySQL 5.0.51b
    DreamPlug | 512 mo ram | SSD 16 GO | Linux debian 2.6.39.4 | armv5tel | Lamp | PHP 5.3.3-7 | Apache 2.2.16 | Mysql 14.14

  6. #6
    Membre à l'essai
    Homme Profil pro
    Etudiant-chercheur
    Inscrit en
    Janvier 2011
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Etudiant-chercheur

    Informations forums :
    Inscription : Janvier 2011
    Messages : 12
    Points : 21
    Points
    21
    Par défaut
    Bonjour,

    Merci pour les infos. J'ai depuis pu dormir () et ait pensé ce matin à aller faire un tour du côté de la doc.

    http://php.net/manual/fr/function.exec.php

    Visiblement exec() retourne un string, il est donc normal que vous n'ayez aucun affichage à l'écran. Pourriez-vous tester :
    ?

    Vous aviez testé une copie (cp), sans qu'il n'y ait d'affichage, mais est-ce que la copie n'a pas été effectuée sur le serveur ?

    Bonne journée,

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    412
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 412
    Points : 79
    Points
    79
    Par défaut
    Bonjour,

    il me répond bien le chemin dans le navigateur
    vous m'avez donné une idée, J'ai fait un test

    dans mon fichier php il y a :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     <?php
    $output0 = shell_exec('pwd');
    echo "<pre>$output0</pre>";
    $output1 = shell_exec('cp -v /home/serveur/liste.txt  /home/serveur/liste-test2.txt');
    echo "<pre>$output1</pre>";
    $output2 = shell_exec('ls -alF /home/serveur/');
    echo "<pre>$output2</pre>";
    $output3 = shell_exec('whoami');
    echo "<pre>$output3</pre>";
    ?>
    le navigateur mozilla affiche :
    [code]/var/www/X10-Linux/X10

    `/home/serveur/liste.txt' -> `/home/serveur/liste-test2.txt'

    total 80
    drwxr-xr-x 11 serveur serveur 4096 Apr 14 11:26 ./
    drwxr-xr-x 3 root root 4096 Apr 7 13:22 ../
    -rw------- 1 serveur serveur 104 Apr 14 11:26 .Xauthority
    -rw-r--r-- 1 serveur serveur 220 Apr 7 12:13 .bash_logout
    -rw-r--r-- 1 serveur serveur 3184 Apr 7 12:13 .bashrc
    -rw-r--r-- 1 serveur serveur 675 Apr 7 12:13 .profile
    drwxr-xr-x 2 root root 4096 Apr 7 12:21 Deb/
    drwxr-xr-x 2 root root 4096 Apr 7 12:21 Documents/
    drwxr-xr-x 3 root root 4096 Apr 9 23:58 Musiques/
    drwxr-xr-x 9 root root 4096 Apr 7 21:17 Pilotes/
    drwxr-xr-x 2 root root 4096 Apr 7 12:21 Programmes/
    drwxr-xr-x 3 root root 4096 Apr 7 22:12 bash/
    -rwxrwxr-x 1 root root 63 Apr 10 00:44 cm15 e1 off.sh*
    drwxr-xr-x 25 root root 4096 Apr 7 16:23 linux-2.6.39.4-dreamplug/
    -rw-r--r-- 1 root root 373 Apr 10 01:41 liste.txt
    -rw-r--r-- 1 root root 9216 Apr 13 18:44 onetext.xdev
    drwxr-xr-x 2 root root 4096 Apr 10 01:45 recup/
    drwxr-xr-x 2 root root 4096 Apr 14 09:22 scripts/

    www-data
    [/code ] le fichier n'a pas été créé, malgré ce qu'il dit certainement un problème de droit ?

    Dans le terminal quand je tape ceci pour changer l'utilisateur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    root@debian:/home/serveur# su - www-data
    $ ls -alF
    total 16
    drwx------  4 www-data www-data 4096 Apr 13 19:54 ./
    drwxr-xr-x 14 root     root     4096 Apr  7 22:32 ../
    drwx------  4 www-data www-data 4096 Apr  7 22:36 X10-Linux/
    drwx------  2 www-data www-data 4096 Apr 13 19:54 test/
    $
    et effectuer un test de copie de fichier, j'ai un problème de droit
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $ cp -v /home/serveur/liste.txt  /home/serveur/liste-test2.txt
    `/home/serveur/liste.txt' -> `/home/serveur/liste-test2.txt'
    cp: cannot create regular file `/home/serveur/liste-test2.txt': Permission denied
    $
    Et la ca marche.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
      <?php
    $output0 = exec('cm15 e1 on');
    echo "<pre>$output0</pre>";
    exec('cm15 e1 off');
    ?>
    pourquoi sous ubuntu ca marche juste avec "exec" et sous debian non ?

    Pour modifier mon proplème de droit j'ai fait :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    root@debian:/home/serveur# chmod -R a+rx /var/www
    root@debian:/home/serveur# chown -R www-data:www-data /home/serveur
    root@debian:/home/serveur# chmod -R 775 /var/www
    root@debian:/home/serveur# chgrp -R www-data /home/serveur/
    root@debian:/home/serveur# su - www-data
    $
    Mais je ne sais pas question sécurité si c'est correct ou si j'ai effectué les bonne manip, faute de réponse ?

    Dans le terminal il copie, c'est bon signe
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    $ cp -v /home/serveur/liste.txt  /home/serveur/liste-test2.txt
    `/home/serveur/liste.txt' -> `/home/serveur/liste-test2.txt'
    $
    Dans mon fichier php j'ai :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <?php
    echo "test avec fichier : text-exec2.php";
    $output0 = shell_exec('pwd');
    echo "<pre>$output0</pre>";
    $output1 = shell_exec('cp -v /home/serveur/liste.txt  /home/serveur/liste-test2.txt');
    echo "<pre>$output1</pre>";
    $output2 = shell_exec('ls -alF /home/serveur/');
    echo "<pre>$output2</pre>";
    ?>
    et le navigateur m'affiche le fichier qui est bien copié
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    test avec fichier : text-exec2.php
     
    /var/www/X10-Linux/X10
     
    `/home/serveur/liste.txt' -> `/home/serveur/liste-test2.txt'
     
    total 88
    drwxr-xr-x 11 www-data www-data 4096 Apr 14 14:54 ./
    drwxr-xr-x  3 root     root     4096 Apr  7 13:22 ../
    -rw-------  1 www-data www-data  104 Apr 14 11:26 .Xauthority
    -rw-------  1 www-data www-data    5 Apr 14 12:49 .bash_history
    -rw-r--r--  1 www-data www-data  220 Apr  7 12:13 .bash_logout
    -rw-r--r--  1 www-data www-data 3184 Apr  7 12:13 .bashrc
    -rw-r--r--  1 www-data www-data  675 Apr  7 12:13 .profile
    drwxr-xr-x  2 www-data www-data 4096 Apr  7 12:21 Deb/
    drwxr-xr-x  2 www-data www-data 4096 Apr  7 12:21 Documents/
    drwxr-xr-x  3 www-data www-data 4096 Apr  9 23:58 Musiques/
    drwxr-xr-x  9 www-data www-data 4096 Apr  7 21:17 Pilotes/
    drwxr-xr-x  2 www-data www-data 4096 Apr  7 12:21 Programmes/
    drwxr-xr-x  3 www-data www-data 4096 Apr  7 22:12 bash/
    -rwxrwxr-x  1 www-data www-data   63 Apr 10 00:44 cm15 e1 off.sh*
    drwxr-xr-x 25 www-data www-data 4096 Apr  7 16:23 linux-2.6.39.4-dreamplug/
    -rw-r--r--  1 www-data www-data  373 Apr 14 14:54 liste-test2.txt
    -rw-r--r--  1 www-data www-data  373 Apr 10 01:41 liste.txt
    -rw-r--r--  1 www-data www-data 9216 Apr 13 18:44 onetext.xdev
    drwxr-xr-x  2 www-data www-data 4096 Apr 10 01:45 recup/
    drwxr-xr-x  2 www-data www-data 4096 Apr 14 09:22 scripts/
    merveille non.


    Dans ce code je voudrai y ajouter ma basse de données Mysql, concernant les nom de modules afin de l'adapter a mes besoins, comment dois je faire m'y prendre ?

    Comment remplacer ceci par ma basse mysql
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $comments = array (
    	"A"	=>	array( 1 => "Receiver Outlet",
    				   2 => "LED Living Room",
    				   3 => "Ceiling Fan Light Living Room"
    				  )
    );


    Le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PHP-BottleRocket/SOSDG - X10 Control Interface</title>
    <style type="text/css">
    <!--
    .footer {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 9px;
    	font-style: italic;
    	color: #666666;
    }
    .header {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: medium;
    	font-weight: bold;
    }
    .listitem {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-style: normal;
    	color: #000000;
    }
    .cmdline {
    	font-family: "Courier New", Courier, monospace;
    	font-size: 10px;
    	font-style: normal;
    	color: #000000;
    }
    .noborder4 {
    	border-top-style: none;
    	border-right-style: none;
    	border-bottom-style: none;
    	border-left-style: none;
    	padding: 2px;
    }
    .error {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: 14px;
    	font-style: italic;
    	font-weight: bold;
    	color: #FF0000;
    }
    .noborder2 {
    	class=\"noborder2\"border-top-style: none;
    	border-right-style: none;
    	border-bottom-style: solid;
    	border-left-style: none;
    	border-bottom-width: thin;
    	border-top-style: none;
    	border-top-width: thin;
    	border-right-width: thin;
    	border-left-width: thin;
    	padding: 2px;
    }
    .noborder3 {
    	class=\"noborder2\"border-top-style: none;
    	border-right-style: none;
    	border-bottom-style: solid;
    	border-left-style: solid;
    	border-bottom-width: thin;
    	border-top-style: none;
    	border-top-width: thin;
    	border-left-width: thin;
    	border-right-width: thin;
    	padding: 2px;
    }
    .noborder3t {
    	border-top-width: thin;
    	border-right-width: thin;
    	border-bottom-width: thin;
    	border-left-width: thin;
    	border-top-style: none;
    	border-right-style: none;
    	border-bottom-style: solid;
    	border-left-style: none;
    	padding: 2px;
    }
    .noborder2r {
    	class=\"noborder2\"border-top-style: none;
    	border-right-style: solid;
    	border-bottom-style: solid;
    	border-left-style: none;
    	border-bottom-width: thin;
    	border-top-style: none;
    	border-top-width: thin;
    	border-right-width: thin;
    	border-left-width: thin;
    	padding: 2px;
    }
    -->
    </style>
    </head>
    <body>
    <?php
    /*
    
    
    PHP-BottleRocket/SOSDG
    By Brielle Bruns <bruns@2mbit.com>
    http://www.sosdg.org
    
    License: GPLv2
    URL: http://www.gnu.org/licenses/gpl-2.0.txt
    
    ChangeLog:
    0.1-boihme  (3/11/2009) =   Initial release, modified slightly from script made for home use
    0.2-boihme  (3/12/2009) =   added new arrays for Home Codes and added somewhat working Dim features.
    							Still some broken code commented out for now.
    0.3         (3/13/2009) =   UTF-8, code cleanups thanks to a quick refresher on PHP syntax, CSS code
                                for nicer (IMHO) output, added global controls.  For some odd reason, All
                                Devices On/Off doesn't seem to affect the appliance module...  Merge in some
                                code I was reserving for my home X10 setup with mainline...  So, no need to have -boihme
                                fork.
    0.4         (3/14/2009) =   Replaced print_r() with a foreach to print out debug from command, make errors not
                                completely fatal, setting $tilt will prevent command from actually running on the
    							system, comments, more interface tweaks
    							
    Known Issues:
    	* My code sucks.  I know.
    	* My CSS sucks.  I know.
    
    
    */
     
    // You can edit stuff in this section to customize parts of the script
     
    // This is the location of bottlerocket
    $brloc="/usr/bin/br";
     
    // Show debugging info, including command line and output.  Turn off if you need pretty output
    $debug=1;
     
    // This is the section where you can define home codes and their associated modules.
    $comments = array (
    	"A"	=>	array( 1 => "Receiver Outlet",
    				   2 => "LED Living Room",
    				   3 => "Ceiling Fan Light Living Room"
    				  )
    );
     
     
    // This is not really meant to be user modified - this is the standard X10 home codes
    // Though, if you really wanted to, this is defined as:
    // "Home Code" => "Display Name"
    // Change display name to whatever you want, but don't mess with the home code field.
    $hcarray = array ("A"=>"A","B"=>"B","C"=>"C","D"=>"D","E"=>"E","F"=>"F","G"=>"G","H"=>"H","I"=>"I",
    				  "J"=>"J","K"=>"K","L"=>"L","M"=>"M","N"=>"N","O"=>"O","P"=>"P");
     
    // The internal version number and name, change if you modify this from the stock
    $program_name="PHP-BottleRocket/SOSDG";
    $interface_version="v0.4";
     
    // Define this script as the actions for POST
    $selfscript=$_SERVER['PHP_SELF'];
     
    // If we are working with a device number, make sure it's an integer and not a string
    if (!empty($_REQUEST[device])) {
    	$device=(int)$_REQUEST[device];
    }
     
     
    // Process homecode if present in POST, if not, assume first load & 'A'
    if (!empty($_REQUEST[homecode])) {
    	if (ereg("^[A-P]$",$_REQUEST[homecode])) {
    		$homecode=$_REQUEST[homecode];
    	} else {
    		$inputerr="Error: invalid homecode";
    	}
    } else {
    	$homecode='A';
    }
     
     
    // If we have debug on, then we add some fun output adjustments
    if (debug) {
    		$debugcmd=" -vvv ";
    }
     
    // DIm POST request
    if (!empty($_REQUEST[dimact])) {
    	$dim=(int)$_REQUEST[dim];
    	if (is_int($device)) {
    		$cmddev=$device;
    	} else {
    		$inputerr="Error: Invalid device ID";
    	}
    	$cmdline=stripslashes(strip_tags(escapeshellcmd("$brloc $debugcmd --house=$homecode --dim=$dim,$device")));
    }
     
    // Device/Lamp On/Off POST request
    if (!empty($_REQUEST[action])) {
    	$action=$_REQUEST[action];
    	unset($dim);
    	unset($cmdline);
    	if ($action == "On") {
    		$cmdact=" --on=";
    	} elseif($action == "Off") {
    		$cmdact=" --off=";
    	} else {
    		$inputerr="Error: Invalid action";
    	}
    	if (is_int($device)) {
    		$cmddev=$device;
    	} else {
    		$inputerr="Error: Invalid device ID";
    	}
    	$cmdline=stripslashes(strip_tags(escapeshellcmd("$brloc $debugcmd --house=$homecode $cmdact$cmddev")));
    }
     
    // All Lights On/Off POST Request
    if (!empty($_REQUEST[AllLight])) {
    	unset($cmdline);
    	unset($cmdact);
    	$alllight=$_REQUEST[AllLight];
    	if ($alllight == "On") {
    		$cmdact=" --lamps_on";
    	} elseif ($alllight == "Off") {
    		$cmdact=" --lamps_off";
    	} else {
    		$inputerr="Error: Invalid action";
    	}
    	$cmdline=stripslashes(strip_tags(escapeshellcmd("$brloc $debugcmd --house=$homecode $cmdact")));
    }
     
    // All Devices On/Off POST Request
    if (!empty($_REQUEST[AllDevice])) {
    	unset($cmdline);
    	unset($cmdact);
    	$alllight=$_REQUEST[AllDevice];
    	if ($alllight == "On") {
    		$cmdact=" --ON";
    	} elseif ($alllight == "Off") {
    		$cmdact=" --OFF";
    	} else {
    		$inputerr="Error: Invalid action";
    	}
    	$cmdline=stripslashes(strip_tags(escapeshellcmd("$brloc $debugcmd --house=$homecode $cmdact")));
    }
     
     
    // If we have some error, set tilt, and display error
    if (!empty($inputerr)) {
    	echo "<span class=\"error\">$inputerr</span><br \>\n";
    	$tilt=1;
    	//exit(1);
    }
     
    // Run the actual command and put the output into $output so if we
    // are in debug mode, we can do something with it.  Don't run the command
    // if we see that the tilt bit is set.
    if (!empty($cmdline) && empty($tilt)) {
    	exec("$cmdline", $output);
    }
    ?>
    <span class="header"><?php echo $program_name; ?> X10 Home Control Interface</span><br />
    <table width="90%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="3" valign="middle" class="noborder4"><form id="homecode" name="homecode" method="post" action="<?php echo $selfscript; ?>">
            <label><span class="listitem">Home Code</span><span class="listitem">
            <select name="homecode">
            <?php foreach ($hcarray as $hcvalue => $hcname) {
       			if ($hcvalue == $homecode) {
    				echo "<option value=\"$hcvalue\" selected=\"selected\">$hcname</option>\n";
    			} else {
    		    	echo "<option value=\"$hcvalue\">$hcname</option>\n";
    			}
    		}
       		?>
            </select>
            </span></label>
            <span class="listitem">
            <input name="Change" type="submit" id="Change" value="change" />
            </span>
          </form></td>
        <td valign="middle" class="listitem"><form id="all" name="all" method="post" action="<?php echo $selfscript; ?>">
            <input name="homecode" type="hidden" value="<?php echo $homecode ?>" />
            All Lamps:
            <input name="AllLight" type="submit" id="LOn" value="On" />
            <input name="AllLight" type="submit" id="LOff" value="Off" />
            &nbsp;&nbsp;&nbsp;&nbsp; All Devices:
            <input name="AllDevice" type="submit" id="AllDevice" value="On" />
            <input name="AllDevice" type="submit" id="AllDevice" value="Off" />
          </form>
          </td>
      </tr>
      <tr>
        <th width="4%" class="noborder3t" scope="col">#</th>
        <th width="12%" class="noborder2" scope="col">Action</th>
        <th width="25%" class="noborder2" scope="col">Dim Level </th>
        <th class="noborder2" scope="col">Comment</th>
      </tr>
      <?php
        for ( $counter = 1; $counter <= 16; $counter++ ) {
    		echo "<tr><td class=\"noborder3\"><span class=\"listitem\"><div align=\"center\"> $homecode $counter </div></span></td>\n";
    		echo "<td class=\"noborder2\"><form id=\"$counter\" name=\"$counter\" method=\"post\" action=\"$selfscript\">\n";
    		echo "<input name=\"device\" type=\"hidden\" value=\"$counter\" />\n";
    		echo "<input name=\"homecode\" type=\"hidden\" value=\"$homecode\" />\n";
    		echo "<span class=\"listitem\"><div align=\"center\"><input name=\"action\" type=\"submit\" id=\"action\" value=\"On\" />\n";
    		echo "<input name=\"action\" type=\"submit\" id=\"action\" value=\"Off\" /></div></span>\n";
    		echo "<td class=\"noborder2\"><span class=\"listitem\"><div align=\"center\">\n";
    		echo "<span class=\"dimlist\"><select name=\"dim\">\n";
    		for ( $dimctr = -12; $dimctr <= 12; $dimctr++ ) {
    			// This code doesn't work right, so its disabled for now.
    			//if ($dimctr == $dim && $counter == $device ) {
    			//	echo "<option value=\"".$dimctr."\" selected=\"selected\">".$dimctr."</option>\n";
    			//} elseif {
    			if ( $dimctr == '0') {
    				echo "<option value=\"$dimctr\" selected=\"selected\">$dimctr</option>\n";
    			} else {
    				echo "<option value=\"$dimctr\">$dimctr</option>\n";
    			}
    		}
    		echo "<input name=\"dimact\" type=\"submit\" id=\"action\" value=\"Dim\" />";
    		echo "</select></span>\n";
    		echo "</div></span></td>\n";
    		echo "</form></td>\n";
    		echo "<td class=\"noborder2r\"><span class=\"listitem\">".$comments[$homecode][$counter]."</div></td>\n";
    	}
      ?>
    </table>
    </p>
    <?php
    // Only display this table if we have debug turned on
    	if (!empty($debug) && !empty($cmdline)) {
    		echo "<p><table width=\"90%\" border=\"1\"><tr><td><span class=\"cmdline\">Command Line: $cmdline<br />";
    		if (is_array($output)) {
    			foreach( $output as $lineout){
    				echo "$lineout <br />";
    			}
    		}
    	echo "</span></td></tr></table></p>";
    }
    ?>
    <p>&nbsp;</p>
    <p><span class="footer"><?php echo "$program_name $interface_version"; ?><br />
      Copyright &copy; <a href="mailto:bruns@2mbit.com">Brielle Bruns</a> of <a href="http://www.sosdg.org">The Summit Open Source Development Group</a><br />
      This program is licensed under the <a href="http://www.gnu.org/licenses/gpl-2.0.txt">GPLv2 license</a>. </span><br />
    </p>
    </body>
    </html>

    Merci.
    Intel I7 960 | 6 Go Ram | 5 HDD au total 3636 Go | Windows 7 Edition intégral x64 | WampServer 2.0c | Apache 2.2.8 | Php 5.2.6 | MySQL 5.0.51b
    DreamPlug | 512 mo ram | SSD 16 GO | Linux debian 2.6.39.4 | armv5tel | Lamp | PHP 5.3.3-7 | Apache 2.2.16 | Mysql 14.14

Discussions similaires

  1. [PHP 5.0] executer une commande en php
    Par lemessindu57 dans le forum Langage
    Réponses: 4
    Dernier message: 10/03/2011, 18h50
  2. Executer une commande sur un serveur linux à partir de php
    Par lanjolanjo dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 2
    Dernier message: 31/07/2009, 10h14
  3. [Système] Execution d'une commande avec php
    Par djspank dans le forum Langage
    Réponses: 1
    Dernier message: 14/03/2007, 08h47
  4. Executer une commande avec sudo a partir de java
    Par barabas123 dans le forum Langage
    Réponses: 16
    Dernier message: 05/01/2007, 16h47
  5. Exécuter une commande avec ssh
    Par GLDavid dans le forum Réseau
    Réponses: 3
    Dernier message: 18/01/2006, 17h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo