moodleにおいた動画をダウンロード禁止にしたい

moodleにおいた動画をダウンロード禁止にしたい

- よしの きたば の投稿
返信数: 6

お世話になっております。

moodleの学習コンテンツとして掲載した動画を、ダウンロードしにくくする方法を探しています。

以下のURLにて

”「安易には」ダウンロードできないように,マウスの右クリック操作を無効にしています”

との記載があります。

https://home.hirosaki-u.ac.jp/on-line/86/


どうすればこの機能を実装できるのか、教えていただけないでしょうか。


お手数をおかけいたします。

よろしくお願いいたします。


Moodleバージョン:

Moodle 3.7.2+ (Build: 20191022)

よしの きたば への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

以下の設定ではいかがでしょうか。

  1. Moodleにサイト管理者として入る。
  2. 「管理 > サイト管理 > アピアランス > 追加HTML」ページに移動する。
  3. 「BODYタグが開かれた時 additionalhtmltopofbody」テキストエリアに右クリック禁止用JavaScript※1を入力する。
  4. 「変更を保存する」ボタンをクリックする。

※1 右クリック禁止用JavaScript
<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("alert(message);return false")

// -->
</script>

参考資料:
[Moodle in English: Re: Disabling right-click]
https://moodle.org/mod/forum/discuss.php?d=260369#p1129544

[Dynamic Drive DHTML Scripts- Disable right mouse click script -  Dynamic Drive]
http://www.dynamicdrive.com/dynamicindex9/noright.htm

評点平均: お役立ち度: ★★★★★★★ (2)
Mitsuhiro Yoshida への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- よしの きたば の投稿
Mitsuhiro Yoshida様

ご回答くださり、ありがとうございます。
ご案内いただいた方法で実装したところ、右クリックが禁止されたことを確認いたしました。
ありがとうございます。

追加で質問させていただきたいのですが、
この設定方法の場合、moodleにのせた動画すべてに「右クリック禁止」が適応されると思うのですが、
「この動画は右クリックしてよし」
「この動画は右クリックを禁止」
のように、個別に設定することはできるのでしょうか。
よしの きたば への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

何らかの設定を追加して動画をアップロードする際に「追加HTML」を読み込まないようにするためのプログラム修正が必要だと思います。具体的には lib/outputrenderers.php の740行目あたりを修正することになると思います。

    /**
     * The standard tags (typically skip links) that should be output just inside
     * the start of the <body> tag. Designed to be called in theme layout.php files.
     *
     * @return string HTML fragment.
     */
    public function standard_top_of_body_html() {
        global $CFG;
        $output = $this->page->requires->get_top_of_body_code($this);
        if ($this->page->pagelayout !== 'embedded' && !empty($CFG->additionalhtmltopofbody)) {
            $output .= "\n".$CFG->additionalhtmltopofbody;
        }

        // Give subsystems an opportunity to inject extra html content. The callback
        // must always return a string containing valid html.
        foreach (\core_component::get_core_subsystems() as $name => $path) {
            if ($path) {
                $output .= component_callback($name, 'before_standard_top_of_body_html', [], '');
            }
        }

        // Give plugins an opportunity to inject extra html content. The callback
        // must always return a string containing valid html.
        $pluginswithfunction = get_plugins_with_function('before_standard_top_of_body_html', 'lib.php');
        foreach ($pluginswithfunction as $plugins) {
            foreach ($plugins as $function) {
                $output .= $function();
            }
        }

        $output .= $this->maintenance_warning();

        return $output;
    }

ウェブブラウザでHTML (ソースコード) を表示して直接動画ファイルにアクセスできるかと思いますが、右クリック禁止用JavaScript以外の別の方法をお考えになってはいかがでしょうか。

Mitsuhiro Yoshida への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- よしの きたば の投稿
Mitsuhiro Yoshida様

ご回答ありがとうございます。
直接修正が必要になる点、承知しました。

追加での質問をお許しください。

「右クリック禁止用JavaScript」を、
ブラウザの管理画面からでなく、直接moodleサーバのファイルを編集して入力する場合、
どのファイルの、何行目に記載するのが適切でしょうか。

お手数をおかけいたします。
よろしくお願いいたします。
よしの きたば への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- Mitsuhiro Yoshida の投稿
画像 Developers 画像 Particularly helpful Moodlers 画像 Translators

PHPコードの中にJavaScriptを記述するのですね。
以下のプログラム修正ではいかがでしょうか。

修正対象プログラム:
lib/outputrenderers.php

修正箇所:
748行目

[ 修正前 ]
    public function standard_top_of_body_html() {
        global $CFG;
        $output = $this->page->requires->get_top_of_body_code($this);

[ 修正後 ]
    public function standard_top_of_body_html() {
        global $CFG;

        $CFG->additionalhtmltopofbody = htmlspecialchars_decode("
        &lt;script language=JavaScript&gt;
        &lt;!--
        var message=\"Function Disabled!\";

        function clickIE4(){
          if (event.button==2){
              alert(message);
              return false;
          }
        }

        function clickNS4(e){
          if (document.layers||document.getElementById&&!document.all){
            if (e.which==2||e.which==3){
                alert(message);
                return false;
            }
          }
        }

        if (document.layers){
          document.captureEvents(Event.MOUSEDOWN);
          document.onmousedown=clickNS4;
        }
        else if (document.all&&!document.getElementById){
          document.onmousedown=clickIE4;
        }

        document.oncontextmenu=new Function(\"alert(message);return false\")

        // --&gt;
        &lt;/script&gt;");

        $output = $this->page->requires->get_top_of_body_code($this);
評点平均: お役立ち度: ★★★★★★★ (1)
Mitsuhiro Yoshida への返信

Re: moodleにおいた動画をダウンロード禁止にしたい

- よしの きたば の投稿
Mitsuhiro Yoshida様

ご回答くださりありがとうございます。
教えてくださった内容で、ファイルを直接編集し、右クリック禁止を設定することができました。

非常に助かりました。
ありがとうございました。