function guifi_device_create_form($form_state, $node) { guifi_log(GUIFILOG_TRACE, 'function guifi_device_create_form()', $node); $types = guifi_types('device'); $zone = guifi_zone_load($node->zone_id); if (!guifi_node_access('create', $node->nid)) { $form['text_add'] = array('#type' => 'item', '#value' => t('You are not allowed to update this node.'), '#weight' => 0); return $form; } $form['nid'] = array('#type' => 'hidden', '#value' => $node->id); $form['device_type'] = array('#type' => 'select', '#title' => t('Add a new device'), '#description' => t('Type of device to be created'), '#options' => $types, '#prefix' => '<table style="width: 0px"><tr><td>', '#suffix' => '</td>'); $form['submit'] = array('#type' => 'submit', '#value' => t('add'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>'); return $form; }
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; }
function guifi_unsolclic($dev, $format = 'html') { global $rc_startup; global $ospf_zone; global $otype; $paramPrefixes = array("zone", "node", "user", "device", "firmware", "radio", "interface", "ipv4", "link", "linkedto_"); $otype = $format; $dev = (object) $dev; $flattenDev = array_flatten((array) $dev, array()); if (isValidConfiguracioUSC($dev->usc_id)) { // carreguem el Twig , versió utilitzada 1.91 include_once 'contrib/Twig/Autoloader.php'; // FINAL. Treure el fitxer unsolclic resultant com a mime text/plain //drupal_set_header('Content-Type: text/plain; charset=utf-8'); // PFC passos // 1. Recuperar informacio del trasto // 1.a Recuperar el id de model del trasto (del camp extra de device) $modelId = $dev->mid; // recollir la configuracio unscolclic actual $uscId = $dev->usc_id; // 1.b recollir de la BD la informacio del model $model = guifi_get_model($modelId); // 1.c recollir les característiques del model // aixo no es fa servir per res!!!! $caractModel = guifi_get_caractmodel($modelId); // 2. Recuperar informacio del firmware // 2.a Recuperar el id del firmware del trasto(del camp extra de device) $firmwareName = $dev->variable['firmware']; $firmwareId = $dev->fid; // 2.b recollir de la BD la informacio del firmware $firmware = guifi_get_firmware($firmwareName); // 2.c recollir els parametres del firmware // tampoc es fa servir per RES!!!!!! $paramsFirmware = guifi_get_paramsFirmware($firmwareId); // 3. Recuperar la configuracióUnSolClic tq modelid i firmware:id $configuracioUSC = guifi_get_configuracioUSC($modelId, $firmwareId, $uscId); // 3.a recuperar la plantilla de la configuracio $plantilla = $configuracioUSC['plantilla']; // a plantilla hi ha el contingut de la plantilla del unsolclic // 4. recuperar TOTS els parametres variables associats al trasto //$paramsDevice = guifi_get_paramsDevice($dev->id); $paramsDevice = guifi_get_paramsClientDevice($dev->id); // 5. Indexar els els parametres variables associats al trasto $indexedParamsDevice = guifi_indexa_paramsDevice($paramsDevice, $paramPrefixes); // 6. recuperar els parametres de la plantilla $paramsconfiguracioUSC = guifi_get_paramsconfiguracioUSC($uscId); // 6.B. recuperar els la informacio de la configuracio de fabricant-model-firmware $paramsMMF = guifi_get_paramsMMF($dev->id); // 4.b Comprovacions sobre el Device $clientModeNoAPError = clientModeError($dev); if ($clientModeNoAPError) { $plantilla = $clientModeNoAPError; } $totalParameters = array_merge($indexedParamsDevice, $paramsMMF, $flattenDev); // altres parametres fixes; TODO posar-lo com a parametre fixe de la plantilla $totalParameters['ospf_name'] = 'backbone'; // proves de twig $zone = guifi_zone_load($totalParameters['zone_id']); list($primary_dns, $secondary_dns, $ternary_dns) = explode(' ', guifi_get_dns($zone, 3)); $totalParameters['zone_primary_dns'] = $primary_dns; $totalParameters['zone_secondary_dns'] = $secondary_dns; $totalParameters['zone_ternary_dns'] = $ternary_dns; list($primary_ntp, $secondary_ntp) = explode(' ', guifi_get_ntp($zone)); $totalParameters['zone_primary_ntp'] = $primary_ntp; $totalParameters['zone_secondary_ntp'] = $secondary_ntp; if ($paramsconfiguracioUSC) { // 7. substituir els parametres a la plantilla foreach ($paramsconfiguracioUSC as $tupla) { $param = $tupla['nom']; $valor = $tupla['valor']; $dinamic = $tupla['dinamic']; $origen = $tupla['origen']; if ($dinamic == true) { // DINAMIC s'ha de fer una segona passatda per buscar el origen de veritat $valor = $totalParameters[$origen]; } $totalParameters[$param] = $valor; //echo "\n<br>param '$param' $dinamic = '$valor $origen' "; } Twig_Autoloader::register(); $loader = new Twig_Loader_String(); //$loader = new Twig_Loader_Filesystem('/home/albert/workspace/guifinet/drupal-6.22/sites/all/modules/guifi/firmware'); $twig = new Twig_Environment($loader); $totalParameters['dev'] = $dev; $twig->addFunction('ip2long', new Twig_Function_Function('ip2long')); $twig->addFunction('long2ip', new Twig_Function_Function('long2ip')); $twig->addFunction('t', new Twig_Function_Function('t')); $twig->addFunction('guifi_to_7bits', new Twig_Function_Function('guifi_to_7bits')); $twig->addFunction('guifi_get_alchemy_ifs', new Twig_Function_Function('guifi_get_alchemy_ifs')); $twig->addFunction('guifi_main_ip', new Twig_Function_Function('guifi_main_ip')); $twig->addFunction('explode', new Twig_Function_Function('explode')); $escaper = new Twig_Extension_Escaper(true); $twig->addExtension($escaper); //$plantilla = $twig->render($configuracioUSC['template_file'], $twigVars); $plantilla = $twig->render($plantilla, $totalParameters); // } if ($totalParameters['manufacturer_name'] != 'Ubiquiti') { $plantilla = str_replace("\n", "\n<br />", $plantilla); } echo $plantilla; die; } if ($dev->variable['firmware'] == 'n/a') { _outln_comment(t("ERROR: I do need a firmware selected at the radio web interface: ") . '<a href="' . base_path() . '/guifi/device/' . $dev->id . '/edit">http://guifi.net/guifi/device/' . $dev->id . '/edit'); return; } else { _outln_comment(t("Generated for:")); _outln_comment($dev->variable['firmware']); } foreach (glob(drupal_get_path('module', 'guifi') . '/firmware/*.inc.php', GLOB_BRACE) as $firm_inc_php) { include_once "{$firm_inc_php}"; // echo "<br>$firm_inc_php"; } if ($dev->radios[0]['mode'] == 'client') { $links = 0; foreach ($dev->radios[0]['interfaces'] as $interface_id => $interface) { foreach ($interface['ipv4'] as $ipv4_id => $ipv4) { if (isset($ipv4['links'])) { foreach ($ipv4['links'] as $key => $link) { if ($link['link_type'] == 'ap/client') { $links++; break; } } } } } if ($links == 0) { _outln_comment(t("ERROR: Radio is in client mode but has no AP selected, please add a link to the AP at: ") . '<a href="' . base_path() . 'guifi/device/' . $dev->id . '/edit">http://guifi.net/guifi/device/' . $dev->id . '/edit'); return; } } switch ($dev->variable['firmware']) { case 'RouterOSv2.9': case 'RouterOSv3.x': case 'RouterOSv4.0+': case 'RouterOSv4.7+': case 'RouterOSv5.x': case 'RouterOSv6.x': unsolclic_routeros($dev); exit; break; case 'DD-guifi': case 'DD-WRTv23': case 'Alchemy': case 'Talisman': unsolclic_wrt($dev); exit; break; case 'AirOsv221': case 'AirOsv30': case 'AirOsv3.6+': unsolclic_airos($dev); exit; break; // case 'AirOsv52': // unsolclic_airos52($dev); // exit; // break; // case 'AirOsv52': // unsolclic_airos52($dev); // exit; // break; case 'GuifiStationOS1.0': unsolclic_guifistationos($dev); exit; break; // case 'qMpv1': // Use a generic one is better // case 'qMpv1': // Use a generic one is better case preg_match('/^qMp/', $dev->variable['firmware']) == 1: unsolclic_qmp($dev); exit; break; } $unsolclic = 'unsolclic_' . $dev->variable['firmware']; if (function_exists(${unsolclic})) { ${unsolclic}($dev); exit; } else { unsolclic_todo($dev); } }
/** node editing functions **/ function guifi_node_prepare(&$node) { global $user; if (empty($node->nid)) { if (is_numeric($node->title)) { $zone = guifi_zone_load($node->title); $node->zone_id = $node->title; $default = t('<nodename>'); $node->title = NULL; $node->nick = $zone->nick . $default; } $node->notification = $user->mail; $node->status_flag = 'Planned'; } // Position // if given parameters get/post, fill lat/lon if (isset($_POST['lat'])) { $node->lat = $_POST['lat']; } if (isset($_POST['lon'])) { $node->lon = $_POST['lon']; } if (isset($_GET['lat'])) { $node->lat = $_GET['lat']; } if (isset($_GET['lon'])) { $node->lon = $_GET['lon']; } if (isset($_GET['Lat'])) { $node->lat = $_GET['Lat']; } if (isset($_GET['Lon'])) { $node->lon = $_GET['Lon']; } if (isset($_GET['zone'])) { $node->zone_id = $_GET['zone']; } if (isset($_GET['zone'])) { $node->zone_id = $_GET['zone']; } if (isset($_GET['lat'])) { if (isset($_GET['lon'])) { $defzone_qry = db_fetch_array(db_query("SELECT id, ((maxx-minx)+(maxy-miny)) as distance FROM {guifi_zone} WHERE minx < '%s' AND maxx > '%s' AND miny < '%s' AND maxy > '%s' ORDER by distance LIMIT 1", $_GET['lon'], $_GET['lon'], $_GET['lat'], $_GET['lat'])); $node->ndfzone = $defzone_qry['id']; } } $coord = guifi_coord_dtodms($node->lat); if ($coord != NULL) { $node->latdeg = $coord[0]; $node->latmin = $coord[1]; $node->latseg = $coord[2]; } $coord = guifi_coord_dtodms($node->lon); if ($coord != NULL) { $node->londeg = $coord[0]; $node->lonmin = $coord[1]; $node->lonseg = $coord[2]; } }
/** * Present the guifi zone editing form. */ function guifi_service_form($node, $param) { global $user; guifi_log(GUIFILOG_TRACE, 'guifi_service_form()', $node); drupal_set_breadcrumb(guifi_zone_ariadna($node->zone_id, 'node/%d/view/services')); // $f = guifi_form_hidden_var($node,array('id')); if (empty($node->nid) and is_numeric($node->title)) { $zone = guifi_zone_load($node->title); $node->zone_id = $node->title; $node->contact = $user->mail; $default = t('<service>'); $node->title = NULL; $node->nick = $zone->nick . $default; $node->status_flag = 'Planned'; } if (isset($node->id)) { $f['id'] = array('#type' => 'hidden', '#value' => $node->id); } $type = db_fetch_object(db_query("SELECT description FROM {guifi_types} WHERE type='service' AND text='%s'", $node->service_type)); if ($node->nid > 0) { $f['service_type'] = array('#type' => 'item', '#value' => t('Service type'), '#description' => t($type->description)); } //$output = form_item(t('Service type'),$node->service_type,t($type->description)); $type = node_get_types('type', $node); if ($type->has_title) { $f['title'] = array('#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title); } $f['nick'] = array('#type' => 'textfield', '#title' => t('Nick'), '#required' => FALSE, '#size' => 20, '#maxlength' => 20, '#default_value' => $node->nick, '#element_validate' => array('guifi_service_nick_validate'), '#collapsible' => FALSE, '#tree' => TRUE, '#description' => t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only.")); //$output .= form_textfield(t("Nick"), "nick", $node->nick, 20, 20, t("Unique identifier for this service. Avoid generic names such 'Disk Server', use something that really describes what is doing and how can be distinguished from the other similar services.<br />Short name, single word with no spaces, 7-bit chars only.") . ($error['nick'] ? $error["nick"] : ''), NULL, TRUE); $f['notification'] = array('#type' => 'textfield', '#title' => t('Contact'), '#required' => FALSE, '#size' => 60, '#maxlength' => 128, '#default_value' => $node->notification, '#element_validate' => array('guifi_emails_validate'), '#description' => t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page.")); //$output .= form_textfield(t("Contact"), "contact", $node->contact, 60, 128, t("Who did possible this service or who to contact with regarding this service if it is distinct of the owner of this page.") . ($error['contact'] ? $error["contact"] : '')); //// $output .= form_select(t('Zone'), 'zone_id', $node->zone_id, guifi_zones_listbox(), t('The zone where this node where this node belongs to.')); $f['server'] = array('#type' => 'textfield', '#title' => t("Device"), '#size' => 60, '#maxlength' => 128, '#default_value' => guifi_server_descr($node->device_id), '#element_validate' => array('guifi_servername_validate'), '#autocomplete_path' => 'guifi/js/select-server', '#description' => t('Where it runs.')); //$params .= guifi_form_column(form_select(t('Device'), "device_id", $node->device_id, guifi_servers_select(),t('Where it runs.'))); if (!$node->nid) { $f['service_type'] = array('#type' => 'select', '#title' => t("Service"), '#default_value' => $node->service_type, '#options' => guifi_types('service'), '#description' => t('Type of service')); //$types = guifi_types('service'); //array_shift($types); //$params.= guifi_form_column(form_select(t('Service'), "service_type", $node->service_type, $types,t('Type of service'))); } else { $f['protocol'] = array('#type' => 'hidden', '#title' => t("service_type"), '#value' => $node->service_type); } //$output .= form_hidden("service_type",$node->service_type); $f['status_flag'] = array('#type' => 'select', '#title' => t("Status"), '#default_value' => $node->status_flag, '#options' => guifi_types('status'), '#description' => t('Current status')); //$params .= guifi_form_column(form_select(t('Status'), 'status_flag', $node->status_flag, guifi_types('status'), t('Current status'))); //$output .= guifi_form_column_group(t('General parameters'),$params, NULL); // $node->var = unserialize($node->extra); if ($node->nid > 0) { $f['var'] = array('#type' => 'fieldset', '#title' => $node->service_type . ' ' . t("settings"), '#tree' => TRUE, '#collapsible' => TRUE, '#collapsed' => FALSE); } if ($node->nid > 0) { switch ($node->service_type) { case 'mail': $f['var']['in'] = array('#type' => 'textfield', '#title' => t('Inbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['in'], '#description' => t('Where email clients have to be configured for getting email messages')); $f['var']['out'] = array('#type' => 'textfield', '#title' => t('Outbound mail server'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['out'], '#description' => t('Where email clients have to be configured for sending email messages')); $f['var']['webmail'] = array('#type' => 'textfield', '#title' => t('Webmail url'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['webmail'], '#description' => t('URL for accessing to this mail server, if there is')); $f['var']['admin'] = array('#type' => 'textfield', '#title' => t('Admin web interface'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['admin'], '#description' => t('Where to create/edit/delete users, change passwords, etc...')); break; case 'asterisk': $f['var']['prefix'] = array('#type' => 'textfield', '#title' => t('Dial prefix'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['prefix'], '#description' => t('Dial prefix for calling this server extensions')); $f['var']['incoming'] = array('#type' => 'textfield', '#title' => t('Incoming calls'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['incoming'], '#description' => t('Server or IP address where the calls have to be sent')); $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('IAX' => 'IAX', 'SIP' => 'SIP')); break; case 'NTP': $f['var']['ntp'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ntp']); break; case 'ftp': $f['var']['ftphost'] = array('#type' => 'textfield', '#title' => t('IP address or hostname'), '#required' => TRUE, '#size' => 60, '#maxlength' => 60, '#default_value' => $node->var['ftphost']); $f['var']['protocols'] = array('#type' => 'checkboxes', '#title' => t('Protocols'), '#required' => TRUE, '#default_value' => $node->var['protocols'], '#options' => array('SMB' => 'SMB (Samba)', 'ftp' => 'FTP', 'nfs' => 'NFS')); break; case 'Proxy': case 'ADSL': $f['var']['down'] = array('#type' => 'select', '#title' => t('Download'), '#default_value' => $node->var['down'], '#options' => guifi_bandwidth_types(), '#description' => t('Download bandwidth')); $f['var']['up'] = array('#type' => 'select', '#title' => t('Upload'), '#options' => guifi_bandwidth_types(), '#default_value' => $node->var['up'], '#description' => t('Upload bandwidth')); if ($node->service_type == 'ADSL') { break; } if (empty($node->var['fed'])) { $node->var['fed'] = array('IN' => '0', 'OUT' => '0'); } $f['var']['fed'] = array('#type' => 'checkboxes', '#title' => t('Proxy federation'), '#default_value' => $node->var['fed'], '#options' => array('IN' => t('Allow login of users from OUT federated proxys'), 'OUT' => t('Allow proxy users to use other IN federated proxys'))); $f['var']['proxy'] = array('#type' => 'textfield', '#title' => t("Name"), '#default_value' => $node->var['proxy'], '#size' => 60, '#maxlength' => 60); $f['var']['port'] = array('#type' => 'textfield', '#title' => t("Port"), '#default_value' => $node->var['port'], '#size' => 60, '#maxlength' => 60); $f['var']['type'] = array('#type' => 'select', '#title' => t("Type"), '#default_value' => $node->var['type'], '#options' => array('HTTP' => 'HTTP', 'Socks4' => 'SOCKS4', 'Socks5' => 'SOCKS5', 'arp' => 'ARP', 'ftp' => 'FTP')); break; case 'SNPgraphs': $f['var']['version'] = array('#type' => 'select', '#title' => t('version'), '#default_value' => $node->var['version'], '#options' => drupal_map_assoc(array('1.0', '2.0')), '#description' => t('version of the CNML services')); $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url'], '#description' => t('Base url to call CNML services')); break; default: $f['var']['url'] = array('#type' => 'textfield', '#title' => t('url'), '#size' => 60, '#maxlength' => 250, '#default_value' => $node->var['url']); break; } } // multiple fields $delta = 0; if ($node->nid > 0) { switch ($node->service_type) { case 'mail': $f['var']['domains'] = guifi_service_multiplefield($node->var['domains'], 'domains', t('Managed domains')); break; case 'web': $f['var']['homepages'] = guifi_service_multiplefield($node->var['homepages'], 'homepages', t('URL pointing to the website homepage')); break; case 'irc': $f['var']['irc'] = guifi_service_multiplefield($node->var['irc'], 'irc', t('IRC server hostname')); break; } } if ($type->has_body) { $f['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count); } return $f; }
/** * Confirm that an edited guifi network has fields properly filled in. */ function guifi_ipv4_form_validate($form, $form_state) { if (empty($form_state['values']['base'])) { form_set_error('base', t('You must specify a base network for the zone.')); } $item = _ipcalc($form_state['values']['base'], $form_state['values']['mask']); if ($item == -1) { form_set_error('base', t('You must specify a valid ipv4 notation.')); } if ($form_state['values']['base'] != $item['netid']) { form_set_error('base', t('You must specify a valid ipv4 network base address. Base address for:') . $form_state['values']['base'] . '/' . $form_state['values']['mask'] . ' ' . t('is') . ' ' . $item['netid']); } if (empty($form_state['values']['id'])) { $result = db_query('SELECT base, mask FROM {guifi_networks} WHERE base = "%s" AND mask = "%s"', $form_state['values']['base'], $form_state['values']['mask']); if (db_affected_rows($result) > 0) { form_set_error('base', t('Network already in use.')); } } $zone = guifi_zone_load($form_state['values']['zone']); /* NO MORE AD-HOC ZONES if (($zone->master != 0) and ($zone->zone_mode != 'ad-hoc')) { if (!in_array($form_state['values']['network_type'],array('public','backbone'))) form_set_error('network_type', t('Only ad-hoc/mesh or root zones can have ad-hoc/mesh ranges assigned')); } if (($zone->zone_mode == 'ad-hoc') and ($form_state['values']['network_type'] == 'backbone')) form_set_error('network_type', t('You must specify the protocol for backbone ranges on ad-hoc/mesh zones')); */ }
function guifi_zone_get_service($id, $type, $path = FALSE) { if (is_numeric($id)) { $z = guifi_zone_load($id); } else { $z = $id; } $ret = NULL; if (!empty($z->{$type})) { $ret = $z->{$type}; } else { if ($z->master) { $ret = guifi_zone_get_service($z->master, $type); } } if ($path) { if ($ret) { $ret = 'node/' . $ret; } } return $ret; }