function guifi_user_delete_confirm_submit($form, &$form_state)
{
    //  global $user;
    guifi_log(GUIFILOG_TRACE, 'guifi_delete_user_confirm_submit()', $form_state['values']);
    if ($form_state['values']['op'] != t('Delete')) {
        return;
    }
    $guifi_user = guifi_user_load($form_state['values']['id']);
    $node = guifi_node_load($guifi_user['nid']);
    $to_mail = array();
    $subject = t('User %username deleted by %user.', array('%username' => $guifi_user['username'], '%user' => $user->name));
    $log .= '<br />' . _guifi_db_delete('guifi_users', array('id' => $guifi_user['id']), $to_mail);
    guifi_notify($to_mail, $subject, $log);
    drupal_goto('node/' . $guifi_user['nid'] . '/view/users');
}
function guifi_device_delete($device, $notify = TRUE, $verbose = TRUE)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_delete()');
    $to_mail = explode(',', $device['notification']);
    if ($_POST['confirm']) {
        $log = _guifi_db_delete('guifi_devices', array('id' => $device['id']), $to_mail);
        drupal_set_message($log);
        $subject = t('The device %name has been DELETED by %user.', array('%name' => $device['nick'], '%user' => $user->name));
        drupal_set_message($subject);
        guifi_notify($to_mail, $subject, $log, $verbose, $notify);
        guifi_node_set_flag($device['nid']);
        drupal_goto('node/' . $device['nid']);
    }
    $node = node_load(array('nid' => $device['nid']));
    drupal_set_breadcrumb(guifi_node_ariadna($node));
    $output = drupal_get_form('guifi_device_delete_confirm', array('name' => $device['nick'], 'id' => $device['id']));
    print theme('page', $output, FALSE);
    return;
}
function guifi_devel_paramusc_delete_confirm_submit($form, &$form_state)
{
    global $user;
    $depth = 0;
    if ($form_state['values']['op'] != t('Delete')) {
        return;
    }
    $to_mail = explode(',', $node->notification);
    $log = _guifi_db_delete('guifi_parametresConfiguracioUnsolclic', array('id' => $form_state['values']['id']), $to_mail, $depth);
    drupal_set_message($log);
    guifi_notify($to_mail, t('The USC Configuration parameter %parametre has been DELETED by %user.', array('%parametre' => $form_state['values']['nom'], '%user' => $user->name)), $log);
    drupal_goto('guifi/menu/devel/parameter');
}
/** guifi_node_delete(): deletes a given node
 **/
function guifi_node_delete($node)
{
    global $user;
    $depth = 0;
    $to_mail = explode(',', $node->notification);
    $log = _guifi_db_delete('guifi_location', array('id' => $node->nid), $to_mail, $depth);
    drupal_set_message($log);
    guifi_notify($to_mail, t('The node %name has been DELETED by %user.', array('%name' => $node->title, '%user' => $user->name)), $log);
    cache_clear_all();
    variable_set('guifi_refresh_cnml', time());
    variable_set('guifi_refresh_maps', time());
    return;
}
Beispiel #5
0
/**
 * Remove a device from guifi.net
 *
 * @param GuifiAPI $gapi
 * @param mixed[] $parameters Parameters to remove the device (device_id, basically)
 * @return boolean Whether the device was removed or not
 */
