Example #1
0
function removeme_post(&$a)
{
    if (!local_user()) {
        return;
    }
    if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) {
        return;
    }
    if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
        return;
    }
    if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
        return;
    }
    if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
        return;
    }
    $account = $a->get_account();
    if (!account_verify_password($account['account_email'], $_POST['qxz_password'])) {
        return;
    }
    if ($account['account_password_changed'] != NULL_DATE) {
        $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
        if ($account['account_password_changed'] > d1) {
            notice(t('Channel removals are not allowed within 48 hours of changing the account password.') . EOL);
            return;
        }
    }
    require_once 'include/Contact.php';
    $global_remove = intval($_POST['global']);
    channel_remove(local_user(), 1 - $global_remove, true);
}
Example #2
0
 function post()
 {
     if (!local_channel()) {
         return;
     }
     if ($_SESSION['delegate']) {
         return;
     }
     if (!x($_POST, 'qxz_password') || !strlen(trim($_POST['qxz_password']))) {
         return;
     }
     if (!x($_POST, 'verify') || !strlen(trim($_POST['verify']))) {
         return;
     }
     if ($_POST['verify'] !== $_SESSION['remove_account_verify']) {
         return;
     }
     $account = \App::get_account();
     $x = account_verify_password($account['account_email'], $_POST['qxz_password']);
     if (!($x && $x['account'])) {
         return;
     }
     if ($account['account_password_changed'] != NULL_DATE) {
         $d1 = datetime_convert('UTC', 'UTC', 'now - 48 hours');
         if ($account['account_password_changed'] > d1) {
             notice(t('Channel removals are not allowed within 48 hours of changing the account password.') . EOL);
             return;
         }
     }
     $global_remove = intval($_POST['global']);
     channel_remove(local_channel(), 1 - $global_remove, true);
 }
