-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdsconnection.module
203 lines (187 loc) · 7.62 KB
/
wdsconnection.module
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
<?php
// $Id$
/**
* @file
* WDSConnection Module.
*
* This File and the whole module is part of a proof-of-concept
* creating a manageable system that would connect a Drupal Website
* and deploy completely configurable systems through the subnet,
* with the ease of buying something inside an e-shop.
*/
/* * *****************************************************************************
* Hook Functions (Drupal)
* **************************************************************************** */
/**
* Display help and module information
* For now there is not any working help for this module
* this is a stub.
* @param path which path of the site we're displaying help
* @param arg array that holds the current path as would be returned from arg() function
* @return help text for the path
*/
function wdsconnection_help($path, $arg) {
switch ($path) {
case "admin/help/wdsconnection":
$output = '<p>' . t("wdsconnection is a module that connects the WDS system on this server with the Drupal Site") . '</p>';
break;
}
return $output;
}
/**
* Valid permissions for this module
* @return array An array of valid permissions for the wdsconnection module
*/
function wdsconnection_perm() {
return array('administer wdsconnection', 'access wdsconnection content');
}
/**
* Menu for this module
* @return array An array with this module's settings.
*/
function wdsconnection_menu() {
$items = array();
//Link to the wdsconnection admin page:
$items['admin/settings/wdsconnection'] = array(
'title' => 'WDS Connection Module',
'description' => 'Administer WDS Module',
'page callback' => 'wdsconnection_message',
'access arguments' => array('administer wdsconnection'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementing hook_user in order to acquire and store the passwords
* in database
*/
function wdsconnection_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register') {
// add additional submit handler
$form['#submit'][] = 'wdsconnection_aftersubmit'; //additional submit handler
//this funcation will be executed after drupal executes default submit handler
// so the user is added and you have the user info in $user object
}
}
function wdsconnection_aftersubmit($form, &$form_state) {
global $user; //user is just added and so we have the user data
drupal_set_message($user->name);
}
/**
* Command line command for creating a new user
* implementing the hook_order function
* and adding him to the appropriate group
* @param op,arg1,arg2
* @return array in case of failure
*/
function wdsconnection_order($op, &$arg1, $arg2) {
global $user;
if ($op == 'submit') {
//aes password decryption
$pass = aes_get_password($user->uid, $decrypt = true);
//command to add a user to the AD-DS
$command = 'net user ' . $user->name . ' ' . $pass . ' /add';
$out = shell_exec($command);
if (substr_count($out, 'successfully') == '1') {
//output of the command
drupal_set_message($out);
drupal_set_message('The user ' . $user->name .
'is corectly stored in AD DS of our server.<br> WRITE DOWN YOUR PASSWORD AND USERNAME TO ENTER AT THE INSTALLATION.');
//we are stopping the service to reduce server load
//wdsconnection_service_stop();
} else {
return array(
array(
'pass' => FALSE,
'message' => t('User either exists, or there is another problem.<br>Try setting up a more difficult password.')));
}
}
}
/**
* Function for moving the uploaded image to the d:\images\images
* or the uploaded drivers to the package manager
* and running the wdsutil for adding the new image to the system
* or the MDT for integrating the drivers, and/or other software
* by implementing the hook_insert function
*/
function wdsconnection_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
//get the type of the node
//drupal_set_message($node->type);
if (($op == "insert")) {
switch ($node->type) {
case 'oses';
//configure the WDS server with the operating system
$command = "wdsutil /add-image /ImageFile:\"C:\wamp\www\\recoveryserver\sites\default\files\\\"" .
substr($node->field_iso[0]['filepath'], 20) .
"\" /Server:yourServer /ImageType:Install /ImageGroup:" .
$node->iimagegroup . " /SingleImage:" . $node->model . " /Name:\"" . $node->title .
"\"/Description:\"" . $node->body . "\" /Filename:\"" . substr($node->field_iso[0]['filepath'], 20) . "\"";
//run as service for the x64 systems
//wdsconnection_service_start($command);
$out = shell_exec($command);
break;
case 'drivers';
//configure the Drivers and Other software with the current tool (MDT-wds)
if (substr($node->field_upload[0]['filepath'], -3) == 'zip') {
//add-load drivers to current setup
}
if (substr($node->field_upload[0]['filepath'], -3) == 'rar') {
//add-load drivers to a current setup
}
if (substr($node->field_upload[0]['filepath'], -3) == 'exe') {
//add to a current setup
}
break;
case 'livecds';
//configure the WDS server with the current Live CD
if (substr($node->field_bootiso[0]['filepath'], -3) == 'wim') {
$boot_command = "wdsutil /add-image /ImageFile:\"C:\wamp\www\\recoveryserver\sites\default\\files\\" .
substr($node->field_bootiso[0]['filepath'], 20) .
"\" /Server:yourServer /ImageType:Boot /Name:\"" .
$node->title . "\" /Description:\"" . $node->body . "\" /Filename:" . $node->model . ".wim";
//run as service for the x64 systems
wdsconnection_service_start($boot_command);
$out = shell_exec($boot_command);
drupal_set_message($out);
drupal_set_message($boot_command);
};
if (substr($node->field_iso[0]['filepath'], -3) == 'iso') {
//mount the iso file and extract the OS
};
break;
default;
break;
}
}
}
/* Because this system does not support calling x64 applications from
* x32 handlers we add a service named fola which executes the
* command as a batch file (named fola as well)
* and we start it
* @file input the command
* @return nothing
*/
function wdsconnection_service_start(&$command) {
$filename = 'fola.bat';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
drupal_set_message("Cannot open file ($filename)");
}
if (fwrite($handle, $command) === FALSE) {
drupal_set_message("Cannot write to file ($filename)");
}
drupal_set_message("Success, wrote ($command) to file ($filename)");
fclose($handle);
} else {
drupal_set_message("The file $filename is not writable");
}
//start the service
$out = shell_exec('sc start fola');
}
/* Stoping of the above service to reduce sources
* inputs nothing , return nothing
*/
function wdsconnection_service_stop() {
//stop the service
$out = shell_exec('sc stop fola');
}