]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #4718 from MrPetovan/bug/fix-console-url-argument
authorMichael Vogel <icarus@dabo.de>
Sat, 31 Mar 2018 04:02:23 +0000 (06:02 +0200)
committerGitHub <noreply@github.com>
Sat, 31 Mar 2018 04:02:23 +0000 (06:02 +0200)
Console: Use $argv instead of $_SERVER['argv']

include/text.php
mod/follow.php
mod/profiles.php
src/Content/Text/BBCode.php
src/Core/Console.php
src/Core/Console/NewPassword.php [new file with mode: 0644]

index 67ce7e65e83df258ae041296b951478453066ca6..311422c5751d9af55f2399298a1b4543f94e0c50 100644 (file)
@@ -2030,6 +2030,10 @@ function text_highlight($s, $lang) {
                $lang = 'javascript';
        }
 
+       if ($lang === 'bash') {
+               $lang = 'sh';
+       }
+
        // @TODO: Replace Text_Highlighter_Renderer_Html by scrivo/highlight.php
 
        // Autoload the library to make constants available
index 1dc20d16d114089eff2f665f8108b2b20e966607..1292d24e3359ca9f401cae2853178ede9094e96e 100644 (file)
@@ -11,10 +11,10 @@ use Friendica\Model\Profile;
 use Friendica\Network\Probe;
 use Friendica\Database\DBM;
 