function channel_close_handles($cid)
{
    global $channels;
    # Sanity check - make sure a channel with the given cid exists
    if (!array_key_exists($cid, $channels)) {
        return;
    }
    $c = $channels[$cid];
    for ($i = 0; $i < 3; $i++) {
        #my_print("closing channel fd $i, {$c[$i]}");
        if (array_key_exists($i, $c) && is_resource($c[$i])) {
            close($c[$i]);
            # Make sure the main loop doesn't select on this resource after we
            # close it.
            remove_reader($c[$i]);
        }
    }
    # axe it from the list only if it doesn't have any leftover data
    if (strlen($c['data']) == 0) {
        channel_remove($cid);
    }
}
Example #4
0
function account_remove($account_id, $local = true, $unset_session = true)
{
    logger('account_remove: ' . $account_id);
    if (!intval($account_id)) {
        logger('account_remove: no account.');
        return false;
    }
    // Don't let anybody nuke the only admin account.
    $r = q("select account_id from account where (account_roles & %d)>0", intval(ACCOUNT_ROLE_ADMIN));
    if ($r !== false && count($r) == 1 && $r[0]['account_id'] == $account_id) {
        logger("Unable to remove the only remaining admin account");
        return false;
    }
    $r = q("select * from account where account_id = %d limit 1", intval($account_id));
    $account_email = $r[0]['account_email'];
    if (!$r) {
        logger('account_remove: No account with id: ' . $account_id);
        return false;
    }
    $x = q("select channel_id from channel where channel_account_id = %d", intval($account_id));
    if ($x) {
        foreach ($x as $xx) {
            channel_remove($xx['channel_id'], $local, false);
        }
    }
    $r = q("delete from account where account_id = %d", intval($account_id));
    if ($unset_session) {
        unset($_SESSION['authenticated']);
        unset($_SESSION['uid']);
        notice(sprintf(t("User '%s' deleted"), $account_email) . EOL);
        goaway(z_root());
    }
    return $r;
}
Example #5
0
 /**
  * @brief
  *
  * @param App &$a
  * @return string
  */
 function admin_page_channels(&$a)
 {
     if (argc() > 2) {
         $uid = argv(3);
         $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
         if (!$channel) {
             notice(t('Channel not found') . EOL);
             goaway(z_root() . '/admin/channels');
         }
         switch (argv(2)) {
             case "delete":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 // delete channel
                 require_once "include/Contact.php";
                 channel_remove($uid, true);
                 notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                 break;
             case "block":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 proc_run('php', 'include/directory.php', $uid, 'nopush');
                 notice(sprintf($pflags & PAGE_CENSORED ? t("Channel '%s' censored") : t("Channel '%s' uncensored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             case "code":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 notice(sprintf($pflags & PAGE_ALLOWCODE ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             default:
                 break;
         }
         goaway(z_root() . '/admin/channels');
     }
     /* get channels */
     $total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0");
     if ($total) {
         \App::set_pager_total($total[0]['total']);
         \App::set_pager_itemspage(100);
     }
     $order = " order by channel_name asc ";
     $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 {$order} limit %d offset %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if ($channels) {
         for ($x = 0; $x < count($channels); $x++) {
             if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                 $channels[$x]['blocked'] = true;
             } else {
                 $channels[$x]['blocked'] = false;
             }
             if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) {
                 $channels[$x]['allowcode'] = true;
             } else {
                 $channels[$x]['allowcode'] = false;
             }
         }
     }
     $t = get_markup_template("admin_channels.tpl");
     $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$code' => t('Allow Code'), '$uncode' => t('Disallow Code'), '$h_channels' => t('Channel'), '$th_channels' => array(t('UID'), t('Name'), t('Address')), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => z_root(), '$channels' => $channels));
     $o .= paginate($a);
     return $o;
 }
Example #6
0
File: admin.php Project: Mauru/red
/**
 * @param App $a
 * @return string
 */
function admin_page_channels(&$a)
{
    if (argc() > 2) {
        $uid = argv(3);
        $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
        if (!$channel) {
            notice(t('Channel not found') . EOL);
            goaway($a->get_baseurl(true) . '/admin/channels');
        }
        switch (argv(2)) {
            case "delete":
                check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                // delete channel
                require_once "include/Contact.php";
                channel_remove($uid, true);
                notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                break;
            case "block":
                check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                q("UPDATE channel SET channel_pageflags = ( channel_pageflags ^ %d ) where channel_id = %d", intval(PAGE_CENSORED), intval($uid));
                notice(sprintf($channel[0]['channel_pageflags'] & PAGE_CENSORED ? t("Channel '%s' uncensored") : t("Channel '%s' censored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                break;
        }
        goaway($a->get_baseurl(true) . '/admin/channels');
        return '';
        // NOTREACHED
    }
    /* get channels */
    $total = q("SELECT count(*) as total FROM channel where not (channel_pageflags & %d)", intval(PAGE_REMOVED));
    if ($total) {
        $a->set_pager_total($total[0]['total']);
        $a->set_pager_itemspage(100);
    }
    $order = " order by channel_name asc ";
    $channels = q("SELECT * from channel where not ( channel_pageflags & %d ) {$order} limit %d , %d ", intval(PAGE_REMOVED), intval($a->pager['start']), intval($a->pager['itemspage']));
    if ($channels) {
        for ($x = 0; $x < count($channels); $x++) {
            if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                $channels[$x]['blocked'] = true;
            } else {
                $channels[$x]['blocked'] = false;
            }
        }
    }
    $t = get_markup_template("admin_channels.tpl");
    $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$h_channels' => t('Channel'), '$th_channels' => array(t('UID'), t('Name'), t('Address')), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => $a->get_baseurl(true), '$channels' => $channels));
    $o .= paginate($a);
    return $o;
}
Example #7
0
 /**
  * @brief
  *
  * @return string
  */
 function get()
 {
     if (argc() > 2) {
         $uid = argv(3);
         $channel = q("SELECT * FROM channel WHERE channel_id = %d", intval($uid));
         if (!$channel) {
             notice(t('Channel not found') . EOL);
             goaway(z_root() . '/admin/channels');
         }
         switch (argv(2)) {
             case "delete":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 // delete channel
                 channel_remove($uid, true);
                 notice(sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
                 break;
             case "block":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_CENSORED;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 \Zotlabs\Daemon\Master::Summon(array('Directory', $uid, 'nopush'));
                 notice(sprintf($pflags & PAGE_CENSORED ? t("Channel '%s' censored") : t("Channel '%s' uncensored"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             case "code":
                 check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
                 $pflags = $channel[0]['channel_pageflags'] ^ PAGE_ALLOWCODE;
                 q("UPDATE channel SET channel_pageflags = %d where channel_id = %d", intval($pflags), intval($uid));
                 notice(sprintf($pflags & PAGE_ALLOWCODE ? t("Channel '%s' code allowed") : t("Channel '%s' code disallowed"), $channel[0]['channel_name'] . ' (' . $channel[0]['channel_address'] . ')') . EOL);
                 break;
             default:
                 break;
         }
         goaway(z_root() . '/admin/channels');
     }
     $key = $_REQUEST['key'] ? dbesc($_REQUEST['key']) : 'channel_id';
     $dir = 'asc';
     if (array_key_exists('dir', $_REQUEST)) {
         $dir = intval($_REQUEST['dir']) ? 'asc' : 'desc';
     }
     $base = z_root() . '/admin/channels?f=';
     $odir = $dir === 'asc' ? '0' : '1';
     /* get channels */
     $total = q("SELECT count(*) as total FROM channel where channel_removed = 0 and channel_system = 0");
     if ($total) {
         \App::set_pager_total($total[0]['total']);
         \App::set_pager_itemspage(100);
     }
     $channels = q("SELECT * from channel where channel_removed = 0 and channel_system = 0 order by {$key} {$dir} limit %d offset %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
     if ($channels) {
         for ($x = 0; $x < count($channels); $x++) {
             if ($channels[$x]['channel_pageflags'] & PAGE_CENSORED) {
                 $channels[$x]['blocked'] = true;
             } else {
                 $channels[$x]['blocked'] = false;
             }
             if ($channels[$x]['channel_pageflags'] & PAGE_ALLOWCODE) {
                 $channels[$x]['allowcode'] = true;
             } else {
                 $channels[$x]['allowcode'] = false;
             }
         }
     }
     $t = get_markup_template("admin_channels.tpl");
     $o = replace_macros($t, array('$title' => t('Administration'), '$page' => t('Channels'), '$submit' => t('Submit'), '$select_all' => t('select all'), '$delete' => t('Delete'), '$block' => t('Censor'), '$unblock' => t('Uncensor'), '$code' => t('Allow Code'), '$uncode' => t('Disallow Code'), '$h_channels' => t('Channel'), '$base' => $base, '$odir' => $odir, '$th_channels' => array([t('UID'), 'channel_id'], [t('Name'), 'channel_name'], [t('Address'), 'channel_address']), '$confirm_delete_multi' => t('Selected channels will be deleted!\\n\\nEverything that was posted in these channels on this site will be permanently deleted!\\n\\nAre you sure?'), '$confirm_delete' => t('The channel {0} will be deleted!\\n\\nEverything that was posted in this channel on this site will be permanently deleted!\\n\\nAre you sure?'), '$form_security_token' => get_form_security_token("admin_channels"), '$baseurl' => z_root(), '$channels' => $channels));
     $o .= paginate($a);
     return $o;
 }