Esempio n. 1
0
/**
 * Checks ARI dependencies
 */
function checkDependencies()
{
    // check for PHP
    if (!version_compare(phpversion(), '4.3', '>=')) {
        echo _("ARI requires a version of PHP 4.3 or later");
        exit;
    }
    // check for PEAR
    $include_path = ini_get('include_path');
    $buf = split(':|,', $include_path);
    $found = 0;
    foreach ($buf as $path) {
        $path = fixPathSlash($path);
        $pear_check_path = $path . "DB.php";
        if (is_file($pear_check_path)) {
            $found = 1;
            break;
        }
    }
    if (!$found) {
        echo _("PHP PEAR must be installed.  Visit http://pear.php.net for help with installation.");
        exit;
    }
}
Esempio n. 2
0
 /**
  * Authenticate user and register user information into a session
  */
 function Auth()
 {
     global $ARI_ADMIN_USERNAME;
     global $ARI_ADMIN_PASSWORD;
     global $ARI_ADMIN_EXTENSIONS;
     global $ARI_CRYPT_PASSWORD;
     global $ASTERISK_VOICEMAIL_CONF;
     global $ASTERISK_VOICEMAIL_CONTEXT;
     global $ASTERISK_VOICEMAIL_PATH;
     global $ASTERISK_PROTOCOLS;
     global $CALLMONITOR_ADMIN_EXTENSIONS;
     global $ARI_NO_LOGIN;
     global $ARI_DEFAULT_ADMIN_PAGE;
     global $ARI_DEFAULT_USER_PAGE;
     $crypt = new Crypt();
     // init variables
     $extension = '';
     $displayname = '';
     $vm_password = '';
     $category = '';
     $context = '';
     $voicemail_enabled = '';
     $voicemail_email_address = '';
     $voicemail_pager_address = '';
     $voicemail_email_enable = '';
     $admin = '';
     $admin_callmonitor = '';
     $default_page = '';
     $username = '';
     $password = '';
     // get the ari authentication cookie
     $data = '';
     $chksum = '';
     if (isset($_COOKIE['ari_auth'])) {
         $buf = unserialize($_COOKIE['ari_auth']);
         list($data, $chksum) = $buf;
     }
     if (md5($data) == $chksum) {
         $data = unserialize($crypt->decrypt($data, $ARI_CRYPT_PASSWORD));
         $username = $data['username'];
         $password = $data['password'];
     }
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
     }
     // init email options array
     $voicemail_email = array();
     // when login, make a new session
     if ($username && !$ARI_NO_LOGIN) {
         $auth = false;
         // check admin
         if (!$auth) {
             if ($username == $ARI_ADMIN_USERNAME && $password == $ARI_ADMIN_PASSWORD) {
                 // authenticated
                 $auth = true;
                 $extension = 'admin';
                 $name = 'Administrator';
                 $admin = 1;
                 $admin_callmonitor = 1;
                 $default_page = $ARI_DEFAULT_ADMIN_PAGE;
             }
         }
         // check voicemail login
         if (!$auth) {
             if (is_readable($ASTERISK_VOICEMAIL_CONF)) {
                 $lines = file($ASTERISK_VOICEMAIL_CONF);
                 // look for include files and tack their lines to end of array
                 foreach ($lines as $key => $line) {
                     if (preg_match("/include/i", $line)) {
                         $include_filename = '';
                         $parts = split(' ', $line);
                         if (isset($parts[1])) {
                             $include_filename = trim($parts[1]);
                         }
                         if ($include_filename) {
                             $path_parts = pathinfo($ASTERISK_VOICEMAIL_CONF);
                             $include_path = fixPathSlash($path_parts['dirname']) . $include_filename;
                             foreach (glob($include_path) as $include_file) {
                                 $include_lines = file($include_file);
                                 $lines = array_merge($include_lines, $lines);
                             }
                         }
                     }
                 }
                 // process
                 foreach ($lines as $key => $line) {
                     // check for current context and process
                     if (preg_match("/\\[.*\\]/i", $line)) {
                         $currentContext = trim(preg_replace('/\\[|\\]/', '', $line));
                     }
                     if ($ASTERISK_VOICEMAIL_CONTEXT && $currentContext != $ASTERISK_VOICEMAIL_CONTEXT) {
                         continue;
                     }
                     // check for user and process
                     unset($value);
                     $parts = split('=>', $line);
                     if (isset($parts[0])) {
                         $var = $parts[0];
                     }
                     if (isset($parts[1])) {
                         $value = $parts[1];
                     }
                     $var = trim($var);
                     if ($var == $username && $value) {
                         $buf = split(',', $value);
                         if ($buf[0] == $password) {
                             // authenticated
                             $auth = true;
                             $extension = $username;
                             $displayname = $buf[1];
                             $vm_password = $buf[0];
                             $default_page = $ARI_DEFAULT_USER_PAGE;
                             $context = $currentContext;
                             $voicemail_enabled = 1;
                             $voicemail_email_address = $buf[2];
                             $voicemail_pager_address = $buf[3];
                             if ($voicemail_email_address || $voicemail_pager_address) {
                                 $voicemail_email_enable = 1;
                             }
                             $options = split('\\|', $buf[4]);
                             foreach ($options as $option) {
                                 $opt_buf = split('=', $option);
                                 $voicemail_email[$opt_buf[0]] = trim($opt_buf[1]);
                             }
                             $admin = 0;
                             if ($ARI_ADMIN_EXTENSIONS) {
                                 $extensions = split(',', $ARI_ADMIN_EXTENSIONS);
                                 foreach ($extensions as $key => $value) {
                                     if ($extension == $value) {
                                         $admin = 1;
                                         break 2;
                                     }
                                 }
                             }
                             $admin_callmonitor = 0;
                             if ($CALLMONITOR_ADMIN_EXTENSIONS) {
                                 $extensions = split(',', $CALLMONITOR_ADMIN_EXTENSIONS);
                                 foreach ($extensions as $key => $value) {
                                     if ($value == 'all' || $extension == $value) {
                                         $admin_callmonitor = 1;
                                         break 2;
                                     }
                                 }
                             }
                         } else {
                             $_SESSION['ari_error'] = "Incorrect Password";
                             return;
                         }
                     }
                 }
             } else {
                 $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
                 return;
             }
         }
         // check sip login
         if (!$auth) {
             foreach ($ASTERISK_PROTOCOLS as $protocol => $value) {
                 $config_files = split(';', $value['config_files']);
                 foreach ($config_files as $config_file) {
                     if (is_readable($config_file)) {
                         $lines = file($config_file);
                         foreach ($lines as $key => $line) {
                             unset($value);
                             $parts = split('=', $line);
                             if (isset($parts[0])) {
                                 $var = trim($parts[0]);
                             }
                             if (isset($parts[1])) {
                                 $value = trim($parts[1]);
                             }
                             if ($var == "username") {
                                 $protocol_username = $value;
                             }
                             if ($var == "secret") {
                                 $protocol_password = $value;
                                 if ($protocol_username == $username && $protocol_password == $password) {
                                     // authenticated
                                     $auth = true;
                                     $extension = $username;
                                     $displayname = $username;
                                     $default_page = $ARI_DEFAULT_ADMIN_PAGE;
                                     $admin = 0;
                                     if ($ARI_ADMIN_EXTENSIONS) {
                                         $extensions = split(',', $ARI_ADMIN_EXTENSIONS);
                                         foreach ($extensions as $key => $value) {
                                             if ($extension == $value) {
                                                 $admin = 1;
                                                 break 2;
                                             }
                                         }
                                     }
                                     $admin_callmonitor = 0;
                                     if ($CALLMONITOR_ADMIN_EXTENSIONS) {
                                         $extensions = split(',', $CALLMONITOR_ADMIN_EXTENSIONS);
                                         foreach ($extensions as $key => $value) {
                                             if ($value == 'all' || $extension == $value) {
                                                 $admin_callmonitor = 1;
                                                 break 2;
                                             }
                                         }
                                     }
                                 } else {
                                     if ($protocol_username == $username && $protocol_password != $password) {
                                         $_SESSION['ari_error'] = _("Incorrect Password");
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // let user know bad login
         if (!$auth) {
             $_SESSION['ari_error'] = _("Incorrect Username or Password");
         }
         // freeside login
         $freeside = new FreesideSelfService();
         $domain = 'svc_phone';
         $response = $freeside->login(array('username' => strtolower($username), 'domain' => $domain, 'password' => strtolower($password)));
         error_log("[login] received response from freeside: {$response}");
         $error = $response['error'];
         if (!$error && $response['session_id']) {
             // sucessful freeside login
             error_log("[login] logged into freeside with session_id={$session_id}");
             // store session id in your session store, to be used for other calls
             //$fs_session_id = $response['session_id'];
             $_SESSION['freeside_session_id'] = $response['session_id'];
             $customer_info = $freeside->customer_info(array('session_id' => $_SESSION['freeside_session_id']));
             //XXX error checking here too
             $displayname = $customer_info['name'];
         } else {
             // unsucessful login
             error_log("[login] error logging into freeside: {$error}");
             $auth = false;
             $extension = '';
             // display error message to user
             $_SESSION['ari_error'] = _("Incorrect Username or Password");
         }
         // if authenticated and user wants to be remembered, set cookie
         $remember = '';
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if ($auth && $remember) {
             $data = array('username' => $username, 'password' => $password);
             $data = $crypt->encrypt(serialize($data), $ARI_CRYPT_PASSWORD);
             $chksum = md5($data);
             $buf = serialize(array($data, $chksum));
             setcookie('ari_auth', $buf, time() + 365 * 24 * 60 * 60, '/');
         }
         // set category
         if (!$category) {
             $category = "general";
         }
         // set context
         if (!$context) {
             $context = "default";
         }
         // no login user
         if ($ARI_NO_LOGIN) {
             $extension = 'admin';
             $name = 'Administrator';
             $admin_callmonitor = 1;
             $default_page = $ARI_DEFAULT_ADMIN_PAGE;
         }
         // get outboundCID if it exists
         $outboundCID = $this->getOutboundCID($extension);
         // set
         if ($extension) {
             $_SESSION['ari_user']['extension'] = $extension;
             $_SESSION['ari_user']['outboundCID'] = $outboundCID;
             $_SESSION['ari_user']['displayname'] = $displayname;
             $_SESSION['ari_user']['voicemail_password'] = $vm_password;
             $_SESSION['ari_user']['category'] = $category;
             $_SESSION['ari_user']['context'] = $context;
             $_SESSION['ari_user']['voicemail_enabled'] = $voicemail_enabled;
             $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address;
             $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address;
             $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable;
             foreach ($voicemail_email as $key => $value) {
                 $_SESSION['ari_user']['voicemail_email'][$key] = $value;
             }
             $_SESSION['ari_user']['admin'] = $admin;
             $_SESSION['ari_user']['admin_callmonitor'] = $admin_callmonitor;
             $_SESSION['ari_user']['default_page'] = $default_page;
             // force the session data saved
             session_write_close();
         }
     }
 }
Esempio n. 3
0
 /**
  * Authenticate user and register user information into a session
  */
 function Auth()
 {
     global $ariadminusername;
     global $ariadminpassword;
     global $ARI_ADMIN_EXTENSIONS;
     global $ARI_CRYPT_PASSWORD;
     global $ASTERISK_VOICEMAIL_CONF;
     global $ASTERISK_VOICEMAIL_CONTEXT;
     global $ASTERISK_VOICEMAIL_PATH;
     global $ASTERISK_PROTOCOLS;
     global $CALLMONITOR_ADMIN_EXTENSIONS;
     global $ARI_NO_LOGIN;
     global $ARI_DEFAULT_ADMIN_PAGE;
     global $ARI_DEFAULT_USER_PAGE;
     $crypt = new Crypt();
     // init variables
     $extension = '';
     $displayname = '';
     $vm_password = '';
     $category = '';
     $context = '';
     $voicemail_enabled = '';
     $voicemail_email_address = '';
     $voicemail_pager_address = '';
     $voicemail_email_enable = '';
     $admin = '';
     $admin_callmonitor = '';
     $default_page = '';
     $username = '';
     $password = '';
     // get the ari authentication cookie
     $data = '';
     $chksum = '';
     if (isset($_COOKIE['ari_auth'])) {
         $buf = unserialize(stripslashes($_COOKIE['ari_auth']));
         list($data, $chksum) = $buf;
     }
     if (md5($data) == $chksum) {
         $data = unserialize($crypt->decrypt($data, $ARI_CRYPT_PASSWORD));
         $username = $data['username'];
         $password = $data['password'];
     }
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
     }
     // init email options array
     $voicemail_email = array();
     // when login, make a new session
     if ($username && !$ARI_NO_LOGIN) {
         $auth = false;
         // check admin
         if (!$auth) {
             if ($username == $ariadminusername && $password == $ariadminpassword) {
                 // authenticated
                 $auth = true;
                 $extension = 'admin';
                 $name = 'Administrator';
                 $admin = 1;
                 $admin_callmonitor = 1;
                 $default_page = $ARI_DEFAULT_ADMIN_PAGE;
             }
         }
         // check voicemail login
         if (!$auth) {
             if (is_readable($ASTERISK_VOICEMAIL_CONF)) {
                 $lines = file($ASTERISK_VOICEMAIL_CONF);
                 // look for include files and tack their lines to end of array
                 foreach ($lines as $key => $line) {
                     if (preg_match("/include/i", $line)) {
                         $include_filename = '';
                         $parts = preg_split('/\\s/', $line);
                         if (isset($parts[1])) {
                             $include_filename = trim($parts[1]);
                         }
                         if ($include_filename) {
                             $path_parts = pathinfo($ASTERISK_VOICEMAIL_CONF);
                             $include_path = fixPathSlash($path_parts['dirname']) . $include_filename;
                             foreach (glob($include_path) as $include_file) {
                                 $include_lines = file($include_file);
                                 $lines = array_merge($include_lines, $lines);
                             }
                         }
                     }
                 }
                 // process
                 foreach ($lines as $key => $line) {
                     // check for current context and process
                     if (preg_match("/\\[.*\\]/i", $line)) {
                         $currentContext = trim(preg_replace('/\\[|\\]/', '', $line));
                     }
                     if ($ASTERISK_VOICEMAIL_CONTEXT && $currentContext != $ASTERISK_VOICEMAIL_CONTEXT) {
                         continue;
                     }
                     // check for user and process
                     unset($value);
                     $parts = preg_split('/=>/', $line);
                     if (isset($parts[0])) {
                         $var = $parts[0];
                     }
                     if (isset($parts[1])) {
                         $value = $parts[1];
                     }
                     $var = trim($var);
                     if ($var == $username && $value) {
                         $buf = preg_split('/,/', $value);
                         if ($buf[0] == $password) {
                             // authenticated
                             $auth = true;
                             $extension = $username;
                             $displayname = $buf[1];
                             $vm_password = $buf[0];
                             $default_page = $ARI_DEFAULT_USER_PAGE;
                             $context = $currentContext;
                             $voicemail_enabled = 1;
                             $voicemail_email_address = $buf[2];
                             $voicemail_pager_address = $buf[3];
                             if ($voicemail_email_address || $voicemail_pager_address) {
                                 $voicemail_email_enable = 1;
                             }
                             $options = preg_split('/\\|/', $buf[4]);
                             foreach ($options as $option) {
                                 $opt_buf = preg_split('/=/', $option);
                                 $voicemail_email[$opt_buf[0]] = trim($opt_buf[1]);
                             }
                             $admin = 0;
                             if ($ARI_ADMIN_EXTENSIONS) {
                                 $extensions = preg_split('/,/', $ARI_ADMIN_EXTENSIONS);
                                 foreach ($extensions as $key => $value) {
                                     if ($extension == $value) {
                                         $admin = 1;
                                         break 2;
                                     }
                                 }
                             }
                             $admin_callmonitor = 0;
                             if ($CALLMONITOR_ADMIN_EXTENSIONS) {
                                 $extensions = preg_split('/,/', $CALLMONITOR_ADMIN_EXTENSIONS);
                                 foreach ($extensions as $key => $value) {
                                     if ($value == 'all' || $extension == $value) {
                                         $admin_callmonitor = 1;
                                         break 2;
                                     }
                                 }
                             }
                         } else {
                             $_SESSION['ari_error'] = _("Incorrect Username or Password");
                             return;
                         }
                     }
                 }
             } else {
                 $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
                 return;
             }
         }
         // check sip login
         if (!$auth) {
             foreach ($ASTERISK_PROTOCOLS as $protocol => $value) {
                 $config_files = preg_split('/;/', $value['config_files']);
                 foreach ($config_files as $config_file) {
                     if (is_readable($config_file)) {
                         $lines = file($config_file);
                         foreach ($lines as $key => $line) {
                             unset($value);
                             $parts = preg_split('/=/', $line);
                             if (isset($parts[0])) {
                                 $var = trim($parts[0]);
                             }
                             if (isset($parts[1])) {
                                 $value = trim($parts[1]);
                             }
                             if ($var == "username") {
                                 $protocol_username = $value;
                             }
                             if ($var == "secret") {
                                 $protocol_password = $value;
                                 if ($protocol_username == $username && $protocol_password == $password) {
                                     // authenticated
                                     $auth = true;
                                     $extension = $username;
                                     $displayname = $username;
                                     $default_page = $ARI_DEFAULT_ADMIN_PAGE;
                                     $admin = 0;
                                     if ($ARI_ADMIN_EXTENSIONS) {
                                         $extensions = preg_split('/,/', $ARI_ADMIN_EXTENSIONS);
                                         foreach ($extensions as $key => $value) {
                                             if ($extension == $value) {
                                                 $admin = 1;
                                                 break 2;
                                             }
                                         }
                                     }
                                     $admin_callmonitor = 0;
                                     if ($CALLMONITOR_ADMIN_EXTENSIONS) {
                                         $extensions = preg_split('/,/', $CALLMONITOR_ADMIN_EXTENSIONS);
                                         foreach ($extensions as $key => $value) {
                                             if ($value == 'all' || $extension == $value) {
                                                 $admin_callmonitor = 1;
                                                 break 2;
                                             }
                                         }
                                     }
                                 } else {
                                     if ($protocol_username == $username && $protocol_password != $password) {
                                         $_SESSION['ari_error'] = _("Incorrect Username or Password");
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // let user know bad login
         if (!$auth) {
             $_SESSION['ari_error'] = _("Incorrect Username or Password");
         }
         // if authenticated and user wants to be remembered, set cookie
         $remember = '';
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if ($auth && $remember) {
             $data = array('username' => $username, 'password' => $password);
             $data = $crypt->encrypt(serialize($data), $ARI_CRYPT_PASSWORD);
             $chksum = md5($data);
             $buf = serialize(array($data, $chksum));
             setcookie('ari_auth', $buf, time() + 365 * 24 * 60 * 60, '/');
         }
         // set category
         if (!$category) {
             $category = "general";
         }
         // set context
         if (!$context) {
             $context = "default";
         }
         // no login user
         if ($ARI_NO_LOGIN) {
             $extension = 'admin';
             $name = 'Administrator';
             $admin_callmonitor = 1;
             $default_page = $ARI_DEFAULT_ADMIN_PAGE;
         }
         // get outboundCID if it exists
         $outboundCID = $this->getOutboundCID($extension);
         // set
         if ($extension) {
             $_SESSION['ari_user']['extension'] = $extension;
             $_SESSION['ari_user']['outboundCID'] = $outboundCID;
             $_SESSION['ari_user']['displayname'] = $displayname;
             $_SESSION['ari_user']['voicemail_password'] = $vm_password;
             $_SESSION['ari_user']['category'] = $category;
             $_SESSION['ari_user']['context'] = $context;
             $_SESSION['ari_user']['voicemail_enabled'] = $voicemail_enabled;
             $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address;
             $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address;
             $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable;
             foreach ($voicemail_email as $key => $value) {
                 $_SESSION['ari_user']['voicemail_email'][$key] = $value;
             }
             $_SESSION['ari_user']['admin'] = $admin;
             $_SESSION['ari_user']['admin_callmonitor'] = $admin_callmonitor;
             $_SESSION['ari_user']['default_page'] = $default_page;
             // Make sure nothing stale is here:
             //
             unset($_SESSION['ari_user']['recfiles']);
             // don't force the session data saved, there may be voicemail or callmonitor files still
         }
     }
 }
Esempio n. 4
0
/**
 * Make the $Paths array, which is used in many places to figure out where files should be
 * read from or written to.
 *
 * @see fixpath()
 */
function Setpaths()
{
    global $Current_weblog, $Paths, $Cfg;
    $Paths['pivot_url'] = get_pivot_url();
    $Paths['cookie_url'] = fixPathSlash(str_replace('\\', '/', dirname($Paths['pivot_url'])));
    // We are setting $Paths['log_url'] in parse_step4 since it can't be
    // set before we know the weblog anyway.
    $Paths['host'] = "http://" . $_SERVER['HTTP_HOST'];
    if (realpath(__FILE__) == "") {
        $Paths['pivot_path'] = str_replace('\\', '/', dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . "/");
    } else {
        $Paths['pivot_path'] = str_replace('\\', '/', dirname(realpath(__FILE__)) . "/");
    }
    $Paths['extensions_path'] = fixpath($Paths['pivot_path'] . '../' . $Cfg['extensions_path']);
    $Paths['extensions_url'] = fixpath($Paths['pivot_url'] . '../' . $Cfg['extensions_path']);
    $Paths['upload_path'] = fixpath($Paths['pivot_path'] . '../' . $Cfg['upload_path']);
    $Paths['upload_url'] = fixpath($Paths['pivot_url'] . '../' . $Cfg['upload_path']);
    if (file_exists($Paths['pivot_path'] . '../bbclone/')) {
        $Paths['bbclone_path'] = fixpath($Paths['pivot_path'] . '../bbclone/');
    } elseif (file_exists($Paths['pivot_path'] . '../../bbclone/')) {
        $Paths['bbclone_path'] = fixpath($Paths['pivot_path'] . '../../bbclone/');
    } else {
        $Paths['bbclone_path'] = "";
    }
    $Paths['templates_path'] = fixpath($Paths['pivot_path'] . 'templates/');
}
Esempio n. 5
0
/**
 * Save an edited weblog, then show the weblogs overview screen
 */
function main_blog_save()
{
    global $Pivot_Vars, $blog_settings, $Weblogs;
    // check against unauthorised direct access.
    check_csrf();
    // unserialize the parsed temp_weblog..
    $temp_weblog = unserialize(urldecode($Pivot_Vars['temp_weblog']));
    // urldecode category names and create a list of all categories
    // in the weblog, not only per subweblog.
    $categories = array();
    foreach ($temp_weblog['sub_weblog'] as $sub_weblog_key => $sub_weblog_value) {
        foreach ($sub_weblog_value['categories'] as $category_key => $category_name) {
            $temp_weblog['sub_weblog'][$sub_weblog_key]['categories'][$category_key] = urldecode($category_name);
            $categories[] = urldecode($category_name);
        }
    }
    $temp_weblog['categories'] = array_unique($categories);
    // Here we determine if we save an edited or a new weblog..
    if (isset($Pivot_Vars['orig_name']) && strlen($Pivot_Vars['orig_name']) > 1) {
        $orig_name = $Pivot_Vars['orig_name'];
        $msg = lang('weblog_config', 'saved_update');
    } else {
        // Urlencode the key/internal name for the weblog, to allow
        // weblogs with non US-ascii characters.
        $orig_name = urlencode(strtolower(safe_string($temp_weblog['name'], TRUE)));
        $msg = lang('weblog_config', 'saved_create');
        // We make sure the new weblog does not overwrite a previous one.
        if (isset($Weblogs[$orig_name])) {
            // It already exists, so we look for the first incremental name that's not yet taken..
            $i = 0;
            do {
                $i++;
                $incr_name = $orig_name . "_" . $i;
            } while (isset($Weblogs[$incr_name]));
            $orig_name = $incr_name;
        }
    }
    // add the new stuff
    $temp_weblog['rss'] = $Pivot_Vars['rss'];
    $temp_weblog['rss_filename'] = $Pivot_Vars['rss_filename'];
    $temp_weblog['atom_filename'] = $Pivot_Vars['atom_filename'];
    $temp_weblog['rss_path'] = fixPathSlash($Pivot_Vars['rss_path']);
    $temp_weblog['rss_full'] = $Pivot_Vars['rss_full'];
    $temp_weblog['rss_link'] = $Pivot_Vars['rss_link'];
    $temp_weblog['rss_img'] = $Pivot_Vars['rss_img'];
    $temp_weblog['lastcomm_amount'] = $Pivot_Vars['lastcomm_amount'];
    $temp_weblog['lastcomm_length'] = $Pivot_Vars['lastcomm_length'];
    $temp_weblog['lastcomm_format'] = stripslashes($Pivot_Vars['lastcomm_format']);
    $temp_weblog['lastcomm_redirect'] = stripslashes($Pivot_Vars['lastcomm_redirect']);
    $temp_weblog['lastref_amount'] = $Pivot_Vars['lastref_amount'];
    $temp_weblog['lastref_length'] = $Pivot_Vars['lastref_length'];
    $temp_weblog['lastref_format'] = stripslashes($Pivot_Vars['lastref_format']);
    $temp_weblog['lastref_graphic'] = stripslashes($Pivot_Vars['lastref_graphic']);
    $temp_weblog['emoticons'] = $Pivot_Vars['emoticons'];
    $temp_weblog['encode_email_addresses'] = $Pivot_Vars['encode_email_addresses'];
    $temp_weblog['target_blank'] = $Pivot_Vars['target_blank'];
    $temp_weblog['search_format'] = stripslashes($Pivot_Vars['search_format']);
    $temp_weblog['fulldate_format'] = stripslashes($Pivot_Vars['fulldate_format']);
    $temp_weblog['entrydate_format'] = stripslashes($Pivot_Vars['entrydate_format']);
    $temp_weblog['diffdate_format'] = stripslashes($Pivot_Vars['diffdate_format']);
    $temp_weblog['comment_sendmail'] = $Pivot_Vars['comment_sendmail'];
    $temp_weblog['comment_emailto'] = $Pivot_Vars['comment_emailto'];
    $temp_weblog['comment_texttolinks'] = $Pivot_Vars['comment_texttolinks'];
    $temp_weblog['comment_wrap'] = $Pivot_Vars['comment_wrap'];
    $temp_weblog['comments_text_0'] = stripslashes($Pivot_Vars['comments_text_0']);
    $temp_weblog['comments_text_1'] = stripslashes($Pivot_Vars['comments_text_1']);
    $temp_weblog['comments_text_2'] = stripslashes($Pivot_Vars['comments_text_2']);
    $temp_weblog['comment_pop'] = $Pivot_Vars['comment_pop'];
    $temp_weblog['comment_width'] = $Pivot_Vars['comment_width'];
    $temp_weblog['comment_height'] = $Pivot_Vars['comment_height'];
    $temp_weblog['comment_format'] = stripslashes($Pivot_Vars['comment_format']);
    $temp_weblog['comment_reply'] = stripslashes($Pivot_Vars['comment_reply']);
    $temp_weblog['comment_forward'] = stripslashes($Pivot_Vars['comment_forward']);
    $temp_weblog['comment_backward'] = stripslashes($Pivot_Vars['comment_backward']);
    $temp_weblog['comment_textile'] = $Pivot_Vars['comment_textile'];
    $temp_weblog['comment_gravatardefault'] = $Pivot_Vars['comment_gravatardefault'];
    $temp_weblog['comment_gravatarhtml'] = $Pivot_Vars['comment_gravatarhtml'];
    $temp_weblog['comment_gravatarsize'] = $Pivot_Vars['comment_gravatarsize'];
    $temp_weblog['trackbacks_text_0'] = stripslashes($Pivot_Vars['trackbacks_text_0']);
    $temp_weblog['trackbacks_text_1'] = stripslashes($Pivot_Vars['trackbacks_text_1']);
    $temp_weblog['trackbacks_text_2'] = stripslashes($Pivot_Vars['trackbacks_text_2']);
    $temp_weblog['trackback_format'] = stripslashes($Pivot_Vars['trackback_format']);
    $temp_weblog['trackback_link_format'] = stripslashes($Pivot_Vars['trackback_link_format']);
    $temp_weblog['blogroll_id'] = $Pivot_Vars['blogroll_id'];
    $temp_weblog['blogroll_fg'] = $Pivot_Vars['blogroll_fg'];
    $temp_weblog['blogroll_bg'] = $Pivot_Vars['blogroll_bg'];
    $temp_weblog['blogroll_line1'] = $Pivot_Vars['blogroll_line1'];
    $temp_weblog['blogroll_line2'] = $Pivot_Vars['blogroll_line2'];
    $temp_weblog['blogroll_c1'] = $Pivot_Vars['blogroll_c1'];
    $temp_weblog['blogroll_c2'] = $Pivot_Vars['blogroll_c2'];
    $temp_weblog['blogroll_c3'] = $Pivot_Vars['blogroll_c3'];
    $temp_weblog['blogroll_c4'] = $Pivot_Vars['blogroll_c4'];
    $Weblogs[$orig_name] = $temp_weblog;
    save_serialize('pv_cfg_weblogs.php', $Weblogs);
    main_blogs($msg);
}