コード例 #1
0
function guifi_funders_save($subject_id, $subject_type, $funders)
{
    guifi_log(GUIFILOG_TRACE, 'function guifi_funders_save(funders)', $funders);
    foreach ($funders as $k => $f) {
        if (!guifi_funders_access('update', $f)) {
            continue;
        }
        $f['subject_type'] = $subject_type;
        $f['subject_id'] = $subject_id;
        if (empty($f['comment']) and empty($f['user']) and empty($f['supplier']) and !empty($f['id'])) {
            $f['deleted'] = true;
        }
        if (empty($f['id'])) {
            $f['new'] = true;
        }
        if ($f['new'] == true and (empty($f['supplier']) and empty($f['user']) and empty($f['comment']))) {
            continue;
        }
        if (!empty($f['supplier'])) {
            $mid = explode('-', $f['supplier']);
            $f['supplier_id'] = $mid[0];
        } else {
            $f['supplier_id'] = 0;
        }
        if (!empty($f['user'])) {
            $mid = explode('-', $f['user']);
            $f['user_id'] = $mid[0];
        } else {
            $f['user_id'] = 0;
        }
        guifi_log(GUIFILOG_TRACE, 'function guifi_funders_save(sql)', $f);
        _guifi_db_sql('guifi_funders', array('id' => $f['id']), $f);
    }
    return;
}
コード例 #2
0
function guifi_maintainers_save($subject_id, $subject_type, $maintainers)
{
    foreach ($maintainers as $k => $m) {
        $m['subject_type'] = $subject_type;
        $m['subject_id'] = $subject_id;
        if (empty($m['maintainer']) and !empty($m['id'])) {
            $m['deleted'] = true;
        }
        if (empty($m['id'])) {
            $m['new'] = true;
        }
        if ($m['new'] == true and empty($m['maintainer'])) {
            continue;
        }
        $mid = explode('-', $m['maintainer']);
        $m['supplier_id'] = $mid[0];
        _guifi_db_sql('guifi_maintainers', array('id' => $m['id']), $m);
    }
    return;
}
コード例 #3
0
function guifi_device_add_ipv4s_submit($form, &$form_state)
{
    global $user;
    $ipv4sdialog = $form_state['values']['ipv4']['ipv4sdialog'];
    guifi_log(GUIFILOG_BASIC, 'function guifi_device_add_ipv4s_submit:', $form_state['values']['ipv4']['ipv4sdialog']);
    if ($ipv4sdialog['ipv4'] == 'false' and $ipv4sdialog['snet'] != 'false') {
        $snet = explode('|', $ipv4sdialog['snet']);
        $ipv4sdialog['ipv4'] = $snet[0];
        $ipv4sdialog['netmask'] = $snet[1];
        $ipv4sdialog['ipv4_type'] = $snet[2];
        guifi_log(GUIFILOG_BASIC, 'function guifi_device_add_ipv4s_submit SNET:', $snet);
    }
    $ipv4 = array('new' => true, 'id' => null, 'interface_id' => $ipv4sdialog['iid'], 'ipv4' => $ipv4sdialog['ipv4'], 'netmask' => $ipv4sdialog['netmask'], 'ipv4_type' => $ipv4sdialog['ipv4_type']);
    guifi_log(GUIFILOG_BASIC, 'function guifi_device_add_ipv4s_submit SAVE:', $ipv4);
    _guifi_db_sql('guifi_ipv4', array('id' => $ipv4['id'], 'interface_id' => $ipv4['interface_id']), $ipv4);
    // $form_state['rebuild'] = TRUE;
}
コード例 #4
0
/**
 * E-mail address update form submit
 */
