Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright Tech To The People http:tttp.eu (c) 2008 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License along with this program; if not, contact CiviCRM LLC | | |
20 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
21 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
22 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
23 | +--------------------------------------------------------------------+ | |
24 | */ | |
25 | ||
26 | /** | |
27 | * A PHP shell script | |
28 | ||
29 | On drupal if you have a symlink to your civi module, don't forget to create a new file - settings_location.php | |
30 | Enter the following code (substitute the actual location of your <drupal root>/sites directory) | |
31 | <?php | |
32 | define( 'CIVICRM_CONFDIR', '/var/www/drupal.6/sites' ); | |
33 | ?> | |
34 | ||
35 | */ | |
bed96570 | 36 | $include_path = "../packages/:" . get_include_path(); |
6a488035 | 37 | set_include_path($include_path); |
a1a55b61 EM |
38 | |
39 | /** | |
40 | * Class civicrm_CLI | |
41 | */ | |
6a488035 TO |
42 | class civicrm_CLI { |
43 | ||
44 | /** | |
45 | * constructor | |
46 | */ | |
47 | function __construct() { | |
48 | // $include_path = "packages/" . get_include_path( ); | |
49 | // set_include_path( $include_path ); | |
50 | require_once 'Console/Getopt.php'; | |
51 | $shortOptions = "s:u:p:k:"; | |
52 | $longOptions = array('site=', 'user', 'pass'); | |
53 | ||
54 | $getopt = new Console_Getopt(); | |
55 | $args = $getopt->readPHPArgv(); | |
56 | array_shift($args); | |
57 | list($valid, $this->args) = $getopt->getopt2($args, $shortOptions, $longOptions); | |
58 | ||
59 | $vars = array( | |
60 | 'user' => 'u', | |
61 | 'pass' => 'p', | |
62 | 'key' => 'k', | |
63 | 'site' => 's', | |
64 | ); | |
65 | ||
66 | foreach ($vars as $var => $short) { | |
67 | $$var = NULL; | |
68 | foreach ($valid as $v) { | |
69 | if ($v[0] == $short || $v[0] == "--$var") { | |
70 | $$var = $v[1]; | |
71 | break; | |
72 | } | |
73 | } | |
74 | if (!$$var) { | |
75 | die("\nUsage: $ php5 " . $_SERVER['PHP_SELF'] . " -k key -u user -p password -s yoursite.org\n"); | |
76 | } | |
77 | } | |
78 | $this->site = $site; | |
79 | $this->key = $key; | |
80 | $this->setEnv(); | |
81 | $this->authenticate($user, $pass); | |
82 | } | |
83 | ||
a1a55b61 EM |
84 | /** |
85 | * @param $user | |
86 | * @param $pass | |
87 | */ | |
6a488035 TO |
88 | function authenticate($user, $pass) { |
89 | session_start(); | |
90 | require_once 'CRM/Core/Config.php'; | |
91 | ||
92 | $config = &CRM_Core_Config::singleton(); | |
93 | ||
94 | // this does not return on failure | |
95 | // require_once 'CRM/Utils/System.php'; | |
96 | // CRM_Utils_System::authenticateScript( true ); | |
97 | CRM_Utils_System::authenticateScript(TRUE, $user, $pass); | |
98 | } | |
99 | ||
100 | function setEnv() { | |
101 | // so the configuration works with php-cli | |
102 | $_SERVER['PHP_SELF'] = "/index.php"; | |
103 | $_SERVER['HTTP_HOST'] = $this->site; | |
104 | $_REQUEST['key'] = $this->key; | |
105 | require_once ("./civicrm.config.php"); | |
106 | } | |
107 | } | |
108 | ||
109 | ||
110 | //$cli=new civicrm_cli (); | |
111 |