function guifi_api_device_remove($gapi, $parameters)
{
    if (!guifi_api_check_fields($gapi, array('device_id'), $parameters)) {
        return FALSE;
    }
    global $user;
    $device = guifi_device_load($parameters['device_id']);
    if (!$device['id']) {
        $gapi->addError(500, "device_id = {$parameters['device_id']}");
        return FALSE;
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_device_delete()');
    $to_mail = explode(',', $device['notification']);
    $log = _guifi_db_delete('guifi_devices', array('id' => $device['id']), $to_mail);
    drupal_set_message($log);
    $subject = t('The device %name has been DELETED by %user.', array('%name' => $device['nick'], '%user' => $user->name));
    guifi_notify($to_mail, $subject, $log, $verbose, $notify);
    guifi_node_set_flag($device['nid']);
    return TRUE;
}
Beispiel #6
0
/** _guifi_db_delete(): Delete SQL statements for node, devices, radios, users, services, interfaces, ipv4, links, zones...
***/
function _guifi_db_delete($table, $key, &$to_mail = array(), $depth = 0, $cascade = TRUE)
{
    global $user;
    $log = str_repeat('- ', $depth);
    $depth++;
    $to_mail = array();
    guifi_log(GUIFILOG_TRACE, sprintf('function _guifi_db_delete(%s,%s)', $table, var_export($key, TRUE)));
    if (!in_array($user->mail, $to_mail)) {
        $to_mail[] = $user->mail;
    }
    switch ($table) {
        // Node (location)
        case 'guifi_location':
            // cascade to node devices
            $qc = db_query("SELECT id FROM {guifi_devices} where nid = '%s'", $key['id']);
            while ($device = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_devices', $device, $to_mail, $depth);
            }
            // cascade to node users
            $qc = db_query("SELECT id FROM {guifi_users} where nid = '%s'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_users', $quser, $to_mail, $depth);
            }
            // delete Device
            // cascade to node maintainers
            $qc = db_query("SELECT id FROM {guifi_maintainers} where subject_id = '%s' and subject_type='location'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_maintainers', $quser, $to_mail, $depth);
            }
            break;
        case 'guifi_dns_domains':
            $item = db_fetch_object(db_query('SELECT d.id did, d.name dname, d.notification, d.sid,
        l.nick nname, l.notification ncontact
       FROM {guifi_dns_domains} d LEFT JOIN {guifi_services} l ON d.sid=l.id
       WHERE d.id = %d', $key['id']));
            $log .= t('Domain %id-%name at node %nname deleted.', array('%id' => $key['id'], '%name' => $item->dname, '%nname' => $item->nname));
            // cascade to dns_hosts
            $qc = db_query('SELECT id, counter FROM {guifi_dns_hosts} WHERE id=%d', $key['id']);
            while ($host = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_dns_hosts', $host, $to_mail, $depth);
            }
            break;
        case 'guifi_devices':
            $item = db_fetch_object(db_query('SELECT d.nick dname, d.notification, d.nid, d.type, d.comment,
        l.nick nname, l.notification ncontact
       FROM {guifi_devices} d LEFT JOIN {guifi_location} l ON d.nid=l.id
       WHERE d.id = %d', $key['id']));
            $log .= t('Device (%type) %id-%name at node %nname deleted.', array('%type' => $item->type, '%id' => $key['id'], '%name' => $item->dname, '%nname' => $item->nname));
            // cascade to device radios
            $qc = db_query('SELECT id, radiodev_counter FROM {guifi_radios} WHERE id=%d', $key['id']);
            while ($radio = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_radios', $radio, $to_mail, $depth);
            }
            // cascade to device interfaces
            $qc = db_query('SELECT id FROM {guifi_interfaces} WHERE device_id=%d', $key['id']);
            while ($interface = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_interfaces', $interface, $to_mail, $depth);
            }
            // cascade to node maintainers
            $qc = db_query("SELECT id FROM {guifi_maintainers} where subject_id = '%s' and subject_type='device'", $key['id']);
            while ($quser = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_maintainers', $quser, $to_mail, $depth);
            }
            break;
            // delete Radio
        // delete Radio
        case 'guifi_radios':
            $item = db_fetch_object(db_query('SELECT
          r.protocol, r.ssid sid, r.mode, r.radiodev_counter,
          d.nick dname, d.notification, d.nid, l.nick nname
        FROM {guifi_radios} r, {guifi_devices} d, {guifi_location} l
        WHERE  r.id = %d AND r.radiodev_counter = %d AND
          r.id=d.id AND d.nid=l.id', $key['id']), $key['radiodev_counter']);
            $log .= t('Radio (%mode-%protocol) %id-%rc %ssid at device %dname deleted.', array('%mode' => $item->mode, '%protocol' => $item->protocol, '%id' => $key['id'], '%rc' => $key['radiodev_counter'], '%ssid' => $item->sid, '%dname' => $item->dname));
            // cascade to radio interfaces
            $qc = db_query('SELECT id, radiodev_counter FROM {guifi_interfaces} WHERE device_id=%d AND radiodev_counter=%d', $key['id'], $key['radiodev_counter']);
            while ($interface = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_interfaces', $interface, $to_mail, $depth);
            }
            break;
            // delete Interfaces
        // delete Interfaces
        case 'guifi_interfaces':
            $item = db_fetch_object(db_query('SELECT i.interface_type, i.radiodev_counter, i.connto_did, i.connto_iid,
               d.nick dname,
               d.notification, d.nid, l.nick nname
        FROM {guifi_interfaces} i LEFT JOIN {guifi_devices} d ON i.device_id=d.id
             LEFT JOIN {guifi_location} l ON d.nid=l.id
        WHERE i.id = %d', $key['id']));
            $log .= t('interface (%type) %id - %rc at device %dname deleted.', array('%type' => $item->interface_type, '%id' => $key['id'], '%rc' => $item->radiodev_counter, '%dname' => $item->dname));
            // cascade ipv4
            $qc = db_query('SELECT id, interface_id FROM {guifi_ipv4} WHERE interface_id=%d', $key['id']);
            while ($ipv4 = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_ipv4', $ipv4, $to_mail, $depth);
            }
            // cascade remote interface plug
            if ($item->connto_did and $item->connto_iid) {
                $if_remote = array('device_id' => $item->connto_did, 'id' => $item->connto_iid, 'connto_did' => '', 'connto_iid' => '');
                _guifi_db_sql('guifi_interfaces', array('device_id' => $item->connto_did, 'id' => $item->connto_iid), $if_remote, $log, $to_mail);
            }
            break;
            // delete ipv4
        // delete ipv4
        case 'guifi_ipv4':
            $item = db_fetch_object(db_query('SELECT a.id, a.interface_id, a.ipv4, i.interface_type, d.nick dname, d.notification, d.nid, l.nick nname
        FROM {guifi_ipv4} a LEFT JOIN {guifi_interfaces} i ON a.interface_id=i.id LEFT JOIN {guifi_devices} d ON i.device_id=d.id LEFT JOIN {guifi_location} l ON d.nid=l.id
        WHERE a.id = %d AND a.interface_id=%d', $key['id'], $key['interface_id']));
            $log .= t('address (%addr) at device %dname deleted.', array('%addr' => $item->ipv4, '%dname' => $item->dname));
            if (!$cascade) {
                break;
            }
            // cascade links
            $qc = db_query('SELECT id, device_id FROM {guifi_links} WHERE ipv4_id=%d AND interface_id=%d', $key['id'], $key['interface_id']);
            while ($link = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_links', $link, $to_mail, $depth);
            }
            break;
            // delete links
        // delete links
        case 'guifi_links':
            $item = db_fetch_object(db_query('SELECT l.id, l.link_type, l.ipv4_id, i.id interface_id, ' . '       d.nick dname, d.id device_id, d.notification, d.nid, n.nick nname
        FROM {guifi_links} l ' . '    LEFT JOIN {guifi_interfaces} i ON l.interface_id=i.id ' . '    LEFT JOIN {guifi_devices} d ON l.device_id=d.id ' . '    LEFT JOIN {guifi_location} n ON l.nid=n.id
        WHERE l.id = %d' . '    AND l.device_id=%d', $key['id'], $key['device_id']));
            $log .= t('link %id-%did (%type) at %nname-%dname deleted.', array('%id' => $key['id'], '%did' => $key['device_id'], '%type' => $item->link_type, '%nname' => $item->nname, '%dname' => $item->dname));
            if (!$cascade) {
                break;
            }
            // cascade to remote link
            $qc = db_query('SELECT id, ipv4_id, interface_id, device_id ' . 'FROM {guifi_links} ' . 'WHERE id=%d ' . '  AND device_id !=%d', $key['id'], $key['device_id']);
            while ($link = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('guifi_links', $link, $to_mail, $depth, FALSE);
                // cleanup of remote ipv4 addresses when appropriate
                $qar = db_query('SELECT * ' . 'FROM {guifi_ipv4} ' . 'WHERE id=%d AND interface_id=%d', $link['ipv4_id'], $link['interface_id']);
                while ($ripv4 = db_fetch_array($qar)) {
                    $aitem = _ipcalc($ripv4['ipv4'], $ripv4['netmask']);
                    if ($ripv4['ipv4_type'] == '2') {
                        // type 2: link is backbone
                        // if the addres is a:
                        // /30 (single p2p link)
                        // or /29 and /28 ( Multilink )
                        if ($ripv4['netmask'] == '255.255.255.252' or $ripv4['netmask'] == '255.255.255.248' or $ripv4['netmask'] == '255.255.255.240') {
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $link['ipv4_id'], 'interface_id' => $link['interface_id']), $to_mail, $depth, FALSE);
                            // cascade to local ipv4
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $item->ipv4_id, 'interface_id' => $item->interface_id), $to_mail, $depth, FALSE);
                        }
                    } else {
                        $mlinks = db_fetch_array(db_query('SELECT count(id) AS links ' . 'FROM {guifi_links} ' . 'WHERE ipv4_id=%d AND interface_id=%d', $link['ipv4_id'], $link['interface_id']));
                        if ($ripv4['ipv4'] != $aitem['netstart'] and $mlinks['links'] < 1) {
                            $log .= '<br />' . _guifi_db_delete('guifi_ipv4', array('id' => $link['ipv4_id'], 'interface_id' => $link['interface_id']), $to_mail, $depth, FALSE);
                        }
                    }
                    // guifi_log(GUIFILOG_BASIC,'function delete cascade remote address()',$link);
                    // cleanup remote interface when appropriate
                    $qir = db_query('SELECT i.id id, i.interface_type, count(a.id) na ' . 'FROM {guifi_interfaces} i ' . '  LEFT OUTER JOIN {guifi_ipv4} a ' . '  ON i.id=a.interface_id ' . 'WHERE i.id=%d ' . 'GROUP BY i.id, i.interface_type', $link['interface_id']);
                    while ($na = db_fetch_array($qir)) {
                        //          guifi_log(GUIFILOG_BASIC,'function delete cascade remote interface()',$na);
                        // delete the interface, if has no other ipv4 address and is not
                        // in the list Wan, wLan/Lan, Lan/Lan, Lan or wds/p2p
                        if (in_array($na['interface_type'], array('Wan', 'wLan/Lan', 'Lan/Lan', 'Lan', 'wds/p2p')) or $na['na'] != 0) {
                            continue;
                        }
                        $log .= '<br />' . _guifi_db_delete('guifi_interfaces', array('id' => $na['id']), $to_mail, $depth, FALSE);
                    }
                }
            }
            // delete services
        // delete services
        case 'guifi_services':
            // cascade interfaces
            break;
            // delete users
        // delete users
        case 'guifi_users':
            $item = db_fetch_object(db_query('SELECT * ' . 'FROM {guifi_users} u ' . 'WHERE id = %d', $key['id']));
            $log .= t('User %id-%name deleted.', array('%id' => $key['id'], '%name' => $item->username));
            break;
        case 'guifi_zone':
            break;
        case 'budgets':
            if (!$cascade) {
                break;
            }
            $qc = db_query('SELECT id, budget_id ' . 'FROM {budget_items} ' . 'WHERE budget_id=%d', $key['id']);
            while ($item = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('budget_items', $item, $to_mail, $depth);
            }
            $qc = db_query('SELECT id, budget_id ' . 'FROM {budget_funds} ' . 'WHERE budget_id=%d', $key['id']);
            while ($fund = db_fetch_array($qc)) {
                $log .= '<br />' . _guifi_db_delete('budget_funds', $fund, $to_mail, $depth);
            }
            break;
    }
    $where_str = '';
    foreach ($key as $k => $value) {
        if ($where_str != '') {
            $where_str .= ' AND ';
        }
        if ($table == 'guifi_types') {
            $where_str .= $k . ' = \'' . $value . '\'';
        } else {
            $where_str .= $k . ' = ' . $value;
        }
    }
    $count = db_fetch_array(db_query("\n    SELECT count(*) c\n    FROM {" . $table . "}\n    WHERE " . $where_str));
    if ($count['c'] != 1) {
        return $log . '<br />' . t('There was nothing to delete at %table with (%where)', array('%table' => $table, '%where' => $where_str));
    }
    if (!in_array($item->notification, $to_mail)) {
        $to_mail[] = $item->notification;
    }
    if (!in_array($item->ncontact, $to_mail)) {
        $to_mail[] = $item->ncontact;
    }
    $where_str = '';
    foreach ($key as $k => $value) {
        if ($where_str != '') {
            $where_str .= ' AND ';
        }
        if ($table == 'guifi_types') {
            $where_str .= $k . ' = \'' . $value . '\'';
        } else {
            $where_str .= $k . ' = ' . $value;
        }
    }
    $delete_str = 'DELETE FROM {' . $table . '} WHERE ' . $where_str;
    $log .= '<br />' . $delete_str;
    guifi_log(GUIFILOG_TRACE, $delete_str);
    db_query($delete_str);
    return $log;
}