-function follow_post(App $a) {
-
+function follow_post(App $a)
+{
        if (!local_user()) {
-               notice(L10n::t('Permission denied.') . EOL);
+               notice(L10n::t('Permission denied.'));
                goaway($_SESSION['return_url']);
                // NOTREACHED
        }
@@ -29,7 +29,7 @@ function follow_post(App $a) {
 
        // Makes the connection request for friendica contacts easier
        // This is just a precaution if maybe this page is called somewhere directly via POST
-       $_SESSION["fastlane"] = $url;
+       $_SESSION['fastlane'] = $url;
 
        $result = Contact::createFromProbe($uid, $url, true);
 
@@ -39,19 +39,19 @@ function follow_post(App $a) {
                }
                goaway($return_url);
        } elseif ($result['cid']) {
-               goaway(System::baseUrl().'/contacts/'.$result['cid']);
+               goaway(System::baseUrl() . '/contacts/' . $result['cid']);
        }
 
-       info(L10n::t('The contact could not be added.').EOL);
+       info(L10n::t('The contact could not be added.'));
 
        goaway($return_url);
        // NOTREACHED
 }
 
-function follow_content(App $a) {
-
+function follow_content(App $a)
+{
        if (!local_user()) {
-               notice(L10n::t('Permission denied.') . EOL);
+               notice(L10n::t('Permission denied.'));
                goaway($_SESSION['return_url']);
                // NOTREACHED
        }
@@ -70,8 +70,8 @@ function follow_content(App $a) {
 
        if ($r) {
                if ($r[0]['pending']) {
-                       notice(L10n::t('You already added this contact.').EOL);
-                       $submit = "";
+                       notice(L10n::t('You already added this contact.'));
+                       $submit = '';
                        //goaway($_SESSION['return_url']);
                        // NOTREACHED
                }
@@ -79,104 +79,107 @@ function follow_content(App $a) {
 
        $ret = Probe::uri($url);
 
-       if (($ret["network"] == NETWORK_DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
-               notice(L10n::t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
-               $submit = "";
+       if (($ret['network'] == NETWORK_DIASPORA) && !Config::get('system', 'diaspora_enabled')) {
+               notice(L10n::t("Diaspora support isn't enabled. Contact can't be added."));
+               $submit = '';
                //goaway($_SESSION['return_url']);
                // NOTREACHED
        }
 
-       if (($ret["network"] == NETWORK_OSTATUS) && Config::get('system', 'ostatus_disabled')) {
-               notice(L10n::t("OStatus support is disabled. Contact can't be added.") . EOL);
-               $submit = "";
+       if (($ret['network'] == NETWORK_OSTATUS) && Config::get('system', 'ostatus_disabled')) {
+               notice(L10n::t("OStatus support is disabled. Contact can't be added."));
+               $submit = '';
                //goaway($_SESSION['return_url']);
                // NOTREACHED
        }
 
-       if ($ret["network"] == NETWORK_PHANTOM) {
-               notice(L10n::t("The network type couldn't be detected. Contact can't be added.") . EOL);
-               $submit = "";
+       if ($ret['network'] == NETWORK_PHANTOM) {
+               notice(L10n::t("The network type couldn't be detected. Contact can't be added."));
+               $submit = '';
                //goaway($_SESSION['return_url']);
                // NOTREACHED
        }
 
-       if ($ret["network"] == NETWORK_MAIL) {
-               $ret["url"] = $ret["addr"];
+       if ($ret['network'] == NETWORK_MAIL) {
+               $ret['url'] = $ret['addr'];
        }
 
        if (($ret['network'] === NETWORK_DFRN) && !DBM::is_result($r)) {
-               $request = $ret["request"];
+               $request = $ret['request'];
                $tpl = get_markup_template('dfrn_request.tpl');
        } else {
-               $request = System::baseUrl()."/follow";
+               $request = System::baseUrl() . '/follow';
                $tpl = get_markup_template('auto_request.tpl');
        }
 
        $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1", intval($uid));
 
        if (!$r) {
-               notice(L10n::t('Permission denied.') . EOL);
+               notice(L10n::t('Permission denied.'));
                goaway($_SESSION['return_url']);
                // NOTREACHED
        }
 
-       $myaddr = $r[0]["url"];
+       $myaddr = $r[0]['url'];
        $gcontact_id = 0;
 
        // Makes the connection request for friendica contacts easier
-       $_SESSION["fastlane"] = $ret["url"];
+       $_SESSION['fastlane'] = $ret['url'];
 
        $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
-               normalise_link($ret["url"]));
+               normalise_link($ret['url']));
 
        if (!$r) {
-               $r = [["location" => "", "about" => "", "keywords" => ""]];
+               $r = [['location' => '', 'about' => '', 'keywords' => '']];
        } else {
-               $gcontact_id = $r[0]["id"];
+               $gcontact_id = $r[0]['id'];
        }
 
        if ($ret['network'] === NETWORK_DIASPORA) {
-               $r[0]["location"] = "";
-               $r[0]["about"] = "";
+               $r[0]['location'] = '';
+               $r[0]['about'] = '';
        }
 
-       $header = L10n::t("Connect/Follow");
-
-       $o  = replace_macros($tpl, [
-                       '$header' => htmlentities($header),
-                       //'$photo' => proxy_url($ret["photo"], false, PROXY_SIZE_SMALL),
-                       '$desc' => "",
-                       '$pls_answer' => L10n::t('Please answer the following:'),
-                       '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret["name"]), false, '', [L10n::t('No'), L10n::t('Yes')]],
-                       '$add_note' => L10n::t('Add a personal note:'),
-                       '$page_desc' => "",
-                       '$friendica' => "",
-                       '$statusnet' => "",
-                       '$diaspora' => "",
-                       '$diasnote' => "",
-                       '$your_address' => L10n::t('Your Identity Address:'),
-                       '$invite_desc' => "",
-                       '$emailnet' => "",
-                       '$submit' => $submit,
-                       '$cancel' => L10n::t('Cancel'),
-                       '$nickname' => "",
-                       '$name' => $ret["name"],
-                       '$url' => $ret["url"],
-                       '$zrl' => Profile::zrl($ret["url"]),
-                       '$url_label' => L10n::t("Profile URL"),
-                       '$myaddr' => $myaddr,
-                       '$request' => $request,
-                       /*'$location' => Friendica\Content\Text\BBCode::::convert($r[0]["location"]),
-                       '$location_label' => L10n::t("Location:"),
-                       '$about' => Friendica\Content\Text\BBCode::::convert($r[0]["about"], false, false),
-                       '$about_label' => L10n::t("About:"), */
-                       '$keywords' => $r[0]["keywords"],
-                       '$keywords_label' => L10n::t("Tags:")
+       $header = L10n::t('Connect/Follow');
+
+       $o = replace_macros($tpl, [
+               '$header'        => htmlentities($header),
+               //'$photo' => proxy_url($ret['photo'], false, PROXY_SIZE_SMALL),
+               '$desc'          => '',
+               '$pls_answer'    => L10n::t('Please answer the following:'),
+               '$does_know_you' => ['knowyou', L10n::t('Does %s know you?', $ret['name']), false, '', [L10n::t('No'), L10n::t('Yes')]],
+               '$add_note'      => L10n::t('Add a personal note:'),
+               '$page_desc'     => '',
+               '$friendica'     => '',
+               '$statusnet'     => '',
+               '$diaspora'      => '',
+               '$diasnote'      => '',
+               '$your_address'  => L10n::t('Your Identity Address:'),
+               '$invite_desc'   => '',
+               '$emailnet'      => '',
+               '$submit'        => $submit,
+               '$cancel'        => L10n::t('Cancel'),
+               '$nickname'      => '',
+               '$name'          => $ret['name'],
+               '$url'           => $ret['url'],
+               '$zrl'           => Profile::zrl($ret['url']),
+               '$url_label'     => L10n::t('Profile URL'),
+               '$myaddr'        => $myaddr,
+               '$request'       => $request,
+               /*'$location'      => Friendica\Content\Text\BBCode::::convert($r[0]['location']),
+               '$location_label'=> L10n::t('Location:'),
+               '$about'         => Friendica\Content\Text\BBCode::::convert($r[0]['about'], false, false),
+               '$about_label'   => L10n::t('About:'),*/
+               '$keywords'      => $r[0]['keywords'],
+               '$keywords_label'=> L10n::t('Tags:')
        ]);
 
-       $a->page['aside'] = "";
+       $a->page['aside'] = '';
 
-       Profile::load($a, "", 0, Contact::getDetailsByURL($ret["url"]), false);
+       $profiledata = Contact::getDetailsByURL($ret['url']);
+       if ($profiledata) {
+               Profile::load($a, '', 0, $profiledata, false);
+       }
 
        if ($gcontact_id <> 0) {
                $o .= replace_macros(get_markup_template('section_title.tpl'),
@@ -184,7 +187,7 @@ function follow_content(App $a) {
                );
 
                // Show last public posts
-               $o .= Contact::getPostsFromUrl($ret["url"]);
+               $o .= Contact::getPostsFromUrl($ret['url']);
        }
 
        return $o;
index bec09e2d07978c870ea391e02bec983550a85f45..8bb09aa6dd76d52379fcc7b9f723b1df17ba93ab 100644 (file)
@@ -14,6 +14,7 @@ use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
+use Friendica\Model\Contact;
 use Friendica\Model\GContact;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
index 7d1c429765337e48d374f07c223eff9c18e7d0ed..5b0aa2cff60d196a169dbd71acce2e9334f8f300 100644 (file)
@@ -1292,13 +1292,17 @@ class BBCode extends BaseObject
 
        private static function textHighlightCallback($match)
        {
+               // Fallback in case the language doesn't exist
+               $return = '[code]' . $match[2] . '[/code]';
+
                if (in_array(strtolower($match[1]),
                                ['php', 'css', 'mysql', 'sql', 'abap', 'diff', 'html', 'perl', 'ruby',
-                               'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh'])
+                               'vbscript', 'avrc', 'dtd', 'java', 'xml', 'cpp', 'python', 'javascript', 'js', 'sh', 'bash'])
                ) {
-                       return text_highlight($match[2], strtolower($match[1]));
+                       $return = text_highlight($match[2], strtolower($match[1]));
                }
-               return $match[0];
+
+               return $return;
        }
 
        /**
index eb6e08057aa24ac94374dcccea321d55b1f17fd1..a1143ae1d975a0ef004725d0c409d6d0dfcdd95f 100644 (file)
@@ -22,6 +22,7 @@ class Console extends \Asika\SimpleConsole\Console
                'globalcommunityblock'   => __NAMESPACE__ . '\Console\GlobalCommunityBlock',
                'globalcommunitysilence' => __NAMESPACE__ . '\Console\GlobalCommunitySilence',
                'maintenance'            => __NAMESPACE__ . '\Console\Maintenance',
+               'newpassword'            => __NAMESPACE__ . '\Console\NewPassword',
                'php2po'                 => __NAMESPACE__ . '\Console\PhpToPo',
                'po2php'                 => __NAMESPACE__ . '\Console\PoToPhp',
                'typo'                   => __NAMESPACE__ . '\Console\Typo',
@@ -42,6 +43,7 @@ Commands:
        globalcommunitysilence Silence remote profile from global community page
        help                   Show help about a command, e.g (bin/console help config)
        maintenance            Set maintenance mode for this node
+       newpassword            Set a new password for a given user
        php2po                 Generate a messages.po file from a strings.php file
        po2php                 Generate a strings.php file from a messages.po file
        typo                   Checks for parse errors in Friendica files
diff --git a/src/Core/Console/NewPassword.php b/src/Core/Console/NewPassword.php
new file mode 100644 (file)
index 0000000..d44286d
--- /dev/null
@@ -0,0 +1,89 @@
+<?php
+
+namespace Friendica\Core\Console;
+
+use Friendica\Core\L10n;
+use Friendica\Model\Contact;
+use Friendica\Model\User;
+use Friendica\Core\Config;
+use Friendica\Database\DBM;
+use dba;
+
+/**
+ * @brief tool to set a new password for a user
+ *
+ * With this tool, you can set a new password for a user
+ *
+ * License: AGPLv3 or later, same as Friendica
+ *
+ * @author Michael Vogel <heluecht@pirati.ca>
+ */
+class NewPassword extends \Asika\SimpleConsole\Console
+{
+       protected $helpOptions = ['h', 'help', '?'];
+
+       protected function getHelp()
+       {
+               $help = <<<HELP
+console newpassword - Creates a new password for a given user
+Usage
+       bin/console newpassword <nickname> <password> [-h|--help|-?] [-v]
+
+Description
+       Creates a new password for a user without using the "forgot password" functionality.
+
+Options
+    -h|--help|-? Show help information
+    -v           Show more debug information.
+HELP;
+               return $help;
+       }
+
+       protected function doExecute()
+       {
+               $a = get_app();
+
+               if ($this->getOption('v')) {
+                       $this->out('Class: ' . __CLASS__);
+                       $this->out('Arguments: ' . var_export($this->args, true));
+                       $this->out('Options: ' . var_export($this->options, true));
+               }
+
+               if (count($this->args) == 0) {
+                       $this->out($this->getHelp());
+                       return 0;
+               }
+
+               if (count($this->args) > 2) {
+                       throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
+               }
+
+               require_once '.htconfig.php';
+               $result = \dba::connect($db_host, $db_user, $db_pass, $db_data);
+               unset($db_host, $db_user, $db_pass, $db_data);
+
+               if (!$result) {
+                       throw new \RuntimeException('Unable to connect to database');
+               }
+
+               $nick = $this->getArgument(0);
+               $password = $this->getArgument(1);
+
+               $user = dba::selectFirst('user', ['uid'], ['nickname' => $nick]);
+               if (!DBM::is_result($user)) {
+                       throw new \RuntimeException(L10n::t('User not found'));
+               }
+
+               if (!Config::get('system', 'disable_password_exposed', false) && User::isPasswordExposed($password)) {
+                       throw new \RuntimeException(L10n::t('The new password has been exposed in a public data dump, please choose another.'));
+               }
+
+               if (!User::updatePassword($user['uid'], $password)) {
+                       throw new \RuntimeException(L10n::t('Password update failed. Please try again.'));
+               }
+
+               $this->out(L10n::t('Password changed.'));
+
+               return 0;
+       }
+}