| 44 |
'title' => 'Edit', |
'title' => 'Edit', |
| 45 |
'description' => 'Administer all your crons from one drupal', |
'description' => 'Administer all your crons from one drupal', |
| 46 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 47 |
'page arguments' => array('cron_edit_form', 5), |
'page arguments' => array('cron_edit_form', 7), |
| 48 |
'access arguments' => array('authenticated user'), |
'access arguments' => array('authenticated user'), |
| 49 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 50 |
); |
); |
| 62 |
function cron_list_form() { |
function cron_list_form() { |
| 63 |
$header = array( |
$header = array( |
| 64 |
t('Site'), |
t('Site'), |
|
t('Cron key (Drupal7)'), |
|
| 65 |
t('Description'), |
t('Description'), |
| 66 |
array('data' => t('Checks'), 'field' => 'checks'), |
array('data' => t('Checks'), 'field' => 'checks'), |
| 67 |
t('Last check'), |
t('Last check'), |
| 69 |
t('Last error') |
t('Last error') |
| 70 |
); |
); |
| 71 |
|
|
| 72 |
$sql = 'SELECT DISTINCT sid, url, description, cron_key, checks, errors, last_check, last_error FROM {cron}'; |
$sql = 'SELECT DISTINCT sid, url, description, checks, errors, last_check, last_error FROM {cron}'; |
| 73 |
$sql .= tablesort_sql($header); |
$sql .= tablesort_sql($header); |
| 74 |
$query_count = 'SELECT COUNT(DISTINCT url) FROM {cron}'; |
$query_count = 'SELECT COUNT(DISTINCT url) FROM {cron}'; |
| 75 |
$result = pager_query($sql, 50, 0, $query_count); |
$result = pager_query($sql, 50, 0, $query_count); |
| 78 |
while ($site = db_fetch_object($result)) { |
while ($site = db_fetch_object($result)) { |
| 79 |
$sites[$site->sid] = ''; |
$sites[$site->sid] = ''; |
| 80 |
$form['url'][$site->sid] = array('#value' => $site->url); |
$form['url'][$site->sid] = array('#value' => $site->url); |
|
$form['cron_key'][$site->sid] = array('#value' => $site->cron_key); |
|
| 81 |
$form['description'][$site->sid] = array('#value' => $site->description); |
$form['description'][$site->sid] = array('#value' => $site->description); |
| 82 |
$form['checks'][$site->sid] = array('#value' => $site->checks); |
$form['checks'][$site->sid] = array('#value' => $site->checks); |
| 83 |
$form['last_check'][$site->sid] = array('#value' => format_interval(time() - $site->last_check)); |
$form['last_check'][$site->sid] = array('#value' => format_interval(time() - $site->last_check)); |
| 97 |
function cron_add_form() { |
function cron_add_form() { |
| 98 |
|
|
| 99 |
$form['notes'] = array( |
$form['notes'] = array( |
| 100 |
'#value' => t('Site: Drupal URL. <br />Description: A description for your site.') |
'#value' => t('Site: Drupal URL. <br />Description: A description for your site. <br /> Cron_key: The cron key required for Drupal 7') |
| 101 |
); |
); |
| 102 |
$form['url'] = array( |
$form['url'] = array( |
| 103 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 104 |
'#size' => 20, |
'#size' => 20, |
| 105 |
'#required' => TRUE, |
'#required' => TRUE, |
| 106 |
); |
); |
|
$form['cron_key'] = array( |
|
|
'#type' => 'textfield', |
|
|
'#size' => 20, |
|
|
); |
|
| 107 |
$form['description'] = array( |
$form['description'] = array( |
| 108 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 109 |
'#size' => 20, |
'#size' => 20, |
| 147 |
|
|
| 148 |
$form_state['values']['url'] = $url; |
$form_state['values']['url'] = $url; |
| 149 |
$url .= '/cron.php'; |
$url .= '/cron.php'; |
|
if (isset($form_state['values']['cron_key'])) { |
|
|
$url .= '?cron_key=' . $form_state['values']['cron_key']; |
|
|
} |
|
| 150 |
$ch = curl_init($url); |
$ch = curl_init($url); |
| 151 |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
| 152 |
curl_setopt($ch, CURLOPT_NOBODY, TRUE); |
curl_setopt($ch, CURLOPT_NOBODY, TRUE); |
| 163 |
} |
} |
| 164 |
|
|
| 165 |
function cron_add_form_submit($form, $form_state) { |
function cron_add_form_submit($form, $form_state) { |
| 166 |
db_query("INSERT INTO {cron} (url, description, cron_key, checks, last_check) VALUES ('%s', '%s', '%s', 1, '%d')", $form_state['values']['url'], $form_state['values']['description'], $form_state['values']['cron_key'], time()); |
db_query("INSERT INTO {cron} (url, description, checks, last_check) VALUES ('%s', '%s', 1, '%d')", $form_state['values']['url'], $form_state['values']['description'], time()); |
| 167 |
drupal_goto('admin/settings/tools/cron'); |
drupal_goto('admin/settings/tools/cron'); |
| 168 |
} |
} |
| 169 |
|
|
| 170 |
function cron_edit_form($form_state, $sid = 0) { |
function cron_edit_form($form_state, $sid = 0) { |
| 171 |
$sql = db_query("SELECT url, description, cron_key, checks, errors FROM {cron} WHERE sid = '%d'", $sid); |
$sql = db_query("SELECT url, description, checks, errors FROM {cron} WHERE sid = '%d'", $sid); |
| 172 |
$row = db_fetch_object($sql); |
$row = db_fetch_object($sql); |
| 173 |
$form['sid'] = array( |
$form['sid'] = array( |
| 174 |
'#type' => 'hidden', |
'#type' => 'hidden', |
| 183 |
'#size' => 20, |
'#size' => 20, |
| 184 |
'#default_value' => $row->url, |
'#default_value' => $row->url, |
| 185 |
); |
); |
|
$form['cron_key'] = array( |
|
|
'#type' => 'textfield', |
|
|
'#size' => 20, |
|
|
'#default_value' => $row->cron_key, |
|
|
); |
|
| 186 |
$form['description'] = array( |
$form['description'] = array( |
| 187 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 188 |
'#size' => 20, |
'#size' => 20, |
| 223 |
|
|
| 224 |
$form_state['values']['url'] = $url; |
$form_state['values']['url'] = $url; |
| 225 |
$url .= '/cron.php'; |
$url .= '/cron.php'; |
|
if (isset($form_state['values']['cron_key'])) { |
|
|
$url .= '?cron_key=' . $form_state['values']['cron_key']; |
|
|
} |
|
| 226 |
$ch = curl_init($url); |
$ch = curl_init($url); |
| 227 |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
| 228 |
curl_setopt($ch, CURLOPT_NOBODY, TRUE); |
curl_setopt($ch, CURLOPT_NOBODY, TRUE); |
| 239 |
} |
} |
| 240 |
|
|
| 241 |
function cron_edit_form_submit($form, $form_state) { |
function cron_edit_form_submit($form, $form_state) { |
| 242 |
db_query("UPDATE {cron} SET url = '%s', description = '%s', cron_key = '%s', checks = '%d', last_check = '%d' WHERE sid = '%d'", $form_state['values']['url'], $form_state['values']['description'], $form_state['values']['cron_key'], $form_state['values']['checks'] + 1, time(), $form_state['values']['sid']); |
db_query("UPDATE {cron} SET url = '%s', description = '%s', checks = '%d', last_check = '%d' WHERE sid = '%d'", $form_state['values']['url'], $form_state['values']['description'], $form_state['values']['checks'] + 1, time(), $form_state['values']['sid']); |
| 243 |
drupal_goto('admin/settings/tools/cron'); |
drupal_goto('admin/settings/tools/cron'); |
| 244 |
} |
} |
| 245 |
|
|
| 275 |
$header = array( |
$header = array( |
| 276 |
theme('table_select_header_cell'), |
theme('table_select_header_cell'), |
| 277 |
t('Site'), |
t('Site'), |
|
t('Cron key (Drupal7)'), |
|
| 278 |
t('Description'), |
t('Description'), |
| 279 |
array('data' => t('Checks'), 'field' => 'checks'), |
array('data' => t('Checks'), 'field' => 'checks'), |
| 280 |
t('Last check'), |
t('Last check'), |
| 287 |
$rows[] = array( |
$rows[] = array( |
| 288 |
drupal_render($form['sites'][$key]), |
drupal_render($form['sites'][$key]), |
| 289 |
drupal_render($form['url'][$key]), |
drupal_render($form['url'][$key]), |
|
drupal_render($form['cron_key'][$key]), |
|
| 290 |
drupal_render($form['description'][$key]), |
drupal_render($form['description'][$key]), |
| 291 |
drupal_render($form['checks'][$key]), |
drupal_render($form['checks'][$key]), |
| 292 |
drupal_render($form['last_check'][$key]), |
drupal_render($form['last_check'][$key]), |
| 319 |
// Overview table: |
// Overview table: |
| 320 |
$header = array( |
$header = array( |
| 321 |
t('Site'), |
t('Site'), |
|
t('Cron key (Drupal7)'), |
|
| 322 |
t('Description'), |
t('Description'), |
| 323 |
t('Operations') |
t('Operations') |
| 324 |
); |
); |
| 326 |
if (isset($form['url']) && is_array($form['url'])) { |
if (isset($form['url']) && is_array($form['url'])) { |
| 327 |
$rows[] = array( |
$rows[] = array( |
| 328 |
drupal_render($form['url']), |
drupal_render($form['url']), |
|
drupal_render($form['cron_key']), |
|
| 329 |
drupal_render($form['description']), |
drupal_render($form['description']), |
| 330 |
drupal_render($form['operations']), |
drupal_render($form['operations']), |
| 331 |
); |
); |
| 348 |
// Overview table: |
// Overview table: |
| 349 |
$header = array( |
$header = array( |
| 350 |
t('Site'), |
t('Site'), |
|
t('Cron key (Drupal7)'), |
|
| 351 |
t('Description'), |
t('Description'), |
| 352 |
t('Operations') |
t('Operations') |
| 353 |
); |
); |
| 354 |
if (isset($form['url']) && is_array($form['url'])) { |
if (isset($form['url']) && is_array($form['url'])) { |
| 355 |
$rows[] = array( |
$rows[] = array( |
| 356 |
drupal_render($form['url']), |
drupal_render($form['url']), |
|
drupal_render($form['cron_key']), |
|
| 357 |
drupal_render($form['description']), |
drupal_render($form['description']), |
| 358 |
drupal_render($form['operations']), |
drupal_render($form['operations']), |
| 359 |
); |
); |
| 372 |
*/ |
*/ |
| 373 |
function cron_cron() { |
function cron_cron() { |
| 374 |
|
|
| 375 |
$sql = db_query("SELECT sid, url, cron_key, checks, errors, last_error FROM {cron}"); |
$sql = db_query("SELECT sid, url, checks, errors, last_error FROM {cron}"); |
| 376 |
while ($row = db_fetch_object($sql)) { |
while ($row = db_fetch_object($sql)) { |
| 377 |
|
|
| 378 |
$checks = $row->checks + 1; |
$checks = $row->checks + 1; |
| 385 |
if (isset($row->cron_key)) { |
if (isset($row->cron_key)) { |
| 386 |
$url .= '?cron_key=' . $row->cron_key; |
$url .= '?cron_key=' . $row->cron_key; |
| 387 |
} |
} |
| 388 |
|
|
| 389 |
|
$options = array( |
| 390 |
|
CURLOPT_RETURNTRANSFER => TRUE, // return web page |
| 391 |
|
CURLOPT_HEADER => TRUE, // don't return headers |
| 392 |
|
CURLOPT_NOBODY => TRUE, |
| 393 |
|
CURLOPT_FOLLOWLOCATION => FALSE, // don't follow redirects |
| 394 |
|
CURLOPT_USERAGENT => 'spider', // who am i |
| 395 |
|
CURLOPT_AUTOREFERER => TRUE, // set referer on redirect |
| 396 |
|
CURLOPT_CUSTOMREQUEST => 'HEAD'. |
| 397 |
|
CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect |
| 398 |
|
CURLOPT_TIMEOUT => 60, // timeout on response |
| 399 |
|
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects |
| 400 |
|
); |
| 401 |
|
|
| 402 |
$ch = curl_init($url); |
$ch = curl_init($url); |
| 403 |
curl_setopt($ch, CURLOPT_HEADER, TRUE); |
curl_setopt_array($ch,$options); |
|
curl_setopt($ch, CURLOPT_NOBODY, TRUE); |
|
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); |
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); |
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); |
|
| 404 |
curl_exec($ch); |
curl_exec($ch); |
| 405 |
|
|
| 406 |
$result = curl_getinfo($ch); |
$result = curl_getinfo($ch); |
| 407 |
$checks = $row->checks + 1; |
$checks = $row->checks + 1; |
| 408 |
$errors = $row->errors ; |
$errors = $row->errors ; |
| 429 |
} |
} |
| 430 |
$fp = fsockopen($url, $port, $errno, $errstr, 30); |
$fp = fsockopen($url, $port, $errno, $errstr, 30); |
| 431 |
$page = $path ."/cron.php"; |
$page = $path ."/cron.php"; |
|
if (isset($row->cron_key)) { |
|
|
$page .= '?cron_key=' . $row->cron_key; |
|
|
} |
|
| 432 |
$out="GET $page HTTP/1.1\r\n"; |
$out="GET $page HTTP/1.1\r\n"; |
| 433 |
$out.="Host: $url\r\n"; |
$out.="Host: $url\r\n"; |
| 434 |
$out.="Connection: Close\r\n\r\n"; |
$out.="Connection: Close\r\n\r\n"; |