'. t('Update Notify is two modules: a "client" and a "server". The client, to be enabled on all sites that are to report to the central tracker, sends a list of installed modules and their status to the tracking site via xmlrpc when cron is run. This information is taken from the update status module. The server component, enabled on the tracking site, receives these lists from all the clients and creates nodes for each module. These nodes will then get updated everytime the cron is run on the tracked sites. For the tracked sites to have the right to create these nodes, the keys of the tracked sites need to be entered into the tracker site.') .'

'; } } /** * Drupal perm Hook */ function update_notify_perm() { return array( 'create update notify module', 'edit own update notify module', 'create update notify site', 'edit own update notify site', ); } /** * Drupal access Hook */ function update_notify_access($op, $node, $account) { if ($node->type == "update_notify_module"){ if ($op == 'create') { return user_access('create update notify module', $account); } if ($op == 'update' || $op == 'delete') { if (user_access('edit own update notify module', $account) && ($account->uid == $node->uid)) { return TRUE; } } } elseif ($node->type == "update_notify_site"){ if ($op == 'create') { return user_access('create update notify site', $account); } if ($op == 'update' || $op == 'delete') { if (user_access('edit own update notify site', $account) && ($account->uid == $node->uid)) { return TRUE; } } } } /** * Implementation of hook_views_tables(). */ function update_notify_views_tables(){ $tables['update_notify'] = array( 'name' => 'update_notify', 'provider' => 'internal', // won't show up in external list. 'join' => array( 'type' => 'inner', 'left' => array( 'table' => 'node', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ), ), "fields" => array( "module" => array( 'name' => t('Update notify Module'), 'help' => t('Update notify Module'), 'sortable' => TRUE, ), "site" => array( 'name' => t('Update notify site'), 'help' => t('Update notify site'), 'sortable' => TRUE, ), "status" => array( 'name' => t('Update notify status'), 'help' => t('Update notify status'), //'handler' => 'views_handler_status', 'sortable' => TRUE, ), ), "filters" => array( "module" => array( "name" => t('Update notify: module'), "help" => "Module name", 'operator' => 'views_handler_operator_like' ), "site" => array( "name" => t('Update notify: site'), "help" => "Site name", 'operator' => 'views_handler_operator_like' ) ) ); return $tables; } /** * Implementation of hook_xmlrpc(). * * Maps external names of XML-RPC methods to callback functions. */ function update_notify_xmlrpc() { return array( array( 'update_notify.notify', // External method name. 'update_notify_xml_notify', // Drupal function to run. array('string','struct'), t('Returns the list of module to update.') // Description. ) ); } /** * Implementation of hook_node_info(). */ function update_notify_node_info() { return array( 'update_notify_module' => array( 'name' => t('Update notification module'), 'module' => 'update_notify', 'description' => t('Tracker/Server module to receive update notifications from tracked sites.'), 'has_title' => TRUE, 'title_label' => t('Name of the module'), 'has_body' => FALSE, ), 'update_notify_site' => array( 'name' => t('Update notification site'), 'module' => 'update_notify', 'description' => t("Notification module that will enable reporting of modules' status to site with update_notify module enabled."), 'has_title' => TRUE, 'title_label' => t('Remote site name'), 'has_body' => FALSE, ), ); } /** * Implementation of hook_load(). */ function update_notify_load($node) { if ($node->type == "update_notify_module"){ return db_fetch_object(db_query('SELECT module, site, status FROM {update_notify} WHERE vid = %d', $node->vid)); } elseif ($node->type == "update_notify_site"){ return db_fetch_object(db_query('SELECT drupal_key FROM {update_notify_keys} WHERE vid = %d', $node->vid)); } } /** * Implementation of hook_view(). * * Display the content in a very simple way. * */ function update_notify_view($node, $teaser = FALSE, $page = FALSE) { if (!$teaser) { if ($node->type == "update_notify_module"){ $node = node_prepare($node, $teaser); $node->content['short_name'] = array( '#value' => t("Module") . ": " . $node->module . "
", '#weight' => 2 ); $node->content['site'] = array( '#value' => t("Site") . ": " . $node->site . "
", '#weight' => 2 ); $status = status_int_to_string($node->status); $node->content['status'] = array( '#value' => t("Status") . ": " . $status . "
", '#weight' => 2 ); } elseif ($node->type == "update_notify_site"){ $node = node_prepare($node, $teaser); $node->content['drupal_key'] = array( '#value' => t("key") . ": " . $node->drupal_key . "
", '#weight' => 0 ); } } if ($teaser){ $node = node_prepare($node, $teaser); } return $node; } /** * Implementation of hook_insert(). */ function update_notify_insert($node) { if ($node->type == "update_notify_module"){ db_query("INSERT INTO {update_notify} (nid, vid, module, site, status) VALUES (%d, %d, '%s', '%s', %d)", $node->nid, $node->vid, $node->short_name, $node->site, $node->status); } elseif ($node->type == "update_notify_site"){ db_query("INSERT INTO {update_notify_keys} (nid, vid, drupal_key) VALUES (%d, %d, '%s')", $node->nid, $node->vid, $node->drupal_key); } } /** * Implementation of hook_update(). */ function update_notify_update($node) { if ($node->revision) { update_notify_insert($node); } else { if ($node->type == "update_notify_module"){ db_query("UPDATE {update_notify} SET module = '%s', site = '%s', status = %d WHERE vid = %d", $node->short_name, $node->site, $node->status, $node->vid); } elseif ($node->type == "update_notify_site"){ db_query("UPDATE {update_notify_keys} SET drupal_key = '%s' WHERE vid = %d", $node->drupal_key, $node->vid); } } } /** * Implementation of hook_delete(). */ function update_notify_delete(&$node) { if ($node->type == "update_notify_module"){ db_query('DELETE FROM {update_notify} WHERE nid = %d', $node->nid); } elseif ($node->type == "update_notify_site"){ db_query('DELETE FROM {update_notify_keys} WHERE nid = %d', $node->nid); } } /** * Implementation of hook_form(). */ function update_notify_form($node) { $type = node_get_types('type', $node); if ($node->type == "update_notify_module"){ $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5 ); $form['short_name'] = array( '#type' => 'textfield', '#title' => t('Module'), '#size' => 60, '#maxlength' => 128, '#default_value' => $node->module, '#required' => TRUE, ); $form['site'] = array( '#type' => 'textfield', '#title' => t("Remote Drupal website's name"), '#size' => 60, '#maxlength' => 128, '#default_value' => $node->site, '#required' => TRUE, ); $form['status'] = array( '#type' => 'textfield', '#title' => t('Status'), '#size' => 60, '#maxlength' => 128, '#default_value' => $node->status, '#required' => TRUE, ); } elseif ($node->type == "update_notify_site"){ $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5 ); $form['drupal_key'] = array( '#type' => 'textfield', '#title' => t('Key'), '#size' => 60, '#maxlength' => 128, '#default_value' => $node->drupal_key, '#required' => TRUE, ); } return $form; } function update_notify_xml_notify($pack) { $key = $pack['key']; unset($pack['key']); $name = db_fetch_object( db_query("SELECT title from update_notify_keys LEFT JOIN node on node.nid = update_notify_keys.nid WHERE drupal_key = '%s'" , $key)); foreach($pack as $module => $status) { /* * skip unknow modules */ if(!empty($module)){ $pre = array( 'type' => 'update_notify_module', 'body' => '', 'title' => $module . " : " . $status, 'created' => time(), 'uid' => 1, 'status' => 1 ); $sql = "SELECT nid FROM {update_notify} WHERE module='%s' AND site='%s'"; $nid = db_result(db_query($sql,$module, $name->title)); if($nid){ $pre['nid'] = $nid; } $pre['short_name'] = $module; $pre['site'] = $name->title; $pre['status'] = $status; $node = node_submit($pre); node_save($node); } } return t("notification send with success"); } function status_int_to_string($number){ switch ($number){ case 1: $status = t('NEED SECURITY UPDATE'); break; case 2: $status = t('REVOKED'); break; case 3: $status = t('NOT SUPPORTED'); break; case 4: $status = t('NEW RELEASE AVAILABLE'); break; case 5: $status = t('UP TO DATE'); break; case -1: $status = t('NOT CHECKED'); break; case -2: $status = t('UNKNOWN'); break; } return $status; } function views_handler_status($fieldinfo, $fielddata, $value, $data){ return status_int_to_string($value); }