function guifi_tools_mail_update_form_submit($form, &$form_state)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'guifi_tools_mail_update_submit()', $form_state['values']);
    // perform the massive update to the granted rows, using guifi db api
    // instead of straight SQL to create the notificaton messages.
    $tables = array('guifi_zone', 'guifi_location', 'guifi_devices', 'guifi_services', 'guifi_users');
    foreach ($tables as $table) {
        $sqlm = db_query('SELECT * FROM {%s} WHERE notification LIKE "%s"', $table, $form_state['values']['mail_search']);
        while ($amails = db_fetch_object($sqlm)) {
            // Check that the user has update access and creates the link
            $continue = FALSE;
            if (!user_access('administer guifi networks')) {
                switch ($table) {
                    case 'guifi_users':
                        $title = $amails->username;
                        $type = t('User');
                        if (guifi_user_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_devices':
                        $title = $amails->nick;
                        $type = t('Device');
                        if (guifi_device_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_zone':
                        $title = $amails->nick;
                        $type = t('Zone');
                        if (guifi_zone_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_location':
                        $title = $amails->nick;
                        $type = t('Node');
                        if (guifi_node_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                    case 'guifi_service':
                        $title = $amails->nick;
                        $type = t('Service');
                        if (guifi_service_access('update', $amails->id)) {
                            $continue = TRUE;
                        }
                        break;
                }
            } else {
                $continue = TRUE;
            }
            if (!$continue) {
                continue;
            }
            // here we have update access, so perform the update
            // Notify prevuious mail id, just in case...
            $to_mail = $amails->notification;
            $amails->notification = str_ireplace($form_state['values']['mail_search'], strtolower($form_state['values']['mail_replacewith']), $amails->notification);
            if ($to_mail == $amails->notification) {
                //no changes, so next
                continue;
            }
            $n = _guifi_db_sql($table, array('id' => $amails->id), (array) $amails, $log, $to_mail);
            guifi_notify($to_mail, t('The notification %notify for %type %title has been CHANGED to %new by %user.', array('%notify' => $form_state['values']['mail_search'], '%new' => $form_state['values']['mail_replacewith'], '%type' => $type, '%title' => $title, '%user' => $user->name)), $log);
        }
        // foreach row with the email found
    }
    // foreach table
    drupal_goto('guifi/menu/ip/mailsearch/' . $form_state['values']['mail_replacewith']);
}
コード例 #5
0
/**
 *
 * Ressegueix tots els unsolclics que te un firmware i li afegeix un parametre
 * @param int $fid
 * @param int $parametre
 * @param string $notification
 * @param int $userid
 */
function afegirParametreConfiguracionsUSC($fid, $parametre, $notification, $userid)
{
    $sql = db_query("select id , enabled from guifi_configuracioUnSolclic where fid = %d", $fid);
    while ($configuracioUSC = db_fetch_object($sql)) {
        $params = array('pid' => $parametre['id'], 'uscid' => $configuracioUSC->id, 'dinamic' => $parametre['dinamic'], 'valor' => $parametre['default_value'], 'notification' => $notification, 'user_created' => $userid, 'new' => true);
        _guifi_db_sql('guifi_parametresConfiguracioUnsolclic', array('id' => $params['id']), $params, $log, $notification);
    }
    return true;
}
コード例 #6
0
function guifi_domain_save($edit, $verbose = TRUE, $notify = TRUE)
{
    global $user;
    $to_mail = array();
    $tomail[] = $user->mail;
    $log = "";
    $to_mail = array();
    // domain
    $ndomain = _guifi_db_sql('guifi_dns_domains', array('id' => $edit['id']), $edit, $log, $to_mail);
    guifi_log(GUIFILOG_TRACE, sprintf('domain saved:'), $ndomain);
    // hosts
    $rc = 0;
    if (is_array($edit['hosts'])) {
        ksort($edit['hosts']);
    }
    $rc = 0;
    if ($edit['hosts']) {
        foreach ($edit['hosts'] as $counter => $host) {
            $keys['id'] = $ndomain['id'];
            $keys['counter'] = $counter;
            $host['id'] = $ndomain['id'];
            $host['counter'] = $rc;
            if ($host['aliases']) {
                foreach ($host['aliases'] as $key => $name) {
                    if (empty($name)) {
                        unset($host['aliases'][$key]);
                    }
                }
                $host['aliases'] = serialize($host['aliases']);
            } else {
                unset($host['aliases']);
            }
            if ($host['host'] == 'ns1' and $host['counter'] == '0') {
                $host['opt']['options']['NS'] = 'NS';
            }
            $host['opt']['options']['mxprior'] = $host['opt']['mxprior'];
            $host['options'] = serialize($host['opt']['options']);
            // save the host
            $nhost = _guifi_db_sql('guifi_dns_hosts', $keys, $host, $log, $to_mail);
            if (empty($nhost) or $host['deleted']) {
                continue;
            }
            $rc++;
        }
    }
    // foreach host
    $to_mail = explode(',', $edit['notification']);
    if ($edit['new']) {
        $subject = t('The domain %name has been CREATED by %user.', array('%name' => $edit['name'], '%user' => $user->name));
    } else {
        $subject = t('The domain %name has been UPDATED by %user.', array('%name' => $edit['name'], '%user' => $user->name));
    }
    //   drupal_set_message($subject);
    guifi_notify($to_mail, $subject, $log, $verbose, $notify);
    variable_set('guifi_refresh_dns', time());
    guifi_clear_cache($edit['sid']);
    guifi_clear_cache($edit['id']);
    return $ndomain['id'];
}
コード例 #7
0
function budgets_supplier_save($node)
{
    global $user;
    guifi_log(GUIFILOG_TRACE, 'function budgets_save()', $node->ack);
    foreach ($node->caps as $cap1 => $cap2) {
        $elements = array();
        foreach ($cap2 as $key => $value) {
            if ($value and guifi_type_relation($cap1, $key, $node->role)) {
                $elements[] = $key . '=' . $value;
            }
        }
        $node->{$cap1} = implode(',', $elements);
    }
    foreach ($node->certs as $cap1 => $cap2) {
        $elements = array();
        foreach ($cap2 as $key => $value) {
            $value ? $elements[] = $key . '=' . $value : NULL;
        }
        $node->{$cap1} = implode(',', $elements);
    }
    $zones = array();
    foreach ($node->zones as $k => $value) {
        if ($value != '') {
            $zone_exploded = explode('-', $value);
            $zones[] = $zone_exploded[0];
        }
    }
    $node->zones = implode(',', $zones);
    $node->zone_id = $zones[0];
    $node->self_rating = $node->sr_commitment . $node->sr_experience;
    $node->official_rating = $node->or_commitment . $node->or_experience . $node->or_trend;
    $node->accounting_urls = serialize($node->accounting_urls);
    $to_mail = $user->mail;
    $log = '';
    $sid = _guifi_db_sql('supplier', array('id' => $node->nid), (array) $node, $log, $to_mail);
    if ($node->deleted) {
        $action = t('DELETED');
    } else {
        if ($node->new) {
            $action = t('CREATED');
        } else {
            $action = t('UPDATED');
        }
    }
    $subject = t('The supplier %title has been %action by %user.', array('%title' => $node->title, '%action' => $action, '%user' => $user->name));
    drupal_set_message($subject);
    guifi_notify($to_mail, $subject, $log);
}
コード例 #8
0
/**
 * Save changes to a guifi network into the database.
 */
function guifi_ipv4_save($edit)
{
    global $user;
    if (!isset($edit['id'])) {
        $edit['new'] = TRUE;
        $msg = t('The network %base/%mask (%type) has been CREATED by %user.', array('%base' => $edit['base'], '%mask' => $edit['mask'], '%type' => $edit['network_type'], '%user' => $user->name));
    } else {
        $msg = t('The network %base/%mask (%type) has been UPDATED by %user.', array('%base' => $edit['base'], '%mask' => $edit['mask'], '%type' => $edit['network_type'], '%user' => $user->name));
    }
    $nnetwork = _guifi_db_sql('guifi_networks', array('id' => $edit['id']), (array) $edit, $log, $to_mail);
    guifi_notify($to_mail, $msg, $log);
}
コード例 #9
0
/** guifi_node_update(): Update a node in the database
*/
function guifi_node_update($node)
{
    global $user;
    $log = '';
    $coord = guifi_coord_dmstod($node->latdeg, $node->latmin, $node->latseg);
    if ($coord != NULL) {
        $node->lat = $coord;
    }
    $coord = guifi_coord_dmstod($node->londeg, $node->lonmin, $node->lonseg);
    if ($coord != NULL) {
        $node->lon = $coord;
    }
    if ($node->lat == 0) {
        $node->lat = NULL;
    }
    if ($node->lon == 0) {
        $node->lon = NULL;
    }
    $to_mail = explode(',', $node->notification);
    // Refresh maps?
    $pn = db_fetch_object(db_query('SELECT l.*
    FROM {guifi_location} l
    WHERE l.id=%d', $node->nid));
    if ($pn->lat != $node->lat || $pn->lon != $node->lon || $pn->status_flag != $node->status_flag) {
        // touch(variable_get('guifi_rebuildmaps','/tmp/ms_tmp/REBUILD'));
        variable_set('guifi_refresh_cnml', time());
        variable_set('guifi_refresh_maps', time());
        cache_clear_all();
    }
    $node->lat = (double) $node->lat;
    $node->lon = (double) $node->lon;
    guifi_maintainers_save($node->nid, 'location', $node->maintainers);
    guifi_funders_save($node->nid, 'location', $node->funders);
    $nnode = _guifi_db_sql('guifi_location', array('id' => $node->nid), (array) $node, $log, $to_mail);
    guifi_notify($to_mail, t('The node %name has been UPDATED by %user.', array('%name' => $node->title, '%user' => $user->name)), $log);
    guifi_clear_cache($node->nid);
}
コード例 #10
0
function guifi_api_service_remove($gapi, $parameters)
{
    global $user;
    if (!guifi_api_check_fields($gapi, array('service_id'), $parameters)) {
        return FALSE;
    }
    $service = guifi_service_load($parameters['service_id']);
    if (!$service) {
        $gapi->addError(403, "This service does not exist.");
        return FALSE;
    }
    $to = explode(',', $service->notification);
    $to[] = variable_get('guifi_contact', '*****@*****.**');
    $log = '';
    $service->deleted = TRUE;
    /* Delete from guifi tables */
    $nservice = _guifi_db_sql('guifi_services', array('id' => $service->id), (array) $service, $log, $to);
    /* delete node */
    node_delete($service->id);
    $gapi->addResponseField('service', $service);
    return TRUE;
}
コード例 #11
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;
}
コード例 #12
0
/**
 * Save changes to the database.
 */
function guifi_user_save($edit)
{
    global $user;
    $n = node_load($edit['nid']);
    $to_mail = $n->notification;
    $log = '';
    if (isset($edit['services'])) {
        if (isset($edit['services']['proxystr'])) {
            unset($edit['services']['proxystr']);
        }
        $edit['services'] = serialize($edit['services']);
    }
    if (isset($edit['var'])) {
        $edit['extra'] = serialize($edit['var']);
    }
    if (isset($edit['content_filters'])) {
        $edit['content_filters'] = serialize($edit['content_filters']);
    }
    if (isset($edit['username_created'])) {
        $cuser = user_load(array('name' => $edit['username_created']));
        $edit['user_created'] = $cuser->uid;
    }
    guifi_log(GUIFILOG_TRACE, 'function guifi_user_save()', $edit);
    _guifi_db_sql('guifi_users', array('id' => $edit['id']), $edit, $log, $to_mail);
    drupal_set_message(t('%user saved. Note that in some cases the change will not take effect until after some time.', array('%user' => $edit['username'])));
    guifi_notify($to_mail, t('The user !username has been UPDATED by !user.', array('!username' => $edit['username'], '!user' => $user->name)), $log);
}
コード例 #13
0
/**
 * @param device id $did
 * @param ethernet ports $ports
 */
function guifi_vinterface_save($iid, $did, $nid, &$to_mail)
{
    guifi_log(GUIFILOG_TRACE, "function guifi_vinterface_save()", $ports);
    foreach ($ports as $kport => $vport) {
        $dev = explode('-', $vport['did']);
        $if = array('id' => $vport['iid'], 'device_id' => $did, 'etherdev_counter' => trim($vport['id']), 'interface_type' => trim($vport['id']), 'connector_type' => $vport['type'], 'vlan' => $vport['vlan'], 'comments' => $vport['comment'], 'connto_did' => is_numeric($dev[0]) ? $dev[0] : 0, 'connto_iid' => is_numeric($dev[0]) ? $vport['if'] : 0);
        // retrieve existing values to $if_current
        $sql_if_exists = 'SELECT id, device_id, etherdev_counter, interface_type, connector_type, vlan, comments, connto_did, connto_iid ' . 'FROM {guifi_interfaces} i ' . 'WHERE id = ' . $if['id'] . ' AND device_id = ' . $did;
        $if_current = db_fetch_array(db_query($sql_if_exists));
        // if new interface, insert
        if (!$if_current) {
            $if['new'] = true;
        } else {
            // if there is no chages, next
            $changes = array_diff_assoc($if, $if_current);
            guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(existing " . $kport . ")", $if_current);
            guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(posted " . $kport . ")", $if);
            guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(changes " . $kport . ")", $changes);
            if (!count($changes)) {
                continue;
            }
        }
        // if remote interface defined, update remote interface
        if (!empty($dev[0]) and !empty($vport['if'])) {
            $if_remote = array('device_id' => $dev[0], 'id' => $vport['if'], 'connector_type' => $vport['type'], 'connto_did' => (string) $did, 'connto_iid' => (string) $vport['iid']);
            guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(remote-set)", $if);
            _guifi_db_sql('guifi_interfaces', array('device_id' => $dev[0], 'id' => $vport['if']), $if_remote);
        }
        // if update, check for the remote reference
        if (empty($if['new'])) {
            // if had another device, clear remote reference
            if (!empty($if_current['connto_did']) and !empty($if_current['connto_iid'])) {
                $if_remote = array('device_id' => (string) $if_current['connto_did'], 'id' => (string) $if_current['connto_iid'], 'connto_did' => (string) null, 'connto_iid' => (string) null);
                guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(remote-clear)", $if_remote);
                _guifi_db_sql('guifi_interfaces', array('device_id' => $if_remote['device_id'], 'id' => $if_remote['id']), $if_remote);
            }
            // Clear remote interface
        }
        guifi_log(GUIFILOG_TRACE, "function _guifi_switch_save(local)", $if);
        _guifi_db_sql('guifi_interfaces', array('device_id' => $if['device_id'], 'id' => $if['id']), $if);
    }
}
コード例 #14
0
function guifi_service_update($node)
{
    global $user;
    $log = '';
    $to_mail = explode(',', $node->notification);
    guifi_log(GUIFILOG_TRACE, 'function guifi_service_update()', $node);
    guifi_service_multiplefield_clean($node->var['domains']);
    guifi_service_multiplefield_clean($node->var['homepages']);
    guifi_service_multiplefield_clean($node->var['irc']);
    $node->extra = serialize($node->var);
    $nnode = _guifi_db_sql('guifi_services', array('id' => $node->id), (array) $node, $log, $to_mail);
    guifi_notify($to_mail, t('The service %name has been UPDATED by %user.', array('%name' => $node->nick, '%user' => $user->name)), $log);
}
コード例 #15
0
function guifi_ipcalc_get_subnet_by_nid($nid, $mask_allocate = '255.255.255.224', $network_type = 'public', $ips_allocated = NULL, $allocate = 'No', $verbose = FALSE)
{
    if (empty($nid)) {
        drupal_set_message(t('Error: trying to search for a network for unknown node or zone'), 'error');
        return;
    }
    if (empty($mask_allocate)) {
        drupal_set_message(t('Error: trying to search for a network of unknown size'), 'error');
        return;
    }
    if (empty($network_type)) {
        drupal_set_message(t('Error: trying to search for a network for unknown type'), 'error');
        return;
    }
    // print "Going to allocate network ".$mask_allocate."-".$network_type;
    global $user;
    $tbegin = microtime(TRUE);
    $zone = node_load(array('nid' => $nid));
    if ($zone->type == 'guifi_node') {
        $zone = guifi_zone_load($zone->zone_id);
    }
    $rzone = $zone;
    $depth = 0;
    $root_zone = $zone->id;
    $lbegin = microtime(TRUE);
    $search_mask = $mask_allocate;
    do {
        // while next is not the master, check within the already allocated ranges
        $result = db_query('SELECT n.id, n.base, n.mask ' . 'FROM {guifi_networks} n ' . 'WHERE n.zone = "%s" ' . '  AND network_type="%s" ' . 'ORDER BY n.id', $zone->id, $network_type);
        if ($verbose) {
            drupal_set_message(t('Searching if %mask is available at %zone, elapsed: %secs', array('%mask' => $mask_allocate, '%zone' => $zone->title, '%secs' => round(microtime(TRUE) - $lbegin, 4))));
        }
        // if there are already networks defined, increase network mask, up to /20 level
        // here, getting the total # of nets defined
        $tnets = 0;
        while ($net = db_fetch_object($result)) {
            $tnets++;
            $item = _ipcalc($net->base, $net->mask);
            // if looking for mesh ip (255.255.255.255) base address & broadcast
            // should be considered as used
            if ($search_mask == '255.255.255.255') {
                $ips_allocated[ip2long($net->base)] = 32;
                $ips_allocated[ip2long($item['netend'])] = 32;
            }
            if ($ip = guifi_ipcalc_find_subnet($net->base, $net->mask, $mask_allocate, $ips_allocated)) {
                if ($verbose) {
                    drupal_set_message(t('Found %ip/%rmask available at %netbase/%amask, got from %zone, elapsed: %secs', array('%amask' => $net->mask, '%netbase' => $net->base, '%ip' => $ip, '%rmask' => guifi_ipcalc_get_maskbits($mask_allocate), '%zone' => $zone->title, '%secs' => round(microtime(TRUE) - $lbegin, 4))));
                }
                // reserve the available range fount into database?
                if ($depth and ($allocate == 'Yes' and $network_type == 'public' and $mask_allocate != '255.255.255.255')) {
                    $msg = strip_tags(t('A new network (%base / %mask) has been allocated for zone %name, got from %name2 by %user.', array('%base' => $ip, '%mask' => $mask_allocate, '%name' => $rzone->title, '%name2' => $zone->title, '%user' => $user->name)));
                    $to_mail = explode(',', $rzone->notification);
                    $to_mail = explode(',', $zone->notification);
                    $nnet = array('new' => TRUE, 'base' => $ip, 'mask' => $mask_allocate, 'zone' => $root_zone, 'newtwork_type' => $network_type);
                    $nnet = _guifi_db_sql('guifi_networks', NULL, $nnet, $log, $to_mail);
                    guifi_notify($to_mail, $msg, $log);
                    drupal_set_message($msg);
                    if ($search_mask == '255.255.255.255') {
                        $ip = long2ip(ip2long($ip) + 1);
                    }
                }
                return $ip;
            }
        }
        // while there is a network defined at the zone
        // Network was not allocated
        if ($verbose) {
            drupal_set_message(t('Unable to find space at %zone, will look at parents, elapsed: %secs', array('%zone' => $zone->title, '%secs' => round(microtime(TRUE) - $lbegin, 4))));
        }
        // Need for an unused range,
        // already allocated networks from others than parents should be considered
        // as allocated ips (skipped)
        // This have to be done once, so do if is the zone being asked for
        if ($root_zone == $zone->id) {
            $parents = guifi_zone_get_parents($root_zone);
            $query = db_query('SELECT base ipv4, mask ' . 'FROM {guifi_networks} ' . 'WHERE zone NOT IN (' . implode(',', guifi_zone_get_parents($root_zone)) . ')');
            while ($nip = db_fetch_array($query)) {
                $ips_allocated[ip2long($nip['ipv4']) + 1] = guifi_ipcalc_get_maskbits($nip['mask']);
            }
            // once merged, sort
            ksort($ips_allocated);
            // calculating the needed mask
            if ($network_type == 'public') {
                $depth++;
                if ($tnets > 0 and $tnets < 5) {
                    // between 1 and 4, 24 - nets defined
                    $maskbits = 24 - $tnets;
                } else {
                    if ($tnets >= 5) {
                        // greater than 4, /20 - 255.255.240.0
                        $maskbits = 20;
                    } else {
                        // first net, /24 - 255.255.255.0
                        $maskbits = 24;
                    }
                }
                $mitem = _ipcalc_by_netbits($net->base, $maskbits);
                $mbits_allocate = guifi_ipcalc_get_maskbits($mask_allocate);
                if ($mbits_allocate > $maskbits or $mask_allocate == '255.255.255.255') {
                    $mask_allocate = $mitem['netmask'];
                }
            }
        }
        // Take a look at the parent network zones
        $master = $zone->master;
        if ($zone->master > 0) {
            $zone = guifi_zone_load($zone->master);
        }
    } while ($master > 0);
    return FALSE;
}
コード例 #16
0
ファイル: quotes.inc.php プロジェクト: itorres/drupal-budgets
function budgets_quote_save($node)
{
    global $user;
    $to_mail = $user->mail;
    $log = '';
    if (isset($node->supplier)) {
        $sup = explode('-', $node->supplier);
        $node->supplier_id = $sup[0];
    }
    $node->expires = mktime(0, 0, 0, $node->arrexpires['month'], $node->arrexpires['day'], $node->arrexpires['year']);
    $sid = _guifi_db_sql('supplier_quote', array('id' => $node->nid), (array) $node, $log, $to_mail);
    if ($node->deleted) {
        $action = t('DELETED');
    } else {
        if ($node->new) {
            $action = t('CREATED');
        } else {
            $action = t('UPDATED');
        }
    }
    $subject = t('The supplier quote %title has been %action by %user.', array('%title' => $node->title, '%action' => $action, '%user' => $user->name));
    drupal_set_message($subject);
    guifi_notify($to_mail, $subject, $log);
}
コード例 #17
0
/** guifi_zone_delete(): Delete a zone
**/
function guifi_zone_delete(&$node)
{
    global $user;
    $log = '';
    $delete = TRUE;
    $qn = db_fetch_object(db_query("\n    SELECT count(*) count\n    FROM {guifi_networks}\n    WHERE zone=%d", $node->nid));
    if ($qn->count) {
        drupal_set_message(t('FATAL ERROR: Can\'t delete a zone which have networks allocated. Database broken. Contact your system administrator'), 'error');
        $delete = FALSE;
    }
    $ql = db_fetch_object(db_query("\n    SELECT count(*) count\n    FROM {guifi_location}\n    WHERE zone_id=%d", $node->nid));
    if ($ql->count) {
        drupal_set_message(t('FATAL ERROR: Can\'t delete a zone with nodes. Database broken. Contact your system administrator'), 'error');
        $delete = FALSE;
    }
    $to = explode(',', $node->notification);
    $to[] = variable_get('guifi_contact', '*****@*****.**');
    if (!$delete) {
        $messages = drupal_get_messages(NULL, FALSE);
        guifi_notify($to, t('ALERT: Zone %nick-%name has been deleted, but have errors:', array('%nick' => $node->nick, '%name' => $node->title)), implode("\n", $messages['error']));
        return;
    }
    // perform deletion
    $node->deleted = TRUE;
    $nzone = _guifi_db_sql('guifi_zone', array('id' => $node->id), (array) $node, $log, $to);
    guifi_notify($to, t('Zone %nick-%name has been deleted', array('%nick' => $node->nick, '%name' => $node->title)), $log);
    cache_clear_all();
    variable_set('guifi_refresh_cnml', time());
    variable_set('guifi_refresh_maps', time());
    return;
}